Fixed updateTargets... again

This commit is contained in:
Garbage Mule 2011-07-16 18:34:28 +02:00
parent 1dc4409857
commit c84158aeb9
6 changed files with 128 additions and 30 deletions

Binary file not shown.

View File

@ -0,0 +1,40 @@
package com.garbagemule.MobArena;
import org.bukkit.entity.Player;
public abstract class AbstractArena
{
/**
* Start the arena session.
* This method should warp all players to their respective warp points, start all
* needed timers, clear/populate all sets and lists, and flag all booleans.
*/
public abstract void startArena();
/**
* Stop the arena session.
* Distribute rewards, clean up arena floor and reset everything to how it was before
* the arena session was started.
*/
public abstract void endArena();
/**
* Player joins the arena/lobby.
*/
public abstract void playerJoin(Player p);
/**
* Player leaves the arena/lobby.
*/
public abstract void playerLeave(Player p);
/**
* Player dies in the arena.
*/
public abstract void playerDeath(Player p);
/**
* Player signals that they are ready.
*/
public abstract void playerReady(Player p);
}

View File

@ -885,6 +885,9 @@ public class Arena
{ {
Material mat = b.getType(); Material mat = b.getType();
if (mat == Material.LAVA) b.setType(Material.STATIONARY_LAVA);
else if (mat == Material.WATER) b.setType(Material.STATIONARY_WATER);
if (mat == Material.WOODEN_DOOR || mat == Material.IRON_DOOR_BLOCK || mat == Material.FIRE || mat == Material.CAKE_BLOCK || mat == Material.WATER || mat == Material.LAVA) if (mat == Material.WOODEN_DOOR || mat == Material.IRON_DOOR_BLOCK || mat == Material.FIRE || mat == Material.CAKE_BLOCK || mat == Material.WATER || mat == Material.LAVA)
{ {
blocks.remove(b); blocks.remove(b);
@ -1112,26 +1115,19 @@ public class Arena
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
/*if (running && livePlayers.contains(event.getPlayer())) if (!livePlayers.contains(event.getPlayer()))
return;
if (running)
{ {
Player p = event.getPlayer(); if (event.hasBlock() && event.getClickedBlock().getType() == Material.SAPLING)
Action a = event.getAction(); addTrunkAndLeaves(event.getClickedBlock());
if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK)
{
if (p.getItemInHand().getType() == Material.BOW)
p.shootArrow();
event.setUseItemInHand(Result.DENY);
event.setCancelled(true);
}
return; return;
}*/ }
if (running || !livePlayers.contains(event.getPlayer()))
return;
Player p = event.getPlayer();
Action a = event.getAction(); Action a = event.getAction();
if ((a == Action.RIGHT_CLICK_AIR) || (a == Action.RIGHT_CLICK_BLOCK)) Player p = event.getPlayer();
if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK)
{ {
event.setUseItemInHand(Result.DENY); event.setUseItemInHand(Result.DENY);
event.setCancelled(true); event.setCancelled(true);
@ -1363,16 +1359,39 @@ public class Arena
public void delayRestoreInventory(final Player p, final String method) public void delayRestoreInventory(final Player p, final String method)
{ {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
new Runnable() new Runnable()
{
public void run()
{ {
public void run() if (method.equals("restoreInventory"))
{ MAUtils.restoreInventory(p);
if (method.equals("restoreInventory")) else if (method.equals("giveRewards"))
MAUtils.restoreInventory(p); MAUtils.giveRewards(p, rewardMap.get(p), plugin);
else if (method.equals("giveRewards")) }
MAUtils.giveRewards(p, rewardMap.get(p), plugin); }, 10);
} }
}, 10);
public void addTrunkAndLeaves(Block b)
{
final int x = b.getX();
final int y = b.getY();
final int z = b.getZ();
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
new Runnable()
{
public void run()
{
List<Block> result = new LinkedList<Block>();
for (int i = x-2; i <= x+2; i++)
for (int j = y; j <= y+10; j++)
for (int k = z-2; k <= z+2; k++)
if (world.getBlockAt(i,j,k).getType() == Material.LOG || world.getBlockAt(i,j,k).getType() == Material.LEAVES)
result.add(world.getBlockAt(i,j,k));
if (running) blocks.addAll(result);
}
}, 10);
} }
public boolean canAfford(Player p) public boolean canAfford(Player p)

View File

@ -396,6 +396,40 @@ public class MACommands implements CommandExecutor
return true; return true;
} }
/*
* Kick player from whichever arena they are in.
*/
if (base.equals("kick"))
{
if (!console && !(player && plugin.has(p, "mobarena.admin.kick")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
return true;
}
if (arg1.isEmpty())
{
MAUtils.tellPlayer(sender, "Usage: /ma kick <player>");
return true;
}
Arena arena = am.getArenaWithPlayer(arg1);
if (arena == null)
{
MAUtils.tellPlayer(sender, "That player is not in an arena.");
return true;
}
else
{
Player pl = server.getPlayer(arg1);
am.arenaMap.remove(pl);
arena.playerLeave(pl);
MAUtils.tellPlayer(sender, "Player '" + arg1 + "' was kicked from arena '" + arena.configName() + "'.");
MAUtils.tellPlayer(pl, "You were kicked by " + ((player) ? p.getName() : "the server."));
return true;
}
}
/* /*
* Restore a player's inventory. * Restore a player's inventory.
*/ */

View File

@ -180,6 +180,9 @@ public class MASpawnThread implements Runnable
LivingEntity e = arena.world.spawnCreature(loc,mob); LivingEntity e = arena.world.spawnCreature(loc,mob);
arena.monsters.add(e); arena.monsters.add(e);
if (mob == CreatureType.WOLF)
((Wolf)e).setOwner(null);
// Grab a random target. // Grab a random target.
Creature c = (Creature) e; Creature c = (Creature) e;
c.setTarget(getClosestPlayer(e)); c.setTarget(getClosestPlayer(e));
@ -253,7 +256,7 @@ public class MASpawnThread implements Runnable
arena.monsters.add(e); arena.monsters.add(e);
if (slime) ((Slime)e).setSize(2); if (slime) ((Slime)e).setSize(2);
if (wolf) ((Wolf)e).setAngry(true); if (wolf) { ((Wolf)e).setAngry(true); ((Wolf)e).setOwner(null); }
if (ghast) ((Ghast)e).setHealth(Math.min(noOfPlayers*25, 200)); if (ghast) ((Ghast)e).setHealth(Math.min(noOfPlayers*25, 200));
if (creeper) ((Creeper)e).setPowered(true); if (creeper) ((Creeper)e).setPowered(true);
@ -358,7 +361,6 @@ public class MASpawnThread implements Runnable
continue; continue;
} }
dist = p.getLocation().distanceSquared(e.getLocation()); dist = p.getLocation().distanceSquared(e.getLocation());
//double dist = MAUtils.distance(p.getLocation(), e.getLocation());
if (dist < current && dist < MobArena.MIN_PLAYER_DISTANCE) if (dist < current && dist < MobArena.MIN_PLAYER_DISTANCE)
{ {
current = dist; current = dist;
@ -377,6 +379,9 @@ public class MASpawnThread implements Runnable
LivingEntity target; LivingEntity target;
for (Entity e : arena.monsters) for (Entity e : arena.monsters)
{ {
if (!(e instanceof Creature))
continue;
c = (Creature) e; c = (Creature) e;
target = c.getTarget(); target = c.getTarget();

View File

@ -173,7 +173,7 @@ public class MAUtils
public static List<ItemStack> makeItemStackList(String string) public static List<ItemStack> makeItemStackList(String string)
{ {
List<ItemStack> result = new LinkedList<ItemStack>(); List<ItemStack> result = new LinkedList<ItemStack>();
if (string == null) return result; if (string == null || string.isEmpty()) return result;
// Trim commas and whitespace, and split items by commas // Trim commas and whitespace, and split items by commas
string = string.trim(); string = string.trim();