Rollback somes changes

This commit is contained in:
Michel Roux 2012-05-20 10:44:45 +02:00
parent ca16c195c3
commit 4b87b11c9e
4 changed files with 89 additions and 2 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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<PathfinderGoal> goals = (UnsafeList<PathfinderGoal>) a.get(this.goalSelector);
ArrayList<PathfinderGoal> goals = (ArrayList<PathfinderGoal>) a.get(this.goalSelector);
for (Object item : goals){
Field goal = item.getClass().getDeclaredField("a");

View File

@ -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")));
}
}
}
}
}
}
}
}