Stupid git...
This commit is contained in:
@@ -5,7 +5,6 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -13,6 +12,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@@ -34,6 +34,9 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.MAMessages.Msg;
|
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||||
|
import com.garbagemule.MobArena.util.WaveUtils;
|
||||||
|
import com.garbagemule.MobArena.waves.Wave;
|
||||||
|
import com.garbagemule.MobArena.waves.Wave.WaveBranch;
|
||||||
|
|
||||||
public class Arena
|
public class Arena
|
||||||
{
|
{
|
||||||
@@ -55,11 +58,24 @@ public class Arena
|
|||||||
protected Map<Player,String> classMap;
|
protected Map<Player,String> classMap;
|
||||||
protected Map<String,List<ItemStack>> classItems, classArmor;
|
protected Map<String,List<ItemStack>> classItems, classArmor;
|
||||||
protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses;
|
protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses;
|
||||||
protected Map<Player,List<ItemStack>> rewardMap;
|
|
||||||
protected List<ItemStack> entryFee;
|
protected List<ItemStack> entryFee;
|
||||||
|
|
||||||
|
// NEW IMPLEMENTATION
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Player sets
|
||||||
|
protected Set<Player> arenaPlayers, lobbyPlayers, readyPlayers, specPlayers;
|
||||||
|
// Wave stuff
|
||||||
|
//protected TreeSet<SingleWave> singleWaves;
|
||||||
|
//protected TreeSet<RecurrentWave> recurrentWaves;
|
||||||
|
protected TreeSet<Wave> singleWaves;
|
||||||
|
protected TreeSet<Wave> recurrentWaves;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// NEW IMPLEMENTATION
|
||||||
|
|
||||||
// Arena sets/maps
|
// Arena sets/maps
|
||||||
protected Set<Player> arenaPlayers, lobbyPlayers, readyPlayers, specPlayers, hasPaid, rewardedPlayers, notifyPlayers, randoms;
|
protected Set<Player> hasPaid, rewardedPlayers, notifyPlayers, randoms;
|
||||||
protected Set<LivingEntity> monsters;
|
protected Set<LivingEntity> monsters;
|
||||||
protected Set<Block> blocks;
|
protected Set<Block> blocks;
|
||||||
protected Set<Wolf> pets;
|
protected Set<Wolf> pets;
|
||||||
@@ -71,17 +87,13 @@ public class Arena
|
|||||||
protected boolean allowMonsters, allowAnimals;
|
protected boolean allowMonsters, allowAnimals;
|
||||||
|
|
||||||
// Other settings
|
// Other settings
|
||||||
protected int repairDelay, playerLimit, joinDistance;
|
protected int repairDelay, minPlayers, maxPlayers, joinDistance;
|
||||||
protected List<String> classes = new LinkedList<String>();
|
protected List<String> classes = new LinkedList<String>();
|
||||||
protected Map<Player,Location> locations = new HashMap<Player,Location>();
|
protected Map<Player,Location> locations = new HashMap<Player,Location>();
|
||||||
|
protected Map<Player,Integer> healthMap = new HashMap<Player,Integer>();
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
protected ArenaLog log;
|
protected ArenaLog log;
|
||||||
protected List<String> classDistribution = new LinkedList<String>();
|
|
||||||
protected Map<Player,Integer> waveMap = new HashMap<Player,Integer>();
|
|
||||||
protected Map<Player,Integer> killMap = new HashMap<Player,Integer>();
|
|
||||||
protected Timestamp startTime;
|
|
||||||
protected Timestamp endTime;
|
|
||||||
|
|
||||||
protected MAListener eventListener;
|
protected MAListener eventListener;
|
||||||
|
|
||||||
@@ -96,7 +108,6 @@ public class Arena
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
plugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
|
plugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
|
||||||
log = new ArenaLog(plugin, this);
|
|
||||||
|
|
||||||
arenaPlayers = new HashSet<Player>();
|
arenaPlayers = new HashSet<Player>();
|
||||||
lobbyPlayers = new HashSet<Player>();
|
lobbyPlayers = new HashSet<Player>();
|
||||||
@@ -111,7 +122,6 @@ public class Arena
|
|||||||
petMap = new HashMap<Player,Integer>();
|
petMap = new HashMap<Player,Integer>();
|
||||||
classMap = new HashMap<Player,String>();
|
classMap = new HashMap<Player,String>();
|
||||||
randoms = new HashSet<Player>();
|
randoms = new HashSet<Player>();
|
||||||
rewardMap = new HashMap<Player,List<ItemStack>>();
|
|
||||||
repairList = new LinkedList<int[]>();
|
repairList = new LinkedList<int[]>();
|
||||||
|
|
||||||
running = false;
|
running = false;
|
||||||
@@ -148,9 +158,7 @@ public class Arena
|
|||||||
{
|
{
|
||||||
p.teleport(arenaLoc);
|
p.teleport(arenaLoc);
|
||||||
p.setHealth(20);
|
p.setHealth(20);
|
||||||
rewardMap.put(p, new LinkedList<ItemStack>());
|
//rewardMap.put(p, new LinkedList<ItemStack>());
|
||||||
waveMap.put(p, 0);
|
|
||||||
killMap.put(p, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn pets.
|
// Spawn pets.
|
||||||
@@ -160,8 +168,8 @@ public class Arena
|
|||||||
startSpawning();
|
startSpawning();
|
||||||
|
|
||||||
// Start logging
|
// Start logging
|
||||||
if (logging)
|
log = new ArenaLog(plugin, this);
|
||||||
log.start();
|
log.start();
|
||||||
|
|
||||||
// Set the boolean.
|
// Set the boolean.
|
||||||
running = true;
|
running = true;
|
||||||
@@ -183,13 +191,9 @@ public class Arena
|
|||||||
// Set the boolean.
|
// Set the boolean.
|
||||||
running = false;
|
running = false;
|
||||||
|
|
||||||
// Stop logging.
|
log.end();
|
||||||
if (logging)
|
log.saveSessionData();
|
||||||
{
|
log.updateArenaTotals();
|
||||||
log.end();
|
|
||||||
log.serialize();
|
|
||||||
log.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop spawning.
|
// Stop spawning.
|
||||||
stopSpawning();
|
stopSpawning();
|
||||||
@@ -210,9 +214,7 @@ public class Arena
|
|||||||
notifyPlayers.clear();
|
notifyPlayers.clear();
|
||||||
rewardedPlayers.clear();
|
rewardedPlayers.clear();
|
||||||
classMap.clear();
|
classMap.clear();
|
||||||
rewardMap.clear();
|
//rewardMap.clear();
|
||||||
waveMap.clear();
|
|
||||||
killMap.clear();
|
|
||||||
spawnThread = null;
|
spawnThread = null;
|
||||||
|
|
||||||
// Notify listeners.
|
// Notify listeners.
|
||||||
@@ -224,9 +226,12 @@ public class Arena
|
|||||||
|
|
||||||
public void forceStart()
|
public void forceStart()
|
||||||
{
|
{
|
||||||
|
if (running)
|
||||||
|
return;
|
||||||
|
|
||||||
// Set operations.
|
// Set operations.
|
||||||
Set<Player> tmp = new HashSet<Player>();
|
Set<Player> tmp = new HashSet<Player>();
|
||||||
//tmp.addAll(livePlayers);
|
tmp.addAll(lobbyPlayers);
|
||||||
tmp.removeAll(readyPlayers);
|
tmp.removeAll(readyPlayers);
|
||||||
|
|
||||||
// Force leave.
|
// Force leave.
|
||||||
@@ -239,11 +244,13 @@ public class Arena
|
|||||||
|
|
||||||
public void forceEnd()
|
public void forceEnd()
|
||||||
{
|
{
|
||||||
|
if (!running)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Bukkit.getServer().getScheduler().cancelTask(spawnTaskId);
|
||||||
|
|
||||||
for (Player p : getAllPlayers())
|
for (Player p : getAllPlayers())
|
||||||
{
|
|
||||||
plugin.getAM().arenaMap.remove(p);
|
|
||||||
playerLeave(p);
|
playerLeave(p);
|
||||||
}
|
|
||||||
|
|
||||||
for (Entity e : monsters)
|
for (Entity e : monsters)
|
||||||
e.remove();
|
e.remove();
|
||||||
@@ -252,9 +259,7 @@ public class Arena
|
|||||||
lobbyPlayers.clear();
|
lobbyPlayers.clear();
|
||||||
readyPlayers.clear();
|
readyPlayers.clear();
|
||||||
|
|
||||||
rewardMap.clear();
|
//rewardMap.clear();
|
||||||
waveMap.clear();
|
|
||||||
killMap.clear();
|
|
||||||
monsters.clear();
|
monsters.clear();
|
||||||
|
|
||||||
spawnTaskId = -1;
|
spawnTaskId = -1;
|
||||||
@@ -262,105 +267,68 @@ public class Arena
|
|||||||
|
|
||||||
public void playerJoin(Player p, Location loc)
|
public void playerJoin(Player p, Location loc)
|
||||||
{
|
{
|
||||||
if (!locations.containsKey(p))
|
storePlayerData(p, loc);
|
||||||
locations.put(p,loc);
|
p.setHealth(20);
|
||||||
|
|
||||||
// Update chunk.
|
|
||||||
updateChunk(lobbyLoc);
|
|
||||||
|
|
||||||
MAUtils.sitPets(p);
|
MAUtils.sitPets(p);
|
||||||
lobbyPlayers.add(p);
|
movePlayerToLobby(p);
|
||||||
p.teleport(lobbyLoc);
|
|
||||||
|
|
||||||
// Notify listeners.
|
|
||||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
|
||||||
listener.onPlayerJoin(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playerReady(Player p)
|
public void playerReady(Player p)
|
||||||
{
|
{
|
||||||
readyPlayers.add(p);
|
readyPlayers.add(p);
|
||||||
|
|
||||||
|
if (minPlayers > 0 && lobbyPlayers.size() < minPlayers)
|
||||||
|
{
|
||||||
|
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_NOT_ENOUGH_PLAYERS, "" + minPlayers));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
startArena();
|
startArena();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playerLeave(Player p)
|
public void playerLeave(Player p)
|
||||||
{
|
{
|
||||||
// Clear class inventory, restore old inventory and fork over rewards.
|
if (arenaPlayers.contains(p) || lobbyPlayers.contains(p))
|
||||||
restoreInvAndGiveRewards(p, (arenaPlayers.contains(p) || lobbyPlayers.contains(p)));
|
MAUtils.clearInventory(p);
|
||||||
|
|
||||||
// Grab the player's entry location, and warp them there.
|
restoreInvAndGiveRewards(p);
|
||||||
Location entry = locations.get(p);
|
if (log.players.get(p) != null) log.players.get(p).lastWave = spawnThread.wave - 1;
|
||||||
if (entry != null)
|
movePlayerToEntry(p);
|
||||||
{
|
finishWithPlayer(p);
|
||||||
updateChunk(entry);
|
|
||||||
p.teleport(entry);
|
|
||||||
}
|
|
||||||
locations.remove(p);
|
|
||||||
|
|
||||||
// Remove from the arenaMap and all the sets.
|
|
||||||
plugin.getAM().arenaMap.remove(p);
|
|
||||||
removePlayer(p);
|
|
||||||
|
|
||||||
// End the arena if conditions are met.
|
|
||||||
endArena();
|
endArena();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playerDeath(Player p)
|
public void playerDeath(Player p)
|
||||||
{
|
{
|
||||||
// If spectate-on-death: false, pass on to playerLeave.
|
MAUtils.clearInventory(p);
|
||||||
if (!specOnDeath)
|
restoreInvAndGiveRewards(p);
|
||||||
|
log.players.get(p).lastWave = spawnThread.wave - 1;
|
||||||
|
|
||||||
|
if (specOnDeath)
|
||||||
{
|
{
|
||||||
p.teleport(arenaLoc);
|
resetPlayer(p);
|
||||||
playerLeave(p);
|
movePlayerToSpec(p);
|
||||||
return;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
movePlayerToEntry(p);
|
||||||
|
finishWithPlayer(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear class inventory, restore old inventory and fork over rewards.
|
|
||||||
restoreInvAndGiveRewards(p, true);
|
|
||||||
|
|
||||||
// Remove player from sets, warp to spectator area, then add to specPlayers.
|
|
||||||
removePlayer(p);
|
|
||||||
p.teleport(arenaLoc); // This will sometimes force players to drop any items held (not confirmed)
|
|
||||||
p.teleport(spectatorLoc);
|
|
||||||
specPlayers.add(p);
|
|
||||||
|
|
||||||
// Update the monster targets.
|
|
||||||
if (running && spawnThread != null)
|
if (running && spawnThread != null)
|
||||||
spawnThread.updateTargets();
|
spawnThread.updateTargets();
|
||||||
|
|
||||||
// Announce and notify
|
|
||||||
MAUtils.tellAll(this, MAMessages.get(Msg.PLAYER_DIED, p.getName()));
|
MAUtils.tellAll(this, MAMessages.get(Msg.PLAYER_DIED, p.getName()));
|
||||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() {
|
||||||
listener.onPlayerDeath(p);
|
|
||||||
|
|
||||||
// End the arena if conditions are met.
|
|
||||||
endArena();
|
endArena();
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playerSpec(Player p, Location loc)
|
public void playerSpec(Player p, Location loc)
|
||||||
{
|
{
|
||||||
if (!locations.containsKey(p))
|
storePlayerData(p, loc);
|
||||||
locations.put(p,loc);
|
|
||||||
|
|
||||||
MAUtils.sitPets(p);
|
MAUtils.sitPets(p);
|
||||||
specPlayers.add(p);
|
movePlayerToSpec(p);
|
||||||
p.teleport(spectatorLoc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removePlayer(Player p)
|
|
||||||
{
|
|
||||||
// Heal and put out fire.
|
|
||||||
p.setFireTicks(0);
|
|
||||||
p.setHealth(20);
|
|
||||||
|
|
||||||
// Remove pets.
|
|
||||||
removePets(p);
|
|
||||||
|
|
||||||
// readyPlayers before lobbyPlayers because of startArena sanity-checks
|
|
||||||
readyPlayers.remove(p);
|
|
||||||
specPlayers.remove(p);
|
|
||||||
arenaPlayers.remove(p);
|
|
||||||
lobbyPlayers.remove(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnPets()
|
private void spawnPets()
|
||||||
@@ -424,31 +392,26 @@ public class Arena
|
|||||||
|
|
||||||
public void playerKill(Player p)
|
public void playerKill(Player p)
|
||||||
{
|
{
|
||||||
if (p == null || killMap.get(p) == null)
|
if (p == null || log.players.get(p) == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
killMap.put(p, killMap.get(p) + 1);
|
log.players.get(p).kills++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restoreInvAndGiveRewards(final Player p, final boolean clear)
|
public void restoreInvAndGiveRewards(final Player p)
|
||||||
{
|
{
|
||||||
final List<ItemStack> rewards = rewardMap.get(p);
|
final List<ItemStack> rewards = log.players.get(p).rewards;
|
||||||
|
//final List<ItemStack> rewards = rewardMap.get(p);
|
||||||
final boolean hadRewards = rewardedPlayers.contains(p);
|
final boolean hadRewards = rewardedPlayers.contains(p);
|
||||||
|
|
||||||
if (clear) MAUtils.clearInventory(p);
|
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||||
new Runnable()
|
new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
//if (clear)
|
|
||||||
// MAUtils.clearInventory(p);
|
|
||||||
|
|
||||||
if (!emptyInvJoin)
|
if (!emptyInvJoin)
|
||||||
MAUtils.restoreInventory(p);
|
MAUtils.restoreInventory(p);
|
||||||
|
|
||||||
//if (rewardedPlayers.contains(p))
|
|
||||||
if (hadRewards)
|
if (hadRewards)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -459,6 +422,70 @@ public class Arena
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void storePlayerData(Player p, Location loc)
|
||||||
|
{
|
||||||
|
plugin.getAM().arenaMap.put(p, this);
|
||||||
|
|
||||||
|
if (!locations.containsKey(p))
|
||||||
|
locations.put(p, loc);
|
||||||
|
|
||||||
|
if (!healthMap.containsKey(p))
|
||||||
|
healthMap.put(p, p.getHealth());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void movePlayerToLobby(Player p)
|
||||||
|
{
|
||||||
|
updateChunk(lobbyLoc);
|
||||||
|
lobbyPlayers.add(p);
|
||||||
|
p.teleport(lobbyLoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void movePlayerToSpec(Player p)
|
||||||
|
{
|
||||||
|
updateChunk(spectatorLoc);
|
||||||
|
specPlayers.add(p);
|
||||||
|
p.teleport(spectatorLoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void movePlayerToEntry(Player p)
|
||||||
|
{
|
||||||
|
Location entry = locations.get(p);
|
||||||
|
if (entry == null) return;
|
||||||
|
|
||||||
|
updateChunk(entry);
|
||||||
|
p.teleport(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPlayer(Player p)
|
||||||
|
{
|
||||||
|
if (healthMap.containsKey(p))
|
||||||
|
p.setHealth(healthMap.remove(p));
|
||||||
|
|
||||||
|
removePlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlayer(Player p)
|
||||||
|
{
|
||||||
|
// Put out fire.
|
||||||
|
p.setFireTicks(0);
|
||||||
|
|
||||||
|
// Remove pets.
|
||||||
|
removePets(p);
|
||||||
|
|
||||||
|
// readyPlayers before lobbyPlayers because of startArena sanity-checks
|
||||||
|
readyPlayers.remove(p);
|
||||||
|
specPlayers.remove(p);
|
||||||
|
arenaPlayers.remove(p);
|
||||||
|
lobbyPlayers.remove(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finishWithPlayer(Player p)
|
||||||
|
{
|
||||||
|
locations.remove(p);
|
||||||
|
plugin.getAM().arenaMap.remove(p);
|
||||||
|
resetPlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*////////////////////////////////////////////////////////////////////
|
/*////////////////////////////////////////////////////////////////////
|
||||||
@@ -602,7 +629,8 @@ public class Arena
|
|||||||
specOnDeath = config.getBoolean(arenaPath + "spectate-on-death", true);
|
specOnDeath = config.getBoolean(arenaPath + "spectate-on-death", true);
|
||||||
shareInArena = config.getBoolean(arenaPath + "share-items-in-arena", true);
|
shareInArena = config.getBoolean(arenaPath + "share-items-in-arena", true);
|
||||||
joinDistance = config.getInt(arenaPath + "max-join-distance", 0);
|
joinDistance = config.getInt(arenaPath + "max-join-distance", 0);
|
||||||
playerLimit = config.getInt(arenaPath + "player-limit", 0);
|
minPlayers = config.getInt(arenaPath + "min-players", 0);
|
||||||
|
maxPlayers = config.getInt(arenaPath + "max-players", 0);
|
||||||
repairDelay = config.getInt(arenaPath + "repair-delay", 5);
|
repairDelay = config.getInt(arenaPath + "repair-delay", 5);
|
||||||
waveDelay = config.getInt(arenaPath + "first-wave-delay", 5) * 20;
|
waveDelay = config.getInt(arenaPath + "first-wave-delay", 5) * 20;
|
||||||
waveInterval = config.getInt(arenaPath + "wave-interval", 20) * 20;
|
waveInterval = config.getInt(arenaPath + "wave-interval", 20) * 20;
|
||||||
@@ -624,6 +652,23 @@ public class Arena
|
|||||||
spectatorLoc = MAUtils.getArenaCoord(config, world, configName, "spectator");
|
spectatorLoc = MAUtils.getArenaCoord(config, world, configName, "spectator");
|
||||||
spawnpoints = MAUtils.getArenaSpawnpoints(config, world, configName);
|
spawnpoints = MAUtils.getArenaSpawnpoints(config, world, configName);
|
||||||
|
|
||||||
|
// NEW WAVES
|
||||||
|
singleWaves = WaveUtils.getWaves(config, configName, WaveBranch.SINGLE);
|
||||||
|
recurrentWaves = WaveUtils.getWaves(config, configName, WaveBranch.RECURRENT);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("ARENA: " + configName);
|
||||||
|
System.out.println("Single waves");
|
||||||
|
int si = singleWaves.size();
|
||||||
|
for (int i = 0; i < si; i++)
|
||||||
|
System.out.println("- " + singleWaves.pollFirst());
|
||||||
|
System.out.println("Reccurent waves");
|
||||||
|
for (Wave w : recurrentWaves)
|
||||||
|
System.out.println("- " + w);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
|
||||||
classes = plugin.getAM().classes;
|
classes = plugin.getAM().classes;
|
||||||
classItems = plugin.getAM().classItems;
|
classItems = plugin.getAM().classItems;
|
||||||
classArmor = plugin.getAM().classArmor;
|
classArmor = plugin.getAM().classArmor;
|
||||||
@@ -847,8 +892,8 @@ public class Arena
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
// Make sure to remove any dead/removed entities first.
|
// Make sure to remove any dead/removed entities first.
|
||||||
List<Entity> tmp = new LinkedList<Entity>(monsters);
|
List<Entity> ms = new LinkedList<Entity>(monsters);
|
||||||
for (Entity e : tmp)
|
for (Entity e : ms)
|
||||||
if (e.isDead())
|
if (e.isDead())
|
||||||
monsters.remove(e);
|
monsters.remove(e);
|
||||||
|
|
||||||
@@ -860,7 +905,8 @@ public class Arena
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear all player inventories, and "kill" all players.
|
// Clear all player inventories, and "kill" all players.
|
||||||
for (Player p : arenaPlayers)
|
List<Player> ps = new LinkedList<Player>(arenaPlayers);
|
||||||
|
for (Player p : ps)
|
||||||
{
|
{
|
||||||
MAUtils.clearInventory(p);
|
MAUtils.clearInventory(p);
|
||||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.FORCE_END_IDLE));
|
MAUtils.tellPlayer(p, MAMessages.get(Msg.FORCE_END_IDLE));
|
||||||
@@ -969,6 +1015,12 @@ public class Arena
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
MAUtils.giveItems(p, entryFee, false, plugin);
|
MAUtils.giveItems(p, entryFee, false, plugin);
|
||||||
|
hasPaid.remove(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getClasses()
|
||||||
|
{
|
||||||
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,134 +1,120 @@
|
|||||||
package com.garbagemule.MobArena;
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.util.data.PlainText;
|
||||||
|
import com.garbagemule.MobArena.util.data.Totals;
|
||||||
|
|
||||||
public class ArenaLog
|
public class ArenaLog
|
||||||
{
|
{
|
||||||
protected MobArena plugin;
|
public MobArena plugin;
|
||||||
protected Arena arena;
|
public Arena arena;
|
||||||
protected List<String> log, classDistribution;
|
public Timestamp startTime, endTime;
|
||||||
protected Timestamp startTime, endTime;
|
public int lastWave;
|
||||||
|
|
||||||
|
public Map<Player,ArenaPlayer> players;
|
||||||
|
public Map<String,Integer> distribution;
|
||||||
|
|
||||||
public ArenaLog(MobArena plugin, Arena arena)
|
public ArenaLog(MobArena plugin, Arena arena)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.arena = arena;
|
this.arena = arena;
|
||||||
log = new LinkedList<String>();
|
this.players = new HashMap<Player,ArenaPlayer>(arena.arenaPlayers.size());
|
||||||
classDistribution = new LinkedList<String>();
|
this.distribution = new HashMap<String,Integer>(arena.classes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start()
|
public void start()
|
||||||
{
|
{
|
||||||
startTime = new Timestamp((new Date()).getTime());
|
// Populate the data maps
|
||||||
|
populatePlayerMap();
|
||||||
|
populateDistributionMap();
|
||||||
|
|
||||||
// Class distribution
|
// Grab the current timestamp
|
||||||
int length = 0;
|
startTime = new Timestamp((new Date()).getTime());
|
||||||
for (String c : plugin.getAM().classes)
|
|
||||||
if (c.length() > length)
|
|
||||||
length = c.length();
|
|
||||||
|
|
||||||
List<String> classList = new LinkedList<String>(arena.classMap.values());
|
|
||||||
for (String c : plugin.getAM().classes)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
int id = classList.indexOf(c);
|
|
||||||
while (id != -1)
|
|
||||||
{
|
|
||||||
classList.remove(id);
|
|
||||||
count++;
|
|
||||||
id = classList.indexOf(c);
|
|
||||||
}
|
|
||||||
//int percentage = (int) (((double) count) / ((double) arena.livePlayers.size())) * 100;
|
|
||||||
int percentage = (int) (((double) count) / ((double) arena.arenaPlayers.size())) * 100;
|
|
||||||
classDistribution.add(MAUtils.padRight(c + ": ", length + 2) + MAUtils.padLeft("" + count, 2) + " (" + percentage + "%)");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void end()
|
public void end()
|
||||||
{
|
{
|
||||||
|
lastWave = arena.spawnThread.wave - 1;
|
||||||
endTime = new Timestamp((new Date()).getTime());
|
endTime = new Timestamp((new Date()).getTime());
|
||||||
|
|
||||||
// General stuff
|
|
||||||
log.add("--------------------------------------------------- ENTRY ---");
|
|
||||||
log.add("Start: " + startTime);
|
|
||||||
log.add("End: " + endTime);
|
|
||||||
log.add("Duration: " + MAUtils.getDuration(endTime.getTime() - startTime.getTime()));
|
|
||||||
log.add("Last wave: " + (arena.spawnThread.wave - 1));
|
|
||||||
log.add(" ");
|
|
||||||
|
|
||||||
// Class distribution
|
|
||||||
log.add("Class Distribution: " + plugin.getAM().classes.size() + " classes");
|
|
||||||
for (String c : classDistribution)
|
|
||||||
log.add("- " + c);
|
|
||||||
classDistribution.clear();
|
|
||||||
log.add(" ");
|
|
||||||
|
|
||||||
// Player data
|
|
||||||
int NAME = 12; int CLASS = 0; int WAVE = 4; int KILLS = 5;
|
|
||||||
for (String c : plugin.getAM().classes)
|
|
||||||
if (c.length() > CLASS)
|
|
||||||
CLASS = c.length();
|
|
||||||
|
|
||||||
log.add("Player Data: " + arena.classMap.keySet().size() + " players");
|
|
||||||
log.add("- " + MAUtils.padRight("Name", NAME + 2, ' ') + MAUtils.padRight("Class", CLASS + 2, ' ') + MAUtils.padRight("Wave", WAVE + 2, ' ') + MAUtils.padRight("Kills", KILLS + 2, ' ') + "Rewards");
|
|
||||||
for (Map.Entry<Player,String> entry : arena.classMap.entrySet())
|
|
||||||
{
|
|
||||||
Player p = entry.getKey();
|
|
||||||
StringBuffer buffy = new StringBuffer();
|
|
||||||
buffy.append(" ");
|
|
||||||
// Name
|
|
||||||
String name = (p.getName().length() <= NAME) ? p.getName() : p.getName().substring(0, NAME+1);
|
|
||||||
buffy.append(MAUtils.padRight(name, NAME + 2, ' '));
|
|
||||||
// Class
|
|
||||||
buffy.append(MAUtils.padRight(entry.getValue(), CLASS + 2, ' '));
|
|
||||||
// Wave
|
|
||||||
buffy.append(MAUtils.padLeft(arena.waveMap.remove(p).toString(), WAVE, ' ') + " ");
|
|
||||||
// Kills
|
|
||||||
buffy.append(MAUtils.padLeft(arena.killMap.remove(p).toString(), KILLS, ' ') + " ");
|
|
||||||
// Rewards
|
|
||||||
buffy.append(MAUtils.listToString(arena.rewardMap.get(p), plugin));
|
|
||||||
log.add(buffy.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
log.add(" ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serialize()
|
/**
|
||||||
|
* Map players to ArenaPlayer objects.
|
||||||
|
*/
|
||||||
|
private void populatePlayerMap()
|
||||||
{
|
{
|
||||||
try
|
for (Player p : arena.arenaPlayers)
|
||||||
{
|
players.put(p, new ArenaPlayer(p, arena, plugin));
|
||||||
new File(plugin.getDataFolder() + File.separator + "logs").mkdir();
|
|
||||||
File logFile = new File(plugin.getDataFolder() + File.separator + "logs" + File.separator + arena.configName() + ".log");
|
|
||||||
if (logFile.exists())
|
|
||||||
logFile.createNewFile();
|
|
||||||
|
|
||||||
FileWriter fw = new FileWriter(logFile, true);
|
|
||||||
BufferedWriter bw = new BufferedWriter(fw);
|
|
||||||
for (String l : log)
|
|
||||||
{
|
|
||||||
bw.write(l);
|
|
||||||
bw.write(System.getProperty("line.separator"));
|
|
||||||
}
|
|
||||||
|
|
||||||
bw.close();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
System.out.println("[MobArena] ERROR! Could not create log file!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(String s) { log.add(s); }
|
/**
|
||||||
public void clear() { log.clear(); }
|
* Map classes to amounts of players playing as the classes.
|
||||||
|
*/
|
||||||
|
private void populateDistributionMap()
|
||||||
|
{
|
||||||
|
// Initialize the map
|
||||||
|
for (String c : arena.classes)
|
||||||
|
distribution.put(c,0);
|
||||||
|
|
||||||
|
// Count occurrences
|
||||||
|
for (String c : arena.classMap.values())
|
||||||
|
distribution.put(c,distribution.get(c) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the data of the current session according to the logging type.
|
||||||
|
*/
|
||||||
|
public void saveSessionData()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Call saveSessionData on the correct utility class
|
||||||
|
*/
|
||||||
|
//XML.saveSessionData(this, plugin);
|
||||||
|
//CSV.saveSessionData(this, plugin);
|
||||||
|
//YAML.saveSessionData(this, plugin);
|
||||||
|
PlainText.saveSessionData(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateArenaTotals()
|
||||||
|
{
|
||||||
|
Totals.updateArenaTotals(this);
|
||||||
|
PlainText.updateArenaTotals(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear maps.
|
||||||
|
*/
|
||||||
|
public void clearSessionData()
|
||||||
|
{
|
||||||
|
players.clear();
|
||||||
|
distribution.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena getArena() { return arena; }
|
||||||
|
public Timestamp getStartTime() { return startTime; }
|
||||||
|
public Timestamp getEndTime() { return endTime; }
|
||||||
|
public String getDuration() { return MAUtils.getDuration(endTime.getTime() - startTime.getTime()); }
|
||||||
|
public long getDurationLong() { return endTime.getTime() - startTime.getTime(); }
|
||||||
|
public int getLastWave() { return lastWave; }
|
||||||
|
|
||||||
|
public void playerKill(Player p)
|
||||||
|
{
|
||||||
|
players.get(p).kills++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playerDamager(Player p, int damage)
|
||||||
|
{
|
||||||
|
players.get(p).dmgDone += damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playerDamagee(Player p, int damage)
|
||||||
|
{
|
||||||
|
players.get(p).dmgTaken += damage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public class ArenaMaster
|
|||||||
{
|
{
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
config = plugin.getConfig();
|
config = plugin.getConfig();
|
||||||
|
arenas = new LinkedList<Arena>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -225,17 +226,14 @@ public class ArenaMaster
|
|||||||
for (String configName : config.getKeys("arenas"))
|
for (String configName : config.getKeys("arenas"))
|
||||||
{
|
{
|
||||||
String arenaPath = "arenas." + configName + ".";
|
String arenaPath = "arenas." + configName + ".";
|
||||||
String worldName = config.getString(arenaPath + "settings.world");
|
String worldName = config.getString(arenaPath + "settings.world", null);
|
||||||
World world;
|
World world;
|
||||||
if (worldName == null)
|
if (worldName == null || worldName.equals(""))
|
||||||
{
|
{
|
||||||
System.out.println("[MobArena] ERROR! Could not find the world for arena '" + configName + "'. Using default world! Check the config-file!");
|
System.out.println("[MobArena] ERROR! Could not find the world for arena '" + configName + "'. Using default world! Check the config-file!");
|
||||||
world = Bukkit.getServer().getWorlds().get(0);
|
world = Bukkit.getServer().getWorlds().get(0);
|
||||||
}
|
}
|
||||||
else
|
else world = Bukkit.getServer().getWorld(worldName);
|
||||||
{
|
|
||||||
world = Bukkit.getServer().getWorld(worldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
Arena arena = new Arena(MAUtils.nameConfigToArena(configName), world);
|
Arena arena = new Arena(MAUtils.nameConfigToArena(configName), world);
|
||||||
arena.load(config);
|
arena.load(config);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.garbagemule.MobArena;
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class MACommands implements CommandExecutor
|
|||||||
COMMANDS.add("delclass"); // Delete a class
|
COMMANDS.add("delclass"); // Delete a class
|
||||||
COMMANDS.add("auto-generate"); // Auto-generate arena
|
COMMANDS.add("auto-generate"); // Auto-generate arena
|
||||||
COMMANDS.add("auto-degenerate"); // Restore cuboid
|
COMMANDS.add("auto-degenerate"); // Restore cuboid
|
||||||
|
COMMANDS.add("lol");
|
||||||
}
|
}
|
||||||
private boolean meanAdmins, showingRegion;
|
private boolean meanAdmins, showingRegion;
|
||||||
private Server server;
|
private Server server;
|
||||||
@@ -115,6 +116,11 @@ public class MACommands implements CommandExecutor
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////*/
|
////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
if (base.equals("spawn"))
|
||||||
|
{
|
||||||
|
p.getWorld().setSpawnLocation(p.getLocation().getBlockX(), p.getLocation().getBlockY() + 1, p.getLocation().getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Player join
|
* Player join
|
||||||
*/
|
*/
|
||||||
@@ -158,7 +164,7 @@ public class MACommands implements CommandExecutor
|
|||||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ALREADY_PLAYING));
|
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ALREADY_PLAYING));
|
||||||
else if (!plugin.has(p, "mobarena.arenas." + arena.configName()))
|
else if (!plugin.has(p, "mobarena.arenas." + arena.configName()))
|
||||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_PERMISSION));
|
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_PERMISSION));
|
||||||
else if (arena.playerLimit > 0 && arena.lobbyPlayers.size() >= arena.playerLimit)
|
else if (arena.maxPlayers > 0 && arena.lobbyPlayers.size() >= arena.maxPlayers)
|
||||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_LIMIT_REACHED));
|
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_LIMIT_REACHED));
|
||||||
else if (arena.joinDistance > 0 && !arena.inRegionRadius(p.getLocation(), arena.joinDistance))
|
else if (arena.joinDistance > 0 && !arena.inRegionRadius(p.getLocation(), arena.joinDistance))
|
||||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_TOO_FAR));
|
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_TOO_FAR));
|
||||||
@@ -182,12 +188,21 @@ public class MACommands implements CommandExecutor
|
|||||||
if (p.isInsideVehicle())
|
if (p.isInsideVehicle())
|
||||||
p.leaveVehicle();
|
p.leaveVehicle();
|
||||||
|
|
||||||
am.arenaMap.put(p,arena);
|
// If player is in a bed, unbed!
|
||||||
|
if (p.isSleeping())
|
||||||
|
{
|
||||||
|
p.kickPlayer("Banned for life... Nah, just don't join from a bed ;)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//am.arenaMap.put(p,arena);
|
||||||
arena.playerJoin(p, p.getLocation());
|
arena.playerJoin(p, p.getLocation());
|
||||||
|
|
||||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_JOINED));
|
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_JOINED));
|
||||||
if (!arena.entryFee.isEmpty())
|
if (!arena.entryFee.isEmpty())
|
||||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_FEE_PAID, MAUtils.listToString(arena.entryFee, plugin)));
|
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_FEE_PAID, MAUtils.listToString(arena.entryFee, plugin)));
|
||||||
|
if (arena.hasPaid.contains(p))
|
||||||
|
arena.hasPaid.remove(p);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -217,7 +232,7 @@ public class MACommands implements CommandExecutor
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arena arena = am.arenaMap.remove(p);
|
Arena arena = am.arenaMap.get(p);
|
||||||
arena.playerLeave(p);
|
arena.playerLeave(p);
|
||||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LEAVE_PLAYER_LEFT));
|
MAUtils.tellPlayer(p, MAMessages.get(Msg.LEAVE_PLAYER_LEFT));
|
||||||
return true;
|
return true;
|
||||||
@@ -489,7 +504,6 @@ public class MACommands implements CommandExecutor
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (arena.livePlayers.isEmpty())
|
|
||||||
if (arena.arenaPlayers.isEmpty())
|
if (arena.arenaPlayers.isEmpty())
|
||||||
{
|
{
|
||||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_END_EMPTY));
|
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_END_EMPTY));
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.event.Event.Result;
|
import org.bukkit.event.Event.Result;
|
||||||
@@ -27,6 +28,7 @@ import org.bukkit.event.entity.EntityTargetEvent;
|
|||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||||
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
||||||
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
@@ -253,7 +255,6 @@ public class MAListener implements ArenaListener
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
event.getDrops().clear();
|
event.getDrops().clear();
|
||||||
arena.waveMap.put(p, arena.spawnThread.wave - 1);
|
|
||||||
arena.playerDeath(p);
|
arena.playerDeath(p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -264,7 +265,7 @@ public class MAListener implements ArenaListener
|
|||||||
EntityDamageByEntityEvent e2 = (e1 instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) e1 : null;
|
EntityDamageByEntityEvent e2 = (e1 instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) e1 : null;
|
||||||
Entity damager = (e2 != null) ? e2.getDamager() : null;
|
Entity damager = (e2 != null) ? e2.getDamager() : null;
|
||||||
|
|
||||||
if (e2 != null && damager instanceof Player)
|
if (damager instanceof Player)
|
||||||
arena.playerKill((Player) damager);
|
arena.playerKill((Player) damager);
|
||||||
|
|
||||||
event.getDrops().clear();
|
event.getDrops().clear();
|
||||||
@@ -275,70 +276,93 @@ public class MAListener implements ArenaListener
|
|||||||
|
|
||||||
public void onEntityDamage(EntityDamageEvent event)
|
public void onEntityDamage(EntityDamageEvent event)
|
||||||
{
|
{
|
||||||
if (!arena.running) return;
|
if (!arena.running) return;
|
||||||
|
|
||||||
EntityDamageByEntityEvent e = (event instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) event : null;
|
EntityDamageByEntityEvent e = (event instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) event : null;
|
||||||
Entity damager = (e != null) ? e.getDamager() : null;
|
Entity damager = (e != null) ? e.getDamager() : null;
|
||||||
Entity damagee = event.getEntity();
|
Entity damagee = event.getEntity();
|
||||||
|
|
||||||
// Damagee - Pet Wolf - cancel all damage.
|
// Pet wolf
|
||||||
if (damagee instanceof Wolf && arena.pets.contains(damagee))
|
if (damagee instanceof Wolf && arena.pets.contains(damagee))
|
||||||
{
|
{
|
||||||
if (event.getCause() == DamageCause.FIRE_TICK)
|
if (damager == null)
|
||||||
{
|
{
|
||||||
damagee.setFireTicks(32768); // For mcMMO
|
damagee.setFireTicks(32768);
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (damager instanceof Player)
|
||||||
|
event.setCancelled(true);
|
||||||
|
else
|
||||||
|
event.setDamage(0);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Arena player
|
||||||
|
else if (damagee instanceof Player)
|
||||||
|
{
|
||||||
|
if (arena.lobbyPlayers.contains(damagee))
|
||||||
|
event.setCancelled(true);
|
||||||
|
else if (!arena.arenaPlayers.contains(damagee))
|
||||||
|
return;
|
||||||
|
else if (!arena.detDamage && event.getCause() == DamageCause.BLOCK_EXPLOSION)
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
else if (damager instanceof Player && !arena.pvp)
|
||||||
if (e != null && damager instanceof Player)
|
{
|
||||||
|
// if 'inLobby' fails, and 'not inArena' fails, 'inArena' is true
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
event.setDamage(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Damager - Pet Wolf - lower damage
|
|
||||||
if (e != null && damager instanceof Wolf && arena.pets.contains(damager))
|
|
||||||
{
|
|
||||||
event.setDamage(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Damagee & Damager - Player - cancel if pvp disabled
|
|
||||||
if (damagee instanceof Player && damager instanceof Player)
|
|
||||||
{
|
|
||||||
if (arena.arenaPlayers.contains(damagee) && !arena.pvp)
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Damagee & Damager - Monsters - cancel if no monsterInfight
|
|
||||||
if (e != null && arena.monsters.contains(damagee) && arena.monsters.contains(damager))
|
|
||||||
{
|
|
||||||
if (!arena.monsterInfight)
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creeper detonations
|
|
||||||
if (arena.inRegion(damagee.getLocation()))
|
|
||||||
{
|
|
||||||
if (!arena.detDamage || !(damagee instanceof Player) || !arena.arenaPlayers.contains((Player) damagee))
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getCause() == DamageCause.BLOCK_EXPLOSION)
|
if (!event.isCancelled())
|
||||||
event.setCancelled(true);
|
arena.log.players.get((Player) damagee).dmgTaken += event.getDamage();
|
||||||
|
}
|
||||||
|
// Other LivingEntity
|
||||||
|
else if (arena.monsters.contains(damagee))
|
||||||
|
{
|
||||||
|
if (damager instanceof Player)
|
||||||
|
{
|
||||||
|
if (!arena.arenaPlayers.contains(damager))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
arena.log.players.get((Player) damager).dmgDone += event.getDamage();
|
||||||
}
|
arena.log.players.get((Player) damager).hits++;
|
||||||
|
}
|
||||||
|
else if (damager instanceof Wolf && arena.pets.contains(damager))
|
||||||
|
{
|
||||||
|
event.setDamage(1);
|
||||||
|
arena.log.players.get((Player) ((Wolf) damager).getOwner()).dmgDone += event.getDamage();
|
||||||
|
}
|
||||||
|
else if (damager instanceof LivingEntity)
|
||||||
|
{
|
||||||
|
if (!arena.monsterInfight)
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onPlayerAnimation(PlayerAnimationEvent event)
|
||||||
|
{
|
||||||
|
if (!arena.running || !arena.arenaPlayers.contains(event.getPlayer()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
arena.log.players.get(event.getPlayer()).swings++;
|
||||||
|
}
|
||||||
|
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event)
|
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||||
{
|
{
|
||||||
if (arena.running && arena.shareInArena) return;
|
if (arena.running && arena.shareInArena) return;
|
||||||
|
|
||||||
Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
|
if (p.getLocation().equals(arena.spectatorLoc))
|
||||||
|
{
|
||||||
|
event.getItemDrop().setItemStack(new ItemStack(1, 0));
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
if (!arena.arenaPlayers.contains(p) && !arena.lobbyPlayers.contains(p))
|
if (!arena.arenaPlayers.contains(p) && !arena.lobbyPlayers.contains(p))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -348,7 +372,6 @@ public class MAListener implements ArenaListener
|
|||||||
|
|
||||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event)
|
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event)
|
||||||
{
|
{
|
||||||
//if (!readyPlayers.contains(event.getPlayer()) && !livePlayers.contains(event.getPlayer()))
|
|
||||||
if (!arena.readyPlayers.contains(event.getPlayer()) && !arena.arenaPlayers.contains(event.getPlayer()))
|
if (!arena.readyPlayers.contains(event.getPlayer()) && !arena.arenaPlayers.contains(event.getPlayer()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -492,7 +515,6 @@ public class MAListener implements ArenaListener
|
|||||||
|
|
||||||
if (arena.running && arena.inRegion(to))
|
if (arena.running && arena.inRegion(to))
|
||||||
{
|
{
|
||||||
//MAUtils.tellPlayer(p, MAMessages.get(Msg.WARP_TO_ARENA));
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -502,7 +524,6 @@ public class MAListener implements ArenaListener
|
|||||||
{
|
{
|
||||||
Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
|
|
||||||
//if (!livePlayers.contains(p))
|
|
||||||
if (!arena.arenaPlayers.contains(p) && !arena.lobbyPlayers.contains(p))
|
if (!arena.arenaPlayers.contains(p) && !arena.lobbyPlayers.contains(p))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class MAMessages
|
|||||||
LOBBY_CLASS_PICKED,
|
LOBBY_CLASS_PICKED,
|
||||||
LOBBY_CLASS_RANDOM,
|
LOBBY_CLASS_RANDOM,
|
||||||
LOBBY_CLASS_PERMISSION,
|
LOBBY_CLASS_PERMISSION,
|
||||||
|
LOBBY_NOT_ENOUGH_PLAYERS,
|
||||||
LOBBY_PLAYER_READY,
|
LOBBY_PLAYER_READY,
|
||||||
LOBBY_DROP_ITEM,
|
LOBBY_DROP_ITEM,
|
||||||
LOBBY_PICK_CLASS,
|
LOBBY_PICK_CLASS,
|
||||||
@@ -108,6 +109,7 @@ public class MAMessages
|
|||||||
defaults.put(Msg.LOBBY_DROP_ITEM, "No sharing allowed at this time!");
|
defaults.put(Msg.LOBBY_DROP_ITEM, "No sharing allowed at this time!");
|
||||||
defaults.put(Msg.LOBBY_PLAYER_READY, "You have been flagged as ready!");
|
defaults.put(Msg.LOBBY_PLAYER_READY, "You have been flagged as ready!");
|
||||||
defaults.put(Msg.LOBBY_PICK_CLASS, "You must first pick a class!");
|
defaults.put(Msg.LOBBY_PICK_CLASS, "You must first pick a class!");
|
||||||
|
defaults.put(Msg.LOBBY_NOT_ENOUGH_PLAYERS, "Not enough players to start. Need at least % players.");
|
||||||
defaults.put(Msg.LOBBY_RIGHT_CLICK, "Punch the sign. Don't right-click.");
|
defaults.put(Msg.LOBBY_RIGHT_CLICK, "Punch the sign. Don't right-click.");
|
||||||
defaults.put(Msg.LOBBY_CLASS_PICKED, "You have chosen % as your class!");
|
defaults.put(Msg.LOBBY_CLASS_PICKED, "You have chosen % as your class!");
|
||||||
defaults.put(Msg.LOBBY_CLASS_RANDOM, "You will get a random class on arena start.");
|
defaults.put(Msg.LOBBY_CLASS_RANDOM, "You will get a random class on arena start.");
|
||||||
@@ -127,7 +129,7 @@ public class MAMessages
|
|||||||
/**
|
/**
|
||||||
* Initializes the msgMap by reading from the announcements-file.
|
* Initializes the msgMap by reading from the announcements-file.
|
||||||
*/
|
*/
|
||||||
public static void init(MobArena plugin, boolean update)
|
public static void init(MobArena plugin)
|
||||||
{
|
{
|
||||||
// Use defaults in case of any errors.
|
// Use defaults in case of any errors.
|
||||||
msgMap = defaults;
|
msgMap = defaults;
|
||||||
@@ -184,11 +186,6 @@ public class MAMessages
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(MobArena plugin)
|
|
||||||
{
|
|
||||||
init(plugin, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grabs the announcement from the msgMap, and in case of
|
* Grabs the announcement from the msgMap, and in case of
|
||||||
* s not being null, replaces the % with s.
|
* s not being null, replaces the % with s.
|
||||||
@@ -217,6 +214,8 @@ public class MAMessages
|
|||||||
*/
|
*/
|
||||||
private static void process(String s)
|
private static void process(String s)
|
||||||
{
|
{
|
||||||
|
if (s.endsWith("="))
|
||||||
|
s += " ";
|
||||||
// Split the string by the equals-sign.
|
// Split the string by the equals-sign.
|
||||||
String[] split = s.split("=");
|
String[] split = s.split("=");
|
||||||
if (split.length != 2)
|
if (split.length != 2)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.garbagemule.MobArena;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
@@ -23,6 +24,13 @@ public class MAPlayerListener extends PlayerListener
|
|||||||
this.am = am;
|
this.am = am;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onPlayerAnimation(PlayerAnimationEvent event)
|
||||||
|
{
|
||||||
|
if (!am.enabled) return;
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.eventListener.onPlayerAnimation(event);
|
||||||
|
}
|
||||||
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event)
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
if (!am.enabled) return;
|
if (!am.enabled) return;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
@@ -21,6 +23,10 @@ import org.bukkit.entity.CreatureType;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.MAMessages.Msg;
|
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||||
|
import com.garbagemule.MobArena.util.WaveUtils;
|
||||||
|
import com.garbagemule.MobArena.waves.RecurrentWave;
|
||||||
|
import com.garbagemule.MobArena.waves.SingleWave;
|
||||||
|
import com.garbagemule.MobArena.waves.Wave;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core class for handling wave spawning.
|
* Core class for handling wave spawning.
|
||||||
@@ -30,8 +36,6 @@ import com.garbagemule.MobArena.MAMessages.Msg;
|
|||||||
* host chooses. It is possible to create default waves that consist of
|
* host chooses. It is possible to create default waves that consist of
|
||||||
* only one type of monster, or ones that have no creepers, for example.
|
* only one type of monster, or ones that have no creepers, for example.
|
||||||
*/
|
*/
|
||||||
// TODO: Allow custom special wave monsters.
|
|
||||||
// TODO: Allow additional "default" waves.
|
|
||||||
public class MASpawnThread implements Runnable
|
public class MASpawnThread implements Runnable
|
||||||
{
|
{
|
||||||
protected int wave, previousSize, taskId;
|
protected int wave, previousSize, taskId;
|
||||||
@@ -42,6 +46,14 @@ public class MASpawnThread implements Runnable
|
|||||||
private MobArena plugin;
|
private MobArena plugin;
|
||||||
private Arena arena;
|
private Arena arena;
|
||||||
|
|
||||||
|
// NEW WAVES
|
||||||
|
/* Single waves are waves with a frequency of 0, and they only
|
||||||
|
* spawn once. Their priority is infinity, meaning they will always
|
||||||
|
* spawn instead of recurrent waves, if the wave numbers clash. */
|
||||||
|
private Wave defaultWave;
|
||||||
|
private TreeSet<SingleWave> singleWaves;
|
||||||
|
private TreeSet<RecurrentWave> recurrentWaves;
|
||||||
|
|
||||||
public MASpawnThread(MobArena plugin, Arena arena)
|
public MASpawnThread(MobArena plugin, Arena arena)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -51,7 +63,6 @@ public class MASpawnThread implements Runnable
|
|||||||
|
|
||||||
taskId = -32768;
|
taskId = -32768;
|
||||||
|
|
||||||
//noOfPlayers = arena.livePlayers.size();
|
|
||||||
noOfPlayers = arena.arenaPlayers.size();
|
noOfPlayers = arena.arenaPlayers.size();
|
||||||
wave = 1;
|
wave = 1;
|
||||||
random = new Random();
|
random = new Random();
|
||||||
@@ -63,6 +74,7 @@ public class MASpawnThread implements Runnable
|
|||||||
dSpiders = dSkeletons + arena.distDefault.get("spiders");
|
dSpiders = dSkeletons + arena.distDefault.get("spiders");
|
||||||
dCreepers = dSpiders + arena.distDefault.get("creepers");
|
dCreepers = dSpiders + arena.distDefault.get("creepers");
|
||||||
dWolves = dCreepers + arena.distDefault.get("wolves");
|
dWolves = dCreepers + arena.distDefault.get("wolves");
|
||||||
|
if (dWolves < 1) { dZombies = 1; dSkeletons = 2; dSpiders = 3; dCreepers = 4; dWolves = 5; }
|
||||||
|
|
||||||
dPoweredCreepers = arena.distSpecial.get("powered-creepers");
|
dPoweredCreepers = arena.distSpecial.get("powered-creepers");
|
||||||
dPigZombies = dPoweredCreepers + arena.distSpecial.get("zombie-pigmen");
|
dPigZombies = dPoweredCreepers + arena.distSpecial.get("zombie-pigmen");
|
||||||
@@ -71,6 +83,98 @@ public class MASpawnThread implements Runnable
|
|||||||
dAngryWolves = dMonsters + arena.distSpecial.get("angry-wolves");
|
dAngryWolves = dMonsters + arena.distSpecial.get("angry-wolves");
|
||||||
dGiants = dAngryWolves + arena.distSpecial.get("giants");
|
dGiants = dAngryWolves + arena.distSpecial.get("giants");
|
||||||
dGhasts = dGiants + arena.distSpecial.get("ghasts");
|
dGhasts = dGiants + arena.distSpecial.get("ghasts");
|
||||||
|
if (dGhasts < 1) { dPoweredCreepers = 1; dPigZombies = 2; dSlimes = 3; dMonsters = 4; dAngryWolves = 5; dGiants = 5; dGhasts = 5; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run2()
|
||||||
|
{
|
||||||
|
// Clear out all dead monsters in the monster set.
|
||||||
|
removeDeadMonsters();
|
||||||
|
|
||||||
|
// If there are no players in the arena, return.
|
||||||
|
if (arena.arenaPlayers.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Check if wave needs to be cleared first. If so, return!
|
||||||
|
if (arena.waveClear && wave > 1 && !arena.monsters.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Grant rewards (if any) for this wave
|
||||||
|
grantRewards(wave);
|
||||||
|
|
||||||
|
// Detonate creepers if needed
|
||||||
|
detonateCreepers(arena.detCreepers);
|
||||||
|
|
||||||
|
// Find the wave to spawn
|
||||||
|
spawnWave(wave);
|
||||||
|
|
||||||
|
wave++;
|
||||||
|
if (arena.monsters.isEmpty())
|
||||||
|
arena.resetIdleTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeDeadMonsters()
|
||||||
|
{
|
||||||
|
List<Entity> tmp = new LinkedList<Entity>(arena.monsters);
|
||||||
|
for (Entity e : tmp)
|
||||||
|
if (e.isDead())
|
||||||
|
arena.monsters.remove(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void grantRewards(int wave)
|
||||||
|
{
|
||||||
|
for (Map.Entry<Integer,List<ItemStack>> entry : arena.everyWaveMap.entrySet())
|
||||||
|
if (wave % entry.getKey() == 0)
|
||||||
|
addReward(entry.getValue());
|
||||||
|
|
||||||
|
if (arena.afterWaveMap.containsKey(wave))
|
||||||
|
addReward(arena.afterWaveMap.get(wave));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawnWave(int wave)
|
||||||
|
{
|
||||||
|
Wave w = null;
|
||||||
|
|
||||||
|
// Check the first element of the single waves.
|
||||||
|
if (!singleWaves.isEmpty() && singleWaves.first().matches(wave))
|
||||||
|
{
|
||||||
|
w = singleWaves.pollFirst();
|
||||||
|
//singleWaves.pollFirst().spawn(wave, arena.spawnpoints.values());
|
||||||
|
//return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SortedSet<Wave> matches = getMatchingRecurrentWaves(wave);
|
||||||
|
|
||||||
|
if (matches.isEmpty())
|
||||||
|
w = defaultWave;
|
||||||
|
else
|
||||||
|
w = matches.last();
|
||||||
|
}
|
||||||
|
|
||||||
|
w.spawn(wave, arena.spawnpoints.values());
|
||||||
|
/*
|
||||||
|
// Otherwise, check the recurrent waves.
|
||||||
|
SortedSet<Wave> matches = getMatchingRecurrentWaves(wave);
|
||||||
|
|
||||||
|
if (matches.isEmpty())
|
||||||
|
defaultWave.spawn(wave, arena.spawnpoints.values());
|
||||||
|
else
|
||||||
|
matches.last().spawn(wave, arena.spawnpoints.values());
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private SortedSet<Wave> getMatchingRecurrentWaves(int wave)
|
||||||
|
{
|
||||||
|
TreeSet<Wave> result = new TreeSet<Wave>(WaveUtils.getRecurrentComparator());
|
||||||
|
|
||||||
|
for (Wave w : recurrentWaves)
|
||||||
|
{
|
||||||
|
if (w.matches(wave))
|
||||||
|
result.add(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
@@ -130,14 +234,16 @@ public class MASpawnThread implements Runnable
|
|||||||
*/
|
*/
|
||||||
private void addReward(List<ItemStack> rewards)
|
private void addReward(List<ItemStack> rewards)
|
||||||
{
|
{
|
||||||
//for (Player p : arena.livePlayers)
|
|
||||||
for (Player p : arena.arenaPlayers)
|
for (Player p : arena.arenaPlayers)
|
||||||
{
|
{
|
||||||
if (arena.rewardMap.get(p) == null)
|
if (arena.log.players.get(p) == null)
|
||||||
continue;
|
continue;
|
||||||
|
/*if (arena.rewardMap.get(p) == null)
|
||||||
|
continue;*/
|
||||||
|
|
||||||
ItemStack reward = MAUtils.getRandomReward(rewards);
|
ItemStack reward = MAUtils.getRandomReward(rewards);
|
||||||
arena.rewardMap.get(p).add(reward);
|
arena.log.players.get(p).rewards.add(reward);
|
||||||
|
//arena.rewardMap.get(p).add(reward);
|
||||||
|
|
||||||
if (reward == null)
|
if (reward == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -885,12 +885,17 @@ public class MAUtils
|
|||||||
|
|
||||||
// ///////////////////////////////////////////////////////////////////// */
|
// ///////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
|
public static void error(String msg)
|
||||||
|
{
|
||||||
|
System.out.println("[MobArena] ERROR! " + msg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to a player.
|
* Sends a message to a player.
|
||||||
*/
|
*/
|
||||||
public static boolean tellPlayer(CommandSender p, String msg)
|
public static boolean tellPlayer(CommandSender p, String msg)
|
||||||
{
|
{
|
||||||
if (p == null)
|
if (p == null || msg.equals(" "))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
p.sendMessage(ChatColor.GREEN + "[MobArena] " + ChatColor.WHITE + msg);
|
p.sendMessage(ChatColor.GREEN + "[MobArena] " + ChatColor.WHITE + msg);
|
||||||
@@ -1045,6 +1050,7 @@ public class MAUtils
|
|||||||
return buffy.toString().substring(0, buffy.length() - trimLength);
|
return buffy.toString().substring(0, buffy.length() - trimLength);
|
||||||
}
|
}
|
||||||
public static <E> String listToString(List<E> list, MobArena plugin) { return listToString(list, true, plugin); }
|
public static <E> String listToString(List<E> list, MobArena plugin) { return listToString(list, true, plugin); }
|
||||||
|
public static <E> String listToString(List<E> list) { return listToString(list, true, (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena")); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a String-list version of a comma-separated list.
|
* Returns a String-list version of a comma-separated list.
|
||||||
@@ -1163,27 +1169,16 @@ public class MAUtils
|
|||||||
return hrs + ":" + ((mins < 10) ? "0" + mins : mins) + ":" + ((secs < 10) ? "0" + secs : secs);
|
return hrs + ":" + ((mins < 10) ? "0" + mins : mins) + ":" + ((secs < 10) ? "0" + secs : secs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String padRight(String s, int length) { return padRight(s, length, ' '); }
|
public static long parseDuration(String duration)
|
||||||
public static String padRight(String s, int length, char pad)
|
|
||||||
{
|
{
|
||||||
StringBuffer buffy = new StringBuffer();
|
String[] elements = duration.split(":");
|
||||||
buffy.append(s);
|
long hrs = Long.parseLong(elements[0]) * 60 * 60;
|
||||||
for (int i = s.length(); i < length; i++)
|
long mins = Long.parseLong(elements[1]) * 60;
|
||||||
buffy.append(pad);
|
long secs = Long.parseLong(elements[2]);
|
||||||
return buffy.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String padLeft(String s, int length) { return padLeft(s, length, ' '); }
|
return (hrs + mins + secs) * 1000;
|
||||||
public static String padLeft(String s, int length, char pad)
|
|
||||||
{
|
|
||||||
StringBuffer buffy = new StringBuffer();
|
|
||||||
for (int i = 0; i < length - s.length(); i++)
|
|
||||||
buffy.append(pad);
|
|
||||||
buffy.append(s);
|
|
||||||
return buffy.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stand back, I'm going to try science!
|
* Stand back, I'm going to try science!
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.bukkit.util.config.Configuration;
|
|||||||
|
|
||||||
import com.nijiko.permissions.PermissionHandler;
|
import com.nijiko.permissions.PermissionHandler;
|
||||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||||
|
import com.garbagemule.MobArena.util.FileUtils;
|
||||||
import com.garbagemule.register.payment.Method;
|
import com.garbagemule.register.payment.Method;
|
||||||
import com.garbagemule.register.payment.Methods;
|
import com.garbagemule.register.payment.Methods;
|
||||||
|
|
||||||
@@ -36,35 +37,83 @@ public class MobArena extends JavaPlugin
|
|||||||
protected Method Method;
|
protected Method Method;
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
protected static final double MIN_PLAYER_DISTANCE = 256.0;
|
public static PluginDescriptionFile desc;
|
||||||
protected static final int ECONOMY_MONEY_ID = -29;
|
public static File dir, arenaDir;
|
||||||
|
public static final double MIN_PLAYER_DISTANCE = 256.0;
|
||||||
|
public static final int ECONOMY_MONEY_ID = -29;
|
||||||
|
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
PluginDescriptionFile pdfFile = this.getDescription();
|
// Description file and data folder
|
||||||
|
desc = getDescription();
|
||||||
|
dir = getDataFolder();
|
||||||
|
arenaDir = new File(dir, "arenas");
|
||||||
|
if (!dir.exists()) dir.mkdir();
|
||||||
|
//if (!arenaDir.exists()) arenaDir.mkdir();
|
||||||
|
|
||||||
// Config, messages and ArenaMaster initialization
|
// Create default files and initialize config-file
|
||||||
|
FileUtils.extractDefaults("config.yml", "announcements.properties");
|
||||||
loadConfig();
|
loadConfig();
|
||||||
MAMessages.init(this);
|
|
||||||
|
// Download external libraries if needed.
|
||||||
|
FileUtils.fetchLibs(config);
|
||||||
|
|
||||||
|
// Set up permissions and economy
|
||||||
|
setupPermissions();
|
||||||
|
setupRegister();
|
||||||
|
|
||||||
|
// Set up the ArenaMaster and the announcements
|
||||||
am = new ArenaMaster(this);
|
am = new ArenaMaster(this);
|
||||||
am.initialize();
|
am.initialize();
|
||||||
|
MAMessages.init(this);
|
||||||
|
|
||||||
// Permissions
|
// Register event listeners
|
||||||
setupPermissions();
|
registerListeners();
|
||||||
|
|
||||||
// Economy
|
// Announce enable!
|
||||||
Methods = new Methods();
|
System.out.println("[MobArena] v" + desc.getVersion() + " enabled.");
|
||||||
if (!Methods.hasMethod() && Methods.setMethod(this))
|
}
|
||||||
|
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
// TODO: Re-implement this!
|
||||||
|
/*
|
||||||
|
// Force all arenas to end.
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.forceEnd();
|
||||||
|
am.arenaMap.clear();
|
||||||
|
|
||||||
|
// Permissions & Economy
|
||||||
|
permissionHandler = null;
|
||||||
|
if (Methods != null && Methods.hasMethod())
|
||||||
{
|
{
|
||||||
Method = Methods.getMethod();
|
Methods = null;
|
||||||
System.out.println("[MobArena] Payment method found (" + Method.getName() + " version: " + Method.getVersion() + ")");
|
System.out.println("[MobArena] Payment method was disabled. No longer accepting payments.");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
System.out.println("[MobArena] disabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfig()
|
||||||
|
{
|
||||||
|
File file = new File(dir, "config.yml");
|
||||||
|
if (!file.exists())
|
||||||
|
{
|
||||||
|
System.out.println("[MobArena] ERROR! Config-file could not be created!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config = new Configuration(file);
|
||||||
|
config.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerListeners()
|
||||||
|
{
|
||||||
// Bind the /ma, /marena, and /mobarena commands to MACommands.
|
// Bind the /ma, /marena, and /mobarena commands to MACommands.
|
||||||
MACommands commandExecutor = new MACommands(this, am);
|
MACommands commandExecutor = new MACommands(this, am);
|
||||||
getCommand("ma").setExecutor(commandExecutor);
|
getCommand("ma").setExecutor(commandExecutor);
|
||||||
getCommand("marena").setExecutor(commandExecutor);
|
getCommand("marena").setExecutor(commandExecutor);
|
||||||
getCommand("mobarena").setExecutor(commandExecutor);
|
getCommand("mobarena").setExecutor(commandExecutor);
|
||||||
|
|
||||||
// Create event listeners.
|
// Create event listeners.
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
@@ -80,6 +129,7 @@ public class MobArena extends JavaPlugin
|
|||||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_KICK, playerListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_KICK, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
||||||
|
pm.registerEvent(Event.Type.PLAYER_ANIMATION, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
|
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.High, this); // mcMMO is "Highest"
|
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.High, this); // mcMMO is "Highest"
|
||||||
@@ -90,79 +140,6 @@ public class MobArena extends JavaPlugin
|
|||||||
pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
|
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Monitor, this);
|
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Monitor, this);
|
||||||
|
|
||||||
System.out.println("[MobArena] v" + pdfFile.getVersion() + " enabled." );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
// Force all arenas to end.
|
|
||||||
for (Arena arena : am.arenas)
|
|
||||||
arena.forceEnd();
|
|
||||||
am.arenaMap.clear();
|
|
||||||
|
|
||||||
// Permissions & Economy
|
|
||||||
permissionHandler = null;
|
|
||||||
if (Methods != null && Methods.hasMethod())
|
|
||||||
{
|
|
||||||
Methods = null;
|
|
||||||
System.out.println("[MobArena] Payment method was disabled. No longer accepting payments.");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("[MobArena] disabled.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the config-file and initialize the Configuration object.
|
|
||||||
*/
|
|
||||||
private void loadConfig()
|
|
||||||
{
|
|
||||||
File file = new File(this.getDataFolder(), "config.yml");
|
|
||||||
if (!file.exists())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.getDataFolder().mkdir();
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: Remove in v1.0
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Configuration tmp = new Configuration(file);
|
|
||||||
tmp.load();
|
|
||||||
if (tmp.getKeys("global-settings") == null)
|
|
||||||
{
|
|
||||||
file.renameTo(new File(this.getDataFolder(), "config_OLD.yml"));
|
|
||||||
file = new File(this.getDataFolder(), "config.yml");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.getDataFolder().mkdir();
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
config = new Configuration(file);
|
|
||||||
config.load();
|
|
||||||
fixConfig();
|
|
||||||
config.setHeader("# MobArena Configuration-file\r\n# Please go to https://github.com/garbagemule/MobArena/wiki/Installing-MobArena for more details.");
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config = new Configuration(file);
|
|
||||||
config.load();
|
|
||||||
config.setHeader("# MobArena Configuration-file\r\n# Please go to https://github.com/garbagemule/MobArena/wiki/Installing-MobArena for more details.");
|
|
||||||
config.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Permissions stuff
|
// Permissions stuff
|
||||||
@@ -188,89 +165,17 @@ public class MobArena extends JavaPlugin
|
|||||||
permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupRegister()
|
||||||
|
{
|
||||||
|
Methods = new Methods();
|
||||||
|
if (!Methods.hasMethod() && Methods.setMethod(this))
|
||||||
|
{
|
||||||
|
Method = Methods.getMethod();
|
||||||
|
System.out.println("[MobArena] Payment method found (" + Method.getName() + " version: " + Method.getVersion() + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Configuration getConfig() { return config; }
|
public Configuration getConfig() { return config; }
|
||||||
public ArenaMaster getAM() { return am; } // More convenient.
|
public ArenaMaster getAM() { return am; } // More convenient.
|
||||||
public ArenaMaster getArenaMaster() { return am; }
|
public ArenaMaster getArenaMaster() { return am; }
|
||||||
|
|
||||||
// TODO: Remove in v1.0
|
|
||||||
private void fixConfig()
|
|
||||||
{
|
|
||||||
// If global-settings is sorted, don't do anything.
|
|
||||||
if (config.getKeys("global-settings") != null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
File oldFile = new File(this.getDataFolder(), "config_OLD.yml");
|
|
||||||
if (!oldFile.exists())
|
|
||||||
return;
|
|
||||||
|
|
||||||
System.out.println("[MobArena] Config-file appears to be old. Trying to fix it...");
|
|
||||||
|
|
||||||
Configuration oldConfig = new Configuration(oldFile);
|
|
||||||
oldConfig.load();
|
|
||||||
|
|
||||||
config.setProperty("global-settings.enabled", true);
|
|
||||||
config.save();
|
|
||||||
config.load();
|
|
||||||
config.setProperty("global-settings.update-notification", true);
|
|
||||||
config.save();
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
// Copy classes
|
|
||||||
for (String s : oldConfig.getKeys("classes"))
|
|
||||||
{
|
|
||||||
config.setProperty("classes." + s + ".items", oldConfig.getString("classes." + s + ".items"));
|
|
||||||
config.setProperty("classes." + s + ".armor", oldConfig.getString("classes." + s + ".armor"));
|
|
||||||
}
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
// Make the default arena node.
|
|
||||||
config.setProperty("arenas.default.settings.enabled", true);
|
|
||||||
config.save();
|
|
||||||
config.load();
|
|
||||||
config.setProperty("arenas.default.settings.world", oldConfig.getString("settings.world"));
|
|
||||||
config.save();
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
// Copy the coords.
|
|
||||||
for (String s : oldConfig.getKeys("coords"))
|
|
||||||
{
|
|
||||||
if (s.equals("spawnpoints"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
StringBuffer buffy = new StringBuffer();
|
|
||||||
buffy.append(oldConfig.getString("coords." + s + ".x"));
|
|
||||||
buffy.append(",");
|
|
||||||
buffy.append(oldConfig.getString("coords." + s + ".y"));
|
|
||||||
buffy.append(",");
|
|
||||||
buffy.append(oldConfig.getString("coords." + s + ".z"));
|
|
||||||
buffy.append(",");
|
|
||||||
buffy.append(oldConfig.getString("coords." + s + ".yaw"));
|
|
||||||
buffy.append(",");
|
|
||||||
buffy.append(oldConfig.getString("coords." + s + ".pitch"));
|
|
||||||
|
|
||||||
config.setProperty("arenas.default.coords." + s, buffy.toString());
|
|
||||||
}
|
|
||||||
config.save();
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
for (String s : oldConfig.getKeys("coords.spawnpoints"))
|
|
||||||
{
|
|
||||||
StringBuffer buffy = new StringBuffer();
|
|
||||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".x"));
|
|
||||||
buffy.append(",");
|
|
||||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".y"));
|
|
||||||
buffy.append(",");
|
|
||||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".z"));
|
|
||||||
buffy.append(",");
|
|
||||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".yaw"));
|
|
||||||
buffy.append(",");
|
|
||||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".pitch"));
|
|
||||||
|
|
||||||
config.setProperty("arenas.default.coords.spawnpoints." + s, buffy.toString());
|
|
||||||
}
|
|
||||||
config.save();
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
System.out.println("[MobArena] Updated the config-file!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user