Added player-limit, fixed a few bugs

This commit is contained in:
Garbage Mule
2011-07-06 20:17:36 +02:00
parent 93e3049f4f
commit 6b457833e1
6 changed files with 30 additions and 27 deletions
BIN
View File
Binary file not shown.
+14 -26
View File
@@ -89,8 +89,8 @@ public class Arena
protected int spawnMonsters;
protected boolean allowMonsters, allowAnimals;
// Global settings
protected int repairDelay;
// Other settings
protected int repairDelay, playerLimit;
protected List<String> classes = new LinkedList<String>();
protected Map<Player,Location> locations = new HashMap<Player,Location>();
@@ -314,25 +314,9 @@ public class Arena
listener.onPlayerLeave(p);
}
public void playerQuit(Player p)
{
p.teleport(locations.get(p));
readyPlayers.remove(p);
livePlayers.remove(p);
deadPlayers.remove(p);
specPlayers.remove(p);
removePets(p);
if (!emptyInvJoin) MAUtils.restoreInventory(p);
if (running && livePlayers.isEmpty())
endArena();
else if (!readyPlayers.isEmpty() && readyPlayers.equals(livePlayers))
startArena();
}
public void playerDeath(final Player p)
{
p.teleport(arenaLoc); // This will force players to drop any items held
p.teleport(spectatorLoc);
p.setFireTicks(0);
p.setHealth(20);
@@ -482,6 +466,7 @@ public class Arena
pvp = config.getBoolean(arenaPath + "pvp-enabled", false);
monsterInfight = config.getBoolean(arenaPath + "monster-infight", false);
allowWarp = config.getBoolean(arenaPath + "allow-teleporting", false);
playerLimit = config.getInt(arenaPath + "player-limit", 0);
repairDelay = config.getInt(arenaPath + "repair-delay", 5);
waveDelay = config.getInt(arenaPath + "first-wave-delay", 5) * 20;
waveInterval = config.getInt(arenaPath + "wave-interval", 20) * 20;
@@ -1049,21 +1034,23 @@ public class Arena
public void onPlayerQuit(PlayerQuitEvent event)
{
Player p = event.getPlayer();
if (!enabled || !getAllPlayers().contains(p))
if (!enabled || !livePlayers.contains(p))
return;
MAUtils.clearInventory(p);
playerQuit(p);
//MAUtils.clearInventory(p);
plugin.getAM().arenaMap.remove(p);
playerLeave(p);
}
public void onPlayerKick(PlayerKickEvent event)
{
Player p = event.getPlayer();
if (!enabled || !getAllPlayers().contains(p))
if (!enabled || !livePlayers.contains(p))
return;
MAUtils.clearInventory(p);
playerQuit(p);
//MAUtils.clearInventory(p);
plugin.getAM().arenaMap.remove(p);
playerLeave(p);
}
// Teleport Listener
@@ -1210,8 +1197,9 @@ public class Arena
for (Player p : livePlayers)
{
MAUtils.clearInventory(p);
playerDeath(p);
MAUtils.tellPlayer(p, MAMessages.get(Msg.FORCE_END_IDLE));
p.damage(32768);
//playerDeath(p);
}
}
}, maxIdleTime);
@@ -261,6 +261,7 @@ public class ArenaMaster
config.setProperty("arenas." + configName + ".settings.pvp-enabled", false);
config.setProperty("arenas." + configName + ".settings.monster-infight", false);
config.setProperty("arenas." + configName + ".settings.allow-teleporting", false);
config.setProperty("arenas." + configName + ".settings.player-limit", 0);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.repair-delay", 5);
@@ -137,6 +137,8 @@ public class MACommands implements CommandExecutor
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_IS_RUNNING));
else if (arena.livePlayers.contains(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ALREADY_PLAYING));
else if (arena.playerLimit > 0 && arena.livePlayers.size() >= arena.playerLimit)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_LIMIT_REACHED));
else if (arena.emptyInvJoin && !MAUtils.hasEmptyInventory(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_EMPTY_INV));
else if (!arena.emptyInvJoin && !MAUtils.storeInventory(p))
@@ -147,6 +149,8 @@ public class MACommands implements CommandExecutor
if (error)
return true;
System.out.println("playerLimit: " + arena.playerLimit + ", livePlayers: " + arena.livePlayers.size());
am.arenaMap.put(p,arena);
arena.playerJoin(p, p.getLocation());
@@ -179,6 +183,8 @@ public class MACommands implements CommandExecutor
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_IS_RUNNING));
else if (arena.livePlayers.contains(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ALREADY_PLAYING));
else if (arena.playerLimit > 0 && arena.livePlayers.size() >= arena.playerLimit)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_LIMIT_REACHED));
else if (arena.emptyInvJoin && !MAUtils.hasEmptyInventory(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_EMPTY_INV));
else if (!arena.emptyInvJoin && !MAUtils.storeInventory(p))
+3 -1
View File
@@ -25,6 +25,7 @@ public class MAMessages
JOIN_ARENA_IS_RUNNING,
JOIN_ALREADY_PLAYING,
JOIN_ARG_NEEDED,
JOIN_PLAYER_LIMIT_REACHED,
JOIN_EMPTY_INV,
JOIN_STORE_INV_FAIL,
LEAVE_PLAYER_LEFT,
@@ -76,6 +77,7 @@ public class MAMessages
defaults.put(Msg.JOIN_ALREADY_PLAYING, "You are already playing!");
defaults.put(Msg.JOIN_ARG_NEEDED, "You must specify an arena. Type /ma arenas for a list.");
defaults.put(Msg.JOIN_EMPTY_INV, "You must empty your inventory to join the arena.");
defaults.put(Msg.JOIN_PLAYER_LIMIT_REACHED, "The player limit of this arena has been reached.");
defaults.put(Msg.JOIN_STORE_INV_FAIL, "Failed to store inventory. Try again.");
defaults.put(Msg.JOIN_PLAYER_JOINED, "You joined the arena. Have fun!");
defaults.put(Msg.LEAVE_NOT_PLAYING, "You are not in the arena.");
@@ -108,7 +110,7 @@ public class MAMessages
defaults.put(Msg.MISC_LIST_PLAYERS, "Live players: %");
defaults.put(Msg.MISC_LIST_ARENAS, "Available arenas: %");
defaults.put(Msg.MISC_COMMAND_NOT_ALLOWED, "You can't use that command in the arena!");
defaults.put(Msg.MISC_NO_ACCESS, "You don't have access to this comand.");
defaults.put(Msg.MISC_NO_ACCESS, "You don't have access to this command.");
defaults.put(Msg.MISC_NONE, "<none>");
}
@@ -330,6 +330,12 @@ public class MAUtils
ItemStack[] armor = p.getInventory().getArmorContents();
ItemStack[] items = p.getInventory().getContents();
/*p.getLocation().getBlock().getRelative(BlockFace.UP).setType(Material.CHEST);
Chest chest = (Chest) p.getLocation().getBlock().getRelative(BlockFace.UP).getState();
for (ItemStack stack : p.getInventory().getContents())
if (stack != null)
chest.getInventory().addItem(stack);*/
String invPath = "plugins" + sep + "MobArena" + sep + "inventories";
new File(invPath).mkdir();
File backupFile = new File(invPath + sep + p.getName() + ".inv");