v0.92 - Added multiple arenas, pet classes, Permissions, etc. and rewrote most of the code

This commit is contained in:
Garbage Mule 2011-07-04 17:55:31 +02:00
parent bb18cc771f
commit 53c70564fd
16 changed files with 4142 additions and 1021 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: MobArena
main: com.garbagemule.MobArena.MobArena
version: 0.91.2
version: 0.92
softdepend: [MultiVerse]
commands:
ma:
@ -8,22 +8,19 @@ commands:
usage: |
/ma join - Join 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 spectator - Warp to the spectator area.
/ma spectate - Warp to the spectator area.
marena:
description: Base command for MobArena
usage: |
/marena join - Join 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 spectator - Warp to the spectator area.
/marena spectate - Warp to the spectator area.
mobarena:
description: Base command for MobArena
usage: |
/mobarena join - Join 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 spectator - Warp to the spectator area.
/mobarena spectate - Warp to the spectator area.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,366 @@
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;
// 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 List<Player> getAllPlayers()
{
List<Player> result = new LinkedList<Player>();
for (Arena arena : arenas)
result.addAll(arena.getAllPlayers());
return result;
}
public List<Player> getAllPlayersInArena(String arenaName)
{
Arena arena = getArenaWithName(arenaName);
return (arena != null) ? arena.getLivingPlayers() : new LinkedList<Player>();
}
public List<Player> getAllLivingPlayers()
{
List<Player> result = new LinkedList<Player>();
for (Arena arena : arenas)
result.addAll(arena.getLivingPlayers());
return result;
}
public List<Player> getLivingPlayersInArena(String arenaName)
{
Arena arena = getArenaWithName(arenaName);
return (arena != null) ? arena.getLivingPlayers() : new LinkedList<Player>();
}
public Arena getArenaWithPlayer(Player p)
{
return arenaMap.get(p);
}
public Arena getArenaWithPlayer(String playerName)
{
return arenaMap.get(Bukkit.getServer().getPlayer(playerName));
}
public Arena getArenaWithSpectator(Player p)
{
for (Arena arena : arenas)
{
if (arena.specPlayers.contains(p))
return arena;
}
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);
}
enabled = config.getBoolean("global-settings.enabled", true);
updateNotify = config.getBoolean("global-settings.update-notification", true);
}
/**
* 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.clear-wave-before-next", 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.soft-restore-drops", false);
config.setProperty("arenas." + configName + ".settings.require-empty-inv-join", false);
config.setProperty("arenas." + configName + ".settings.require-empty-inv-spec", 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.setProperty("arenas." + configName + ".settings.allow-teleporting", false);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.repair-delay", 5);
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.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); }
}

View File

@ -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);
}
}

View File

@ -1,69 +1,27 @@
package com.garbagemule.MobArena;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockBreakEvent;
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 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)
{
if (!ArenaManager.isSetup || !ArenaManager.isProtected)
return;
Block b = event.getBlock();
if (ArenaManager.blockSet.remove(b) || b.getType() == Material.TNT)
return;
if (MAUtils.inRegion(b.getLocation()))
event.setCancelled(true);
for (Arena arena : am.arenas)
arena.onBlockBreak(event);
}
/**
* 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)
{
if (!ArenaManager.isSetup || !ArenaManager.isProtected)
return;
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);
for (Arena arena : am.arenas)
arena.onBlockPlace(event);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -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);
}
}

View File

@ -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; }
}

View File

@ -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,
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_CLASS_PERMISSION,
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_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.LOBBY_CLASS_PERMISSION, "You don't have permission to use this 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 + "\". Check announcements-file.");
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. Check announcements-file.");
return;
}
}
}

View File

@ -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);
}
}

View File

@ -1,6 +1,12 @@
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.Set;
import org.bukkit.Location;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.Ghast;
@ -11,6 +17,9 @@ import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.CreatureType;
import org.bukkit.inventory.ItemStack;
import com.garbagemule.MobArena.MAMessages.Msg;
/**
* Core class for handling wave spawning.
@ -20,92 +29,107 @@ import org.bukkit.entity.CreatureType;
* 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.
*/
// TO-DO: Allow custom special wave interval.
// TO-DO: Allow custom special wave monsters.
// TO-DO: Allow additional "default" waves.
// TODO: Allow custom special wave monsters.
// TODO: Allow additional "default" waves.
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 dPoweredCreepers, dPigZombies, dSlimes, dMonsters, dAngryWolves, dGiants, dGhasts;
private Random random;
private String reward, currentRewards;
private MobArena plugin;
private Arena arena;
private final double MIN_DISTANCE = 256;
public MASpawnThread()
public MASpawnThread(MobArena plugin, Arena arena)
{
modulo = ArenaManager.specialModulo;
this.plugin = plugin;
this.arena = arena;
modulo = arena.specialModulo;
if (modulo <= 0) modulo = -32768;
noOfPlayers = ArenaManager.playerSet.size();
noOfSpawnPoints = ArenaManager.spawnpoints.size();
taskId = -32768;
noOfPlayers = arena.livePlayers.size();
wave = 1;
random = new Random();
// Set up the distribution variables for the random spawner.
dZombies = ArenaManager.dZombies;
dSkeletons = dZombies + ArenaManager.dSkeletons;
dSpiders = dSkeletons + ArenaManager.dSpiders;
dCreepers = dSpiders + ArenaManager.dCreepers;
dWolves = dCreepers + ArenaManager.dWolves;
dZombies = arena.distDefault.get("zombies");
dSkeletons = dZombies + arena.distDefault.get("skeletons");
dSpiders = dSkeletons + arena.distDefault.get("spiders");
dCreepers = dSpiders + arena.distDefault.get("creepers");
dWolves = dCreepers + arena.distDefault.get("wolves");
dPoweredCreepers = ArenaManager.dPoweredCreepers;
dPigZombies = dPoweredCreepers + ArenaManager.dPigZombies;
dSlimes = dPigZombies + ArenaManager.dSlimes;
dMonsters = dSlimes + ArenaManager.dMonsters;
dAngryWolves = dMonsters + ArenaManager.dAngryWolves;
dGiants = dAngryWolves + ArenaManager.dGiants;
dGhasts = dGiants + ArenaManager.dGhasts;
dPoweredCreepers = arena.distSpecial.get("powered-creepers");
dPigZombies = dPoweredCreepers + arena.distSpecial.get("zombie-pigmen");
dSlimes = dPigZombies + arena.distSpecial.get("slimes");
dMonsters = dSlimes + arena.distSpecial.get("humans");
dAngryWolves = dMonsters + arena.distSpecial.get("angry-wolves");
dGiants = dAngryWolves + arena.distSpecial.get("giants");
dGhasts = dGiants + arena.distSpecial.get("ghasts");
}
public void run()
{
// Check if we need to grant more rewards with the recurrent waves.
for (Integer i : ArenaManager.everyWaveMap.keySet())
{
// Check if wave needs to be cleared first. If so, return!
if (arena.waveClear && wave > 1)
{
if (wave % i != 0)
continue;
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 (!arena.monsters.isEmpty())
return;
}
// 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.
if (ArenaManager.afterWaveMap.containsKey(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);
}
}
if (arena.afterWaveMap.containsKey(wave))
addReward(arena.afterWaveMap.get(wave));
// Check if this is a special wave.
if (wave % modulo == 0)
{
ArenaManager.tellAll("Get ready for wave #" + wave + "! [SPECIAL]");
for (MobArenaListener m : ArenaManager.listeners)
m.onSpecialWave(wave, wave/modulo);
MAUtils.tellAll(arena, MAMessages.get(Msg.WAVE_SPECIAL, ""+wave));
detonateCreepers(arena.detCreepers);
specialWave();
// Notify listeners.
for (MobArenaListener listener : plugin.getAM().listeners)
listener.onSpecialWave(wave, wave/modulo);
}
else
{
ArenaManager.tellAll("Get ready for wave #" + wave + "!");
for (MobArenaListener m : ArenaManager.listeners)
m.onDefaultWave(wave);
MAUtils.tellAll(arena, MAMessages.get(Msg.WAVE_DEFAULT, ""+wave));
detonateCreepers(arena.detCreepers);
defaultWave();
// Notify listeners.
for (MobArenaListener listener : plugin.getAM().listeners)
listener.onDefaultWave(wave);
}
ArenaManager.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 +138,15 @@ public class MASpawnThread implements Runnable
private void defaultWave()
{
Location loc;
for (int i = 0; i < wave + noOfPlayers; i++)
List<Location> spawnpoints = getValidSpawnpoints();
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);
CreatureType mob;
/* Because of the nature of the if-elseif-else statement,
* we're able to evaluate the random number in this way.
@ -133,8 +160,8 @@ public class MASpawnThread implements Runnable
else if (ran < dWolves) mob = CreatureType.WOLF;
else continue;
LivingEntity e = ArenaManager.world.spawnCreature(loc,mob);
ArenaManager.monsterSet.add(e);
LivingEntity e = arena.world.spawnCreature(loc,mob);
arena.monsters.add(e);
// Grab a random target.
Creature c = (Creature) e;
@ -148,6 +175,8 @@ public class MASpawnThread implements Runnable
private void specialWave()
{
Location loc;
List<Location> spawnpoints = getValidSpawnpoints();
int noOfSpawnpoints = spawnpoints.size();
CreatureType mob;
ran = random.nextInt(dGhasts);
@ -202,13 +231,10 @@ public class MASpawnThread implements Runnable
// Spawn the hippie monsters.
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);
if (!ArenaManager.monsterSet.contains(e))
ArenaManager.monsterSet.add(e);
else
System.out.println("MASpawnThread - monsterSet contains this entity");
LivingEntity e = arena.world.spawnCreature(loc,mob);
arena.monsters.add(e);
if (slime) ((Slime)e).setSize(2);
if (wolf) ((Wolf)e).setAngry(true);
@ -224,38 +250,85 @@ public class MASpawnThread implements Runnable
c.setTarget(getClosestPlayer(e));
}
if (!ArenaManager.lightning)
if (!arena.lightning)
return;
// 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
* means a complexity of O(n).
* Get all the spawnpoints that have players nearby.
*/
// TO-DO: Move this into MAUtils
public static Player getClosestPlayer(Entity e)
public List<Location> getValidSpawnpoints()
{
// Grab the coordinates.
double x = e.getLocation().getX();
double y = e.getLocation().getY();
double z = e.getLocation().getZ();
List<Location> result = new ArrayList<Location>();
for (Location s : arena.spawnpoints.values())
{
for (Player p : arena.livePlayers)
{
if (s.distanceSquared(p.getLocation()) > MIN_DISTANCE)
continue;
result.add(s);
break;
}
}
// 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.
double dist = 0;
double current = Double.POSITIVE_INFINITY;
Player result = null;
/* Iterate through the ArrayList, and update current and result every
* 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);
if (dist < current)
dist = p.getLocation().distance(e.getLocation());
//double dist = MAUtils.distance(p.getLocation(), e.getLocation());
if (dist < current && dist < 256)
{
current = dist;
result = p;
@ -263,17 +336,4 @@ public class MASpawnThread implements Runnable
}
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

View File

@ -1,30 +1,33 @@
package com.garbagemule.MobArena;
import java.util.List;
import java.io.File;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.util.config.Configuration;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
/**
* MobArena
*
* @author garbagemule
*/
public class MobArena extends JavaPlugin
{
/* Array of commands used to determine if a command belongs to MobArena
* or Mean Admins. */
public final String[] COMMANDS = {"join", "j", "leave", "l", "list", "who", "spectate", "spec",
"ready", "notready", "enabled", "force", "config", "setwarp",
"addspawn", "delspawn", "setregion", "expandregion", "protect",
"undo", "dooooo", "reset"};
public List<String> DISABLED_COMMANDS;
private Configuration config;
private ArenaMaster am;
// Permissions stuff
protected static PermissionHandler permissionHandler;
public MobArena()
{
@ -34,52 +37,217 @@ public class MobArena extends JavaPlugin
{
PluginDescriptionFile pdfFile = this.getDescription();
// Initialize convenience variables in ArenaManager.
ArenaManager.init(this);
DISABLED_COMMANDS = MAUtils.getDisabledCommands();
// Config, messages and ArenaMaster initialization
loadConfig();
MAMessages.init(this);
am = new ArenaMaster(this);
am.initialize();
// Bind the /ma and /marena commands to MACommands.
getCommand("ma").setExecutor(new MACommands());
getCommand("marena").setExecutor(new MACommands());
getCommand("mobarena").setExecutor(new MACommands());
// Permissions
setupPermissions();
// Bind the /ma, /marena, and /mobarena commands to MACommands.
MACommands commandExecutor = new MACommands(this, am);
getCommand("ma").setExecutor(commandExecutor);
getCommand("marena").setExecutor(commandExecutor);
getCommand("mobarena").setExecutor(commandExecutor);
// Create event listeners.
PluginManager pm = getServer().getPluginManager();
PlayerListener commandListener = new MADisabledCommands(this);
PlayerListener lobbyListener = new MALobbyListener(this);
PlayerListener teleportListener = new MATeleportListener(this);
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.
PlayerListener playerListener = new MAPlayerListener(this, am);
EntityListener entityListener = new MAEntityListener(am);
BlockListener blockListener = new MABlockListener(am);
// Register events.
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, commandListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, lobbyListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, lobbyListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, lobbyListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_TELEPORT, teleportListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, discListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_KICK, discListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, discListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DEATH, deathListener, Priority.Lowest, this); // Lowest because of Tombstone
pm.registerEvent(Event.Type.ENTITY_EXPLODE, monsterListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_COMBUST, monsterListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_TARGET, monsterListener, Priority.Normal, this);
pm.registerEvent(Event.Type.CREATURE_SPAWN, monsterListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_TELEPORT, 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_JOIN, playerListener, Priority.Normal, 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.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Lowest, this); // Lowest because of Tombstone
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
pm.registerEvent(Event.Type.ENTITY_COMBUST, 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.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()
{
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();
}
// Permissions stuff
public static boolean has(Player p, String s)
{
//return (permissionHandler != null && permissionHandler.has(p, s));
return (permissionHandler == null || permissionHandler.has(p, s));
}
public static boolean hasDefTrue(Player p, String s)
{
return (permissionHandler == null || permissionHandler.has(p, s));
}
private void setupPermissions()
{
if (permissionHandler != null)
return;
Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
if (permissionsPlugin == null) return;
permissionHandler = ((Permissions) permissionsPlugin).getHandler();
}
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();
// 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!");
}
}

View File

@ -1,34 +1,105 @@
package com.garbagemule.MobArena;
import java.util.List;
import java.util.LinkedList;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class MobArenaHandler
{
MobArena plugin;
public MobArenaHandler()
{
plugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
}
// 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.
public boolean isPlaying(Player p) { return ArenaManager.playerSet.contains(p); }
// Check if the specified player is in an arena.
public boolean isPlaying(Player p) { return (plugin.getAM().getArenaWithPlayer(p) != null); }
// Get a list of all players currently in the arena.
public List<Player> getPlayers() { return new LinkedList<Player>(ArenaManager.playerSet); }
// Arena getters
public Arena getArenaWithName(String arenaName) { return plugin.getAM().getArenaWithName(arenaName); }
public Arena getArenaWithPlayer(Player p) { return plugin.getAM().getArenaWithPlayer(p); }
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.
public Location getArenaLocation() { return ArenaManager.arenaLoc; }
public Location getLobbyLocation() { return ArenaManager.lobbyLoc; }
public Location getSpectatorLocation() { return ArenaManager.spectatorLoc; }
// Player lists
public List<Player> getAllPlayers() { return plugin.getAM().getAllPlayers(); }
public List<Player> getAllLivingPlayers() { return plugin.getAM().getAllLivingPlayers(); }
public List<Player> getAllPlayersInArena(String arenaName) { return plugin.getAM().getAllPlayersInArena(arenaName); }
public List<Player> getLivingPlayersInArena(String arenaName) { return plugin.getAM().getLivingPlayersInArena(arenaName); }
// 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.
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 boolean inRegion(Location l) { return MAUtils.inRegion(l); }
public int getWave(String arenaName)
{
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;
}
}

View File

@ -1,5 +1,6 @@
package com.garbagemule.MobArena;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class MobArenaListener
@ -7,9 +8,9 @@ public class MobArenaListener
protected MobArena plugin;
public MobArenaListener()
{
plugin = ArenaManager.plugin;
ArenaManager.listeners.add(this);
{
plugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
plugin.getAM().listeners.add(this);
}
public void onArenaStart() {}