Sorted the methods and renamed them

This commit is contained in:
Andrew 2013-11-06 19:02:31 +13:00
parent 03dcdb9c61
commit f202fb7f52
2 changed files with 39 additions and 39 deletions

View File

@ -155,11 +155,11 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
value = (double) obj; value = (double) obj;
} }
} else { } else {
throw parseString("number", valueString, methodName); throw parseToException("number", valueString, methodName);
} }
} else if (boolean.class == param) { } else if (boolean.class == param) {
if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString)))
throw parseString("true/false", valueString, methodName); throw parseToException("true/false", valueString, methodName);
value = (boolean) "true".equalsIgnoreCase(valueString); value = (boolean) "true".equalsIgnoreCase(valueString);
} else if (param == String.class) { } else if (param == String.class) {
value = ChatColor.translateAlternateColorCodes('&', valueString); value = ChatColor.translateAlternateColorCodes('&', valueString);
@ -167,11 +167,11 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
try { try {
value = AnimalColor.valueOf(valueString.toUpperCase()); value = AnimalColor.valueOf(valueString.toUpperCase());
} catch (Exception ex) { } catch (Exception ex) {
throw parseString("animal color", valueString, methodName); throw parseToException("animal color", valueString, methodName);
} }
} else if (param == ItemStack.class) { } else if (param == ItemStack.class) {
try { try {
value = parseString(valueString); value = parseToItemstack(valueString);
} catch (Exception ex) { } catch (Exception ex) {
throw new Exception(String.format(ex.getMessage(), methodName)); throw new Exception(String.format(ex.getMessage(), methodName));
} }
@ -181,15 +181,15 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
if (split.length == 4) { if (split.length == 4) {
for (int a = 0; a < 4; a++) { for (int a = 0; a < 4; a++) {
try { try {
ItemStack item = parseString(split[a]); ItemStack item = parseToItemstack(split[a]);
items[a] = item; items[a] = item;
} catch (Exception ex) { } catch (Exception ex) {
throw parseString("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
} }
} }
} else { } else {
throw parseString("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
} }
value = items; value = items;
@ -207,12 +207,12 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
return disguise; return disguise;
} }
private Exception parseString(String expectedValue, String receivedInstead, String methodName) { private Exception parseToException(String expectedValue, String receivedInstead, String methodName) {
return new Exception(ChatColor.RED + "Expected " + ChatColor.GREEN + expectedValue + ChatColor.RED + ", received " return new Exception(ChatColor.RED + "Expected " + ChatColor.GREEN + expectedValue + ChatColor.RED + ", received "
+ ChatColor.GREEN + receivedInstead + ChatColor.RED + " instead for " + ChatColor.GREEN + methodName); + ChatColor.GREEN + receivedInstead + ChatColor.RED + " instead for " + ChatColor.GREEN + methodName);
} }
private ItemStack parseString(String string) throws Exception { private ItemStack parseToItemstack(String string) throws Exception {
String[] split = string.split(":", -1); String[] split = string.split(":", -1);
if (isNumeric(split[0])) { if (isNumeric(split[0])) {
int itemId = Integer.parseInt(split[0]); int itemId = Integer.parseInt(split[0]);
@ -221,15 +221,15 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
if (isNumeric(split[1])) { if (isNumeric(split[1])) {
itemDura = Short.parseShort(split[1]); itemDura = Short.parseShort(split[1]);
} else { } else {
throw parseString("item ID:Durability combo", string, "%s"); throw parseToException("item ID:Durability combo", string, "%s");
} }
} }
return new ItemStack(itemId, 1, itemDura); return new ItemStack(itemId, 1, itemDura);
} else { } else {
if (split.length == 1) { if (split.length == 1) {
throw parseString("item ID", string, "%s"); throw parseToException("item ID", string, "%s");
} else { } else {
throw parseString("item ID:Durability combo", string, "%s"); throw parseToException("item ID:Durability combo", string, "%s");
} }
} }
} }

View File

@ -19,6 +19,7 @@ import org.bukkit.scheduler.BukkitRunnable;
public class DisguiseListener implements Listener { public class DisguiseListener implements Listener {
private String currentVersion; private String currentVersion;
private DisguiseAPI disguiseAPI = new DisguiseAPI();
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<String, BukkitRunnable>(); private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<String, BukkitRunnable>();
private HashMap<String, Disguise> disguiseSlap = new HashMap<String, Disguise>(); private HashMap<String, Disguise> disguiseSlap = new HashMap<String, Disguise>();
private String latestVersion; private String latestVersion;
@ -27,7 +28,6 @@ public class DisguiseListener implements Listener {
private String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED private String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED
+ "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED
+ ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"; + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!";
private DisguiseAPI disguiseAPI = new DisguiseAPI();
public DisguiseListener(LibsDisguises libsDisguises) { public DisguiseListener(LibsDisguises libsDisguises) {
plugin = libsDisguises; plugin = libsDisguises;
@ -58,32 +58,6 @@ public class DisguiseListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.MONITOR)
public void onVechileLeave(VehicleExitEvent event) {
if (event.isCancelled())
return;
final Disguise disguise = DisguiseAPI.getDisguise(event.getExited());
if (disguise != null && event.getExited() instanceof Player) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
disguiseAPI.setupFakeDisguise(disguise);
((Player) disguise.getEntity()).updateInventory();
}
});
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onVechileEnter(VehicleEnterEvent event) {
if (event.isCancelled())
return;
Disguise disguise = DisguiseAPI.getDisguise(event.getEntered());
if (disguise != null && event.getEntered() instanceof Player) {
disguiseAPI.removeVisibleDisguise((Player) event.getEntered());
((Player) event.getEntered()).updateInventory();
}
}
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) { public void onJoin(PlayerJoinEvent event) {
Player p = event.getPlayer(); Player p = event.getPlayer();
@ -113,6 +87,32 @@ public class DisguiseListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.MONITOR)
public void onVechileEnter(VehicleEnterEvent event) {
if (event.isCancelled())
return;
Disguise disguise = DisguiseAPI.getDisguise(event.getEntered());
if (disguise != null && event.getEntered() instanceof Player) {
disguiseAPI.removeVisibleDisguise((Player) event.getEntered());
((Player) event.getEntered()).updateInventory();
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onVechileLeave(VehicleExitEvent event) {
if (event.isCancelled())
return;
final Disguise disguise = DisguiseAPI.getDisguise(event.getExited());
if (disguise != null && event.getExited() instanceof Player) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
disguiseAPI.setupFakeDisguise(disguise);
((Player) disguise.getEntity()).updateInventory();
}
});
}
}
public void setSlap(final String player, Disguise disguise) { public void setSlap(final String player, Disguise disguise) {
if (disguiseSlap.containsKey(player)) { if (disguiseSlap.containsKey(player)) {
disguiseSlap.remove(player); disguiseSlap.remove(player);