mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-26 20:45:17 +01:00
Fixed disable command. Minor code cleanup.
This commit is contained in:
parent
1f7d280ac8
commit
e3c22c98e0
BIN
MobArena.jar
BIN
MobArena.jar
Binary file not shown.
@ -191,6 +191,7 @@ public class ArenaImpl implements Arena
|
||||
@Override
|
||||
public void setEnabled(boolean value) {
|
||||
enabled = value;
|
||||
settings.set("enabled", enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -647,15 +648,15 @@ public class ArenaImpl implements Arena
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerSpec(Player p, Location loc)
|
||||
{
|
||||
public void playerSpec(Player p, Location loc) {
|
||||
storePlayerData(p, loc);
|
||||
MAUtils.sitPets(p);
|
||||
movePlayerToSpec(p);
|
||||
|
||||
Messenger.tellPlayer(p, Msg.SPEC_PLAYER_SPECTATE);
|
||||
}
|
||||
|
||||
private void spawnPets()
|
||||
{
|
||||
private void spawnPets() {
|
||||
for (Map.Entry<Player,ArenaPlayer> entry : arenaPlayerMap.entrySet()) {
|
||||
ArenaClass arenaClass = entry.getValue().getArenaClass();
|
||||
int petAmount = arenaClass.getPetAmount();
|
||||
@ -687,8 +688,7 @@ public class ArenaImpl implements Arena
|
||||
}
|
||||
}
|
||||
|
||||
private void startSpawner()
|
||||
{
|
||||
private void startSpawner() {
|
||||
// Set the spawn flags to enable monster spawning.
|
||||
world.setSpawnFlags(true, true);
|
||||
//world.setDifficulty(Difficulty.NORMAL);
|
||||
|
@ -24,7 +24,6 @@ import com.garbagemule.MobArena.ArenaClass.ArmorType;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
import com.garbagemule.MobArena.util.ItemParser;
|
||||
import com.garbagemule.MobArena.util.TextUtils;
|
||||
import com.garbagemule.MobArena.util.config.Config;
|
||||
import com.garbagemule.MobArena.util.config.ConfigSection;
|
||||
import com.garbagemule.MobArena.util.config.ConfigUtils;
|
||||
@ -42,6 +41,8 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
|
||||
private Set<String> allowedCommands;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
@ -55,6 +56,8 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
this.classes = new HashMap<String, ArenaClass>();
|
||||
|
||||
this.allowedCommands = new HashSet<String>();
|
||||
|
||||
this.enabled = config.getBoolean("global-settings.enabled", true);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -68,11 +71,12 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return config.getBoolean("global-settings.enabled", true);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean value) {
|
||||
config.set("global-settings.enabled", value);
|
||||
enabled = value;
|
||||
config.set("global-settings.enabled", enabled);
|
||||
}
|
||||
|
||||
public boolean notifyOnUpdates() {
|
||||
@ -118,6 +122,10 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
*/
|
||||
|
||||
public List<Arena> getEnabledArenas() {
|
||||
return getEnabledArenas(arenas);
|
||||
}
|
||||
|
||||
public List<Arena> getEnabledArenas(List<Arena> arenas) {
|
||||
List<Arena> result = new LinkedList<Arena>();
|
||||
for (Arena arena : arenas)
|
||||
if (arena.isEnabled())
|
||||
@ -416,7 +424,6 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
}
|
||||
|
||||
private boolean addRemoveClassPermission(String classname, String perm, boolean add) {
|
||||
String lowercase = classname.toLowerCase();
|
||||
String path = "classes." + classname;
|
||||
if (config.getConfigSection(path) == null)
|
||||
return false;
|
||||
|
@ -17,7 +17,8 @@ public enum Msg
|
||||
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_ARG_NEEDED("You must specify an arena."),
|
||||
JOIN_NO_PERMISSION("You don't have permission to join any arenas."),
|
||||
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),
|
||||
@ -29,7 +30,6 @@ public enum Msg
|
||||
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: %"),
|
||||
|
@ -9,6 +9,7 @@ import com.garbagemule.MobArena.Messenger;
|
||||
import com.garbagemule.MobArena.Msg;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
import com.garbagemule.MobArena.util.TextUtils;
|
||||
|
||||
public class Commands
|
||||
{
|
||||
@ -16,16 +17,63 @@ public class Commands
|
||||
return (sender instanceof Player);
|
||||
}
|
||||
|
||||
public static boolean sanityChecks(Player p, ArenaMaster am, Arena arena, String arg1, List<Arena> arenas) {
|
||||
if (arenas.size() > 1 && arg1.isEmpty())
|
||||
Messenger.tellPlayer(p, Msg.JOIN_ARG_NEEDED);
|
||||
else if (arena == null)
|
||||
Messenger.tellPlayer(p, Msg.ARENA_DOES_NOT_EXIST);
|
||||
else if (am.getArenaWithPlayer(p) != null && !arena.equals(am.getArenaWithPlayer(p)))
|
||||
Messenger.tellPlayer(p, Msg.JOIN_IN_OTHER_ARENA);
|
||||
else
|
||||
return true;
|
||||
public static Arena getArenaToJoinOrSpec(ArenaMaster am, Player p, String arg1) {
|
||||
// Check if MobArena is enabled first.
|
||||
if (!am.isEnabled()) {
|
||||
Messenger.tellPlayer(p, Msg.JOIN_NOT_ENABLED);
|
||||
return null;
|
||||
}
|
||||
|
||||
return false;
|
||||
// Then check if we have permission at all.
|
||||
List<Arena> arenas = am.getPermittedArenas(p);
|
||||
if (arenas.isEmpty()) {
|
||||
Messenger.tellPlayer(p, Msg.JOIN_NO_PERMISSION);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Then check if we have any enabled arenas.
|
||||
arenas = am.getEnabledArenas(arenas);
|
||||
if (arenas.isEmpty()) {
|
||||
Messenger.tellPlayer(p, Msg.JOIN_NOT_ENABLED);
|
||||
return null;
|
||||
}
|
||||
|
||||
// The arena to join.
|
||||
Arena arena = null;
|
||||
|
||||
// Branch on whether there's an argument or not.
|
||||
if (arg1 != null) {
|
||||
arena = am.getArenaWithName(arg1);
|
||||
if (arena == null) {
|
||||
Messenger.tellPlayer(p, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!arenas.contains(arena)) {
|
||||
Messenger.tellPlayer(p, Msg.JOIN_ARENA_NOT_ENABLED);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (arenas.size() > 1) {
|
||||
Messenger.tellPlayer(p, Msg.JOIN_ARG_NEEDED);
|
||||
Messenger.tellPlayer(p, Msg.MISC_LIST_ARENAS.toString(TextUtils.listToString(arenas)));
|
||||
return null;
|
||||
}
|
||||
arena = arenas.get(0);
|
||||
}
|
||||
|
||||
// If player is in a boat/minecart, eject!
|
||||
if (p.isInsideVehicle()) {
|
||||
p.leaveVehicle();
|
||||
}
|
||||
|
||||
// If player is in a bed, unbed!
|
||||
if (p.isSleeping()) {
|
||||
p.kickPlayer("Banned for life... Nah, just don't join from a bed ;)");
|
||||
return null;
|
||||
}
|
||||
|
||||
return arena;
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class DisableCommand implements Command
|
||||
return true;
|
||||
}
|
||||
|
||||
am.setEnabled(true);
|
||||
am.setEnabled(false);
|
||||
am.saveConfig();
|
||||
Messenger.tellPlayer(sender, "MobArena " + ChatColor.RED + "disabled");
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.garbagemule.MobArena.commands.user;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -26,46 +24,22 @@ public class JoinCommand implements Command
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grab the argument, if any.
|
||||
String arg1 = (args.length > 0 ? args[0] : "");
|
||||
// Cast the sender, grab the argument, if any.
|
||||
Player p = (Player) sender;
|
||||
String arg1 = (args.length > 0 ? args[0] : null);
|
||||
|
||||
// Cast the sender.
|
||||
Player p = (Player) sender;
|
||||
|
||||
List<Arena> arenas = am.getEnabledArenas();
|
||||
if (!am.isEnabled() || arenas.size() < 1) {
|
||||
Messenger.tellPlayer(p, Msg.JOIN_NOT_ENABLED);
|
||||
return true;
|
||||
// Run some rough sanity checks, and grab the arena to join.
|
||||
Arena arena = Commands.getArenaToJoinOrSpec(am, p, arg1);
|
||||
if (arena == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grab the arena to join
|
||||
Arena arena = arenas.size() == 1 ? arenas.get(0) : am.getArenaWithName(arg1);
|
||||
|
||||
// Run a couple of basic sanity checks
|
||||
if (!Commands.sanityChecks(p, am, arena, arg1, arenas)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Run a bunch of per-arena sanity checks
|
||||
// Per-arena sanity checks
|
||||
if (!arena.canJoin(p)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If player is in a boat/minecart, eject!
|
||||
if (p.isInsideVehicle())
|
||||
p.leaveVehicle();
|
||||
|
||||
// If player is in a bed, unbed!
|
||||
if (p.isSleeping()) {
|
||||
p.kickPlayer("Banned for life... Nah, just don't join from a bed ;)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Join the arena!
|
||||
if (!arena.playerJoin(p, p.getLocation())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return arena.playerJoin(p, p.getLocation());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.garbagemule.MobArena.commands.user;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -26,45 +24,23 @@ public class SpecCommand implements Command
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grab the argument, if any.
|
||||
String arg1 = (args.length > 0 ? args[0] : "");
|
||||
// Cast the sender, grab the argument, if any.
|
||||
Player p = (Player) sender;
|
||||
String arg1 = (args.length > 0 ? args[0] : null);
|
||||
|
||||
// Cast the sender.
|
||||
Player p = (Player) sender;
|
||||
|
||||
List<Arena> arenas = am.getEnabledArenas();
|
||||
if (!am.isEnabled() || arenas.size() < 1) {
|
||||
Messenger.tellPlayer(p, Msg.JOIN_NOT_ENABLED);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Grab the arena to join
|
||||
Arena arena = arenas.size() == 1 ? arenas.get(0) : am.getArenaWithName(arg1);
|
||||
|
||||
// Run a couple of basic sanity checks
|
||||
if (!Commands.sanityChecks(p, am, arena, arg1, arenas)) {
|
||||
// Run some rough sanity checks, and grab the arena to spec.
|
||||
Arena arena = Commands.getArenaToJoinOrSpec(am, p, arg1);
|
||||
if (arena == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Run a bunch of arena-specific sanity-checks
|
||||
// Per-arena sanity checks
|
||||
if (!arena.canSpec(p)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If player is in a boat/minecart, eject!
|
||||
if (p.isInsideVehicle())
|
||||
p.leaveVehicle();
|
||||
|
||||
// If player is in a bed, unbed!
|
||||
if (p.isSleeping()) {
|
||||
p.kickPlayer("Banned for life... Nah, just don't join from a bed ;)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Spectate the arena!
|
||||
// Spec the arena!
|
||||
arena.playerSpec(p, p.getLocation());
|
||||
|
||||
Messenger.tellPlayer(p, Msg.SPEC_PLAYER_SPECTATE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.garbagemule.MobArena.framework;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -55,6 +56,8 @@ public interface ArenaMaster
|
||||
|
||||
public List<Arena> getEnabledArenas();
|
||||
|
||||
public List<Arena> getEnabledArenas(List<Arena> arenas);
|
||||
|
||||
public List<Arena> getPermittedArenas(Player p);
|
||||
|
||||
public List<Arena> getEnabledAndPermittedArenas(Player p);
|
||||
@ -83,6 +86,8 @@ public interface ArenaMaster
|
||||
|
||||
public Arena getArenaWithName(String configName);
|
||||
|
||||
public Arena getArenaWithName(Collection<Arena> arenas, String configName);
|
||||
|
||||
public boolean isAllowed(String command);
|
||||
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
package com.garbagemule.MobArena.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.garbagemule.MobArena.Msg;
|
||||
|
||||
public class TextUtils
|
||||
{
|
||||
/**
|
||||
@ -61,4 +67,28 @@ public class TextUtils
|
||||
String firstLetter = s.substring(0,1).toUpperCase();
|
||||
return firstLetter + s.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
public static String playerListToString(Collection<? extends Player> list) {
|
||||
if (list.isEmpty()) {
|
||||
return Msg.MISC_NONE.toString();
|
||||
}
|
||||
|
||||
StringBuffer buffy = new StringBuffer();
|
||||
for (Player p : list) {
|
||||
buffy.append(", " + p.getName());
|
||||
}
|
||||
return buffy.substring(2);
|
||||
}
|
||||
|
||||
public static String listToString(Collection<? extends Object> list) {
|
||||
if (list.isEmpty()) {
|
||||
return Msg.MISC_NONE.toString();
|
||||
}
|
||||
|
||||
StringBuffer buffy = new StringBuffer();
|
||||
for (Object o : list) {
|
||||
buffy.append(", " + o.toString());
|
||||
}
|
||||
return buffy.substring(2);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user