Implement mounts.

This commit is contained in:
garbagemule 2013-10-07 02:05:59 +02:00
parent 24caeab24f
commit 56a616ee76
3 changed files with 67 additions and 19 deletions

View File

@ -1,7 +1,7 @@
name: MobArena name: MobArena
author: garbagemule author: garbagemule
main: com.garbagemule.MobArena.MobArena main: com.garbagemule.MobArena.MobArena
version: 0.95.5.35 version: 0.95.5.36
softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault] softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault]
commands: commands:
ma: ma:

View File

@ -624,8 +624,9 @@ public class ArenaImpl implements Arena
return false; return false;
} }
// Clear inventory if player is an arena player // Clear inventory if player is an arena player, and unmount
if (arenaPlayers.contains(p)) { if (arenaPlayers.contains(p)) {
unmount(p);
clearInv(p); clearInv(p);
} }
@ -667,8 +668,9 @@ public class ArenaImpl implements Arena
ArenaPlayerDeathEvent event = new ArenaPlayerDeathEvent(p, this, last); ArenaPlayerDeathEvent event = new ArenaPlayerDeathEvent(p, this, last);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
// Clear the player's inventory // Clear the player's inventory, and unmount
if (arenaPlayers.remove(p)) { if (arenaPlayers.remove(p)) {
unmount(p);
clearInv(p); clearInv(p);
} }
@ -692,6 +694,15 @@ public class ArenaImpl implements Arena
} }
} }
private void unmount(Player p) {
Entity v = p.getVehicle();
if (v != null) {
monsterManager.removeMount(v);
v.eject();
v.remove();
}
}
@Override @Override
public void playerRespawn(Player p) { public void playerRespawn(Player p) {
if (settings.getBoolean("auto-respawn", true)) { if (settings.getBoolean("auto-respawn", true)) {
@ -774,21 +785,60 @@ public class ArenaImpl implements Arena
} }
private void spawnMounts() { private void spawnMounts() {
/* TODO: Uncomment for 1.6 for (Player p : arenaPlayers) {
for (Map.Entry<Player,ArenaPlayer> entry : arenaPlayerMap.entrySet()) { // Skip players who are either null or offline
ArenaClass arenaClass = entry.getValue().getArenaClass(); if (p == null || !p.isOnline()) continue;
if (!arenaClass.hasMount()) continue;
// Remove the hay bale // Grab the inventory
Player p = entry.getKey(); PlayerInventory inv = p.getInventory();
p.getInventory().removeItem(new ItemStack(Material.HAY_BLOCK, 1)); if (inv == null) continue;
// Spawn the horse // Find the first slot containing a haybale
int hay = inv.first(Material.HAY_BLOCK);
if (hay == -1) continue;
// Grab the amount and calculate the configuration
int amount = inv.getItem(hay).getAmount();
// Variant
Horse.Variant variant = Horse.Variant.HORSE;
switch (amount % 8) {
case 2: variant = Horse.Variant.DONKEY; break;
case 3: variant = Horse.Variant.MULE; break;
case 4: variant = Horse.Variant.SKELETON_HORSE; break;
case 5: variant = Horse.Variant.UNDEAD_HORSE; break;
default: break;
}
// Barding
Material barding = null;
switch ((amount >> 3) % 4) {
case 1: barding = Material.IRON_BARDING; break;
case 2: barding = Material.GOLD_BARDING; break;
case 3: barding = Material.DIAMOND_BARDING; break;
default: break;
}
// Spawn the horse, set its variant, tame it, etc.
Horse horse = (Horse) world.spawnEntity(p.getLocation(), EntityType.HORSE); Horse horse = (Horse) world.spawnEntity(p.getLocation(), EntityType.HORSE);
horse.setVariant(variant);
horse.setTamed(true);
horse.setOwner(p);
horse.setPassenger(p); horse.setPassenger(p);
horse.setHealth(horse.getMaxHealth()); horse.setHealth(horse.getMaxHealth());
// Give it a saddle and possibly barding
horse.getInventory().setSaddle(new ItemStack(Material.SADDLE));
if (barding != null) {
horse.getInventory().setArmor(new ItemStack(barding));
}
// Add to monster manager
monsterManager.addMount(horse); monsterManager.addMount(horse);
}*/
// Remove the hay
inv.setItem(hay, null);
}
} }
private void removePotionEffects(Player p) { private void removePotionEffects(Player p) {

View File

@ -457,7 +457,7 @@ public class ArenaListener
} }
private void onMountDeath(EntityDeathEvent event) { private void onMountDeath(EntityDeathEvent event) {
// Shouldn't ever happen
} }
private void onMonsterDeath(EntityDeathEvent event) { private void onMonsterDeath(EntityDeathEvent event) {
@ -566,10 +566,9 @@ public class ArenaListener
onPetDamage(event, (Wolf) damagee, damager); onPetDamage(event, (Wolf) damagee, damager);
} }
// Mount // Mount
/* TODO: Uncomment for 1.6
else if (damagee instanceof Horse && monsters.hasMount(damagee)) { else if (damagee instanceof Horse && monsters.hasMount(damagee)) {
onMountDamage(event, (Horse) damagee, damager); 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);
@ -613,11 +612,10 @@ 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);
} }
/* TODO: Uncomment for 1.6
private void onMountDamage(EntityDamageEvent event, Horse mount, Entity damager) {
}*/ private void onMountDamage(EntityDamageEvent event, Horse mount, Entity damager) {
event.setCancelled(true);
}
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) {