diff --git a/plugin.yml b/plugin.yml index 4679bdc..21df613 100644 --- a/plugin.yml +++ b/plugin.yml @@ -86,4 +86,9 @@ commands: description: This is Lastquit command. usage: / default: op - permission: gigantic.lastquit \ No newline at end of file + permission: gigantic.lastquit + halfguard: + description: This is HalfGuard command. + usage: / + default: op + permission: gigantic.halfguard \ No newline at end of file diff --git a/src/com/github/unchama/command/CommandType.java b/src/com/github/unchama/command/CommandType.java index f7d13bd..251aa2c 100644 --- a/src/com/github/unchama/command/CommandType.java +++ b/src/com/github/unchama/command/CommandType.java @@ -1,20 +1,8 @@ package com.github.unchama.command; +import com.github.unchama.command.commands.*; import org.bukkit.command.TabExecutor; -import com.github.unchama.command.commands.AchieveCommand; -import com.github.unchama.command.commands.DebugCommand; -import com.github.unchama.command.commands.EnchantmentCommand; -import com.github.unchama.command.commands.FlyCommand; -import com.github.unchama.command.commands.GachaCommand; -import com.github.unchama.command.commands.GrowthCommand; -import com.github.unchama.command.commands.HomeCommand; -import com.github.unchama.command.commands.LastquitCommand; -import com.github.unchama.command.commands.ListenCommand; -import com.github.unchama.command.commands.MineBoostCommand; -import com.github.unchama.command.commands.PresentBoxCommand; -import com.github.unchama.command.commands.StickCommand; -import com.github.unchama.command.commands.TakeoverCommand; /** * @author tar0ss * @@ -33,6 +21,7 @@ public enum CommandType { TAKEOVER(new TakeoverCommand()), LASTQUIT(new LastquitCommand()), ACHIEVE(new AchieveCommand()), + HALFGUARD(new HalfBlockProtectCommand()), ; diff --git a/src/com/github/unchama/command/commands/HalfBlockProtectCommand.java b/src/com/github/unchama/command/commands/HalfBlockProtectCommand.java new file mode 100644 index 0000000..4d1f7d6 --- /dev/null +++ b/src/com/github/unchama/command/commands/HalfBlockProtectCommand.java @@ -0,0 +1,58 @@ +package com.github.unchama.command.commands; + + +import com.github.unchama.gigantic.PlayerManager; +import com.github.unchama.player.GiganticPlayer; +import com.github.unchama.player.protect.HalfBlockProtectData; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * Y5ハーフブロック破壊可能フラグ変更コマンド + * 権限を有する人のみ使用可能 + * + * @author karayuu + */ +public class HalfBlockProtectCommand implements TabExecutor { + + @Override + public List onTabComplete(CommandSender arg0, Command arg1, String arg2, String[] arg3) { + return null; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + //プレイヤーからの送信ではない時終了 + if(!(commandSender instanceof Player)){ + commandSender.sendMessage(ChatColor.RED + "このコマンドはゲーム内から実行してください."); + return false; + } + + if (strings.length == 0) { + // /halfguard 実行時 + GiganticPlayer gp = PlayerManager.getGiganticPlayer((Player) commandSender); + if (gp == null) { + throw new NullPointerException("/HalfGuardコマンドData取得処理でnull.開発者に報告してください."); + } + HalfBlockProtectData data= gp.getManager(HalfBlockProtectData.class); + + data.toggleHalfBreakFlag(); + commandSender.sendMessage("現在ハーフブロックは" + getStats(data.canBreakHalfBlock()) + ChatColor.RESET + "です."); + return true; + } + return false; + } + + private String getStats (Boolean canBreak) { + if (canBreak) { + return ChatColor.GREEN + "破壊可能"; + } else { + return ChatColor.RED + "破壊不可能"; + } + } +} diff --git a/src/com/github/unchama/enchantment/EnchantmentEnum.java b/src/com/github/unchama/enchantment/EnchantmentEnum.java index edbbcc5..14b5d1e 100644 --- a/src/com/github/unchama/enchantment/EnchantmentEnum.java +++ b/src/com/github/unchama/enchantment/EnchantmentEnum.java @@ -12,6 +12,20 @@ public enum EnchantmentEnum { //コメントアウトは保留案件 + + //II + CHOBA("跳馬", new ChobaEnchantment(), MaterialUtil.getHelmets()), + TOSSHIN("突進", new TosshinEnchantment(), MaterialUtil.getHelmets()), + FUROFUSHI("不老不死", new FuroFushiEnchantment(), MaterialUtil.getLeggings()), + KOTUEI("骨影", new KotueiEnchantment(), MaterialUtil.getPickaxes()), + YUWAKU("誘惑", new YuwakuEnchantment(), MaterialUtil.getSwords()), + HANGEKI("反撃", new HangekiEnchantment(), Material.BOW), + ITAZURA("悪戯", new ItazuraEnchantment(), MaterialUtil.getAxes()), + //NIDANJUMP("二段ジャンプ", new NidanJumpEnchantment(), MaterialUtil.getBoots()), + SYUNPO("瞬歩", new SyunpoEnchantment(), MaterialUtil.getShovels()), + ANTIKNOWKBACK("ノックバック耐性", new AntiKnockbackEnchantment(), MaterialUtil.getBoots()), + + //III HAHUU("覇風", new HahuuEnchantment(), MaterialUtil.getPickaxes(), 1), //DENSEN("伝染", new DensenEnchantment(), MaterialUtil.getAxes()), HYOKA("氷華", new HyokaEnchantment(), MaterialUtil.getShovels(), 1), diff --git a/src/com/github/unchama/enchantment/enchantments/AntiKnockbackEnchantment.java b/src/com/github/unchama/enchantment/enchantments/AntiKnockbackEnchantment.java new file mode 100644 index 0000000..5f5032b --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/AntiKnockbackEnchantment.java @@ -0,0 +1,27 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import com.github.unchama.event.PlayerDamageWithArmorEvent; +import com.github.unchama.gigantic.Gigantic; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +/** + * @author Mon_chi + */ +public class AntiKnockbackEnchantment implements GiganticEnchantment { + + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof PlayerDamageWithArmorEvent) { + System.out.println(player.getName()); + player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_PLACE, 3, 3); + Bukkit.getScheduler().runTaskLater(Gigantic.plugin, () -> player.setVelocity(new Vector(0, 0, 0)), 1L); + } + return false; + } +} diff --git a/src/com/github/unchama/enchantment/enchantments/ChobaEnchantment.java b/src/com/github/unchama/enchantment/enchantments/ChobaEnchantment.java new file mode 100644 index 0000000..a787e10 --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/ChobaEnchantment.java @@ -0,0 +1,44 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import com.github.unchama.event.PlayerDamageWithArmorEvent; +import com.github.unchama.event.SecondEvent; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +/** + * @author Mon_chi + */ +public class ChobaEnchantment implements GiganticEnchantment { + + private int countFlag; + + public ChobaEnchantment() { + this.countFlag = 0; + } + + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof SecondEvent) { + if (countFlag < 2) { + this.countFlag += 1; + } + else { + this.countFlag = 0; + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * 5, 2)); + player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20 * 5, 2)); + } + } + else if (event instanceof PlayerDamageWithArmorEvent) { + EntityDamageEvent e = ((PlayerDamageWithArmorEvent) event).getOriginEvent(); + if (e.getCause() == EntityDamageEvent.DamageCause.FALL) { + e.setDamage(e.getDamage() * 0.5); + } + } + return false; + } +} diff --git a/src/com/github/unchama/enchantment/enchantments/FuroFushiEnchantment.java b/src/com/github/unchama/enchantment/enchantments/FuroFushiEnchantment.java new file mode 100644 index 0000000..88c644a --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/FuroFushiEnchantment.java @@ -0,0 +1,23 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.inventory.ItemStack; + +/** + * @author Mon_chi + */ +public class FuroFushiEnchantment implements GiganticEnchantment { + + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof FoodLevelChangeEvent) { + if (((FoodLevelChangeEvent) event).getFoodLevel() < 7) { + ((FoodLevelChangeEvent) event).setFoodLevel(7); + } + } + return false; + } +} diff --git a/src/com/github/unchama/enchantment/enchantments/HahuuEnchantment.java b/src/com/github/unchama/enchantment/enchantments/HahuuEnchantment.java index 0d46ee4..38be0df 100644 --- a/src/com/github/unchama/enchantment/enchantments/HahuuEnchantment.java +++ b/src/com/github/unchama/enchantment/enchantments/HahuuEnchantment.java @@ -2,6 +2,7 @@ import com.github.unchama.enchantment.GiganticEnchantment; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -21,10 +22,10 @@ public boolean onEvent(Event event, Player player, ItemStack item, int level) { if (entity instanceof LivingEntity) { LivingEntity livingEntity = ((LivingEntity) entity); livingEntity.damage(6, player); - if (!livingEntity.isDead()) { + if (livingEntity.getType() != EntityType.PLAYER && !livingEntity.isDead()) { Vector direction = entity.getLocation().getDirection().normalize().multiply(3); direction.setX(-direction.getX()).setY(-direction.getY()).setZ(-direction.getZ()); - entity.setVelocity(direction); + entity.setVelocity(direction.add(entity.getVelocity())); } } } diff --git a/src/com/github/unchama/enchantment/enchantments/HangekiEnchantment.java b/src/com/github/unchama/enchantment/enchantments/HangekiEnchantment.java new file mode 100644 index 0000000..47c4265 --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/HangekiEnchantment.java @@ -0,0 +1,27 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +/** + * @author Mon_chi + */ +public class HangekiEnchantment implements GiganticEnchantment { + + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof EntityDamageByEntityEvent) { + EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; + if (e.getEntity() == player && e.getDamager() != player) { + Vector direction = e.getDamager().getLocation().getDirection().normalize().multiply(10); + direction.setX(-direction.getX()).setY(-direction.getY()).setZ(-direction.getZ()); + e.getDamager().setVelocity(direction.add(e.getDamager().getVelocity())); + } + } + return false; + } +} diff --git a/src/com/github/unchama/enchantment/enchantments/HyokaEnchantment.java b/src/com/github/unchama/enchantment/enchantments/HyokaEnchantment.java index a3c966a..a7201d6 100644 --- a/src/com/github/unchama/enchantment/enchantments/HyokaEnchantment.java +++ b/src/com/github/unchama/enchantment/enchantments/HyokaEnchantment.java @@ -24,7 +24,7 @@ public boolean onEvent(Event event, Player player, ItemStack item, int level) { LivingEntity livingEntity = (LivingEntity) entity; livingEntity.damage(6, player); if (!livingEntity.isDead()) - livingEntity.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20 * 10, 1)); + livingEntity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20 * 10, 255)); } } } diff --git a/src/com/github/unchama/enchantment/enchantments/ItazuraEnchantment.java b/src/com/github/unchama/enchantment/enchantments/ItazuraEnchantment.java new file mode 100644 index 0000000..187d054 --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/ItazuraEnchantment.java @@ -0,0 +1,28 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.inventory.ItemStack; + +/** + * @author Mon_chi + */ +public class ItazuraEnchantment implements GiganticEnchantment { + + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof EntityDamageByEntityEvent) { + EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; + if (e.getDamager() == player && e.getEntity() instanceof LivingEntity && e.getEntityType() != EntityType.CHICKEN) { + e.getEntity().remove(); + e.getEntity().getWorld().spawnEntity(e.getEntity().getLocation(), EntityType.CHICKEN); + return true; + } + } + return false; + } +} diff --git a/src/com/github/unchama/enchantment/enchantments/KotueiEnchantment.java b/src/com/github/unchama/enchantment/enchantments/KotueiEnchantment.java new file mode 100644 index 0000000..dbd12cb --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/KotueiEnchantment.java @@ -0,0 +1,30 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import com.github.unchama.util.Util; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +/** + * @author Mon_chi + */ +public class KotueiEnchantment implements GiganticEnchantment { + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof BlockBreakEvent) { + for (Entity entity : player.getNearbyEntities(20, 20, 20)) { + if (entity.getType() == EntityType.SKELETON && !entity.isDead()) { + ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 4)); + } + } + } + return false; + } +} diff --git a/src/com/github/unchama/enchantment/enchantments/RaiteiEnchantment.java b/src/com/github/unchama/enchantment/enchantments/RaiteiEnchantment.java index 7015a6f..bb5e708 100644 --- a/src/com/github/unchama/enchantment/enchantments/RaiteiEnchantment.java +++ b/src/com/github/unchama/enchantment/enchantments/RaiteiEnchantment.java @@ -6,6 +6,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; @@ -19,21 +20,23 @@ public class RaiteiEnchantment implements GiganticEnchantment { @Override public boolean onEvent(Event event, Player player, ItemStack item, int level) { if (event instanceof PlayerDamageWithArmorEvent) { - PlayerDamageWithArmorEvent e = (PlayerDamageWithArmorEvent) event; - if (e.getOriginEvent().getDamager() instanceof LivingEntity) { - LivingEntity damager = (LivingEntity) e.getOriginEvent().getDamager(); - damager.damage(12, player); - List entitiesAroundDamager = damager.getNearbyEntities(10, 10, 10); - List damagedEntities = new ArrayList<>(); - for (Entity entity : entitiesAroundDamager) { - if (entity instanceof LivingEntity) { - LivingEntity livingEntity = (LivingEntity) entity; - livingEntity.damage(8, player); - damagedEntities.add(livingEntity.getEntityId()); - for (Entity nestedEntity: livingEntity.getNearbyEntities(10, 10, 10)) { - if (!entitiesAroundDamager.contains(nestedEntity) && !damagedEntities.contains(nestedEntity.getEntityId())) { - livingEntity.damage(4, player); - damagedEntities.add(nestedEntity.getEntityId()); + if (((PlayerDamageWithArmorEvent) event).getOriginEvent() instanceof EntityDamageByEntityEvent) { + EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) ((PlayerDamageWithArmorEvent) event).getOriginEvent(); + if (e.getDamager() instanceof LivingEntity) { + LivingEntity damager = (LivingEntity) e.getDamager(); + damager.damage(12, player); + List entitiesAroundDamager = damager.getNearbyEntities(10, 10, 10); + List damagedEntities = new ArrayList<>(); + for (Entity entity : entitiesAroundDamager) { + if (entity instanceof LivingEntity) { + LivingEntity livingEntity = (LivingEntity) entity; + livingEntity.damage(8, player); + damagedEntities.add(livingEntity.getEntityId()); + for (Entity nestedEntity : livingEntity.getNearbyEntities(10, 10, 10)) { + if (!entitiesAroundDamager.contains(nestedEntity) && !damagedEntities.contains(nestedEntity.getEntityId())) { + livingEntity.damage(4, player); + damagedEntities.add(nestedEntity.getEntityId()); + } } } } diff --git a/src/com/github/unchama/enchantment/enchantments/SyunpoEnchantment.java b/src/com/github/unchama/enchantment/enchantments/SyunpoEnchantment.java new file mode 100644 index 0000000..c85af46 --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/SyunpoEnchantment.java @@ -0,0 +1,20 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +/** + * @author Mon_chi + */ +public class SyunpoEnchantment implements GiganticEnchantment { + + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof PlayerInteractEvent) { + } + return false; + } +} diff --git a/src/com/github/unchama/enchantment/enchantments/TosshinEnchantment.java b/src/com/github/unchama/enchantment/enchantments/TosshinEnchantment.java new file mode 100644 index 0000000..42ad7bf --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/TosshinEnchantment.java @@ -0,0 +1,25 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.inventory.ItemStack; + +/** + * @author Mon_chi + */ +public class TosshinEnchantment implements GiganticEnchantment { + + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof EntityDamageByEntityEvent) { + EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; + if (e.isApplicable(EntityDamageEvent.DamageModifier.HARD_HAT)) { + e.setDamage(e.getDamage() * 1.3); + } + } + return false; + } +} diff --git a/src/com/github/unchama/enchantment/enchantments/YuwakuEnchantment.java b/src/com/github/unchama/enchantment/enchantments/YuwakuEnchantment.java new file mode 100644 index 0000000..8f37148 --- /dev/null +++ b/src/com/github/unchama/enchantment/enchantments/YuwakuEnchantment.java @@ -0,0 +1,25 @@ +package com.github.unchama.enchantment.enchantments; + +import com.github.unchama.enchantment.GiganticEnchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.bukkit.inventory.ItemStack; + +/** + * @author Mon_chi + */ +public class YuwakuEnchantment implements GiganticEnchantment { + + @Override + public boolean onEvent(Event event, Player player, ItemStack item, int level) { + if (event instanceof EntityTargetLivingEntityEvent) { + EntityTargetLivingEntityEvent e = (EntityTargetLivingEntityEvent) event; + if (e.getReason() == EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY) { + return true; + } + } + return false; + } +} diff --git a/src/com/github/unchama/event/PlayerDamageWithArmorEvent.java b/src/com/github/unchama/event/PlayerDamageWithArmorEvent.java index 45a8c2c..78a9de9 100644 --- a/src/com/github/unchama/event/PlayerDamageWithArmorEvent.java +++ b/src/com/github/unchama/event/PlayerDamageWithArmorEvent.java @@ -2,7 +2,7 @@ import com.github.unchama.event.moduler.CustomEvent; import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; /** @@ -10,19 +10,19 @@ */ public class PlayerDamageWithArmorEvent extends CustomEvent { - private EntityDamageByEntityEvent originEvent; + private EntityDamageEvent originEvent; private Player player; private ItemStack item; private ArmorType armorType; - public PlayerDamageWithArmorEvent(EntityDamageByEntityEvent originEvent, Player player, ItemStack item, ArmorType armorType) { + public PlayerDamageWithArmorEvent(EntityDamageEvent originEvent, Player player, ItemStack item, ArmorType armorType) { this.originEvent = originEvent; this.player = player; this.item = item; this.armorType = armorType; } - public EntityDamageByEntityEvent getOriginEvent() { + public EntityDamageEvent getOriginEvent() { return originEvent; } diff --git a/src/com/github/unchama/growthtool/GrowthTool.java b/src/com/github/unchama/growthtool/GrowthTool.java index d3b06f1..3d26b70 100644 --- a/src/com/github/unchama/growthtool/GrowthTool.java +++ b/src/com/github/unchama/growthtool/GrowthTool.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Random; +import com.github.unchama.event.GiganticInteractEvent; import org.apache.commons.lang3.StringUtils; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -175,6 +176,9 @@ public static void onEvent(Event event) { } else if (event instanceof BlockBreakEvent) { player.add(((BlockBreakEvent) event).getPlayer()); dropChance(((BlockBreakEvent) event).getPlayer()); + } else if (event instanceof GiganticInteractEvent) { + player.add(((GiganticInteractEvent) event).getPlayer()); + dropChance(((GiganticInteractEvent) event).getPlayer()); } else if (event instanceof EntityDamageByEntityEvent) { if (((EntityDamageByEntityEvent) event).getEntity() instanceof Player) { player.add((Player) ((EntityDamageByEntityEvent) event).getEntity()); diff --git a/src/com/github/unchama/growthtool/moduler/GrowthToolManager.java b/src/com/github/unchama/growthtool/moduler/GrowthToolManager.java index f7f3189..d706ef1 100644 --- a/src/com/github/unchama/growthtool/moduler/GrowthToolManager.java +++ b/src/com/github/unchama/growthtool/moduler/GrowthToolManager.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.Map; +import com.github.unchama.event.GiganticInteractEvent; import de.tr7zw.itemnbtapi.NBTItem; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -352,6 +353,11 @@ public String getMessage(Event event, Player player) { setTool(player, tool); } ret = onBlockBreakMsg.talk(tool, player, null); + } else if (event instanceof GiganticInteractEvent) { + if (tool.addExp(player)) { + setTool(player, tool); + } + ret = onBlockBreakMsg.talk(tool, player, null); } else if (event instanceof EntityDamageByEntityEvent) { if (tool.isWarn()) { // 破損警告時メッセージ(強制) diff --git a/src/com/github/unchama/growthtool/moduler/message/GrwMessage.java b/src/com/github/unchama/growthtool/moduler/message/GrwMessage.java index 959a7e2..a7e6eae 100644 --- a/src/com/github/unchama/growthtool/moduler/message/GrwMessage.java +++ b/src/com/github/unchama/growthtool/moduler/message/GrwMessage.java @@ -53,7 +53,7 @@ public String talk(GrwTool grwtool, Player player, Entity entity) { String message = getRandom(); // PlayerNameタグの置換 if (player != null) { - message = GrwTag.PlayerName.replace(message, getNotEmpty(grwtool.getCall(), player.getDisplayName())); + message = GrwTag.PlayerName.replace(message, getNotEmpty(grwtool.getCall(), player.getName())); } // MonsterNameタグの置換 if (entity != null && (entity instanceof Monster || entity instanceof CraftSlime)) { diff --git a/src/com/github/unchama/growthtool/moduler/tool/GrwTool.java b/src/com/github/unchama/growthtool/moduler/tool/GrwTool.java index 1f953bd..c122c16 100644 --- a/src/com/github/unchama/growthtool/moduler/tool/GrwTool.java +++ b/src/com/github/unchama/growthtool/moduler/tool/GrwTool.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.UUID; +import com.github.unchama.gigantic.PlayerManager; import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.enchantments.Enchantment; @@ -89,7 +90,7 @@ public GrwTool(Player player, String itemname, List identLore, GrwStatus identify = identLore; itemlv = 1; enchantTable = enchants; - owner = player.getDisplayName(); + owner = player.getName(); this.status = status; playerName = ""; playerUuid = player.getUniqueId(); @@ -121,15 +122,8 @@ public GrwTool(ItemStack tool, List identLore, GrwStatus status, GrwEnch } name = itemmeta.hasDisplayName() ? itemmeta.getDisplayName() : ""; identify = Collections.unmodifiableList(identLore); - itemlv = getNBT(GrwNbti.ItemLv, Integer.class); - enchantTable = enchants; - owner = getNBT(GrwNbti.PlayerMcid, String.class); - this.status = status; - playerName = getNBT(GrwNbti.PlayerName, String.class); - playerUuid = getNBT(GrwNbti.PlayerUuid, UUID.class); - currentExp = getNBT(GrwNbti.CurrentExp, Integer.class); - // [移行用] アイテムレベルがNBTに登録されていない場合は取得する - if (itemlv < 1) { + if (!hasNBT(GrwNbti.ItemLv)) { + // [移行用] アイテムレベルがNBTに登録されていない場合は取得する itemlv = 1; for (String s : itemlore) { if (s.startsWith(GrwDefine.ILHEAD)) { @@ -145,9 +139,12 @@ public GrwTool(ItemStack tool, List identLore, GrwStatus status, GrwEnch break; } } + } else { + itemlv = getNBT(GrwNbti.ItemLv, Integer.class); } + enchantTable = enchants; // [移行用] 所有者がNBTに登録されていない場合は取得する - if (owner.isEmpty()) { + if (!hasNBT(GrwNbti.PlayerMcid)) { for (String s : itemlore) { if (s.startsWith(GrwDefine.OWNERHEAD)) { owner = s.replace(GrwDefine.OWNERHEAD, ""); @@ -158,6 +155,22 @@ public GrwTool(ItemStack tool, List identLore, GrwStatus status, GrwEnch GrowthTool.GrwDebugWarning("ownerがemptyのためunchamaとして扱います。"); owner = "unchama"; } + } else { + owner = getNBT(GrwNbti.PlayerMcid, String.class); + } + this.status = status; + playerName = getNBT(GrwNbti.PlayerName, String.class); + if (!hasNBT(GrwNbti.PlayerUuid)) { + //[移行用] + playerUuid = PlayerManager.getUUID(owner); + } else { + playerUuid = getNBT(GrwNbti.PlayerUuid, UUID.class); + } + if (!hasNBT(GrwNbti.CurrentExp)) { + //[移行用] + currentExp = 0; + } else { + currentExp = getNBT(GrwNbti.CurrentExp, Integer.class); } } catch (NullPointerException e) { GrowthTool.GrwDebugWarning("ItemStackコンストラクタにGrowth Tool以外が渡されました。"); @@ -237,6 +250,17 @@ private T getNBT(GrwNbti tag, Class type) { return nbti.getObject(tag.toString(), type); } + /** + * NBTが存在するか確認する + * + * @param tag NBTに対応するenum + * @return 成否(true: 存在する / false: 存在しない) + */ + private boolean hasNBT(GrwNbti tag) { + NBTItem nbtItem = new NBTItem(this); + return nbtItem.hasKey(tag.toString()); + } + /** * 経験値加算処理。経験値の加算、及びレベルアップの判定を行う。
* 経験値情報はNBTとLoreに書き込まれるため、アイテムレベル最大時を除きアイテムは更新される。
@@ -349,7 +373,7 @@ public static boolean isOwner(ItemStack item, Player player) { return true; } // [移行用] ItemStackの所有者欄にtoLowerCaseが登録されている場合 - if (itemlore.contains(GrwDefine.OWNERHEAD + player.getDisplayName().toLowerCase())) { + if (itemlore.contains(GrwDefine.OWNERHEAD + player.getName().toLowerCase())) { return true; } return false; diff --git a/src/com/github/unchama/listener/listeners/BlockBreakListener.java b/src/com/github/unchama/listener/listeners/BlockBreakListener.java index 23896ed..70ad06c 100644 --- a/src/com/github/unchama/listener/listeners/BlockBreakListener.java +++ b/src/com/github/unchama/listener/listeners/BlockBreakListener.java @@ -1,10 +1,10 @@ package com.github.unchama.listener.listeners; +import com.github.unchama.player.protect.HalfBlockProtectData; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import net.md_5.bungee.api.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -37,9 +37,11 @@ public class BlockBreakListener implements Listener { ConfigManager config = Gigantic.yml.getManager(ConfigManager.class); DebugManager debug = Gigantic.yml.getManager(DebugManager.class); Zenchantments Ze; + WorldGuardPlugin Wg; public BlockBreakListener() { Ze = Util.getZenchantments(); + Wg = Util.getWorldGuard(); } @EventHandler(priority = EventPriority.LOWEST) @@ -81,6 +83,8 @@ public void Explosion(BlockBreakEvent event) { // トグルがオフなら終了 if (!skill.getToggle()) { debug.sendMessage(player, DebugEnum.SKILL, "スキルのトグルがオフなため発動できません"); + //スキルを使っていない→そのまま加算(GrowthTool) + GrowthTool.onEvent(event); return; } @@ -142,6 +146,8 @@ public void Explosion(BlockBreakEvent event) { if(skill.run(player, tool, block)){ //スキル破壊成功 gp.getManager(SecureBreakManager.class).run(player, tool, block, skill); + //GrowthTool用イベント + GrowthTool.onEvent(event); } } @@ -151,8 +157,72 @@ public void Explosion(BlockBreakEvent event) { * * @param event ブロック破壊Bukkitイベント */ + /* @EventHandler(priority = EventPriority.LOWEST) public void growthToolEvent(BlockBreakEvent event) { GrowthTool.onEvent(event); } + */ + + /** + * y5ハーフブロック破壊抑制 + * + * @param + */ + @EventHandler(priority = EventPriority.HIGHEST) + @SuppressWarnings("deprecation") + public void onBreakHalfBlock(BlockBreakEvent event) { + //プレイヤー・破壊ブロック・ワールドを取得 + Player p = event.getPlayer(); + Block b = event.getBlock(); + World world = p.getWorld(); + GiganticPlayer gp = PlayerManager.getGiganticPlayer(p); + + //整地ワールド名を取得しておく + final String SEICHIWORLDNAME = config.getSeichiWorldName(); + + //自分の保護下でない + if (Wg.canBuild(p, b)) { + return; + } + + if (b.getType().equals(Material.DOUBLE_STEP) && b.getData() == 0) { + //重ねハーフブロックの時下面は残す + b.setType(Material.STEP); + b.setData((byte) 0); + + //ドロップ処理 + Location location = b.getLocation(); + world.dropItemNaturally(location, new ItemStack(Material.STEP)); + } + + //ハーフブロックでない + if (!b.getType().equals(Material.STEP)) { + return; + } + + //Y=5でない + if (b.getY() != 5) { + return; + } + + //ハーフブロックの上面・下面のデータ値 上面:8, 下面:0(下面のみ対象) + if (b.getData() != 0) { + return; + } + + if (!p.getWorld().getName().toLowerCase().startsWith(SEICHIWORLDNAME)) { + //整地系ワールドではないので解除 + return; + } + + if (gp.getManager(HalfBlockProtectData.class).canBreakHalfBlock()) { + //権限保持者なので解除 + return; + } + + //該当するのでキャンセル + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "Y5に敷かれたハーフブロックは破壊不可能です."); + } } diff --git a/src/com/github/unchama/listener/listeners/EnchantmentListener.java b/src/com/github/unchama/listener/listeners/EnchantmentListener.java index a4ccfc7..3c3846b 100644 --- a/src/com/github/unchama/listener/listeners/EnchantmentListener.java +++ b/src/com/github/unchama/listener/listeners/EnchantmentListener.java @@ -17,9 +17,11 @@ import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.inventory.ItemStack; @@ -127,8 +129,19 @@ else if (player.getInventory().getItemInOffHand() != null && player.getInventory } @EventHandler - public void playerDamageWithArmorEvent(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player) && event.getEntity() instanceof Player) { + public void onPlayerAttack(EntityDamageByEntityEvent event) { + if (event.getDamager() instanceof Player) { + Player attacker = (Player) event.getDamager(); + AtomicBoolean result = new AtomicBoolean(false); + result.compareAndSet(false, runEnchantments(event, attacker, attacker.getInventory().getItemInMainHand())); + result.compareAndSet(false, runEnchantments(event, attacker, attacker.getInventory().getHelmet())); + if (result.get()) event.setCancelled(true); + } + } + + @EventHandler + public void playerDamageEvent(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); if (player.getInventory().getHelmet() != null && player.getInventory().getHelmet().getType() != Material.AIR) Bukkit.getPluginManager().callEvent(new PlayerDamageWithArmorEvent(event, player, player.getInventory().getHelmet(), PlayerDamageWithArmorEvent.ArmorType.HELMET)); @@ -138,6 +151,7 @@ public void playerDamageWithArmorEvent(EntityDamageByEntityEvent event) { Bukkit.getPluginManager().callEvent(new PlayerDamageWithArmorEvent(event, player, player.getInventory().getLeggings(), PlayerDamageWithArmorEvent.ArmorType.LEGGINGS)); if (player.getInventory().getBoots() != null && player.getInventory().getBoots().getType() != Material.AIR) Bukkit.getPluginManager().callEvent(new PlayerDamageWithArmorEvent(event, player, player.getInventory().getBoots(), PlayerDamageWithArmorEvent.ArmorType.BOOTS)); + runEnchantments(event, player, player.getInventory().getItemInMainHand()); } } @@ -157,10 +171,37 @@ public void onPlayerDamageWithArmor(PlayerDamageWithArmorEvent event) { @EventHandler public void onSecond(SecondEvent event) { for (Player player : event.getOnlinePlayers()) { + ItemStack helmet = player.getInventory().getHelmet(); + if (helmet != null) + runEnchantments(event, player, helmet); + ItemStack chestPlate = player.getInventory().getChestplate(); - if (chestPlate != null && chestPlate.getType() == Material.ELYTRA) { + if (chestPlate != null) { runEnchantments(event, player, chestPlate); } } } + + @EventHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) { + AtomicBoolean result = new AtomicBoolean(false); + result.compareAndSet(false, runEnchantments(event, (Player)event.getEntity(), event.getEntity().getInventory().getLeggings())); + } + + @EventHandler + public void onEntityTargeted(EntityTargetLivingEntityEvent event) { + if (event.getTarget() instanceof Player) { + Player player = (Player) event.getTarget(); + boolean result = runEnchantments(event, player, player.getInventory().getItemInMainHand()); + if (result) + event.setCancelled(true); + } + } + + @EventHandler + public void onPlayerRightClick(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + runEnchantments(event, event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand()); + } + } } diff --git a/src/com/github/unchama/listener/listeners/GiganticInteractListener.java b/src/com/github/unchama/listener/listeners/GiganticInteractListener.java index bdf42d4..ce69c96 100644 --- a/src/com/github/unchama/listener/listeners/GiganticInteractListener.java +++ b/src/com/github/unchama/listener/listeners/GiganticInteractListener.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.List; +import com.github.unchama.growthtool.GrowthTool; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; @@ -352,6 +353,9 @@ public void MagicDrive(GiganticInteractEvent event) { new MagicDriveTaskRunnable(player, skill, tool, block) .runTaskTimerAsynchronously(plugin, 0, 1); + + //GrowthTool用イベント + GrowthTool.onEvent(event); } /** diff --git a/src/com/github/unchama/player/GiganticPlayer.java b/src/com/github/unchama/player/GiganticPlayer.java index 94f8279..683b29c 100644 --- a/src/com/github/unchama/player/GiganticPlayer.java +++ b/src/com/github/unchama/player/GiganticPlayer.java @@ -4,6 +4,7 @@ import java.util.LinkedHashMap; import java.util.UUID; +import com.github.unchama.player.protect.HalfBlockProtectData; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -118,6 +119,7 @@ public static enum ManagerType { SKILLBREAKBLOCK(SkillBreakBlockManager.class), EXP(ExpManager.class), INVENTORY(InventoryManager.class), + HALFBLOCKPROTECT(HalfBlockProtectData.class), ; private Class managerClass; diff --git a/src/com/github/unchama/player/protect/HalfBlockProtectData.java b/src/com/github/unchama/player/protect/HalfBlockProtectData.java new file mode 100644 index 0000000..295350f --- /dev/null +++ b/src/com/github/unchama/player/protect/HalfBlockProtectData.java @@ -0,0 +1,32 @@ +package com.github.unchama.player.protect; + +import com.github.unchama.player.GiganticPlayer; +import com.github.unchama.player.moduler.DataManager; + +/** + * Y5ハーフブロック破壊可能フラグ保持用 + * 権限を持っている人のみtrueにすることが可能 + * @author karayuu + */ +public class HalfBlockProtectData extends DataManager { + + //フラグ + private boolean halfBreakFlag; + + public HalfBlockProtectData(GiganticPlayer gp) { + super(gp); + halfBreakFlag = false; + } + + public boolean canBreakHalfBlock() { + return halfBreakFlag; + } + + public void toggleHalfBreakFlag() { + if (halfBreakFlag) { + halfBreakFlag = false; + } else { + halfBreakFlag = true; + } + } +} diff --git a/src/com/github/unchama/util/MaterialUtil.java b/src/com/github/unchama/util/MaterialUtil.java index 314b3c6..e492c14 100644 --- a/src/com/github/unchama/util/MaterialUtil.java +++ b/src/com/github/unchama/util/MaterialUtil.java @@ -30,4 +30,8 @@ public static Material[] getHelmets() { public static Material[] getLeggings() { return new Material[]{Material.DIAMOND_LEGGINGS, Material.GOLD_LEGGINGS, Material.IRON_LEGGINGS, Material.GOLD_LEGGINGS, Material.LEATHER_LEGGINGS, Material.CHAINMAIL_LEGGINGS}; } + + public static Material[] getBoots() { + return new Material[]{Material.DIAMOND_BOOTS, Material.GOLD_BOOTS, Material.IRON_BOOTS, Material.GOLD_BOOTS, Material.LEATHER_BOOTS, Material.CHAINMAIL_BOOTS}; + } }