From 509705d96c0377db8c64f01cb1834f20a765006c Mon Sep 17 00:00:00 2001 From: max Date: Sun, 25 May 2014 16:53:12 +0200 Subject: [PATCH] Enable 1.6.4 stuff again --- pom.xml | 2 +- .../com/extrahardmode/features/Players.java | 2 +- .../features/monsters/Horses.java | 456 +++++++++--------- .../features/monsters/Zombies.java | 13 +- 4 files changed, 237 insertions(+), 236 deletions(-) diff --git a/pom.xml b/pom.xml index 7977eb21..62322bed 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ com.extrahardmode.ExtraHardMode ${project.build.outputDirectory} - 1.5.2 + 1.6.4 R1.0 ${basedir}/src/test/ ${basedir}/src/main/java/ diff --git a/src/main/java/com/extrahardmode/features/Players.java b/src/main/java/com/extrahardmode/features/Players.java index c4a8ccaa..d18c3a53 100644 --- a/src/main/java/com/extrahardmode/features/Players.java +++ b/src/main/java/com/extrahardmode/features/Players.java @@ -109,7 +109,7 @@ public void onPlayerRespawn(PlayerRespawnEvent respawnEvent) if (respawnFood < 20 && respawnHealthPercentage > 0 && respawnHealthPercentage < 100) { //TODO HIGH EhmPlayerRespawnEvent - SetPlayerHealthAndFoodTask task = new SetPlayerHealthAndFoodTask(player, player.getMaxHealth() * respawnHealthPercentage / 100, respawnFood); + SetPlayerHealthAndFoodTask task = new SetPlayerHealthAndFoodTask(player, (int) player.getMaxHealth() * respawnHealthPercentage / 100, respawnFood); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, 10L); // half-second delay } // FEATURE: players can't swim when they're carrying a lot of weight, reset the cached value diff --git a/src/main/java/com/extrahardmode/features/monsters/Horses.java b/src/main/java/com/extrahardmode/features/monsters/Horses.java index 389a5a11..5cf3b1b9 100644 --- a/src/main/java/com/extrahardmode/features/monsters/Horses.java +++ b/src/main/java/com/extrahardmode/features/monsters/Horses.java @@ -19,231 +19,231 @@ * along with ExtraHardMode. If not, see . */ -//package com.extrahardmode.features.monsters; - - -//import com.extrahardmode.ExtraHardMode; -//import com.extrahardmode.config.RootConfig; -//import com.extrahardmode.config.RootNode; -//import com.extrahardmode.service.ListenerModule; -//import org.bukkit.entity.Horse; -//import org.bukkit.entity.LivingEntity; -//import org.bukkit.event.EventHandler; -//import org.bukkit.event.EventPriority; -//import org.bukkit.event.entity.EntityDamageEvent; -//import org.bukkit.event.inventory.InventoryAction; -//import org.bukkit.event.inventory.InventoryClickEvent; -//import org.bukkit.inventory.HorseInventory; -//import org.bukkit.inventory.Inventory; -//import org.bukkit.potion.PotionEffect; -//import org.bukkit.potion.PotionEffectType; -// -//import java.util.*; -// -///** @author Diemex */ -//public class Horses extends ListenerModule -//{ -// /** Store the food value of each horse */ -// private Map healthMap = new HashMap(8); -// -// /** Is the horse being ridden and should we drain its food */ -// private Set horsesBeingRidden = new HashSet(8); -// -// private RootConfig CFG; -// -// /** This horse has been right clicked with food and player shouldn't mount the horse */ -// private Set enterMap = new HashSet(1); -// -// private final String horseMessage = "extrahardmode.horse.health"; -// -// -// public Horses(ExtraHardMode plugin) -// { -// super(plugin); -// } -// -// -// @Override -// public void starting() -// { -// super.starting(); -// CFG = plugin.getModuleForClass(RootConfig.class); -// } -// -// -// /** Block using of horse inventory in caves, prevent usage of horses as transportable chests */ -// @EventHandler(priority = EventPriority.LOWEST) -// public void onHorseInvClick(InventoryClickEvent event) -// { -// final Inventory inv = event.getInventory(); -// final int maxHeight = CFG.getInt(RootNode.HORSE_CHEST_BLOCK_BELOW, event.getWhoClicked().getWorld().getName()); -// -// if (inv instanceof HorseInventory && event.getWhoClicked().getLocation().getBlockY() < maxHeight) -// { -// Inventory horseInv = event.getView().getTopInventory(); -// int clickedSlot = event.getRawSlot(); -// -// //In a horse inventory the first two slots are saddle + armor, a mule only has a saddle + potentially a chest -// //Block usage of the chest in caves, but allow taking of the saddle -// if (horseInv.getSize() > 2 && ((clickedSlot < horseInv.getSize() && clickedSlot > 0) || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY)) -// event.setCancelled(true); -// } -// } -// -// -// //TODO Save who is on a horse and who not -// -// -// /** Greatly increase damage to horses */ -// @EventHandler -// public void onHorseDamage(EntityDamageEvent event) -// { -// String world = event.getEntity().getWorld().getName(); -// final boolean enhancedEnvironmentaldamage = CFG.getBoolean(RootNode.ENHANCED_ENVIRONMENTAL_DAMAGE, world); -// -// if (event.getEntity() instanceof Horse && enhancedEnvironmentaldamage) -// { -// final LivingEntity horse = (LivingEntity) event.getEntity(); -// final EntityDamageEvent.DamageCause cause = event.getCause(); -// -// switch (cause) -// { -// case BLOCK_EXPLOSION: -// case ENTITY_EXPLOSION: -// if (event.getDamage() > 2.0) -// horse.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 15, 3)); -// break; -// case FALL: -// horse.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, (int) (20 * event.getDamage()), 4)); -// event.setDamage(event.getDamage() * 2); -// break; -// case SUFFOCATION: -// event.setDamage(event.getDamage() * 5); -// break; -// case LAVA: -// event.setDamage(event.getDamage() * 2); -// break; -// case FIRE_TICK: -// horse.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1)); -// break; -// } -// } -// } -// -// /** -// * Make horse armor wear out -// */ -// /** -// * Make saddle wear out -// */ -// -// /** -// * Make horses require food. -// * Rightclicking a horse with food feeds it, player shouldnt enter the horse afterwards -// */ -// /*@EventHandler -// public void onvehicleEnter(VehicleEnterEvent event) -// { -// plugin.getServer().broadcastMessage(event.getEntered().getType() + " Entered " + event.getVehicle().getType()); -// if (enterMap.contains(event.getVehicle().getUniqueId())) -// { -// //TODO player view resetting -// enterMap.remove(event.getVehicle().getUniqueId()); -// event.setCancelled(true); -// } -// }*/ -// -// -// /** -// * Make horses require food -// */ -// /*@EventHandler -// public void onVehicleExit(VehicleExitEvent event) -// { -// plugin.getServer().broadcastMessage(event.getExited().getType() + " Exited " + event.getVehicle().getType()); -// }*/ -// -// -// /** -// * When a Player right clicks a horse with food in his hand fill up the food meter of the horse -// */ -// /*@EventHandler -// public void onPlayerInteract(PlayerInteractEntityEvent event) -// { -// final Player player = event.getPlayer(); -// final Horse horse = event.getRightClicked() instanceof Horse ? (Horse) event.getRightClicked() : null; -// -// plugin.getServer().broadcastMessage("Right Clicked: " + event.getRightClicked().getType()); -// plugin.getServer().getLogger().info(player.getItemInHand().getType() + " horse food " + (BlockModule.isHorseFood(player.getItemInHand().getType()) ? "true" : "false")); -// -// //Player feeds horse when he has a veggie in his hand and the horse is tamed -// if (horse != null && horse.isTamed() && BlockModule.isHorseFood(player.getItemInHand().getType())) -// { -// final UUID horseId = event.getRightClicked().getUniqueId(); -// int oldValue = healthMap.containsKey(horseId) ? healthMap.get(horseId) : 0, newValue; -// -// switch (player.getItemInHand().getType()) -// { -// //TODO lol good nutrition -// case CARROT_ITEM: -// case POTATO_ITEM: -// case WHEAT: -// newValue = incrementFood(horseId, 5); -// break; -// case HAY_BLOCK: -// newValue = incrementFood(horseId, 40); -// break; -// default: -// throw new UnsupportedOperationException(player.getItemInHand().getType() + " has been added to eatable blocks but no food value has been defined."); -// } -// -// //TODO visual effects sound when eating -// //Consume food if the horse ate it -// if (newValue > oldValue) -// player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1); -// -// //TODO horses dont spawn with full food -// //TODO only tamed horses -// //Update player on new value -// if (oldValue < 20 && newValue >= 20) -// messenger.send(player, MessageNode.HORSE_FEED_LOW); -// else if (oldValue < 50 && newValue >= 50) -// messenger.send(player, MessageNode.HORSE_FEED_MIDDLE); -// else if (oldValue < 80 && newValue >= 80) -// messenger.send(player, MessageNode.HORSE_FEED_HIGH); -// -// //Save that the Player just feed the horse and cancel the upcoming VehicleEnterEvent -// enterMap.add(horseId); -// } -// }*/ -// -// -// /** -// * Increment the food level of the given horse -// * -// * @param horse entity id of the horse -// * @param amount amount to add to the food bar -// * -// * @return new value -// */ -// public int incrementFood(UUID horse, int amount) -// { -// int oldValue = healthMap.containsKey(horse) ? healthMap.get(horse) : 0; -// if (oldValue + amount < 100) -// healthMap.put(horse, oldValue + amount); -// return oldValue + amount; -// } -// -// -// /** -// * Increment the food level of the given horse -// * -// * @param horse entity id of the horse -// * @param amount amount to subtract from the food bar -// */ -// public void decrementFood(UUID horse, int amount) -// { -// int oldValue = healthMap.containsKey(horse) ? healthMap.get(horse) : 0; -// healthMap.put(horse, oldValue - amount); -// } -//} +package com.extrahardmode.features.monsters; + + +import com.extrahardmode.ExtraHardMode; +import com.extrahardmode.config.RootConfig; +import com.extrahardmode.config.RootNode; +import com.extrahardmode.service.ListenerModule; +import org.bukkit.entity.Horse; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.HorseInventory; +import org.bukkit.inventory.Inventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.*; + +/** @author Diemex */ +public class Horses extends ListenerModule +{ + /** Store the food value of each horse */ + private Map healthMap = new HashMap(8); + + /** Is the horse being ridden and should we drain its food */ + private Set horsesBeingRidden = new HashSet(8); + + private RootConfig CFG; + + /** This horse has been right clicked with food and player shouldn't mount the horse */ + private Set enterMap = new HashSet(1); + + private final String horseMessage = "extrahardmode.horse.health"; + + + public Horses(ExtraHardMode plugin) + { + super(plugin); + } + + + @Override + public void starting() + { + super.starting(); + CFG = plugin.getModuleForClass(RootConfig.class); + } + + + /** Block using of horse inventory in caves, prevent usage of horses as transportable chests */ + @EventHandler(priority = EventPriority.LOWEST) + public void onHorseInvClick(InventoryClickEvent event) + { + final Inventory inv = event.getInventory(); + final int maxHeight = CFG.getInt(RootNode.HORSE_CHEST_BLOCK_BELOW, event.getWhoClicked().getWorld().getName()); + + if (inv instanceof HorseInventory && event.getWhoClicked().getLocation().getBlockY() < maxHeight) + { + Inventory horseInv = event.getView().getTopInventory(); + int clickedSlot = event.getRawSlot(); + + //In a horse inventory the first two slots are saddle + armor, a mule only has a saddle + potentially a chest + //Block usage of the chest in caves, but allow taking of the saddle + if (horseInv.getSize() > 2 && ((clickedSlot < horseInv.getSize() && clickedSlot > 0) || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY)) + event.setCancelled(true); + } + } + + + //TODO Save who is on a horse and who not + + + /** Greatly increase damage to horses */ + @EventHandler + public void onHorseDamage(EntityDamageEvent event) + { + String world = event.getEntity().getWorld().getName(); + final boolean enhancedEnvironmentaldamage = CFG.getBoolean(RootNode.ENHANCED_ENVIRONMENTAL_DAMAGE, world); + + if (event.getEntity() instanceof Horse && enhancedEnvironmentaldamage) + { + final LivingEntity horse = (LivingEntity) event.getEntity(); + final EntityDamageEvent.DamageCause cause = event.getCause(); + + switch (cause) + { + case BLOCK_EXPLOSION: + case ENTITY_EXPLOSION: + if (event.getDamage() > 2.0) + horse.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 15, 3)); + break; + case FALL: + horse.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, (int) (20 * event.getDamage()), 4)); + event.setDamage(event.getDamage() * 2); + break; + case SUFFOCATION: + event.setDamage(event.getDamage() * 5); + break; + case LAVA: + event.setDamage(event.getDamage() * 2); + break; + case FIRE_TICK: + horse.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1)); + break; + } + } + } + + /** + * Make horse armor wear out + */ + /** + * Make saddle wear out + */ + + /** + * Make horses require food. + * Rightclicking a horse with food feeds it, player shouldnt enter the horse afterwards + */ + /*@EventHandler + public void onvehicleEnter(VehicleEnterEvent event) + { + plugin.getServer().broadcastMessage(event.getEntered().getType() + " Entered " + event.getVehicle().getType()); + if (enterMap.contains(event.getVehicle().getUniqueId())) + { + //TODO player view resetting + enterMap.remove(event.getVehicle().getUniqueId()); + event.setCancelled(true); + } + }*/ + + + /** + * Make horses require food + */ + /*@EventHandler + public void onVehicleExit(VehicleExitEvent event) + { + plugin.getServer().broadcastMessage(event.getExited().getType() + " Exited " + event.getVehicle().getType()); + }*/ + + + /** + * When a Player right clicks a horse with food in his hand fill up the food meter of the horse + */ + /*@EventHandler + public void onPlayerInteract(PlayerInteractEntityEvent event) + { + final Player player = event.getPlayer(); + final Horse horse = event.getRightClicked() instanceof Horse ? (Horse) event.getRightClicked() : null; + + plugin.getServer().broadcastMessage("Right Clicked: " + event.getRightClicked().getType()); + plugin.getServer().getLogger().info(player.getItemInHand().getType() + " horse food " + (BlockModule.isHorseFood(player.getItemInHand().getType()) ? "true" : "false")); + + //Player feeds horse when he has a veggie in his hand and the horse is tamed + if (horse != null && horse.isTamed() && BlockModule.isHorseFood(player.getItemInHand().getType())) + { + final UUID horseId = event.getRightClicked().getUniqueId(); + int oldValue = healthMap.containsKey(horseId) ? healthMap.get(horseId) : 0, newValue; + + switch (player.getItemInHand().getType()) + { + //TODO lol good nutrition + case CARROT_ITEM: + case POTATO_ITEM: + case WHEAT: + newValue = incrementFood(horseId, 5); + break; + case HAY_BLOCK: + newValue = incrementFood(horseId, 40); + break; + default: + throw new UnsupportedOperationException(player.getItemInHand().getType() + " has been added to eatable blocks but no food value has been defined."); + } + + //TODO visual effects sound when eating + //Consume food if the horse ate it + if (newValue > oldValue) + player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1); + + //TODO horses dont spawn with full food + //TODO only tamed horses + //Update player on new value + if (oldValue < 20 && newValue >= 20) + messenger.send(player, MessageNode.HORSE_FEED_LOW); + else if (oldValue < 50 && newValue >= 50) + messenger.send(player, MessageNode.HORSE_FEED_MIDDLE); + else if (oldValue < 80 && newValue >= 80) + messenger.send(player, MessageNode.HORSE_FEED_HIGH); + + //Save that the Player just feed the horse and cancel the upcoming VehicleEnterEvent + enterMap.add(horseId); + } + }*/ + + + /** + * Increment the food level of the given horse + * + * @param horse entity id of the horse + * @param amount amount to add to the food bar + * + * @return new value + */ + public int incrementFood(UUID horse, int amount) + { + int oldValue = healthMap.containsKey(horse) ? healthMap.get(horse) : 0; + if (oldValue + amount < 100) + healthMap.put(horse, oldValue + amount); + return oldValue + amount; + } + + + /** + * Increment the food level of the given horse + * + * @param horse entity id of the horse + * @param amount amount to subtract from the food bar + */ + public void decrementFood(UUID horse, int amount) + { + int oldValue = healthMap.containsKey(horse) ? healthMap.get(horse) : 0; + healthMap.put(horse, oldValue - amount); + } +} diff --git a/src/main/java/com/extrahardmode/features/monsters/Zombies.java b/src/main/java/com/extrahardmode/features/monsters/Zombies.java index ea8c87b9..da17e197 100644 --- a/src/main/java/com/extrahardmode/features/monsters/Zombies.java +++ b/src/main/java/com/extrahardmode/features/monsters/Zombies.java @@ -35,6 +35,7 @@ import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; @@ -64,14 +65,14 @@ public void starting() super.starting(); CFG = plugin.getModuleForClass(RootConfig.class); playerModule = plugin.getModuleForClass(PlayerModule.class); - /*try + try { CreatureSpawnEvent.SpawnReason doesEnumExist = CreatureSpawnEvent.SpawnReason.REINFORCEMENTS; hasReinforcements = true; } catch (NoSuchFieldError e) - {*/ - hasReinforcements = false; - //} + { + hasReinforcements = false; + } } @@ -159,12 +160,12 @@ public void onEntityDamage(EntityDamageEvent event) /** Flag Zombies that have been called in as reinforcements to not respawn */ - /*@EventHandler + @EventHandler public void onZombieReinforcements(CreatureSpawnEvent event) { if (hasReinforcements && event.getEntity() instanceof Zombie && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.REINFORCEMENTS) { EntityHelper.flagIgnore(plugin, event.getEntity()); } - }*/ + } }