From 0a6a49410da4cc138cdad2807a1fafc4b2cf348f Mon Sep 17 00:00:00 2001 From: garbagemule Date: Wed, 3 Jul 2013 13:36:41 +0200 Subject: [PATCH] Some 1.6 updates... --- src/com/garbagemule/MobArena/ArenaClass.java | 11 +++++++ src/com/garbagemule/MobArena/ArenaImpl.java | 31 +++++++++++++------ .../garbagemule/MobArena/ArenaListener.java | 29 ++++++++++------- .../MobArena/ArenaPlayerStatistics.java | 2 +- .../garbagemule/MobArena/MonsterManager.java | 22 +++++++++++++ src/com/garbagemule/MobArena/PlayerData.java | 5 +-- .../MobArena/health/HealthStrategy.java | 2 +- .../MobArena/health/HealthStrategyHeroes.java | 6 ++-- .../health/HealthStrategyStandard.java | 2 +- .../garbagemule/MobArena/util/MutableInt.java | 2 +- .../garbagemule/MobArena/waves/MABoss.java | 4 +-- 11 files changed, 84 insertions(+), 32 deletions(-) diff --git a/src/com/garbagemule/MobArena/ArenaClass.java b/src/com/garbagemule/MobArena/ArenaClass.java index 0093a91..b206ec3 100644 --- a/src/com/garbagemule/MobArena/ArenaClass.java +++ b/src/com/garbagemule/MobArena/ArenaClass.java @@ -17,6 +17,7 @@ public class ArenaClass private Map perms; private int pets; private boolean unbreakableWeapons; + private boolean mount; /** * Create a new, empty arena class with the given name. @@ -109,6 +110,12 @@ public class ArenaClass else if (stack.getType() == Material.BONE) { pets += stack.getAmount(); } + + else if (stack.getType() == Material.HAY_BLOCK && stack.getAmount() == 1) { + if (mount) return; + mount = true; + } + else if (stack.getAmount() > 64) { while (stack.getAmount() > 64) { items.add(new ItemStack(stack.getType(), 64)); @@ -244,6 +251,10 @@ public class ArenaClass return unbreakableWeapons; } + public boolean hasMount() { + return mount; + } + /** * Used by isWeapon() to determine if an ItemStack is a weapon type. */ diff --git a/src/com/garbagemule/MobArena/ArenaImpl.java b/src/com/garbagemule/MobArena/ArenaImpl.java index 600906b..52bc585 100644 --- a/src/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/com/garbagemule/MobArena/ArenaImpl.java @@ -13,14 +13,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.ExperienceOrb; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.entity.Slime; -import org.bukkit.entity.Vehicle; -import org.bukkit.entity.Wolf; +import org.bukkit.entity.*; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -456,6 +449,9 @@ public class ArenaImpl implements Arena // Spawn pets (must happen after 'running = true;') spawnPets(); + // Spawn mounts + spawnMounts(); + // Clear the classes in use map, as they're no longer needed limitManager.clearClassesInUse(); @@ -727,6 +723,23 @@ public class ArenaImpl implements Arena } } + private void spawnMounts() { + for (Map.Entry entry : arenaPlayerMap.entrySet()) { + ArenaClass arenaClass = entry.getValue().getArenaClass(); + if (!arenaClass.hasMount()) continue; + + // Remove the hay bale + Player p = entry.getKey(); + p.getInventory().removeItem(new ItemStack(Material.HAY_BLOCK, 1)); + + // Spawn the horse + Horse horse = (Horse) world.spawnEntity(p.getLocation(), EntityType.HORSE); + horse.setPassenger(p); + horse.setHealth(horse.getMaxHealth()); + monsterManager.addMount(horse); + } + } + private void removePotionEffects(Player p) { for (PotionEffect effect : p.getActivePotionEffects()) { p.removePotionEffect(effect.getType()); @@ -923,7 +936,7 @@ public class ArenaImpl implements Arena scoreboard.removePlayer(p); } - private void setHealth(Player p, int health) { + private void setHealth(Player p, double health) { plugin.getHealthStrategy().setHealth(p, health); } diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index 4df6256..db4e45e 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -14,15 +14,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.Slime; -import org.bukkit.entity.Snowman; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.entity.ThrownPotion; -import org.bukkit.entity.Wolf; +import org.bukkit.entity.*; import org.bukkit.event.Event.Result; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; @@ -419,6 +411,9 @@ public class ArenaListener else if (monsters.removeMonster(event.getEntity())) { onMonsterDeath(event); } + else if (monsters.removeMount(event.getEntity())) { + onMountDeath(event); + } else if (monsters.removeGolem(event.getEntity())) { Messenger.tellAll(arena, Msg.GOLEM_DIED); } @@ -445,7 +440,11 @@ public class ArenaListener arena.playerRespawn(p); return true; } - + + private void onMountDeath(EntityDeathEvent event) { + + } + private void onMonsterDeath(EntityDeathEvent event) { EntityDamageEvent e1 = event.getEntity().getLastDamageCause(); EntityDamageByEntityEvent e2 = (e1 instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) e1 : null; @@ -504,8 +503,6 @@ public class ArenaListener if (loot != null && !loot.isEmpty()) { event.getDrops().add(getRandomItem(loot)); } - - return; } private ItemStack getRandomItem(List stacks) { @@ -541,6 +538,10 @@ public class ArenaListener if (damagee instanceof Wolf && arena.hasPet(damagee)) { onPetDamage(event, (Wolf) damagee, damager); } + // Mount + if (damagee instanceof Horse && monsters.hasMount(damagee)) { + onMountDamage(event, (Horse) damagee, damager); + } // Player else if (damagee instanceof Player) { onPlayerDamage(event, (Player) damagee, damager); @@ -579,7 +580,11 @@ public class ArenaListener private void onPetDamage(EntityDamageEvent event, Wolf pet, Entity damager) { event.setCancelled(true); } + + private void onMountDamage(EntityDamageEvent event, Horse mount, Entity damager) { + } + private void onMonsterDamage(EntityDamageEvent event, Entity monster, Entity damager) { if (damager instanceof Player) { Player p = (Player) damager; diff --git a/src/com/garbagemule/MobArena/ArenaPlayerStatistics.java b/src/com/garbagemule/MobArena/ArenaPlayerStatistics.java index dea22c5..5dee247 100644 --- a/src/com/garbagemule/MobArena/ArenaPlayerStatistics.java +++ b/src/com/garbagemule/MobArena/ArenaPlayerStatistics.java @@ -64,7 +64,7 @@ public class ArenaPlayerStatistics ints.get(s).inc(); } - public void add(String s, int amount) { + public void add(String s, double amount) { ints.get(s).add(amount); } diff --git a/src/com/garbagemule/MobArena/MonsterManager.java b/src/com/garbagemule/MobArena/MonsterManager.java index 5c42876..e3a0c41 100644 --- a/src/com/garbagemule/MobArena/MonsterManager.java +++ b/src/com/garbagemule/MobArena/MonsterManager.java @@ -21,6 +21,7 @@ public class MonsterManager private Set pets; private Map bosses; private Map> suppliers; + private Set mounts; public MonsterManager() { this.monsters = new HashSet(); @@ -29,6 +30,7 @@ public class MonsterManager this.pets = new HashSet(); this.bosses = new HashMap(); this.suppliers = new HashMap>(); + this.mounts = new HashSet(); } public void reset() { @@ -38,6 +40,7 @@ public class MonsterManager pets.clear(); bosses.clear(); suppliers.clear(); + mounts.clear(); } public void clear() { @@ -47,6 +50,7 @@ public class MonsterManager removeAll(pets); removeAll(bosses.keySet()); removeAll(suppliers.keySet()); + removeAll(mounts); reset(); } @@ -130,6 +134,24 @@ public class MonsterManager } } + public void addMount(LivingEntity e) { + mounts.add(e); + } + + public boolean hasMount(Entity e) { + return mounts.contains(e); + } + + public boolean removeMount(Entity e) { + return mounts.remove(e); + } + + public void removeMounts() { + for (LivingEntity e : mounts) { + e.remove(); + } + } + public void addSupplier(LivingEntity e, List drops) { suppliers.put(e, drops); } diff --git a/src/com/garbagemule/MobArena/PlayerData.java b/src/com/garbagemule/MobArena/PlayerData.java index 439dcbb..ec2d58d 100644 --- a/src/com/garbagemule/MobArena/PlayerData.java +++ b/src/com/garbagemule/MobArena/PlayerData.java @@ -11,7 +11,8 @@ public class PlayerData { private Player player; - private int health, food, level; + private double health; + private int food, level; private float exp; private GameMode mode = null; private Location entry = null; @@ -54,7 +55,7 @@ public class PlayerData return player; } - public int health() { + public double health() { return health; } diff --git a/src/com/garbagemule/MobArena/health/HealthStrategy.java b/src/com/garbagemule/MobArena/health/HealthStrategy.java index ea5bc12..6283448 100644 --- a/src/com/garbagemule/MobArena/health/HealthStrategy.java +++ b/src/com/garbagemule/MobArena/health/HealthStrategy.java @@ -9,5 +9,5 @@ public interface HealthStrategy * @param p a player * @param health amount of health */ - public void setHealth(Player p, int health); + public void setHealth(Player p, double health); } diff --git a/src/com/garbagemule/MobArena/health/HealthStrategyHeroes.java b/src/com/garbagemule/MobArena/health/HealthStrategyHeroes.java index e8a62fb..22af62b 100644 --- a/src/com/garbagemule/MobArena/health/HealthStrategyHeroes.java +++ b/src/com/garbagemule/MobArena/health/HealthStrategyHeroes.java @@ -8,9 +8,9 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; public class HealthStrategyHeroes implements HealthStrategy { @Override - public void setHealth(Player p, int health) { - int current = p.getHealth(); - int regain = health == 20 ? 20 : health - current; + public void setHealth(Player p, double health) { + double current = p.getHealth(); + double regain = health == p.getMaxHealth() ? p.getMaxHealth() : health - current; try { EntityRegainHealthEvent event = new EntityRegainHealthEvent(p, regain, RegainReason.CUSTOM); diff --git a/src/com/garbagemule/MobArena/health/HealthStrategyStandard.java b/src/com/garbagemule/MobArena/health/HealthStrategyStandard.java index 7f8aece..4660892 100644 --- a/src/com/garbagemule/MobArena/health/HealthStrategyStandard.java +++ b/src/com/garbagemule/MobArena/health/HealthStrategyStandard.java @@ -5,7 +5,7 @@ import org.bukkit.entity.Player; public class HealthStrategyStandard implements HealthStrategy { @Override - public void setHealth(Player p, int health) { + public void setHealth(Player p, double health) { p.setHealth(health); } } diff --git a/src/com/garbagemule/MobArena/util/MutableInt.java b/src/com/garbagemule/MobArena/util/MutableInt.java index a0879e9..a831429 100644 --- a/src/com/garbagemule/MobArena/util/MutableInt.java +++ b/src/com/garbagemule/MobArena/util/MutableInt.java @@ -23,7 +23,7 @@ public class MutableInt * Add the given amount to the internal int value. * @param amount the amount to add */ - public void add(int amount) { + public void add(double amount) { this.value += amount; } diff --git a/src/com/garbagemule/MobArena/waves/MABoss.java b/src/com/garbagemule/MobArena/waves/MABoss.java index bb4c110..207580e 100644 --- a/src/com/garbagemule/MobArena/waves/MABoss.java +++ b/src/com/garbagemule/MobArena/waves/MABoss.java @@ -33,7 +33,7 @@ public class MABoss * Get the current health of this MABoss * @return the current health of the boss */ - public int getHealth() { + public double getHealth() { return entity.getHealth(); } @@ -41,7 +41,7 @@ public class MABoss * Get the maximum health of this MABoss * @return the maximum health of the boss */ - public int getMaxHealth() { + public double getMaxHealth() { return entity.getMaxHealth(); }