From 4b87b11c9e5707c29c471bed548e4ba86b3758c9 Mon Sep 17 00:00:00 2001 From: Xefir Date: Sun, 20 May 2012 10:44:45 +0200 Subject: [PATCH] Rollback somes changes --- .../co/jacekk/bukkit/bloodmoon/BloodMoon.java | 5 ++ .../bukkit/bloodmoon/BloodMoonConfig.java | 9 +++ .../entities/BloodMoonEntitySkeleton.java | 4 +- .../featurelisteners/SwordDamageListener.java | 73 +++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/uk/co/jacekk/bukkit/bloodmoon/featurelisteners/SwordDamageListener.java diff --git a/src/uk/co/jacekk/bukkit/bloodmoon/BloodMoon.java b/src/uk/co/jacekk/bukkit/bloodmoon/BloodMoon.java index 163b73f..86ff21c 100755 --- a/src/uk/co/jacekk/bukkit/bloodmoon/BloodMoon.java +++ b/src/uk/co/jacekk/bukkit/bloodmoon/BloodMoon.java @@ -25,6 +25,7 @@ import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.MoreSpawningListener; import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SpawnOnKillListener; import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SpawnOnSleepListener; import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SuperCreepersListener; +import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SwordDamageListener; import uk.co.jacekk.bukkit.bloodmoon.listeners.EntityListener; import uk.co.jacekk.bukkit.bloodmoon.listeners.PlayerListener; import uk.co.jacekk.bukkit.bloodmoon.listeners.WorldListener; @@ -130,6 +131,10 @@ public class BloodMoon extends JavaPlugin { // arrow-rate is handled in BloodMoonEntitySkeleton + if (BloodMoon.config.getBoolean("features.sword-damage.enabled")){ + this.manager.registerEvents(new SwordDamageListener(this), this); + } + if (BloodMoon.config.getBoolean("features.lock-in-world.enabled") && BloodMoon.config.getBoolean("always-on") == false){ this.manager.registerEvents(new LockInWorldListener(), this); } diff --git a/src/uk/co/jacekk/bukkit/bloodmoon/BloodMoonConfig.java b/src/uk/co/jacekk/bukkit/bloodmoon/BloodMoonConfig.java index 460cf3e..272b947 100755 --- a/src/uk/co/jacekk/bukkit/bloodmoon/BloodMoonConfig.java +++ b/src/uk/co/jacekk/bukkit/bloodmoon/BloodMoonConfig.java @@ -44,6 +44,15 @@ public class BloodMoonConfig { this.configDefaults.put("features.more-exp.enabled", true); this.configDefaults.put("features.more-exp.multiplier", 2); + this.configDefaults.put("features.sword-damage.enabled", true); + this.configDefaults.put("features.sword-damage.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); + this.configDefaults.put("features.sword-damage.chance", 10); + this.configDefaults.put("features.sword-damage.damage.diamond", 100); + this.configDefaults.put("features.sword-damage.damage.iron", 20); + this.configDefaults.put("features.sword-damage.damage.gold", 10); + this.configDefaults.put("features.sword-damage.damage.stone", 20); + this.configDefaults.put("features.sword-damage.damage.wood", 10); + this.configDefaults.put("features.super-creepers.enabled", true); this.configDefaults.put("features.super-creepers.power", 4.0D); diff --git a/src/uk/co/jacekk/bukkit/bloodmoon/entities/BloodMoonEntitySkeleton.java b/src/uk/co/jacekk/bukkit/bloodmoon/entities/BloodMoonEntitySkeleton.java index 06cd13d..357e3a5 100755 --- a/src/uk/co/jacekk/bukkit/bloodmoon/entities/BloodMoonEntitySkeleton.java +++ b/src/uk/co/jacekk/bukkit/bloodmoon/entities/BloodMoonEntitySkeleton.java @@ -1,9 +1,9 @@ package uk.co.jacekk.bukkit.bloodmoon.entities; import java.lang.reflect.Field; +import java.util.ArrayList; import org.bukkit.Location; -import org.bukkit.craftbukkit.util.UnsafeList; import org.bukkit.entity.Skeleton; import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; @@ -28,7 +28,7 @@ public class BloodMoonEntitySkeleton extends net.minecraft.server.EntitySkeleton a.setAccessible(true); @SuppressWarnings("unchecked") - UnsafeList goals = (UnsafeList) a.get(this.goalSelector); + ArrayList goals = (ArrayList) a.get(this.goalSelector); for (Object item : goals){ Field goal = item.getClass().getDeclaredField("a"); diff --git a/src/uk/co/jacekk/bukkit/bloodmoon/featurelisteners/SwordDamageListener.java b/src/uk/co/jacekk/bukkit/bloodmoon/featurelisteners/SwordDamageListener.java new file mode 100644 index 0000000..2f37df1 --- /dev/null +++ b/src/uk/co/jacekk/bukkit/bloodmoon/featurelisteners/SwordDamageListener.java @@ -0,0 +1,73 @@ +package uk.co.jacekk.bukkit.bloodmoon.featurelisteners; + +import org.bukkit.entity.Creature; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; + +import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; + +public class SwordDamageListener implements Listener { + + private BloodMoon plugin; + + public SwordDamageListener(BloodMoon instance){ + this.plugin = instance; + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onEntityDamage(EntityDamageEvent event){ + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + + if (event.getCause() == DamageCause.ENTITY_ATTACK && BloodMoon.bloodMoonWorlds.contains(entity.getWorld().getName())){ + if (entity instanceof Creature){ + Creature creature = (Creature) entity; + + LivingEntity target = creature.getTarget(); + + if (target instanceof Player){ + Player player = (Player) target; + + ItemStack item = player.getItemInHand(); + + // 190 character line :D + if (BloodMoon.config.isCreatureOnMobList("features.sword-damage.mobs", creature) && plugin.rand.nextInt(100) <= BloodMoon.config.getInt("features.sword-damage.chance")){ + short damage = item.getDurability(); + + switch (item.getType()){ + case DIAMOND_SWORD: + if (damage > BloodMoon.config.getInt("features.sword-damage.damage.diamond")){ + item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.diamond"))); + } + case IRON_SWORD: + if (damage > BloodMoon.config.getInt("features.sword-damage.damage.iron")){ + item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.iron"))); + } + case GOLD_SWORD: + if (damage > BloodMoon.config.getInt("features.sword-damage.damage.gold")){ + item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.gold"))); + } + case STONE_SWORD: + if (damage > BloodMoon.config.getInt("features.sword-damage.damage.stone")){ + item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.stone"))); + } + case WOOD_SWORD: + if (damage > BloodMoon.config.getInt("features.sword-damage.damage.wood")){ + item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.wood"))); + } + } + } + } + } + } + } + +}