JoinCommand and ArenaListCommand somewhat done.

This commit is contained in:
Garbage Mule
2011-12-10 23:49:39 +01:00
parent 289b1792f5
commit c420568cb9
28 changed files with 2723 additions and 343 deletions
+2
View File
@@ -232,6 +232,8 @@ public abstract class Arena
public abstract boolean inLobby(Player p);
public abstract boolean isEnabled();
public abstract boolean isRunning();
public abstract boolean isPvpEnabled();
@@ -1,5 +1,6 @@
package com.garbagemule.MobArena;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -51,6 +52,8 @@ public abstract class ArenaMaster //implements Master
public abstract List<Arena> getPermittedArenas(Player p);
public abstract List<Arena> getEnabledAndPermittedArenas(Player p);
public abstract Arena getArenaAtLocation(Location loc);
public abstract List<Arena> getArenasInWorld(World world);
@@ -75,6 +78,8 @@ public abstract class ArenaMaster //implements Master
public abstract Arena getArenaWithName(String configName);
public abstract Arena getArenaWithName(Collection<Arena> arenas, String configName);
/*/////////////////////////////////////////////////////////////////////////
@@ -1,5 +1,6 @@
package com.garbagemule.MobArena;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -10,37 +11,13 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
//import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.util.Config;
//import com.garbagemule.ArenaPlugin.Master;
public class ArenaMasterStandard extends ArenaMaster
{
private MobArena plugin;
//private Configuration config;
private Config config;
//protected Arena selectedArena;
// Settings
//protected boolean enabled, updateNotify;
// Classes
//protected Set<String> classes;
//protected Map<String,List<ItemStack>> classItems, classArmor;
//protected Map<String,Map<String,Boolean>> classPerms;
//protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses;
//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>();
@@ -81,6 +58,15 @@ public class ArenaMasterStandard extends ArenaMaster
return result;
}
public List<Arena> getEnabledAndPermittedArenas(Player p)
{
List<Arena> result = new LinkedList<Arena>();
for (Arena arena : arenas)
if (arena.enabled && plugin.has(p, "mobarena.arenas." + arena.configName()))
result.add(arena);
return result;
}
public Arena getArenaAtLocation(Location loc)
{
for (Arena arena : arenas)
@@ -163,6 +149,11 @@ public class ArenaMasterStandard extends ArenaMaster
}
public Arena getArenaWithName(String configName)
{
return getArenaWithName(this.arenas, configName);
}
public Arena getArenaWithName(Collection<Arena> arenas, String configName)
{
for (Arena arena : arenas)
if (arena.configName().equals(configName))
@@ -48,7 +48,6 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.permissions.PermissionAttachment;
//import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.leaderboards.Leaderboard;
import com.garbagemule.MobArena.repairable.Repairable;
import com.garbagemule.MobArena.repairable.RepairableComparator;
@@ -65,65 +64,6 @@ import com.garbagemule.MobArena.waves.Wave.WaveBranch;
public class ArenaStandard extends Arena
{
private MobArena plugin;
/*
// Setup fields
protected String name;
protected World world;
protected boolean enabled, protect, running, setup, lobbySetup, autoEquip, forceRestore, softRestore, softRestoreDrops, emptyInvJoin, emptyInvSpec, pvp, monsterInfight, allowWarp;
protected boolean edit, waveClear, detCreepers, detDamage, lightning, hellhounds, specOnDeath, shareInArena, spoutSelect;
protected Location p1, p2, l1, l2, arenaLoc, lobbyLoc, spectatorLoc;
protected Map<String,Location> spawnpoints, spawnpointsBoss, containers;
protected String logging;
// Wave/reward/entryfee fields
protected int spawnTaskId, sheepTaskId, waveDelay, waveInterval, specialModulo, spawnMonstersInt, maxIdleTime, finalWave;
protected MASpawnThread spawnThread;
protected Map<Integer,List<ItemStack>> everyWaveMap, afterWaveMap;
protected Map<Player,String> classMap;
protected Map<String,List<ItemStack>> classItems, classArmor;
protected Map<String,Map<String,Boolean>> classPerms;
protected Map<Player,PermissionAttachment> attachments;
protected List<ItemStack> entryFee;
// Player sets
protected Set<Player> arenaPlayers, lobbyPlayers, readyPlayers, specPlayers;
// Wave stuff
protected TreeSet<Wave> singleWaves, singleWavesInstance;
protected TreeSet<Wave> recurrentWaves;
protected BossWave bossWave;
protected Wave currentWave;
// Arena sets/maps
protected Set<Player> hasPaid, rewardedPlayers, notifyPlayers, randoms;
protected Set<LivingEntity> monsters, explodingSheep, plaguedPigs, madCows;
protected Set<Block> blocks;
protected Set<Wolf> pets;
protected Map<Player,Integer> petMap;
protected LinkedList<Repairable> repairables, containables;
// Spawn overriding
protected int spawnMonsters;
protected boolean allowMonsters, allowAnimals;
// Other settings
protected int minPlayers, maxPlayers, joinDistance;
protected List<String> classes = new LinkedList<String>();
protected Map<Player,Location> locations = new HashMap<Player,Location>();
protected Map<Player,Integer> healthMap = new HashMap<Player,Integer>();
protected Map<Player,Integer> hungerMap = new HashMap<Player,Integer>();
protected Map<Player,GameMode> modeMap = new HashMap<Player,GameMode>();
// Logging
protected ArenaLog log;
protected Map<Player,ArenaPlayer> arenaPlayerMap;
protected Leaderboard leaderboard;
protected MAListener eventListener;
protected PriorityBlockingQueue<Repairable> repairQueue;
*/
/**
* Primary constructor. Requires a name and a world.
@@ -1121,6 +1061,10 @@ public class ArenaStandard extends Arena
return lobbyPlayers.contains(p);
}
public boolean isEnabled() {
return enabled;
}
public boolean isRunning()
{
return running;
+5 -7
View File
@@ -18,8 +18,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.ConsoleCommandSender;
import com.garbagemule.MobArena.MAMessages.Msg;
public class MACommands implements CommandExecutor
{
public static List<String> ALLOWED_COMMANDS = new LinkedList<String>();
@@ -187,7 +185,7 @@ public class MACommands implements CommandExecutor
MAUtils.tellPlayer(p, Msg.JOIN_PLAYER_JOINED);
if (!arena.entryFee.isEmpty())
MAUtils.tellPlayer(p, Msg.JOIN_FEE_PAID.get(MAUtils.listToString(arena.entryFee, plugin)));
MAUtils.tellPlayer(p, Msg.JOIN_FEE_PAID.toString(MAUtils.listToString(arena.entryFee, plugin)));
if (arena.hasPaid.contains(p))
arena.hasPaid.remove(p);
@@ -277,7 +275,7 @@ public class MACommands implements CommandExecutor
if (base.equals("arenas"))
{
String list = MAUtils.listToString(player ? am.getPermittedArenas(p) : am.arenas, plugin);
MAUtils.tellPlayer(sender, Msg.MISC_LIST_ARENAS.get(list));
MAUtils.tellPlayer(sender, Msg.MISC_LIST_ARENAS.toString(list));
return true;
}
@@ -296,7 +294,7 @@ public class MACommands implements CommandExecutor
}
String list = MAUtils.listToString(arena.getLivingPlayers(), plugin);
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(list));
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.toString(list));
}
else
{
@@ -305,7 +303,7 @@ public class MACommands implements CommandExecutor
for (Arena arena : am.arenas)
players.addAll(arena.getLivingPlayers());
buffy.append(MAUtils.listToString(players, plugin));
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(buffy.toString()));
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.toString(buffy.toString()));
}
return true;
}
@@ -341,7 +339,7 @@ public class MACommands implements CommandExecutor
}
String list = MAUtils.listToString(arena.getNonreadyPlayers(), plugin);
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(list));
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.toString(list));
return true;
}
@@ -53,7 +53,6 @@ import org.bukkit.material.Bed;
import org.bukkit.material.Door;
import org.bukkit.material.Redstone;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.leaderboards.Leaderboard;
import com.garbagemule.MobArena.repairable.*;
+46 -189
View File
@@ -7,198 +7,60 @@ import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import org.bukkit.Material;
public class MAMessages
{
public static enum Msg
{
ARENA_START("Let the slaughter begin!", "Arena started!", Material.REDSTONE_TORCH_ON),
ARENA_END("Arena finished.", "Arena finished.", Material.REDSTONE_TORCH_OFF),
ARENA_DOES_NOT_EXIST("That arena does not exist. Type /ma arenas for a list.", "Can't find arena."),
JOIN_NOT_ENABLED("MobArena is not enabled.", "MobArena disabled.", Material.REDSTONE_TORCH_OFF),
JOIN_IN_OTHER_ARENA("You are already in an arena! Leave that one first.", "In another arena."),
JOIN_ARENA_NOT_ENABLED("This arena is not enabled.", "Arena disabled.", Material.REDSTONE_TORCH_OFF),
JOIN_ARENA_NOT_SETUP("This arena has not been set up yet.", "Arena not set up.", Material.REDSTONE_TORCH_OFF),
JOIN_ARENA_EDIT_MODE("This arena is in edit mode.", "Arena in edit mode.", Material.IRON_SPADE),
JOIN_ARENA_PERMISSION("You don't have permission to join this arena.", "No permission!", Material.FENCE),
JOIN_FEE_REQUIRED("Insufficient funds. Price: %", "Price: %", Material.DIAMOND),
JOIN_FEE_PAID("Price to join was: %", "Paid: %", Material.DIAMOND),
JOIN_ARENA_IS_RUNNING("This arena is in already progress.", "Already running!", Material.GOLD_RECORD),
JOIN_ALREADY_PLAYING("You are already playing!", "Already playing!", Material.GOLD_RECORD),
JOIN_ARG_NEEDED("You must specify an arena. Type /ma arenas for a list."),
JOIN_TOO_FAR("You are too far away from the arena to join/spectate.", "Too far from arena.", Material.COMPASS),
JOIN_EMPTY_INV("You must empty your inventory to join the arena.", "Empty your inventory.", Material.CHEST),
JOIN_PLAYER_LIMIT_REACHED("The player limit of this arena has been reached.", "No spots left.", Material.MILK_BUCKET),
JOIN_STORE_INV_FAIL("Failed to store inventory. Try again."),
JOIN_EXISTING_INV_RESTORED("Your old inventory items have been restored."),
JOIN_PLAYER_JOINED("You joined the arena. Have fun!", "Joined arena.", Material.IRON_SWORD),
LEAVE_NOT_PLAYING("You are not in the arena.", "Not in arena."),
LEAVE_PLAYER_LEFT("You left the arena. Thanks for playing!", "Left arena.", Material.WOOD_DOOR),
PLAYER_DIED("% died!", "% died!", Material.BONE),
SPEC_PLAYER_SPECTATE("Enjoy the show!", "Enjoy the show!"),
SPEC_NOT_RUNNING("This arena isn't running.", "Arena not running.", Material.REDSTONE_TORCH_OFF),
SPEC_ARG_NEEDED("You must specify an arena. Type /ma arenas for a list.", "Arena name required."),
SPEC_EMPTY_INV("Empty your inventory first!", "Empty your inventory.", Material.CHEST),
SPEC_ALREADY_PLAYING("Can't spectate when in the arena!", "Already playing!"),
NOT_READY_PLAYERS("Not ready: %"),
FORCE_START_RUNNING("Arena has already started."),
FORCE_START_NOT_READY("Can't force start, no players are ready."),
FORCE_START_STARTED("Forced arena start."),
FORCE_END_EMPTY("No one is in the arena."),
FORCE_END_ENDED("Forced arena end."),
FORCE_END_IDLE("You weren't quick enough!"),
REWARDS_GIVE("Here are all of your rewards!"),
LOBBY_DROP_ITEM("No sharing allowed at this time!", "Can't drop items here."),
LOBBY_PLAYER_READY("You have been flagged as ready!", "Flagged as ready!"),
LOBBY_PICK_CLASS("You must first pick a class!", "Pick a class first!"),
LOBBY_NOT_ENOUGH_PLAYERS("Not enough players to start. Need at least % players.", "Need more players."),
LOBBY_RIGHT_CLICK("Punch the sign. Don't right-click.", "Punch the sign."),
LOBBY_CLASS_PICKED("You have chosen % as your class!", "%"),
LOBBY_CLASS_RANDOM("You will get a random class on arena start."),
LOBBY_CLASS_PERMISSION("You don't have permission to use this class!", "No permission!", Material.FENCE),
WARP_TO_ARENA("Can't warp to the arena during battle!"),
WARP_FROM_ARENA("Warping not allowed in the arena!"),
WAVE_DEFAULT("Wave #%!", "Wave #%!", Material.YELLOW_FLOWER),
WAVE_SPECIAL("Wave #%! [SPECIAL]", "Wave #%! [SPECIAL]", Material.RED_ROSE),
WAVE_SWARM("Wave #%! [SWARM]", "Wave #%! [SWARM]", Material.LONG_GRASS),
WAVE_BOSS("Wave #%! [BOSS]", "Wave #%! [BOSS]", Material.FIRE),
WAVE_BOSS_ABILITY("Boss used ability: %!", "Boss: %", Material.FIRE),
WAVE_BOSS_LOW_HEALTH("Boss is almost dead!", "Boss almost dead!", Material.FIRE),
WAVE_REWARD("You just earned a reward: %", "Reward: %"),
MISC_LIST_PLAYERS("Live players: %"),
MISC_LIST_ARENAS("Available arenas: %"),
MISC_COMMAND_NOT_ALLOWED("You can't use that command in the arena!"),
MISC_NO_ACCESS("You don't have access to this command."),
MISC_NONE("<none>");
public static void init(MobArena plugin) {
// Grab the file
File msgFile = new File(MobArena.dir, "anouncements.properties");
private String msg, spoutMsg;
private Material logo;
// If it couldn't be loaded for some reason
if (!load(msgFile))
return;
private Msg(String msg)
{
this(msg, null);
// Otherwise, start parsing!
parseFile(msgFile);
}
private static boolean load(File file) {
// If the file exists, continue on!
if (file.exists()) {
return true;
}
private Msg(String msg, String spoutMsg)
{
this(msg, spoutMsg, null);
}
private Msg(String msg, String spoutMsg, Material logo)
{
this.msg = msg;
this.spoutMsg = spoutMsg;
this.logo = logo;
}
public String get()
{
return msg;
}
public String get(String s)
{
return (s != null) ? msg.replace("%", s) : msg;
}
public String getSpout(String s)
{
if (spoutMsg == null)
return get(s);
// Otherwise, create it, and populate it with the defaults.
try {
file.createNewFile();
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
return (s != null) ? spoutMsg.replace("%", s) : spoutMsg;
}
public void set(String msg)
{
this.msg = msg;
}
public void setSpout(String spoutMsg)
{
this.spoutMsg = spoutMsg;
for (Msg m : Msg.values()) {
if (m.hasSpoutMsg()) {
bw.write(m.name() + "=" + m + "|" + m.toSpoutString());
} else {
bw.write(m.name() + "=" + m);
}
bw.newLine();
}
bw.close();
if (spoutMsg == null)
logo = null;
return true;
}
public boolean hasSpoutMsg()
{
return spoutMsg != null;
}
public Material getLogo()
{
return logo == null ? Material.SLIME_BALL : logo;
}
public static String get(Msg m)
{
return m.msg;
}
public static String get(Msg m, String s)
{
return m.msg.replace("%", s);
}
public static void set(Msg m, String msg)
{
m.msg = msg;
}
public String toString()
{
return msg;
catch (Exception e) {
MobArena.warning("Couldn't initialize announcements-file. Using defaults.");
return false;
}
}
/**
* Initializes the msgMap by reading from the announcements-file.
*/
public static void init(MobArena plugin)
{
// Grab the announcements-file.
File msgFile = new File(MobArena.dir, "announcements.properties");
// If the file doesn't exist, create it and use defaults.
if (!msgFile.exists())
{
try
{
msgFile.createNewFile();
BufferedWriter bw = new BufferedWriter(new FileWriter(msgFile));
for (Msg m : Msg.values())
{
if (m.hasSpoutMsg())
bw.write(m.name() + "=" + m.msg + "|" + m.spoutMsg);
else
bw.write(m.name() + "=" + m.msg);
bw.newLine();
}
bw.close();
return;
}
catch (Exception e)
{
MobArena.warning("Couldn't initialize announcements-file. Using defaults.");
}
return;
}
// Otherwise, read the file's contents.
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(msgFile), "UTF-8"));
private static void parseFile(File file) {
try {
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
// Check for BOM character.
br.mark(1); int bom = br.read();
if (bom != 65279) br.reset();
br.mark(1);
int bom = br.read();
if (bom != 65279)
br.reset();
String s;
while ((s = br.readLine()) != null)
@@ -206,8 +68,7 @@ public class MAMessages
br.close();
}
catch (Exception e)
{
catch (Exception e) {
e.printStackTrace();
MobArena.warning("Problem with announcements-file. Using defaults.");
return;
@@ -218,15 +79,13 @@ public class MAMessages
* Helper-method for parsing the strings from the
* announcements-file.
*/
private static void process(String s)
{
// If the line ends with =, just add a space
private static void process(String s) {
// If the line ends with = or |, just add a space
if (s.endsWith("=") || s.endsWith("|")) s += " ";
// Split the string by the equals-sign.
String[] split = s.split("=");
if (split.length != 2)
{
if (split.length != 2) {
MobArena.warning("Couldn't parse \"" + s + "\". Check announcements-file.");
return;
}
@@ -239,14 +98,12 @@ public class MAMessages
String val = vals.length == 2 ? vals[0] : split[1];
String spoutVal = vals.length == 2 ? vals[1] : null;
try
{
try {
Msg msg = Msg.valueOf(key);
msg.set(val);
msg.setSpout(spoutVal);
}
catch (Exception e)
{
catch (Exception e) {
MobArena.warning(key + " is not a valid key. Check announcements-file.");
return;
}
@@ -15,7 +15,6 @@ import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.WaveUtils;
import com.garbagemule.MobArena.waves.Wave;
+4 -5
View File
@@ -37,7 +37,6 @@ import org.bukkit.inventory.PlayerInventory;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.EntityPosition;
import com.garbagemule.MobArena.util.InventoryItem;
@@ -977,7 +976,7 @@ public class MAUtils
if (msg.hasSpoutMsg() && sp != null && sp.isSpoutCraftEnabled())
{
// Grab the message text.
String text = msg.getSpout(s);
String text = msg.toSpoutString(s);
// If more than 26 characters, truncate.
if (text.length() > 26)
@@ -991,7 +990,7 @@ public class MAUtils
sp.sendNotification("MobArena", text, logo, (short) 0, 2000);
return true;
}
else return tellPlayer(p, msg.get(s));
else return tellPlayer(p, msg.toString(s));
}
public static boolean tellSpoutPlayer(Player p, Msg msg, Material logo)
@@ -1025,7 +1024,7 @@ public class MAUtils
if (spout && p instanceof Player)
return tellSpoutPlayer((Player) p, msg, s, logo);
return tellPlayer(p, msg.get(s));
return tellPlayer(p, msg.toString(s));
}
public static boolean tellPlayer(CommandSender p, Msg msg, String s, Material logo)
@@ -1168,7 +1167,7 @@ public class MAUtils
if (list == null || list.isEmpty())
{
if (none)
return Msg.MISC_NONE.get();
return Msg.MISC_NONE.toString();
else
return "";
}
+15 -17
View File
@@ -4,6 +4,8 @@ import java.io.File;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
@@ -39,9 +41,6 @@ public class MobArena extends JavaPlugin implements MobArenaPlugin
// Spout stuff
public static boolean hasSpout;
// Heroes stuff
//private HeroManager heroManager = null;
// Global variables
public static PluginDescriptionFile desc;
public static File dir, arenaDir;
@@ -69,7 +68,6 @@ public class MobArena extends JavaPlugin implements MobArenaPlugin
// Set up soft dependencies
setupRegister();
setupSpout();
//setupHeroes();
setupMagicSpells();
// Set up the ArenaMaster and the announcements
@@ -162,6 +160,19 @@ public class MobArena extends JavaPlugin implements MobArenaPlugin
public static void warning(String msg) { Bukkit.getServer().getLogger().warning("[MobArena] " + msg); }
public static void error(String msg) { Bukkit.getServer().getLogger().severe("[MobArena] " + msg); }
@Override
public void tell(CommandSender sender, String msg) {
if (sender == null || msg.equals("") || msg.equals(" "))
return;
sender.sendMessage(ChatColor.GREEN + "[MobArena] " + ChatColor.WHITE + msg);
}
@Override
public void tell(CommandSender sender, Msg msg) {
tell(sender, msg.toString());
}
private void setupRegister()
{
Methods.setMethod(getServer().getPluginManager());
@@ -184,14 +195,6 @@ public class MobArena extends JavaPlugin implements MobArenaPlugin
Spouty.registerEvents(this);
}
/*private void setupHeroes()
{
Plugin heroes = this.getServer().getPluginManager().getPlugin("Heroes");
if (heroes == null) return;
heroManager = ((Heroes) heroes).getHeroManager();
}*/
private void setupMagicSpells()
{
Plugin spells = this.getServer().getPluginManager().getPlugin("MagicSpells");
@@ -208,11 +211,6 @@ public class MobArena extends JavaPlugin implements MobArenaPlugin
@Override
public ArenaMaster getArenaMaster() { return am; }
/*public HeroManager getHeroManager()
{
return heroManager;
}*/
private String getHeader()
{
String sep = System.getProperty("line.separator");
@@ -1,6 +1,12 @@
package com.garbagemule.MobArena;
import org.bukkit.command.CommandSender;
public interface MobArenaPlugin
{
public ArenaMaster getArenaMaster();
public void tell(CommandSender sender, String msg);
public void tell(CommandSender sender, Msg msg);
}
+167
View File
@@ -0,0 +1,167 @@
package com.garbagemule.MobArena;
import org.bukkit.Material;
public enum Msg
{
ARENA_START("Let the slaughter begin!", "Arena started!", Material.REDSTONE_TORCH_ON),
ARENA_END("Arena finished.", "Arena finished.", Material.REDSTONE_TORCH_OFF),
ARENA_DOES_NOT_EXIST("That arena does not exist. Type /ma arenas for a list.", "Can't find arena."),
JOIN_NOT_ENABLED("MobArena is not enabled.", "MobArena disabled.", Material.REDSTONE_TORCH_OFF),
JOIN_IN_OTHER_ARENA("You are already in an arena! Leave that one first.", "In another arena."),
JOIN_ARENA_NOT_ENABLED("This arena is not enabled.", "Arena disabled.", Material.REDSTONE_TORCH_OFF),
JOIN_ARENA_NOT_SETUP("This arena has not been set up yet.", "Arena not set up.", Material.REDSTONE_TORCH_OFF),
JOIN_ARENA_EDIT_MODE("This arena is in edit mode.", "Arena in edit mode.", Material.IRON_SPADE),
JOIN_ARENA_PERMISSION("You don't have permission to join this arena.", "No permission!", Material.FENCE),
JOIN_FEE_REQUIRED("Insufficient funds. Price: %", "Price: %", Material.DIAMOND),
JOIN_FEE_PAID("Price to join was: %", "Paid: %", Material.DIAMOND),
JOIN_ARENA_IS_RUNNING("This arena is in already progress.", "Already running!", Material.GOLD_RECORD),
JOIN_ALREADY_PLAYING("You are already playing!", "Already playing!", Material.GOLD_RECORD),
JOIN_ARG_NEEDED("You must specify an arena. Type /ma arenas for a list."),
JOIN_TOO_FAR("You are too far away from the arena to join/spectate.", "Too far from arena.", Material.COMPASS),
JOIN_EMPTY_INV("You must empty your inventory to join the arena.", "Empty your inventory.", Material.CHEST),
JOIN_PLAYER_LIMIT_REACHED("The player limit of this arena has been reached.", "No spots left.", Material.MILK_BUCKET),
JOIN_STORE_INV_FAIL("Failed to store inventory. Try again."),
JOIN_EXISTING_INV_RESTORED("Your old inventory items have been restored."),
JOIN_PLAYER_JOINED("You joined the arena. Have fun!", "Joined arena.", Material.IRON_SWORD),
LEAVE_NOT_PLAYING("You are not in the arena.", "Not in arena."),
LEAVE_PLAYER_LEFT("You left the arena. Thanks for playing!", "Left arena.", Material.WOOD_DOOR),
PLAYER_DIED("% died!", "% died!", Material.BONE),
SPEC_PLAYER_SPECTATE("Enjoy the show!", "Enjoy the show!"),
SPEC_NOT_RUNNING("This arena isn't running.", "Arena not running.", Material.REDSTONE_TORCH_OFF),
SPEC_ARG_NEEDED("You must specify an arena. Type /ma arenas for a list.", "Arena name required."),
SPEC_EMPTY_INV("Empty your inventory first!", "Empty your inventory.", Material.CHEST),
SPEC_ALREADY_PLAYING("Can't spectate when in the arena!", "Already playing!"),
NOT_READY_PLAYERS("Not ready: %"),
FORCE_START_RUNNING("Arena has already started."),
FORCE_START_NOT_READY("Can't force start, no players are ready."),
FORCE_START_STARTED("Forced arena start."),
FORCE_END_EMPTY("No one is in the arena."),
FORCE_END_ENDED("Forced arena end."),
FORCE_END_IDLE("You weren't quick enough!"),
REWARDS_GIVE("Here are all of your rewards!"),
LOBBY_DROP_ITEM("No sharing allowed at this time!", "Can't drop items here."),
LOBBY_PLAYER_READY("You have been flagged as ready!", "Flagged as ready!"),
LOBBY_PICK_CLASS("You must first pick a class!", "Pick a class first!"),
LOBBY_NOT_ENOUGH_PLAYERS("Not enough players to start. Need at least % players.", "Need more players."),
LOBBY_RIGHT_CLICK("Punch the sign. Don't right-click.", "Punch the sign."),
LOBBY_CLASS_PICKED("You have chosen % as your class!", "%"),
LOBBY_CLASS_RANDOM("You will get a random class on arena start."),
LOBBY_CLASS_PERMISSION("You don't have permission to use this class!", "No permission!", Material.FENCE),
WARP_TO_ARENA("Can't warp to the arena during battle!"),
WARP_FROM_ARENA("Warping not allowed in the arena!"),
WAVE_DEFAULT("Wave #%!", "Wave #%!", Material.YELLOW_FLOWER),
WAVE_SPECIAL("Wave #%! [SPECIAL]", "Wave #%! [SPECIAL]", Material.RED_ROSE),
WAVE_SWARM("Wave #%! [SWARM]", "Wave #%! [SWARM]", Material.LONG_GRASS),
WAVE_BOSS("Wave #%! [BOSS]", "Wave #%! [BOSS]", Material.FIRE),
WAVE_BOSS_ABILITY("Boss used ability: %!", "Boss: %", Material.FIRE),
WAVE_BOSS_LOW_HEALTH("Boss is almost dead!", "Boss almost dead!", Material.FIRE),
WAVE_REWARD("You just earned a reward: %", "Reward: %"),
MISC_LIST_PLAYERS("Live players: %"),
MISC_LIST_ARENAS("Available arenas: %"),
MISC_COMMAND_NOT_ALLOWED("You can't use that command in the arena!"),
MISC_NO_ACCESS("You don't have access to this command."),
MISC_NONE("<none>");
private String msg, spoutMsg;
private Material logo;
/**
* Default constructor.
* @param msg a string for the chat window
* @param spoutMsg a string for Spout
* @param logo a logo for Spout
*/
private Msg(String msg, String spoutMsg, Material logo) {
this.msg = msg;
this.spoutMsg = spoutMsg;
this.logo = logo;
}
/**
* Custom Spout constructor.
* @param msg a string for the chat window
* @param spoutMsg a string for Spout
*/
private Msg(String msg, String spoutMsg) {
this(msg, spoutMsg, null);
}
/**
* Custom normal constructor.
* @param msg a string for the chat window
*/
private Msg(String msg) {
this(msg, null);
}
/**
* Change this enum's chat window string.
* @param msg a string for the chat window
*/
public void set(String msg) {
this.msg = msg;
}
/**
* Change this enum's Spout string.
* @param spoutMsg a string for Spout
*/
public void setSpout(String spoutMsg) {
this.spoutMsg = spoutMsg;
if (spoutMsg == null)
logo = null;
}
/**
* Check if this enum has a Spout string associated with it.
* @return true, if a Spout string is available, false otherwise.
*/
public boolean hasSpoutMsg() {
return spoutMsg != null;
}
/**
* Get the logo of this enum.
* The default logo is Material.SLIME_BALL if none is specified.
* @return the logo for this enum
*/
public Material getLogo() {
return logo == null ? Material.SLIME_BALL : logo;
}
@Override
public String toString() {
return msg;
}
/**
* Same as above, just returning the string for Spout instead.
* @return the string for Spout
*/
public String toSpoutString() {
return spoutMsg;
}
/**
* Extended toString method that allows a variable.
* @param s the variable value
* @return the string for the chat window, with all %'s replaced by the input
*/
public String toString(String s) {
return (s != null) ? msg.replace("%", s) : msg;
}
/**
* Same as above, but for the Spout string.
* @param s the variable value
* @return the string for Spout, with all %'s replaced by the input
*/
public String toSpoutString(String s) {
if (spoutMsg == null)
return toString(s);
return (s != null) ? spoutMsg.replace("%", s) : spoutMsg;
}
}
@@ -30,7 +30,7 @@ public class CommandHandler implements CommandExecutor
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage("You need arguments, pal!");
plugin.tell(sender, Msg.MISC_NONE);
return true;
}
@@ -21,28 +21,16 @@ public class ArenaListCommand implements MACommand
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
// Grab the arena master.
// Grab the arena master and the args.
ArenaMaster am = plugin.getArenaMaster();
// Get the arenas.
List<Arena> arenas = am.getEnabledArenas();
List<Arena> arenas = am.getEnabledAndPermittedArenas(sender);
String msg = "Available arenas: ";
if (arenas.size() == 0) {
sender.sendMessage(msg + "<none>");
return true;
}
// Turn the list into a string.
String msg = Msg.MISC_LIST_ARENAS.toString(listToString(arenas));
// Enumerate arenas.
for (Arena a : arenas) {
msg += a.configName() + ", ";
}
// Trim off the trailing comma.
msg = msg.substring(0, msg.length() - 2);
// Send the message!
sender.sendMessage(msg);
plugin.tell(sender, msg);
return true;
}
@@ -50,4 +38,17 @@ public class ArenaListCommand implements MACommand
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args) {
return false;
}
private <E> String listToString(List<E> list) {
String result = "";
for (E e : list) {
result += e + ", ";
}
if (result.equals(""))
return Msg.MISC_NONE.toString();
return result.substring(0, result.length() - 2);
}
}
@@ -21,28 +21,46 @@ public class JoinCommand implements MACommand
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
// Grab the arena master
ArenaMaster am = plugin.getArenaMaster();
// Grab the arena master and get the argument.
ArenaMaster am = plugin.getArenaMaster();
String arenaName = (args.length == 1) ? args[0] : null;
// Get all enabled arenas.
List<Arena> arenas = am.getEnabledArenas();
// Get all arenas this player is eligible for.
List<Arena> arenas = am.getEnabledAndPermittedArenas(sender);
// If no arena was specified, and multiple arenas are available, notify.
if (args.length < 1 && arenas.size() > 1) {
sender.sendMessage("There are more than one arena. Pick one, damnit!");
return false;
}
// If only one arena, pick it no matter what, otherwise, look for name.
Arena arena = arenas.size() == 1 ? arenas.get(0) : am.getArenaWithName(args[0]);
// If null, no arena was found.
if (arena == null) {
sender.sendMessage("The arena '" + args[0] + "' does not exist.");
// If no arenas found, just tell the player it's not enabled.
if (arenas.size() == 0) {
plugin.tell(sender, Msg.JOIN_ARENA_NOT_ENABLED);
return false;
}
sender.sendMessage("You've joined arena '" + arena.configName() + "'!");
// Require an argument in case of multiple arenas.
if (arenaName == null && arenas.size() > 1) {
plugin.tell(sender, Msg.JOIN_ARG_NEEDED);
return false;
}
/* At this point in time, if there was no argument, there must be only
* a single arena in the list. If there was an argument, we can safely
* get the arena with that name, because canJoin() will do the rest of
* the sanity checks. */
Arena a = (arenaName == null) ? arenas.get(0) : am.getArenaWithName(arenaName);
// If the arena is null, it doesn't exist.
if (a == null) {
plugin.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
return false;
}
// Let the arena itself do the rest of the sanity checking.
if (!a.canJoin(sender)) {
return false;
}
// If no problems, let the guy join and notify.
a.playerJoin(sender, sender.getLocation());
plugin.tell(sender, Msg.JOIN_PLAYER_JOINED);
return true;
}
@@ -16,7 +16,7 @@ import org.bukkit.entity.LivingEntity;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils;
@@ -10,7 +10,7 @@ import org.bukkit.Location;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils;
@@ -10,7 +10,7 @@ import org.bukkit.Location;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils;
@@ -8,7 +8,7 @@ import org.bukkit.entity.LivingEntity;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils;