mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 19:16:41 +01:00
Some 1.6 updates...
This commit is contained in:
parent
97e9bbc923
commit
0a6a49410d
@ -17,6 +17,7 @@ public class ArenaClass
|
||||
private Map<String,Boolean> 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.
|
||||
*/
|
||||
|
@ -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<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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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<ItemStack> 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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ public class MonsterManager
|
||||
private Set<Wolf> pets;
|
||||
private Map<LivingEntity,MABoss> bosses;
|
||||
private Map<LivingEntity,List<ItemStack>> suppliers;
|
||||
private Set<LivingEntity> mounts;
|
||||
|
||||
public MonsterManager() {
|
||||
this.monsters = new HashSet<LivingEntity>();
|
||||
@ -29,6 +30,7 @@ public class MonsterManager
|
||||
this.pets = new HashSet<Wolf>();
|
||||
this.bosses = new HashMap<LivingEntity,MABoss>();
|
||||
this.suppliers = new HashMap<LivingEntity,List<ItemStack>>();
|
||||
this.mounts = new HashSet<LivingEntity>();
|
||||
}
|
||||
|
||||
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<ItemStack> drops) {
|
||||
suppliers.put(e, drops);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user