Some 1.6 updates...

This commit is contained in:
garbagemule
2013-07-03 13:36:41 +02:00
parent 97e9bbc923
commit 0a6a49410d
11 changed files with 84 additions and 32 deletions
@@ -17,6 +17,7 @@ public class ArenaClass
private Map<String,Boolean> perms; private Map<String,Boolean> perms;
private int pets; private int pets;
private boolean unbreakableWeapons; private boolean unbreakableWeapons;
private boolean mount;
/** /**
* Create a new, empty arena class with the given name. * Create a new, empty arena class with the given name.
@@ -109,6 +110,12 @@ public class ArenaClass
else if (stack.getType() == Material.BONE) { else if (stack.getType() == Material.BONE) {
pets += stack.getAmount(); pets += stack.getAmount();
} }
else if (stack.getType() == Material.HAY_BLOCK && stack.getAmount() == 1) {
if (mount) return;
mount = true;
}
else if (stack.getAmount() > 64) { else if (stack.getAmount() > 64) {
while (stack.getAmount() > 64) { while (stack.getAmount() > 64) {
items.add(new ItemStack(stack.getType(), 64)); items.add(new ItemStack(stack.getType(), 64));
@@ -244,6 +251,10 @@ public class ArenaClass
return unbreakableWeapons; return unbreakableWeapons;
} }
public boolean hasMount() {
return mount;
}
/** /**
* Used by isWeapon() to determine if an ItemStack is a weapon type. * Used by isWeapon() to determine if an ItemStack is a weapon type.
*/ */
+22 -9
View File
@@ -13,14 +13,7 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.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.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
@@ -456,6 +449,9 @@ public class ArenaImpl implements Arena
// Spawn pets (must happen after 'running = true;') // Spawn pets (must happen after 'running = true;')
spawnPets(); spawnPets();
// Spawn mounts
spawnMounts();
// Clear the classes in use map, as they're no longer needed // Clear the classes in use map, as they're no longer needed
limitManager.clearClassesInUse(); limitManager.clearClassesInUse();
@@ -727,6 +723,23 @@ public class ArenaImpl implements Arena
} }
} }
private void spawnMounts() {
for (Map.Entry<Player,ArenaPlayer> 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) { private void removePotionEffects(Player p) {
for (PotionEffect effect : p.getActivePotionEffects()) { for (PotionEffect effect : p.getActivePotionEffects()) {
p.removePotionEffect(effect.getType()); p.removePotionEffect(effect.getType());
@@ -923,7 +936,7 @@ public class ArenaImpl implements Arena
scoreboard.removePlayer(p); scoreboard.removePlayer(p);
} }
private void setHealth(Player p, int health) { private void setHealth(Player p, double health) {
plugin.getHealthStrategy().setHealth(p, health); plugin.getHealthStrategy().setHealth(p, health);
} }
+17 -12
View File
@@ -14,15 +14,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Entity; import org.bukkit.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.event.Event.Result; import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
@@ -419,6 +411,9 @@ public class ArenaListener
else if (monsters.removeMonster(event.getEntity())) { else if (monsters.removeMonster(event.getEntity())) {
onMonsterDeath(event); onMonsterDeath(event);
} }
else if (monsters.removeMount(event.getEntity())) {
onMountDeath(event);
}
else if (monsters.removeGolem(event.getEntity())) { else if (monsters.removeGolem(event.getEntity())) {
Messenger.tellAll(arena, Msg.GOLEM_DIED); Messenger.tellAll(arena, Msg.GOLEM_DIED);
} }
@@ -445,7 +440,11 @@ public class ArenaListener
arena.playerRespawn(p); arena.playerRespawn(p);
return true; return true;
} }
private void onMountDeath(EntityDeathEvent event) {
}
private void onMonsterDeath(EntityDeathEvent event) { private void onMonsterDeath(EntityDeathEvent event) {
EntityDamageEvent e1 = event.getEntity().getLastDamageCause(); EntityDamageEvent e1 = event.getEntity().getLastDamageCause();
EntityDamageByEntityEvent e2 = (e1 instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) e1 : null; EntityDamageByEntityEvent e2 = (e1 instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) e1 : null;
@@ -504,8 +503,6 @@ public class ArenaListener
if (loot != null && !loot.isEmpty()) { if (loot != null && !loot.isEmpty()) {
event.getDrops().add(getRandomItem(loot)); event.getDrops().add(getRandomItem(loot));
} }
return;
} }
private ItemStack getRandomItem(List<ItemStack> stacks) { private ItemStack getRandomItem(List<ItemStack> stacks) {
@@ -541,6 +538,10 @@ public class ArenaListener
if (damagee instanceof Wolf && arena.hasPet(damagee)) { if (damagee instanceof Wolf && arena.hasPet(damagee)) {
onPetDamage(event, (Wolf) damagee, damager); onPetDamage(event, (Wolf) damagee, damager);
} }
// Mount
if (damagee instanceof Horse && monsters.hasMount(damagee)) {
onMountDamage(event, (Horse) damagee, damager);
}
// Player // Player
else if (damagee instanceof Player) { else if (damagee instanceof Player) {
onPlayerDamage(event, (Player) damagee, damager); onPlayerDamage(event, (Player) damagee, damager);
@@ -579,7 +580,11 @@ public class ArenaListener
private void onPetDamage(EntityDamageEvent event, Wolf pet, Entity damager) { private void onPetDamage(EntityDamageEvent event, Wolf pet, Entity damager) {
event.setCancelled(true); event.setCancelled(true);
} }
private void onMountDamage(EntityDamageEvent event, Horse mount, Entity damager) {
}
private void onMonsterDamage(EntityDamageEvent event, Entity monster, Entity damager) { private void onMonsterDamage(EntityDamageEvent event, Entity monster, Entity damager) {
if (damager instanceof Player) { if (damager instanceof Player) {
Player p = (Player) damager; Player p = (Player) damager;
@@ -64,7 +64,7 @@ public class ArenaPlayerStatistics
ints.get(s).inc(); ints.get(s).inc();
} }
public void add(String s, int amount) { public void add(String s, double amount) {
ints.get(s).add(amount); ints.get(s).add(amount);
} }
@@ -21,6 +21,7 @@ public class MonsterManager
private Set<Wolf> pets; private Set<Wolf> pets;
private Map<LivingEntity,MABoss> bosses; private Map<LivingEntity,MABoss> bosses;
private Map<LivingEntity,List<ItemStack>> suppliers; private Map<LivingEntity,List<ItemStack>> suppliers;
private Set<LivingEntity> mounts;
public MonsterManager() { public MonsterManager() {
this.monsters = new HashSet<LivingEntity>(); this.monsters = new HashSet<LivingEntity>();
@@ -29,6 +30,7 @@ public class MonsterManager
this.pets = new HashSet<Wolf>(); this.pets = new HashSet<Wolf>();
this.bosses = new HashMap<LivingEntity,MABoss>(); this.bosses = new HashMap<LivingEntity,MABoss>();
this.suppliers = new HashMap<LivingEntity,List<ItemStack>>(); this.suppliers = new HashMap<LivingEntity,List<ItemStack>>();
this.mounts = new HashSet<LivingEntity>();
} }
public void reset() { public void reset() {
@@ -38,6 +40,7 @@ public class MonsterManager
pets.clear(); pets.clear();
bosses.clear(); bosses.clear();
suppliers.clear(); suppliers.clear();
mounts.clear();
} }
public void clear() { public void clear() {
@@ -47,6 +50,7 @@ public class MonsterManager
removeAll(pets); removeAll(pets);
removeAll(bosses.keySet()); removeAll(bosses.keySet());
removeAll(suppliers.keySet()); removeAll(suppliers.keySet());
removeAll(mounts);
reset(); 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<ItemStack> drops) { public void addSupplier(LivingEntity e, List<ItemStack> drops) {
suppliers.put(e, drops); suppliers.put(e, drops);
} }
+3 -2
View File
@@ -11,7 +11,8 @@ public class PlayerData
{ {
private Player player; private Player player;
private int health, food, level; private double health;
private int food, level;
private float exp; private float exp;
private GameMode mode = null; private GameMode mode = null;
private Location entry = null; private Location entry = null;
@@ -54,7 +55,7 @@ public class PlayerData
return player; return player;
} }
public int health() { public double health() {
return health; return health;
} }
@@ -9,5 +9,5 @@ public interface HealthStrategy
* @param p a player * @param p a player
* @param health amount of health * @param health amount of health
*/ */
public void setHealth(Player p, int health); public void setHealth(Player p, double health);
} }
@@ -8,9 +8,9 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
public class HealthStrategyHeroes implements HealthStrategy public class HealthStrategyHeroes implements HealthStrategy
{ {
@Override @Override
public void setHealth(Player p, int health) { public void setHealth(Player p, double health) {
int current = p.getHealth(); double current = p.getHealth();
int regain = health == 20 ? 20 : health - current; double regain = health == p.getMaxHealth() ? p.getMaxHealth() : health - current;
try { try {
EntityRegainHealthEvent event = new EntityRegainHealthEvent(p, regain, RegainReason.CUSTOM); EntityRegainHealthEvent event = new EntityRegainHealthEvent(p, regain, RegainReason.CUSTOM);
@@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
public class HealthStrategyStandard implements HealthStrategy public class HealthStrategyStandard implements HealthStrategy
{ {
@Override @Override
public void setHealth(Player p, int health) { public void setHealth(Player p, double health) {
p.setHealth(health); p.setHealth(health);
} }
} }
@@ -23,7 +23,7 @@ public class MutableInt
* Add the given amount to the internal int value. * Add the given amount to the internal int value.
* @param amount the amount to add * @param amount the amount to add
*/ */
public void add(int amount) { public void add(double amount) {
this.value += amount; this.value += amount;
} }
@@ -33,7 +33,7 @@ public class MABoss
* Get the current health of this MABoss * Get the current health of this MABoss
* @return the current health of the boss * @return the current health of the boss
*/ */
public int getHealth() { public double getHealth() {
return entity.getHealth(); return entity.getHealth();
} }
@@ -41,7 +41,7 @@ public class MABoss
* Get the maximum health of this MABoss * Get the maximum health of this MABoss
* @return the maximum health of the boss * @return the maximum health of the boss
*/ */
public int getMaxHealth() { public double getMaxHealth() {
return entity.getMaxHealth(); return entity.getMaxHealth();
} }