v0.92 - First commit to dev branch!
This commit is contained in:
Binary file not shown.
+4
-7
@@ -1,6 +1,6 @@
|
|||||||
name: MobArena
|
name: MobArena
|
||||||
main: com.garbagemule.MobArena.MobArena
|
main: com.garbagemule.MobArena.MobArena
|
||||||
version: 0.91.2
|
version: 0.92
|
||||||
softdepend: [MultiVerse]
|
softdepend: [MultiVerse]
|
||||||
commands:
|
commands:
|
||||||
ma:
|
ma:
|
||||||
@@ -8,22 +8,19 @@ commands:
|
|||||||
usage: |
|
usage: |
|
||||||
/ma join - Join the arena.
|
/ma join - Join the arena.
|
||||||
/ma leave - Leave the arena.
|
/ma leave - Leave the arena.
|
||||||
/ma list - List of players in the arena.
|
|
||||||
/ma notready - List of players who aren't ready.
|
/ma notready - List of players who aren't ready.
|
||||||
/ma spectator - Warp to the spectator area.
|
/ma spectate - Warp to the spectator area.
|
||||||
marena:
|
marena:
|
||||||
description: Base command for MobArena
|
description: Base command for MobArena
|
||||||
usage: |
|
usage: |
|
||||||
/marena join - Join the arena.
|
/marena join - Join the arena.
|
||||||
/marena leave - Leave the arena.
|
/marena leave - Leave the arena.
|
||||||
/marena list - List of players in the arena.
|
|
||||||
/marena notready - List of players who aren't ready.
|
/marena notready - List of players who aren't ready.
|
||||||
/marena spectator - Warp to the spectator area.
|
/marena spectate - Warp to the spectator area.
|
||||||
mobarena:
|
mobarena:
|
||||||
description: Base command for MobArena
|
description: Base command for MobArena
|
||||||
usage: |
|
usage: |
|
||||||
/mobarena join - Join the arena.
|
/mobarena join - Join the arena.
|
||||||
/mobarena leave - Leave the arena.
|
/mobarena leave - Leave the arena.
|
||||||
/mobarena list - List of players in the arena.
|
|
||||||
/mobarena notready - List of players who aren't ready.
|
/mobarena notready - List of players who aren't ready.
|
||||||
/mobarena spectator - Warp to the spectator area.
|
/mobarena spectate - Warp to the spectator area.
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,334 @@
|
|||||||
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
|
public class ArenaMaster
|
||||||
|
{
|
||||||
|
private MobArena plugin;
|
||||||
|
private Configuration config;
|
||||||
|
protected Arena selectedArena;
|
||||||
|
protected Lobby masterLobby;
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
protected boolean enabled, updateNotify, autoEquip, emptyInvs, hellhounds;
|
||||||
|
protected int repairDelay;
|
||||||
|
|
||||||
|
// Classes
|
||||||
|
protected List<String> classes;
|
||||||
|
protected Map<String,List<ItemStack>> classItems, classArmor;
|
||||||
|
protected Map<Player,Arena> arenaMap;
|
||||||
|
|
||||||
|
// Location map
|
||||||
|
protected Map<Player,Location> locations = new HashMap<Player,Location>();
|
||||||
|
|
||||||
|
// Arena list
|
||||||
|
protected List<Arena> arenas;
|
||||||
|
|
||||||
|
// Listeners
|
||||||
|
protected Set<MobArenaListener> listeners = new HashSet<MobArenaListener>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public ArenaMaster(MobArena instance)
|
||||||
|
{
|
||||||
|
plugin = instance;
|
||||||
|
config = plugin.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*/////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Arena getters
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
public Arena getArenaInLocation(Location loc)
|
||||||
|
{
|
||||||
|
for (Arena arena : arenas)
|
||||||
|
if (arena.inRegion(loc))
|
||||||
|
return arena;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Arena> getArenasInWorld(World world)
|
||||||
|
{
|
||||||
|
List<Arena> result = new LinkedList<Arena>();
|
||||||
|
for (Arena arena : arenas)
|
||||||
|
if (arena.world.equals(world))
|
||||||
|
result.add(arena);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena getArenaWithPlayer(Player p)
|
||||||
|
{
|
||||||
|
return arenaMap.get(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena getArenaWithPlayer(String s)
|
||||||
|
{
|
||||||
|
for (Map.Entry<Player,Arena> entry : arenaMap.entrySet())
|
||||||
|
{
|
||||||
|
if (entry.getKey().getName().equals(s))
|
||||||
|
return entry.getValue();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena getArenaWithMonster(Entity e)
|
||||||
|
{
|
||||||
|
for (Arena arena : arenas)
|
||||||
|
if (arena.monsters.contains(e))
|
||||||
|
return arena;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena getArenaWithPet(Entity e)
|
||||||
|
{
|
||||||
|
for (Arena arena : arenas)
|
||||||
|
if (arena.pets.contains(e))
|
||||||
|
return arena;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena getArenaWithName(String configName)
|
||||||
|
{
|
||||||
|
for (Arena arena : arenas)
|
||||||
|
if (arena.configName().equals(configName))
|
||||||
|
return arena;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*/////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Initialization
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
public void initialize()
|
||||||
|
{
|
||||||
|
config.load();
|
||||||
|
loadSettings();
|
||||||
|
loadClasses();
|
||||||
|
loadArenas();
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the global settings.
|
||||||
|
*/
|
||||||
|
public void loadSettings()
|
||||||
|
{
|
||||||
|
if (config.getKeys("global-settings") == null)
|
||||||
|
{
|
||||||
|
config.setProperty("global-settings.enabled", true);
|
||||||
|
config.setProperty("global-settings.update-notification", true);
|
||||||
|
config.setProperty("global-settings.repair-delay", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
enabled = config.getBoolean("global-settings.enabled", true);
|
||||||
|
updateNotify = config.getBoolean("global-settings.update-notification", true);
|
||||||
|
repairDelay = config.getInt("global-settings.repair-delay", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load all class-related stuff.
|
||||||
|
*/
|
||||||
|
public void loadClasses()
|
||||||
|
{
|
||||||
|
if (config.getKeys("classes") == null)
|
||||||
|
{
|
||||||
|
config.setProperty("classes.Archer.items", "wood_sword, bow, arrow:128, grilled_pork");
|
||||||
|
config.setProperty("classes.Archer.armor", "298,299,300,301");
|
||||||
|
config.setProperty("classes.Knight.items", "diamond_sword, grilled_pork:2");
|
||||||
|
config.setProperty("classes.Knight.armor", "306,307,308,309");
|
||||||
|
config.setProperty("classes.Tank.items", "iron_sword, grilled_pork:3, apple");
|
||||||
|
config.setProperty("classes.Tank.armor", "310,311,312,313");
|
||||||
|
config.setProperty("classes.Oddjob.items", "stone_sword, flint_and_steel, netherrack:2, wood_pickaxe, tnt:4, fishing_rod, apple, grilled_pork:3");
|
||||||
|
config.setProperty("classes.Oddjob.armor", "298,299,300,301");
|
||||||
|
config.setProperty("classes.Chef.items", "stone_sword, bread:6, grilled_pork:4, mushroom_soup, cake:3, cookie:12");
|
||||||
|
config.setProperty("classes.Chef.armor", "314,315,316,317");
|
||||||
|
}
|
||||||
|
classes = config.getKeys("classes");
|
||||||
|
classItems = MAUtils.getClassItems(config, "items");
|
||||||
|
classArmor = MAUtils.getClassItems(config, "armor");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load all arena-related stuff.
|
||||||
|
*/
|
||||||
|
public void loadArenas()
|
||||||
|
{
|
||||||
|
arenas = new LinkedList<Arena>();
|
||||||
|
|
||||||
|
if (config.getKeys("arenas") == null)
|
||||||
|
createArenaNode("default", Bukkit.getServer().getWorlds().get(0));
|
||||||
|
|
||||||
|
for (String configName : config.getKeys("arenas"))
|
||||||
|
{
|
||||||
|
String arenaPath = "arenas." + configName + ".";
|
||||||
|
String worldName = config.getString(arenaPath + "settings.world");
|
||||||
|
World world;
|
||||||
|
if (worldName == null)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
world = Bukkit.getServer().getWorld(worldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Arena arena = new Arena(MAUtils.nameConfigToArena(configName), world, this);
|
||||||
|
arena.load(config);
|
||||||
|
arenas.add(arena);
|
||||||
|
}
|
||||||
|
|
||||||
|
arenaMap = new HashMap<Player,Arena>();
|
||||||
|
selectedArena = arenas.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena createArenaNode(String configName, World world)
|
||||||
|
{
|
||||||
|
config.setProperty("arenas." + configName + ".settings.world", world.getName());
|
||||||
|
config.save();
|
||||||
|
config.load();
|
||||||
|
config.setProperty("arenas." + configName + ".settings.enabled", true);
|
||||||
|
config.save();
|
||||||
|
config.load();
|
||||||
|
config.setProperty("arenas." + configName + ".settings.protect", true);
|
||||||
|
config.save();
|
||||||
|
config.load();
|
||||||
|
config.setProperty("arenas." + configName + ".settings.wave-clear", false);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.detonate-creepers", false);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.detonate-damage", false);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.lightning", true);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.auto-equip-armor", true);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.force-restore", false);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.soft-restore", false);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.require-empty-inventory", false);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.hellhounds", false);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.pvp-enabled", false);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.monster-infight", false);
|
||||||
|
config.save();
|
||||||
|
config.load();
|
||||||
|
config.setProperty("arenas." + configName + ".settings.first-wave-delay", 5);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.wave-interval", 20);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.special-modulo", 4);
|
||||||
|
config.setProperty("arenas." + configName + ".settings.max-idle-time", 0);
|
||||||
|
config.save();
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
Arena arena = new Arena(MAUtils.nameConfigToArena(configName), world, this);
|
||||||
|
arena.load(config);
|
||||||
|
return arena;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeArenaNode(String configName)
|
||||||
|
{
|
||||||
|
config.removeProperty("arenas." + configName);
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*/////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Update and serialization methods
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update one, two or all three of global settings, classes
|
||||||
|
* and arenas (arenas with deserialization).
|
||||||
|
*/
|
||||||
|
public void update(boolean settings, boolean classes, boolean arenalist)
|
||||||
|
{
|
||||||
|
boolean tmp = enabled;
|
||||||
|
enabled = false;
|
||||||
|
|
||||||
|
for (Arena arena : arenas)
|
||||||
|
arena.forceEnd();
|
||||||
|
|
||||||
|
config.load();
|
||||||
|
if (settings) loadSettings();
|
||||||
|
if (classes) loadClasses();
|
||||||
|
if (arenalist) deserializeArenas();
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
enabled = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the global settings.
|
||||||
|
*/
|
||||||
|
public void serializeSettings()
|
||||||
|
{
|
||||||
|
String settings = "global-settings.";
|
||||||
|
config.setProperty(settings + "enabled", enabled);
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize all arena configs.
|
||||||
|
*/
|
||||||
|
public void serializeArenas()
|
||||||
|
{
|
||||||
|
for (Arena arena : arenas)
|
||||||
|
arena.serializeConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize all arena configs. Updates the arena list to
|
||||||
|
* include only the current arenas (not ones added in the
|
||||||
|
* actual file) that are also in the config-file.
|
||||||
|
*/
|
||||||
|
public void deserializeArenas()
|
||||||
|
{
|
||||||
|
// Get only the arenas in the config.
|
||||||
|
List<String> strings = config.getKeys("arenas");
|
||||||
|
if (strings == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Get their Arena objects.
|
||||||
|
List<Arena> configArenas = new LinkedList<Arena>();
|
||||||
|
for (String s : strings)
|
||||||
|
if (getArenaWithName(s) != null)
|
||||||
|
configArenas.add(getArenaWithName(s));
|
||||||
|
|
||||||
|
// Remove all Arenas no longer in the config.
|
||||||
|
arenas.retainAll(configArenas);
|
||||||
|
//for (Arena arena : arenas)
|
||||||
|
// arena.serializeConfig();
|
||||||
|
|
||||||
|
for (Arena arena : arenas)
|
||||||
|
arena.deserializeConfig();
|
||||||
|
|
||||||
|
// Make sure to update the selected arena to a valid one.
|
||||||
|
if (!arenas.contains(selectedArena) && arenas.size() >= 1)
|
||||||
|
selectedArena = arenas.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateSettings() { update(true, false, false); }
|
||||||
|
public void updateClasses() { update(false, true, false); }
|
||||||
|
public void updateArenas() { update(false, false, true); }
|
||||||
|
public void updateAll() { update(true, true, true); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Lobby
|
||||||
|
{
|
||||||
|
protected Arena arena;
|
||||||
|
protected ArenaMaster am;
|
||||||
|
protected Location warp, l1, l2;
|
||||||
|
|
||||||
|
public Lobby(Arena arena)
|
||||||
|
{
|
||||||
|
this.arena = arena;
|
||||||
|
}
|
||||||
|
public Lobby()
|
||||||
|
{
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playerJoin(Player p)
|
||||||
|
{
|
||||||
|
p.teleport(warp);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,69 +1,27 @@
|
|||||||
package com.garbagemule.MobArena;
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.BlockListener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
//import org.bukkit.event.block.BlockDamageEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener serves as a protection class. Blocks within
|
|
||||||
* the arena region cannot be destroyed, and blocks can only
|
|
||||||
* be placed by a participant in the current arena session.
|
|
||||||
* Any placed blocks will be removed by the cleanup method in
|
|
||||||
* ArenaManager when the session ends.
|
|
||||||
*/
|
|
||||||
public class MABlockListener extends BlockListener
|
public class MABlockListener extends BlockListener
|
||||||
{
|
{
|
||||||
public MABlockListener(MobArena instance)
|
private ArenaMaster am;
|
||||||
|
|
||||||
|
public MABlockListener(ArenaMaster am)
|
||||||
{
|
{
|
||||||
|
this.am = am;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevents blocks from breaking if block protection is on.
|
|
||||||
*/
|
|
||||||
public void onBlockBreak(BlockBreakEvent event)
|
public void onBlockBreak(BlockBreakEvent event)
|
||||||
{
|
{
|
||||||
if (!ArenaManager.isSetup || !ArenaManager.isProtected)
|
for (Arena arena : am.arenas)
|
||||||
return;
|
arena.onBlockBreak(event);
|
||||||
|
|
||||||
Block b = event.getBlock();
|
|
||||||
|
|
||||||
if (ArenaManager.blockSet.remove(b) || b.getType() == Material.TNT)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (MAUtils.inRegion(b.getLocation()))
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds player-placed blocks to a set for removal and item
|
|
||||||
* drop purposes. If the block is placed within the arena
|
|
||||||
* region, cancel the event if protection is on.
|
|
||||||
*/
|
|
||||||
public void onBlockPlace(BlockPlaceEvent event)
|
public void onBlockPlace(BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
if (!ArenaManager.isSetup || !ArenaManager.isProtected)
|
for (Arena arena : am.arenas)
|
||||||
return;
|
arena.onBlockPlace(event);
|
||||||
|
|
||||||
Block b = event.getBlock();
|
|
||||||
|
|
||||||
if (!MAUtils.inRegion(b.getLocation()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ArenaManager.isRunning && ArenaManager.playerSet.contains(event.getPlayer()))
|
|
||||||
{
|
|
||||||
ArenaManager.blockSet.add(b);
|
|
||||||
Material type = b.getType();
|
|
||||||
|
|
||||||
// Make sure to add the top parts of doors.
|
|
||||||
if (type == Material.WOODEN_DOOR || type == Material.IRON_DOOR_BLOCK)
|
|
||||||
ArenaManager.blockSet.add(b.getRelative(0,1,0));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,65 @@
|
|||||||
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
import org.bukkit.event.entity.EntityCombustEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
import org.bukkit.event.entity.EntityListener;
|
||||||
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.Arena;
|
||||||
|
import com.garbagemule.MobArena.ArenaMaster;
|
||||||
|
|
||||||
|
public class MAEntityListener extends EntityListener
|
||||||
|
{
|
||||||
|
private ArenaMaster am;
|
||||||
|
|
||||||
|
public MAEntityListener(ArenaMaster am)
|
||||||
|
{
|
||||||
|
this.am = am;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntityRegainHealth(EntityRegainHealthEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onEntityRegainHealth(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntityDeath(EntityDeathEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onEntityDeath(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntityDamage(EntityDamageEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onEntityDamage(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onCreatureSpawn(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntityExplode(EntityExplodeEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onEntityExplode(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntityCombust(EntityCombustEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onEntityCombust(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntityTarget(EntityTargetEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onEntityTarget(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class MAInventoryItem implements Serializable
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 739709220350581510L;
|
||||||
|
private int typeId;
|
||||||
|
private int amount;
|
||||||
|
private short durability;
|
||||||
|
|
||||||
|
public MAInventoryItem(int typeId, int amount, short durability)
|
||||||
|
{
|
||||||
|
this.typeId = typeId;
|
||||||
|
this.amount = amount;
|
||||||
|
this.durability = durability;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTypeId() { return typeId; }
|
||||||
|
public int getAmount() { return amount; }
|
||||||
|
public short getDurability() { return durability; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MAMessages
|
||||||
|
{
|
||||||
|
protected static Map<Msg,String> msgMap;
|
||||||
|
private static Map<Msg,String> defaults = new HashMap<Msg,String>();
|
||||||
|
protected static enum Msg
|
||||||
|
{
|
||||||
|
ARENA_START,
|
||||||
|
ARENA_END,
|
||||||
|
ARENA_DOES_NOT_EXIST,
|
||||||
|
JOIN_PLAYER_JOINED,
|
||||||
|
JOIN_NOT_ENABLED,
|
||||||
|
JOIN_IN_OTHER_ARENA,
|
||||||
|
JOIN_ARENA_NOT_ENABLED,
|
||||||
|
JOIN_ARENA_NOT_SETUP,
|
||||||
|
JOIN_ARENA_IS_RUNNING,
|
||||||
|
JOIN_ALREADY_PLAYING,
|
||||||
|
JOIN_ARG_NEEDED,
|
||||||
|
JOIN_EMPTY_INV,
|
||||||
|
JOIN_STORE_INV_FAIL,
|
||||||
|
LEAVE_PLAYER_LEFT,
|
||||||
|
LEAVE_NOT_PLAYING,
|
||||||
|
PLAYER_DIED,
|
||||||
|
SPEC_PLAYER_SPECTATE,
|
||||||
|
SPEC_NOT_RUNNING,
|
||||||
|
SPEC_ARG_NEEDED,
|
||||||
|
SPEC_EMPTY_INV,
|
||||||
|
SPEC_ALREADY_PLAYING,
|
||||||
|
NOT_READY_PLAYERS,
|
||||||
|
NOT_READY_RUNNING,
|
||||||
|
FORCE_START_STARTED,
|
||||||
|
FORCE_START_RUNNING,
|
||||||
|
FORCE_START_NOT_READY,
|
||||||
|
FORCE_END_ENDED,
|
||||||
|
FORCE_END_EMPTY,
|
||||||
|
FORCE_END_IDLE,
|
||||||
|
REWARDS_GIVE,
|
||||||
|
LOBBY_CLASS_PICKED,
|
||||||
|
LOBBY_PLAYER_READY,
|
||||||
|
LOBBY_DROP_ITEM,
|
||||||
|
LOBBY_PICK_CLASS,
|
||||||
|
LOBBY_RIGHT_CLICK,
|
||||||
|
WARP_TO_ARENA,
|
||||||
|
WARP_FROM_ARENA,
|
||||||
|
WAVE_DEFAULT,
|
||||||
|
WAVE_SPECIAL,
|
||||||
|
WAVE_REWARD,
|
||||||
|
// Misc
|
||||||
|
MISC_LIST_ARENAS,
|
||||||
|
MISC_LIST_PLAYERS,
|
||||||
|
MISC_COMMAND_NOT_ALLOWED,
|
||||||
|
MISC_NO_ACCESS,
|
||||||
|
MISC_NONE
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate the defaults map.
|
||||||
|
static
|
||||||
|
{
|
||||||
|
defaults.put(Msg.ARENA_START, "Let the slaughter begin!");
|
||||||
|
defaults.put(Msg.ARENA_END, "Arena finished.");
|
||||||
|
defaults.put(Msg.ARENA_DOES_NOT_EXIST, "That arena does not exist. Type /ma arenas for a list.");
|
||||||
|
defaults.put(Msg.JOIN_NOT_ENABLED, "MobArena is not enabled.");
|
||||||
|
defaults.put(Msg.JOIN_IN_OTHER_ARENA, "You are already in an arena! Leave that one first.");
|
||||||
|
defaults.put(Msg.JOIN_ARENA_NOT_ENABLED, "This arena is not enabled.");
|
||||||
|
defaults.put(Msg.JOIN_ARENA_NOT_SETUP, "This arena has not been set up yet.");
|
||||||
|
defaults.put(Msg.JOIN_ARENA_IS_RUNNING, "This arena is in already progress.");
|
||||||
|
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_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.");
|
||||||
|
defaults.put(Msg.LEAVE_PLAYER_LEFT, "You left the arena. Thanks for playing!");
|
||||||
|
defaults.put(Msg.PLAYER_DIED, "% died!");
|
||||||
|
defaults.put(Msg.SPEC_PLAYER_SPECTATE, "Enjoy the show!");
|
||||||
|
defaults.put(Msg.SPEC_NOT_RUNNING, "This arena isn't running.");
|
||||||
|
defaults.put(Msg.SPEC_ARG_NEEDED, "You must specify an arena. Type /ma arenas for a list.");
|
||||||
|
defaults.put(Msg.SPEC_EMPTY_INV, "Empty your inventory first!");
|
||||||
|
defaults.put(Msg.SPEC_ALREADY_PLAYING, "Can't spectate when in the arena!");
|
||||||
|
defaults.put(Msg.NOT_READY_RUNNING, "The lobby is empty!");
|
||||||
|
defaults.put(Msg.NOT_READY_PLAYERS, "Not ready: %");
|
||||||
|
defaults.put(Msg.FORCE_START_RUNNING, "Arena has already started.");
|
||||||
|
defaults.put(Msg.FORCE_START_NOT_READY, "Can't force start, no players are ready.");
|
||||||
|
defaults.put(Msg.FORCE_START_STARTED, "Forced arena start.");
|
||||||
|
defaults.put(Msg.FORCE_END_EMPTY, "No one is in the arena.");
|
||||||
|
defaults.put(Msg.FORCE_END_ENDED, "Forced arena end.");
|
||||||
|
defaults.put(Msg.FORCE_END_IDLE, "You weren't quick enough!");
|
||||||
|
defaults.put(Msg.REWARDS_GIVE, "Here are all of your rewards!");
|
||||||
|
defaults.put(Msg.LOBBY_DROP_ITEM, "No sharing before the arena starts!");
|
||||||
|
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_RIGHT_CLICK, "Punch the sign. Don't right-click.");
|
||||||
|
defaults.put(Msg.LOBBY_CLASS_PICKED, "You have chosen % as your class!");
|
||||||
|
defaults.put(Msg.WARP_TO_ARENA, "Can't warp to the arena during battle!");
|
||||||
|
defaults.put(Msg.WARP_FROM_ARENA, "Warping not allowed in the arena!");
|
||||||
|
defaults.put(Msg.WAVE_DEFAULT, "Get ready for wave #%!");
|
||||||
|
defaults.put(Msg.WAVE_SPECIAL, "Get ready for wave #%! [SPECIAL]");
|
||||||
|
defaults.put(Msg.WAVE_REWARD, "You just earned a reward: %");
|
||||||
|
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_NONE, "<none>");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the msgMap by reading from the announcements-file.
|
||||||
|
*/
|
||||||
|
public static void init(MobArena plugin, boolean update)
|
||||||
|
{
|
||||||
|
// Use defaults in case of any errors.
|
||||||
|
msgMap = defaults;
|
||||||
|
|
||||||
|
// Grab the announcements-file.
|
||||||
|
File msgFile;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
msgFile = new File(plugin.getDataFolder(), "announcements.properties");
|
||||||
|
|
||||||
|
// If it doesn't exist, create it.
|
||||||
|
if (!msgFile.exists())
|
||||||
|
{
|
||||||
|
System.out.println("[MobArena] Announcements-file not found. Creating one...");
|
||||||
|
msgFile.createNewFile();
|
||||||
|
|
||||||
|
FileWriter fw = new FileWriter(msgFile);
|
||||||
|
BufferedWriter bw = new BufferedWriter(fw);
|
||||||
|
|
||||||
|
// Write default announcements to the file.
|
||||||
|
for (Msg m : Msg.values())
|
||||||
|
{
|
||||||
|
bw.write(m.toString() + "=" + defaults.get(m));
|
||||||
|
bw.newLine();
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("[MobArena] ERROR: Couldn't initialize announcements-file. Using defaults.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the file was found, populate the msgMap.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileReader fr = new FileReader(msgFile);
|
||||||
|
BufferedReader br = new BufferedReader(fr);
|
||||||
|
|
||||||
|
String s;
|
||||||
|
while ((s = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
process(s);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("[MobArena] ERROR: Problem with announcements-file. Using defaults.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(MobArena plugin)
|
||||||
|
{
|
||||||
|
init(plugin, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grabs the announcement from the msgMap, and in case of
|
||||||
|
* s not being null, replaces the % with s.
|
||||||
|
*/
|
||||||
|
public static String get(Msg msg, String s)
|
||||||
|
{
|
||||||
|
// If p is null, just return the announcement as is.
|
||||||
|
if (s == null)
|
||||||
|
return msgMap.get(msg);
|
||||||
|
|
||||||
|
// Otherwise, replace the % with the input string.
|
||||||
|
return msgMap.get(msg).replace("%", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grabs the announcement from the msgMap.
|
||||||
|
*/
|
||||||
|
public static String get(Msg msg)
|
||||||
|
{
|
||||||
|
return get(msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper-method for parsing the strings from the
|
||||||
|
* announcements-file.
|
||||||
|
*/
|
||||||
|
private static void process(String s)
|
||||||
|
{
|
||||||
|
// Split the string by the equals-sign.
|
||||||
|
String[] split = s.split("=");
|
||||||
|
if (split.length != 2)
|
||||||
|
{
|
||||||
|
System.out.println("[MobArena] ERROR: Couldn't parse \"" + s + "\".");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For simplicity...
|
||||||
|
String key = split[0];
|
||||||
|
String val = split[1];
|
||||||
|
Msg msg;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
msg = Msg.valueOf(key);
|
||||||
|
msgMap.put(msg, val);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("[MobArena] ERROR: " + key + " is not a valid key!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerListener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
|
public class MAPlayerListener extends PlayerListener
|
||||||
|
{
|
||||||
|
private MobArena plugin;
|
||||||
|
private ArenaMaster am;
|
||||||
|
|
||||||
|
public MAPlayerListener(MobArena plugin, ArenaMaster am)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.am = am;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
|
{
|
||||||
|
if (!am.enabled) return;
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onPlayerInteract(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||||
|
{
|
||||||
|
if (!am.enabled) return;
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onPlayerDropItem(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event)
|
||||||
|
{
|
||||||
|
if (!am.enabled) return;
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onPlayerBucketEmpty(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||||
|
{
|
||||||
|
if (!am.enabled) return;
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onPlayerTeleport(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||||
|
{
|
||||||
|
if (!am.enabled) return;
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onPlayerCommandPreprocess(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onPlayerQuit(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerKick(PlayerKickEvent event)
|
||||||
|
{
|
||||||
|
for (Arena arena : am.arenas)
|
||||||
|
arena.onPlayerKick(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
if (!am.updateNotify || !event.getPlayer().isOp()) return;
|
||||||
|
|
||||||
|
final Player p = event.getPlayer();
|
||||||
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||||
|
new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
MAUtils.checkForUpdates(plugin, p, false);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
package com.garbagemule.MobArena;
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.entity.Ghast;
|
import org.bukkit.entity.Ghast;
|
||||||
@@ -11,6 +17,9 @@ import org.bukkit.entity.Creature;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.CreatureType;
|
import org.bukkit.entity.CreatureType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core class for handling wave spawning.
|
* Core class for handling wave spawning.
|
||||||
@@ -20,92 +29,103 @@ import org.bukkit.entity.CreatureType;
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
// TO-DO: Allow custom special wave interval.
|
// TODO: Allow custom special wave monsters.
|
||||||
// TO-DO: Allow custom special wave monsters.
|
// TODO: Allow additional "default" waves.
|
||||||
// TO-DO: Allow additional "default" waves.
|
|
||||||
public class MASpawnThread implements Runnable
|
public class MASpawnThread implements Runnable
|
||||||
{
|
{
|
||||||
private int wave, ran, noOfSpawnPoints, noOfPlayers, modulo;
|
protected int wave, previousSize, taskId;
|
||||||
|
private int ran, noOfPlayers, modulo;
|
||||||
private int dZombies, dSkeletons, dSpiders, dCreepers, dWolves;
|
private int dZombies, dSkeletons, dSpiders, dCreepers, dWolves;
|
||||||
private int dPoweredCreepers, dPigZombies, dSlimes, dMonsters, dAngryWolves, dGiants, dGhasts;
|
private int dPoweredCreepers, dPigZombies, dSlimes, dMonsters, dAngryWolves, dGiants, dGhasts;
|
||||||
private Random random;
|
private Random random;
|
||||||
private String reward, currentRewards;
|
private Arena arena;
|
||||||
|
private final double MIN_DISTANCE = 256;
|
||||||
|
|
||||||
public MASpawnThread()
|
public MASpawnThread(Arena arena)
|
||||||
{
|
{
|
||||||
modulo = ArenaManager.specialModulo;
|
this.arena = arena;
|
||||||
|
modulo = arena.specialModulo;
|
||||||
if (modulo <= 0) modulo = -32768;
|
if (modulo <= 0) modulo = -32768;
|
||||||
|
|
||||||
noOfPlayers = ArenaManager.playerSet.size();
|
taskId = -32768;
|
||||||
noOfSpawnPoints = ArenaManager.spawnpoints.size();
|
|
||||||
|
noOfPlayers = arena.livePlayers.size();
|
||||||
wave = 1;
|
wave = 1;
|
||||||
random = new Random();
|
random = new Random();
|
||||||
|
|
||||||
// Set up the distribution variables for the random spawner.
|
// Set up the distribution variables for the random spawner.
|
||||||
dZombies = ArenaManager.dZombies;
|
dZombies = arena.distDefault.get("zombies");
|
||||||
dSkeletons = dZombies + ArenaManager.dSkeletons;
|
dSkeletons = dZombies + arena.distDefault.get("skeletons");
|
||||||
dSpiders = dSkeletons + ArenaManager.dSpiders;
|
dSpiders = dSkeletons + arena.distDefault.get("spiders");
|
||||||
dCreepers = dSpiders + ArenaManager.dCreepers;
|
dCreepers = dSpiders + arena.distDefault.get("creepers");
|
||||||
dWolves = dCreepers + ArenaManager.dWolves;
|
dWolves = dCreepers + arena.distDefault.get("wolves");
|
||||||
|
|
||||||
dPoweredCreepers = ArenaManager.dPoweredCreepers;
|
dPoweredCreepers = arena.distSpecial.get("powered-creepers");
|
||||||
dPigZombies = dPoweredCreepers + ArenaManager.dPigZombies;
|
dPigZombies = dPoweredCreepers + arena.distSpecial.get("zombie-pigmen");
|
||||||
dSlimes = dPigZombies + ArenaManager.dSlimes;
|
dSlimes = dPigZombies + arena.distSpecial.get("slimes");
|
||||||
dMonsters = dSlimes + ArenaManager.dMonsters;
|
dMonsters = dSlimes + arena.distSpecial.get("humans");
|
||||||
dAngryWolves = dMonsters + ArenaManager.dAngryWolves;
|
dAngryWolves = dMonsters + arena.distSpecial.get("angry-wolves");
|
||||||
dGiants = dAngryWolves + ArenaManager.dGiants;
|
dGiants = dAngryWolves + arena.distSpecial.get("giants");
|
||||||
dGhasts = dGiants + ArenaManager.dGhasts;
|
dGhasts = dGiants + arena.distSpecial.get("ghasts");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
// Check if we need to grant more rewards with the recurrent waves.
|
// Check if wave needs to be cleared first. If so, return!
|
||||||
for (Integer i : ArenaManager.everyWaveMap.keySet())
|
if (arena.waveClear && wave > 1)
|
||||||
{
|
{
|
||||||
if (wave % i != 0)
|
if (!arena.monsters.isEmpty())
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
for (Player p : ArenaManager.playerSet)
|
|
||||||
{
|
|
||||||
currentRewards = ArenaManager.rewardMap.get(p);
|
|
||||||
reward = MAUtils.getRandomReward(ArenaManager.everyWaveMap.get(i));
|
|
||||||
currentRewards += reward + ",";
|
|
||||||
ArenaManager.rewardMap.put(p, currentRewards);
|
|
||||||
ArenaManager.tellPlayer(p, "You just earned a reward: " + reward);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If maxIdleTime is defined, reset the timer.
|
||||||
|
//if (arena.maxIdleTime > 0) arena.resetIdleTimer();
|
||||||
|
|
||||||
|
// Check if we need to grant more rewards with the recurrent waves.
|
||||||
|
for (Map.Entry<Integer,List<ItemStack>> entry : arena.everyWaveMap.entrySet())
|
||||||
|
if (wave % entry.getKey() == 0)
|
||||||
|
addReward(entry.getValue());
|
||||||
|
|
||||||
// Same deal, this time with the one-time waves.
|
// Same deal, this time with the one-time waves.
|
||||||
if (ArenaManager.afterWaveMap.containsKey(wave))
|
if (arena.afterWaveMap.containsKey(wave))
|
||||||
{
|
addReward(arena.afterWaveMap.get(wave));
|
||||||
for (Player p : ArenaManager.playerSet)
|
|
||||||
{
|
|
||||||
currentRewards = ArenaManager.rewardMap.get(p);
|
|
||||||
reward = MAUtils.getRandomReward(ArenaManager.afterWaveMap.get(wave));
|
|
||||||
currentRewards += reward + ",";
|
|
||||||
ArenaManager.rewardMap.put(p, currentRewards);
|
|
||||||
ArenaManager.tellPlayer(p, "You just earned a reward: " + reward);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if this is a special wave.
|
// Check if this is a special wave.
|
||||||
if (wave % modulo == 0)
|
if (wave % modulo == 0)
|
||||||
{
|
{
|
||||||
ArenaManager.tellAll("Get ready for wave #" + wave + "! [SPECIAL]");
|
MAUtils.tellAll(arena, MAMessages.get(Msg.WAVE_SPECIAL, ""+wave));
|
||||||
for (MobArenaListener m : ArenaManager.listeners)
|
/*for (MobArenaListener m : ArenaManager.listeners) TODO: Get API back up to speed.
|
||||||
m.onSpecialWave(wave, wave/modulo);
|
m.onSpecialWave(wave, wave/modulo);*/
|
||||||
|
detonateCreepers(arena.detCreepers);
|
||||||
|
|
||||||
specialWave();
|
specialWave();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ArenaManager.tellAll("Get ready for wave #" + wave + "!");
|
MAUtils.tellAll(arena, MAMessages.get(Msg.WAVE_DEFAULT, ""+wave));
|
||||||
for (MobArenaListener m : ArenaManager.listeners)
|
/*for (MobArenaListener m : ArenaManager.listeners) TODO: More API
|
||||||
m.onDefaultWave(wave);
|
m.onDefaultWave(wave);*/
|
||||||
|
detonateCreepers(arena.detCreepers);
|
||||||
|
|
||||||
defaultWave();
|
defaultWave();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArenaManager.wave = wave;
|
|
||||||
wave++;
|
wave++;
|
||||||
|
if (arena.maxIdleTime > 0) arena.resetIdleTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewards all players with an item from the input String.
|
||||||
|
*/
|
||||||
|
private void addReward(List<ItemStack> rewards)
|
||||||
|
{
|
||||||
|
for (Player p : arena.livePlayers)
|
||||||
|
{
|
||||||
|
ItemStack reward = MAUtils.getRandomReward(rewards);
|
||||||
|
arena.rewardMap.get(p).add(reward);
|
||||||
|
|
||||||
|
MAUtils.tellPlayer(p, MAMessages.get(Msg.WAVE_REWARD, MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,12 +134,15 @@ public class MASpawnThread implements Runnable
|
|||||||
private void defaultWave()
|
private void defaultWave()
|
||||||
{
|
{
|
||||||
Location loc;
|
Location loc;
|
||||||
|
List<Location> spawnpoints = getValidSpawnpoints();
|
||||||
for (int i = 0; i < wave + noOfPlayers; i++)
|
int noOfSpawnpoints = spawnpoints.size();
|
||||||
|
int count = wave + noOfPlayers;
|
||||||
|
CreatureType mob;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
loc = ArenaManager.spawnpoints.get(i % noOfSpawnPoints);
|
loc = spawnpoints.get(i % noOfSpawnpoints);
|
||||||
ran = random.nextInt(dWolves);
|
ran = random.nextInt(dWolves);
|
||||||
CreatureType mob;
|
|
||||||
|
|
||||||
/* Because of the nature of the if-elseif-else statement,
|
/* Because of the nature of the if-elseif-else statement,
|
||||||
* we're able to evaluate the random number in this way.
|
* we're able to evaluate the random number in this way.
|
||||||
@@ -133,8 +156,8 @@ public class MASpawnThread implements Runnable
|
|||||||
else if (ran < dWolves) mob = CreatureType.WOLF;
|
else if (ran < dWolves) mob = CreatureType.WOLF;
|
||||||
else continue;
|
else continue;
|
||||||
|
|
||||||
LivingEntity e = ArenaManager.world.spawnCreature(loc,mob);
|
LivingEntity e = arena.world.spawnCreature(loc,mob);
|
||||||
ArenaManager.monsterSet.add(e);
|
arena.monsters.add(e);
|
||||||
|
|
||||||
// Grab a random target.
|
// Grab a random target.
|
||||||
Creature c = (Creature) e;
|
Creature c = (Creature) e;
|
||||||
@@ -148,6 +171,8 @@ public class MASpawnThread implements Runnable
|
|||||||
private void specialWave()
|
private void specialWave()
|
||||||
{
|
{
|
||||||
Location loc;
|
Location loc;
|
||||||
|
List<Location> spawnpoints = getValidSpawnpoints();
|
||||||
|
int noOfSpawnpoints = spawnpoints.size();
|
||||||
CreatureType mob;
|
CreatureType mob;
|
||||||
ran = random.nextInt(dGhasts);
|
ran = random.nextInt(dGhasts);
|
||||||
|
|
||||||
@@ -202,13 +227,10 @@ public class MASpawnThread implements Runnable
|
|||||||
// Spawn the hippie monsters.
|
// Spawn the hippie monsters.
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
loc = ArenaManager.spawnpoints.get(i % noOfSpawnPoints);
|
loc = spawnpoints.get(i % noOfSpawnpoints);
|
||||||
|
|
||||||
LivingEntity e = ArenaManager.world.spawnCreature(loc,mob);
|
LivingEntity e = arena.world.spawnCreature(loc,mob);
|
||||||
if (!ArenaManager.monsterSet.contains(e))
|
arena.monsters.add(e);
|
||||||
ArenaManager.monsterSet.add(e);
|
|
||||||
else
|
|
||||||
System.out.println("MASpawnThread - monsterSet contains this entity");
|
|
||||||
|
|
||||||
if (slime) ((Slime)e).setSize(2);
|
if (slime) ((Slime)e).setSize(2);
|
||||||
if (wolf) ((Wolf)e).setAngry(true);
|
if (wolf) ((Wolf)e).setAngry(true);
|
||||||
@@ -224,38 +246,78 @@ public class MASpawnThread implements Runnable
|
|||||||
c.setTarget(getClosestPlayer(e));
|
c.setTarget(getClosestPlayer(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ArenaManager.lightning)
|
if (!arena.lightning)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Lightning, just for effect ;)
|
// Lightning, just for effect ;)
|
||||||
for (Location spawn : ArenaManager.spawnpoints)
|
for (Location spawn : arena.spawnpoints.values())
|
||||||
|
arena.world.strikeLightningEffect(spawn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Detonates" all the Creepers in the monsterSet.
|
||||||
|
*/
|
||||||
|
public void detonateCreepers(boolean really)
|
||||||
|
{
|
||||||
|
if (!really)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Set<Entity> tmp = new HashSet<Entity>();
|
||||||
|
for (Entity e : arena.monsters)
|
||||||
{
|
{
|
||||||
ArenaManager.world.strikeLightningEffect(spawn);
|
if (!(e instanceof Creeper) || e.isDead())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
tmp.add(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Location loc;
|
||||||
|
for (Entity e : tmp)
|
||||||
|
{
|
||||||
|
arena.monsters.remove(e);
|
||||||
|
loc = e.getLocation().getBlock().getRelative(0,2,0).getLocation();
|
||||||
|
arena.world.createExplosion(loc, 2);
|
||||||
|
e.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the player closest to the input entity. ArrayList implementation
|
* Get all the spawnpoints that have players nearby.
|
||||||
* means a complexity of O(n).
|
|
||||||
*/
|
*/
|
||||||
// TO-DO: Move this into MAUtils
|
public List<Location> getValidSpawnpoints()
|
||||||
public static Player getClosestPlayer(Entity e)
|
|
||||||
{
|
{
|
||||||
// Grab the coordinates.
|
List<Location> result = new ArrayList<Location>();
|
||||||
double x = e.getLocation().getX();
|
|
||||||
double y = e.getLocation().getY();
|
|
||||||
double z = e.getLocation().getZ();
|
|
||||||
|
|
||||||
|
for (Location s : arena.spawnpoints.values())
|
||||||
|
for (Player p : arena.livePlayers)
|
||||||
|
if (s.distanceSquared(p.getLocation()) < MIN_DISTANCE)
|
||||||
|
result.add(s);
|
||||||
|
|
||||||
|
// If no players are in range, just use all the spawnpoints.
|
||||||
|
if (result.isEmpty())
|
||||||
|
result.addAll(arena.spawnpoints.values());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the player closest to the input entity.
|
||||||
|
*/
|
||||||
|
// TODO: Move this into MAUtils
|
||||||
|
public Player getClosestPlayer(Entity e)
|
||||||
|
{
|
||||||
// Set up the comparison variable and the result.
|
// Set up the comparison variable and the result.
|
||||||
|
double dist = 0;
|
||||||
double current = Double.POSITIVE_INFINITY;
|
double current = Double.POSITIVE_INFINITY;
|
||||||
Player result = null;
|
Player result = null;
|
||||||
|
|
||||||
/* Iterate through the ArrayList, and update current and result every
|
/* Iterate through the ArrayList, and update current and result every
|
||||||
* time a squared distance smaller than current is found. */
|
* time a squared distance smaller than current is found. */
|
||||||
for (Player p : ArenaManager.playerSet)
|
for (Player p : arena.livePlayers)
|
||||||
{
|
{
|
||||||
double dist = distance(p.getLocation(), x, y, z);
|
dist = p.getLocation().distance(e.getLocation());
|
||||||
if (dist < current)
|
//double dist = MAUtils.distance(p.getLocation(), e.getLocation());
|
||||||
|
if (dist < current && dist < 256)
|
||||||
{
|
{
|
||||||
current = dist;
|
current = dist;
|
||||||
result = p;
|
result = p;
|
||||||
@@ -263,17 +325,4 @@ public class MASpawnThread implements Runnable
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the squared distance between locations.
|
|
||||||
*/
|
|
||||||
// TO-DO: Move this into MAUtils
|
|
||||||
private static double distance(Location loc, double d1, double d2, double d3)
|
|
||||||
{
|
|
||||||
double d4 = loc.getX() - d1;
|
|
||||||
double d5 = loc.getY() - d2;
|
|
||||||
double d6 = loc.getZ() - d3;
|
|
||||||
|
|
||||||
return d4*d4 + d5*d5 + d6*d6;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
package com.garbagemule.MobArena;
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.File;
|
||||||
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
@@ -10,21 +10,17 @@ import org.bukkit.event.entity.EntityListener;
|
|||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MobArena
|
* MobArena
|
||||||
*
|
|
||||||
* @author garbagemule
|
* @author garbagemule
|
||||||
*/
|
*/
|
||||||
public class MobArena extends JavaPlugin
|
public class MobArena extends JavaPlugin
|
||||||
{
|
{
|
||||||
/* Array of commands used to determine if a command belongs to MobArena
|
/* Other useful variables. */
|
||||||
* or Mean Admins. */
|
private Configuration config;
|
||||||
public final String[] COMMANDS = {"join", "j", "leave", "l", "list", "who", "spectate", "spec",
|
private ArenaMaster am;
|
||||||
"ready", "notready", "enabled", "force", "config", "setwarp",
|
|
||||||
"addspawn", "delspawn", "setregion", "expandregion", "protect",
|
|
||||||
"undo", "dooooo", "reset"};
|
|
||||||
public List<String> DISABLED_COMMANDS;
|
|
||||||
|
|
||||||
public MobArena()
|
public MobArena()
|
||||||
{
|
{
|
||||||
@@ -34,52 +30,204 @@ public class MobArena extends JavaPlugin
|
|||||||
{
|
{
|
||||||
PluginDescriptionFile pdfFile = this.getDescription();
|
PluginDescriptionFile pdfFile = this.getDescription();
|
||||||
|
|
||||||
// Initialize convenience variables in ArenaManager.
|
loadConfig();
|
||||||
ArenaManager.init(this);
|
MAMessages.init(this);
|
||||||
DISABLED_COMMANDS = MAUtils.getDisabledCommands();
|
am = new ArenaMaster(this);
|
||||||
|
am.initialize();
|
||||||
|
|
||||||
// Bind the /ma and /marena commands to MACommands.
|
// Bind the /ma, /marena, and /mobarena commands to MACommands.
|
||||||
getCommand("ma").setExecutor(new MACommands());
|
MACommands commandExecutor = new MACommands(this, am);
|
||||||
getCommand("marena").setExecutor(new MACommands());
|
getCommand("ma").setExecutor(commandExecutor);
|
||||||
getCommand("mobarena").setExecutor(new MACommands());
|
getCommand("marena").setExecutor(commandExecutor);
|
||||||
|
getCommand("mobarena").setExecutor(commandExecutor);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Create event listeners.
|
// Create event listeners.
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
PlayerListener commandListener = new MADisabledCommands(this);
|
PlayerListener playerListener = new MAPlayerListener(this, am);
|
||||||
PlayerListener lobbyListener = new MALobbyListener(this);
|
EntityListener entityListener = new MAEntityListener(am);
|
||||||
PlayerListener teleportListener = new MATeleportListener(this);
|
BlockListener blockListener = new MABlockListener(am);
|
||||||
PlayerListener discListener = new MADisconnectListener(this);
|
|
||||||
BlockListener blockListener = new MABlockListener(this);
|
|
||||||
EntityListener deathListener = new MADeathListener(this);
|
|
||||||
EntityListener monsterListener = new MAMonsterListener(this);
|
|
||||||
// TO-DO: PlayerListener to check for kills/deaths.
|
|
||||||
|
|
||||||
// Register events.
|
// Register events.
|
||||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, commandListener, Priority.Monitor, this);
|
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, lobbyListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, lobbyListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, lobbyListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_TELEPORT, teleportListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_QUIT, discListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_KICK, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_KICK, discListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_JOIN, discListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Event.Type.ENTITY_DEATH, deathListener, Priority.Lowest, this); // Lowest because of Tombstone
|
pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Lowest, this); // Lowest because of Tombstone
|
||||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, monsterListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.ENTITY_COMBUST, monsterListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Event.Type.ENTITY_TARGET, monsterListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, monsterListener, 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.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Monitor, this);
|
||||||
|
|
||||||
System.out.println(pdfFile.getName() + " v" + pdfFile.getVersion() + " enabled." );
|
System.out.println("[MobArena] v" + pdfFile.getVersion() + " enabled." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
System.out.println("WAIT! WHAT ARE YOU DOING?!");
|
for (Arena arena : am.arenas)
|
||||||
|
arena.forceEnd();
|
||||||
|
am.arenaMap.clear();
|
||||||
|
|
||||||
ArenaManager.forceEnd(null);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Configuration getConfig() { return config; }
|
||||||
|
public ArenaMaster getAM() { return am; } // More convenient.
|
||||||
|
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();
|
||||||
|
config.setProperty("global-settings.repair-delay", 5);
|
||||||
|
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 waves and rewards to the new default arena.
|
||||||
|
for (String s : oldConfig.getKeys("waves.default"))
|
||||||
|
config.setProperty("arenas.default.waves.default." + s, oldConfig.getString("waves.default." + s));
|
||||||
|
config.save();
|
||||||
|
for (String s : oldConfig.getKeys("rewards.waves.every"))
|
||||||
|
config.setProperty("arenas.default.rewards.waves.every." + s, oldConfig.getString("rewards.waves.every." + s));
|
||||||
|
for (String s : oldConfig.getKeys("rewards.waves.after"))
|
||||||
|
config.setProperty("arenas.default.rewards.waves.after." + s, oldConfig.getString("rewards.waves.after." + s));
|
||||||
|
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!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,32 +3,121 @@ package com.garbagemule.MobArena;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class MobArenaHandler
|
public class MobArenaHandler
|
||||||
{
|
{
|
||||||
|
MobArena plugin;
|
||||||
|
|
||||||
public MobArenaHandler()
|
public MobArenaHandler()
|
||||||
{
|
{
|
||||||
|
plugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there is an active arena session running.
|
// Check if there is an active arena session running.
|
||||||
public boolean isRunning() { return ArenaManager.isRunning; }
|
public boolean isRunning(String arenaName)
|
||||||
|
{
|
||||||
|
Arena arena = plugin.getAM().getArenaWithName(arenaName);
|
||||||
|
if (arena == null)
|
||||||
|
throw new NullPointerException("Arena with name '" + arenaName + "' does not exist!");
|
||||||
|
|
||||||
|
return arena.running;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the specified player is in the arena/lobby.
|
// Check if the specified player is in an arena.
|
||||||
public boolean isPlaying(Player p) { return ArenaManager.playerSet.contains(p); }
|
public boolean isPlaying(Player p) { return (plugin.getAM().getArenaWithPlayer(p) != null); }
|
||||||
|
|
||||||
// Get a list of all players currently in the arena.
|
// Arena getters
|
||||||
public List<Player> getPlayers() { return new LinkedList<Player>(ArenaManager.playerSet); }
|
public Arena getArenaWithName(String arenaName) { return plugin.getAM().getArenaWithName(arenaName); }
|
||||||
|
public Arena getArenaWithPlayer(Player p) { return plugin.getAM().getArenaWithPlayer(p); }
|
||||||
|
public Arena getArenaWithPlayer(String player) { return plugin.getAM().getArenaWithPlayer(player); }
|
||||||
|
public Arena getArenaWithPet(Entity wolf) { return plugin.getAM().getArenaWithPet(wolf); }
|
||||||
|
public Arena getArenaWithMonster(Entity monster) { return plugin.getAM().getArenaWithMonster(monster); }
|
||||||
|
public Arena getArenaInLocation(Location l) { return plugin.getAM().getArenaInLocation(l); }
|
||||||
|
|
||||||
// Get the warp locations.
|
// Player lists
|
||||||
public Location getArenaLocation() { return ArenaManager.arenaLoc; }
|
public List<Player> getAllPlayers() { return new LinkedList<Player>(plugin.getAM().arenaMap.keySet()); }
|
||||||
public Location getLobbyLocation() { return ArenaManager.lobbyLoc; }
|
public List<Player> getAllPlayers(Arena arena) { return arena.getAllPlayers(); }
|
||||||
public Location getSpectatorLocation() { return ArenaManager.spectatorLoc; }
|
public List<Player> getAllPlayers(String arenaName) { return getAllPlayers(plugin.getAM().getArenaWithName(arenaName)); }
|
||||||
|
|
||||||
|
public List<Player> getLivingPlayers()
|
||||||
|
{
|
||||||
|
List<Player> result = new LinkedList<Player>();
|
||||||
|
for (Arena arena : plugin.getAM().arenas)
|
||||||
|
result.addAll(arena.getLivingPlayers());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Player> getLivingPlayers(String arenaName)
|
||||||
|
{
|
||||||
|
Arena arena = plugin.getAM().getArenaWithName(arenaName);
|
||||||
|
if (arena == null)
|
||||||
|
throw new NullPointerException("Arena with name '" + arenaName + "' does not exist!");
|
||||||
|
|
||||||
|
return new LinkedList<Player>(arena.livePlayers);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warp locations.
|
||||||
|
public Location getArenaLocation(String arenaName)
|
||||||
|
{
|
||||||
|
Arena arena = plugin.getAM().getArenaWithName(arenaName);
|
||||||
|
if (arena == null)
|
||||||
|
throw new NullPointerException("Arena with name '" + arenaName + "' does not exist!");
|
||||||
|
|
||||||
|
return arena.arenaLoc;
|
||||||
|
}
|
||||||
|
public Location getLobbyLocation(String arenaName)
|
||||||
|
{
|
||||||
|
Arena arena = plugin.getAM().getArenaWithName(arenaName);
|
||||||
|
if (arena == null)
|
||||||
|
throw new NullPointerException("Arena with name '" + arenaName + "' does not exist!");
|
||||||
|
|
||||||
|
return arena.lobbyLoc;
|
||||||
|
}
|
||||||
|
public Location getSpectatorLocation(String arenaName)
|
||||||
|
{
|
||||||
|
Arena arena = plugin.getAM().getArenaWithName(arenaName);
|
||||||
|
if (arena == null)
|
||||||
|
throw new NullPointerException("Arena with name '" + arenaName + "' does not exist!");
|
||||||
|
|
||||||
|
return arena.spectatorLoc;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the current wave number.
|
// Get the current wave number.
|
||||||
public int getWave() { return ArenaManager.wave; }
|
public int getWave(Arena arena) { return arena.spawnThread.wave; }
|
||||||
|
|
||||||
// Check if a location is in the arena region
|
public int getWave(String arenaName)
|
||||||
public boolean inRegion(Location l) { return MAUtils.inRegion(l); }
|
{
|
||||||
|
Arena arena = plugin.getAM().getArenaWithName(arenaName);
|
||||||
|
if (arena == null)
|
||||||
|
throw new NullPointerException("Arena with name '" + arenaName + "' does not exist!");
|
||||||
|
|
||||||
|
if (arena.spawnThread == null)
|
||||||
|
throw new NullPointerException("Arena with name '" + arenaName + "' has not started!");
|
||||||
|
|
||||||
|
return arena.spawnThread.wave;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a location is within any arena regions.
|
||||||
|
|
||||||
|
public boolean inRegion(Location l, Arena arena) { return arena.inRegion(l); }
|
||||||
|
|
||||||
|
public boolean inRegion(Location l, String arenaName)
|
||||||
|
{
|
||||||
|
Arena arena = plugin.getAM().getArenaWithName(arenaName);
|
||||||
|
if (arena == null)
|
||||||
|
throw new NullPointerException("Arena with name '" + arenaName + "' does not exist!");
|
||||||
|
|
||||||
|
return arena.inRegion(l);
|
||||||
|
}
|
||||||
|
public boolean inRegion(Location l)
|
||||||
|
{
|
||||||
|
for (Arena arena : plugin.getAM().arenas)
|
||||||
|
if (arena.inRegion(l))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.garbagemule.MobArena;
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class MobArenaListener
|
public class MobArenaListener
|
||||||
@@ -7,9 +8,9 @@ public class MobArenaListener
|
|||||||
protected MobArena plugin;
|
protected MobArena plugin;
|
||||||
|
|
||||||
public MobArenaListener()
|
public MobArenaListener()
|
||||||
{
|
{
|
||||||
plugin = ArenaManager.plugin;
|
plugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
|
||||||
ArenaManager.listeners.add(this);
|
plugin.getAM().listeners.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onArenaStart() {}
|
public void onArenaStart() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user