From bb0b26e03c4015e88de787b95f074776f9f12117 Mon Sep 17 00:00:00 2001 From: "main()" Date: Wed, 4 Jan 2012 13:17:10 +0100 Subject: [PATCH] Another huge commit. Style once again, hopefully for the last time. And we're now using CheckStyle-suppression-comments, thanks @lithium3141. --- config/mv_checks.xml | 30 +++++++++-------- .../onarandombox/MultiverseCore/MVWorld.java | 24 ++++++++++---- .../MultiverseCore/MultiverseCore.java | 3 +- .../commands/AnchorCommand.java | 2 +- .../commands/CreateCommand.java | 2 +- .../MultiverseCore/commands/HelpCommand.java | 3 +- .../MultiverseCore/commands/ListCommand.java | 2 +- .../commands/ModifyAddCommand.java | 3 +- .../commands/ModifyClearCommand.java | 9 ++++-- .../commands/ModifyCommand.java | 3 +- .../commands/ModifyRemoveCommand.java | 3 +- .../commands/ModifySetCommand.java | 6 ++-- .../MultiverseCore/commands/SpoutCommand.java | 3 ++ .../configuration/BooleanConfigProperty.java | 28 +++++++++++++--- .../configuration/ColorConfigProperty.java | 28 +++++++++++++--- .../DifficultyConfigProperty.java | 28 +++++++++++++--- .../configuration/DoubleConfigProperty.java | 28 +++++++++++++--- .../configuration/GameModeConfigProperty.java | 28 +++++++++++++--- .../configuration/IntegerConfigProperty.java | 28 +++++++++++++--- .../configuration/LocationConfigProperty.java | 28 +++++++++++++--- .../configuration/MVConfigMigrator.java | 15 ++++++++- .../configuration/StringConfigProperty.java | 28 +++++++++++++--- .../TempStringConfigProperty.java | 32 ++++++++++++++++--- .../destination/CannonDestination.java | 22 +++++++------ .../destination/ExactDestination.java | 8 ++--- .../MultiverseCore/utils/BlockSafety.java | 4 +-- .../utils/LocationManipulation.java | 8 +++-- .../MultiverseCore/utils/MVMessaging.java | 2 +- .../MultiverseCore/utils/MVPlayerSession.java | 2 +- .../MultiverseCore/utils/SafeTTeleporter.java | 4 +-- .../MultiverseCore/utils/UpdateChecker.java | 15 +++++++++ .../utils/webpaste/PasteFailedException.java | 3 ++ .../utils/webpaste/PasteService.java | 1 + .../utils/webpaste/PasteServiceFactory.java | 18 +++++++++-- .../utils/webpaste/PasteServiceType.java | 12 +++++++ .../utils/webpaste/PastebinPasteService.java | 23 +++++++++++-- .../utils/webpaste/PastiePasteService.java | 23 ++++++++++--- 37 files changed, 400 insertions(+), 109 deletions(-) diff --git a/config/mv_checks.xml b/config/mv_checks.xml index a3815a42..30f45212 100644 --- a/config/mv_checks.xml +++ b/config/mv_checks.xml @@ -5,7 +5,9 @@ ~ with this project. ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - + @@ -23,7 +25,19 @@ - + + + + + + + + + + + + + @@ -98,17 +112,7 @@ - - - - - - - - - - - + diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index a2aa8ff1..3ea497c8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -66,14 +67,18 @@ public class MVWorld implements MultiverseWorld { private Map propertyAliases; private Permission ignoreperm; - private static final Map staticTimes = new HashMap(); + private static final Map TIME_ALIASES; static { + Map staticTimes = new HashMap(); staticTimes.put("morning", "8:00"); staticTimes.put("day", "12:00"); staticTimes.put("noon", "12:00"); staticTimes.put("midnight", "0:00"); staticTimes.put("night", "20:00"); + + // now set TIME_ALIASES to a "frozen" map + TIME_ALIASES = Collections.unmodifiableMap(staticTimes); } public MVWorld(World world, FileConfiguration config, MultiverseCore instance, Long seed, String generatorString, boolean fixSpawn) { @@ -239,7 +244,7 @@ public class MVWorld implements MultiverseWorld { private double getDefaultScale(Environment environment) { if (environment == Environment.NETHER) { - return 8.0; + return 8.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck } return 1.0; } @@ -931,7 +936,8 @@ public class MVWorld implements MultiverseWorld { if (newerSpawn != null) { this.setSpawnLocation(newerSpawn); configLocation = this.getSpawnLocation(); - this.plugin.log(Level.INFO, "New Spawn for '" + this.getName() + "' is Located at: " + LocationManipulation.locationToString(configLocation)); + this.plugin.log(Level.INFO, "New Spawn for '" + this.getName() + + "' is Located at: " + LocationManipulation.locationToString(configLocation)); } else { this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!"); } @@ -1052,8 +1058,12 @@ public class MVWorld implements MultiverseWorld { long time = this.getCBWorld().getTime(); // I'm tired, so they get time in 24 hour for now. // Someone else can add 12 hr format if they want :P + + // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck int hours = (int) ((time / 1000 + 8) % 24); int minutes = (int) (60 * (time % 1000) / 1000); + // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck + return String.format("%d:%02d", hours, minutes); } @@ -1061,9 +1071,10 @@ public class MVWorld implements MultiverseWorld { * {@inheritDoc} */ @Override + // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck public boolean setTime(String timeAsString) { - if (staticTimes.containsKey(timeAsString.toLowerCase())) { - return this.setTime(staticTimes.get(timeAsString.toLowerCase())); + if (TIME_ALIASES.containsKey(timeAsString.toLowerCase())) { + return this.setTime(TIME_ALIASES.get(timeAsString.toLowerCase())); } // Regex that extracts a time in the following formats: // 11:11pm, 11:11, 23:11, 1111, 1111p, and the aliases at the top of this file. @@ -1087,7 +1098,7 @@ public class MVWorld implements MultiverseWorld { } } // Translate 24th hour to 0th hour. - if (hour == 24) { + if (hour == 24) { // SUPPRESS CHECKSTYLE MagicNumberCheck hour = 0; } // Clamp the hour @@ -1110,6 +1121,7 @@ public class MVWorld implements MultiverseWorld { this.getCBWorld().setTime((long) totaltime); return true; } + // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck @Override public String toString() { diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 52beb5fd..9425eb66 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -70,6 +70,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { // Multiverse should stop other plugins from teleporting players // to worlds. // TODO This is REALLY bad style! We have to change this! + // No, I'm NOT going to suppress these warnings because we HAVE TO CHANGE THIS! public static boolean EnforceAccess; public static boolean PrefixChat; public static boolean DisplayPermErrors; @@ -367,7 +368,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { // Should permissions errors display to users? DisplayPermErrors = this.multiverseConfig.getBoolean("displaypermerrors", true); - this.messaging.setCooldown(this.multiverseConfig.getInt("messagecooldown", 5000)); + this.messaging.setCooldown(this.multiverseConfig.getInt("messagecooldown", 5000)); // SUPPRESS CHECKSTYLE: MagicNumberCheck // Update the version of the config! this.multiverseConfig.set("version", coreDefaults.get("version")); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java index 2c220da9..232aabc0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java @@ -35,7 +35,7 @@ public class AnchorCommand extends PaginatedCoreCommand { this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d"); this.addCommandExample("/mv anchors "); this.setPermission("multiverse.core.anchor", "Allows management of Anchor Destinations.", PermissionDefault.OP); - this.setItemsPerPage(8); + this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck } private List getFancyAnchorList(Player p) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index 0a122d3c..e6613c17 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -29,7 +29,7 @@ public class CreateCommand extends MultiverseCommand { super(plugin); this.setName("Create World"); this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] [-n]"); - this.setArgRange(2, 7); + this.setArgRange(2, 7); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.addKey("mvcreate"); this.addKey("mvc"); this.addKey("mv create"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java index 26c1faef..656345fd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java @@ -5,6 +5,7 @@ * with this project. * ******************************************************************************/ +// TODO maybe remove this comment...? // This file is no longer licensed under that silly CC license. I have blanked it out and will start implementaiton of my own in a few days. For now there is no help. package com.onarandombox.MultiverseCore.commands; @@ -36,7 +37,7 @@ public class HelpCommand extends PaginatedCoreCommand { this.addKey("mv search"); this.addCommandExample("/mv help ?"); this.setPermission("multiverse.help", "Displays a nice help menu.", PermissionDefault.TRUE); - this.setItemsPerPage(7); + this.setItemsPerPage(7); // SUPPRESS CHECKSTYLE: MagicNumberCheck } @Override diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java index 8df221a6..e882aa02 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java @@ -32,7 +32,7 @@ public class ListCommand extends PaginatedCoreCommand { this.addKey("mvl"); this.addKey("mv list"); this.setPermission("multiverse.core.list.worlds", "Displays a listing of all worlds that you can enter.", PermissionDefault.OP); - this.setItemsPerPage(8); + this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck } private List getFancyWorldList(Player p) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyAddCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyAddCommand.java index 0113fc06..abd3e135 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyAddCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyAddCommand.java @@ -39,7 +39,8 @@ public class ModifyAddCommand extends MultiverseCommand { this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals"); this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters"); this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist"); - this.setPermission("multiverse.core.modify.add", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP); + this.setPermission("multiverse.core.modify.add", "Modify various aspects of worlds. See the help wiki for how to use this command properly. " + + "If you do not include a world, the current world will be used.", PermissionDefault.OP); this.worldManager = this.plugin.getMVWorldManager(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java index ba29ea2c..78075432 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java @@ -36,7 +36,8 @@ public class ModifyClearCommand extends MultiverseCommand { this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "animals"); this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "monsters"); this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "worldblacklist"); - this.setPermission("multiverse.core.modify.clear", "Removes all values from a property. This will work on properties that contain lists.", PermissionDefault.OP); + this.setPermission("multiverse.core.modify.clear", + "Removes all values from a property. This will work on properties that contain lists.", PermissionDefault.OP); this.worldManager = this.plugin.getMVWorldManager(); } @@ -76,9 +77,11 @@ public class ModifyClearCommand extends MultiverseCommand { } if (world.clearList(property)) { sender.sendMessage(property + " was cleared. It contains 0 values now."); - sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was " + ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now."); + sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was " + + ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now."); } else { - sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property + ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared."); + sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property + + ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared."); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java index cdf317fe..d8c74ac3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java @@ -37,7 +37,8 @@ public class ModifyCommand extends MultiverseCommand { children.put("multiverse.core.modify.modify", true); children.put("multiverse.core.modify.clear", true); children.put("multiverse.core.modify.remove", true); - Permission modify = new Permission("multiverse.core.modify", "Modify various aspects of worlds. It requires add/set/clear/remove. See the examples below", PermissionDefault.OP, children); + Permission modify = new Permission("multiverse.core.modify", + "Modify various aspects of worlds. It requires add/set/clear/remove. See the examples below", PermissionDefault.OP, children); this.addCommandExample(ChatColor.AQUA + "/mv modify set ?"); this.addCommandExample(ChatColor.GREEN + "/mv modify add ?"); this.addCommandExample(ChatColor.BLUE + "/mv modify clear ?"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyRemoveCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyRemoveCommand.java index 7e57365a..57b4a262 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyRemoveCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyRemoveCommand.java @@ -40,7 +40,8 @@ public class ModifyRemoveCommand extends MultiverseCommand { this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals"); this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters"); this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist"); - this.setPermission("multiverse.core.modify.remove", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP); + this.setPermission("multiverse.core.modify.remove", "Modify various aspects of worlds. See the help wiki for how to use this command properly. " + + "If you do not include a world, the current world will be used.", PermissionDefault.OP); this.worldManager = this.plugin.getMVWorldManager(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java index e8b0a7a7..7c753ce4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java @@ -51,7 +51,8 @@ public class ModifySetCommand extends MultiverseCommand { this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "heal " + ChatColor.RED + "true"); this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "adjustspawn " + ChatColor.RED + "false"); this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "spawn"); - this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP); + this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. " + + "If you do not include a world, the current world will be used.", PermissionDefault.OP); } @Override @@ -108,7 +109,8 @@ public class ModifySetCommand extends MultiverseCommand { } try { if (world.setProperty(property, value, sender)) { - sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value); + sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property + + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value); } else { sender.sendMessage(world.getProperty(property, Object.class).getHelp()); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/SpoutCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/SpoutCommand.java index 5642fd63..b993d5b1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/SpoutCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/SpoutCommand.java @@ -51,10 +51,13 @@ public class SpoutCommand extends MultiverseCommand { } PopupScreen pop = new GenericPopup(); GenericButton button = new GenericButton("Fish"); + // TODO maybe use constants for these + // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck button.setX(50); button.setY(50); button.setWidth(100); button.setHeight(40); + // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck pop.attachWidget(this.plugin, button); sender.sendMessage(ChatColor.GREEN + "YAY!"); p.getMainScreen().attachPopupScreen(pop); diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/BooleanConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/BooleanConfigProperty.java index 85c33605..e186bed5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/BooleanConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/BooleanConfigProperty.java @@ -32,16 +32,25 @@ public class BooleanConfigProperty implements MVConfigProperty { this.setValue(this.section.getBoolean(this.configNode, defaultValue)); } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public Boolean getValue() { return this.value; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(Boolean value) { if (value == null) { @@ -52,6 +61,9 @@ public class BooleanConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { if (value == null) { @@ -64,18 +76,24 @@ public class BooleanConfigProperty implements MVConfigProperty { return false; } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return this.configNode; } + /** + * {@inheritDoc} + */ + @Override + public String getHelp() { + return this.help; + } + @Override public String toString() { return value.toString(); } - - @Override - public String getHelp() { - return this.help; - } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/ColorConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/ColorConfigProperty.java index e4230a1d..1149b815 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/ColorConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/ColorConfigProperty.java @@ -33,16 +33,25 @@ public class ColorConfigProperty implements MVConfigProperty { this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public EnglishChatColor getValue() { return this.value; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(EnglishChatColor value) { if (value == null) { @@ -53,6 +62,9 @@ public class ColorConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { EnglishChatColor color = EnglishChatColor.fromString(value); @@ -63,18 +75,24 @@ public class ColorConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return this.configNode; } + /** + * {@inheritDoc} + */ + @Override + public String getHelp() { + return this.help; + } + @Override public String toString() { return value.toString(); } - - @Override - public String getHelp() { - return this.help; - } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/DifficultyConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/DifficultyConfigProperty.java index 9116f751..d6e8d5a1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/DifficultyConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/DifficultyConfigProperty.java @@ -33,16 +33,25 @@ public class DifficultyConfigProperty implements MVConfigProperty { this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public Difficulty getValue() { return this.value; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(Difficulty value) { if (value == null) { @@ -53,6 +62,9 @@ public class DifficultyConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { try { @@ -66,18 +78,24 @@ public class DifficultyConfigProperty implements MVConfigProperty { } } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return this.configNode; } + /** + * {@inheritDoc} + */ + @Override + public String getHelp() { + return this.help; + } + @Override public String toString() { return value.toString(); } - - @Override - public String getHelp() { - return this.help; - } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/DoubleConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/DoubleConfigProperty.java index e1740900..9903d65d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/DoubleConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/DoubleConfigProperty.java @@ -32,16 +32,25 @@ public class DoubleConfigProperty implements MVConfigProperty { this.setValue(this.section.getDouble(this.configNode, defaultValue)); } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public Double getValue() { return this.value; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(Double value) { if (value == null) { @@ -52,6 +61,9 @@ public class DoubleConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { try { @@ -62,18 +74,24 @@ public class DoubleConfigProperty implements MVConfigProperty { } } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return this.configNode; } + /** + * {@inheritDoc} + */ + @Override + public String getHelp() { + return this.help; + } + @Override public String toString() { return value.toString(); } - - @Override - public String getHelp() { - return this.help; - } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/GameModeConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/GameModeConfigProperty.java index 2edf8e9d..a71ad07c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/GameModeConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/GameModeConfigProperty.java @@ -33,16 +33,25 @@ public class GameModeConfigProperty implements MVConfigProperty { this.parseValue(this.section.getString(this.configNode, defaultValue.toString())); } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public GameMode getValue() { return this.value; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(GameMode value) { if (value == null) { @@ -53,6 +62,9 @@ public class GameModeConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { try { @@ -66,18 +78,24 @@ public class GameModeConfigProperty implements MVConfigProperty { } } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return this.configNode; } + /** + * {@inheritDoc} + */ + @Override + public String getHelp() { + return this.help; + } + @Override public String toString() { return value.toString(); } - - @Override - public String getHelp() { - return this.help; - } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/IntegerConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/IntegerConfigProperty.java index aaf136ef..27961a24 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/IntegerConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/IntegerConfigProperty.java @@ -32,16 +32,25 @@ public class IntegerConfigProperty implements MVConfigProperty { this.setValue(this.section.getInt(this.configNode, defaultValue)); } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public Integer getValue() { return this.value; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(Integer value) { if (value == null) { @@ -52,6 +61,9 @@ public class IntegerConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { try { @@ -62,18 +74,24 @@ public class IntegerConfigProperty implements MVConfigProperty { } } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return this.configNode; } + /** + * {@inheritDoc} + */ + @Override + public String getHelp() { + return this.help; + } + @Override public String toString() { return value.toString(); } - - @Override - public String getHelp() { - return this.help; - } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java index 3833dc18..6079a06e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocationConfigProperty.java @@ -34,37 +34,50 @@ public class LocationConfigProperty implements MVConfigProperty { this.setValue(this.getLocationFromConfig(defaultValue)); } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public Location getValue() { return this.value; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { Location parsed = LocationManipulation.stringToLocation(value); return this.setValue(parsed); } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return this.configNode; } - @Override - public String toString() { - return LocationManipulation.strCoordsRaw(this.value); - } - + /** + * {@inheritDoc} + */ @Override public String getHelp() { return this.help; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(Location value) { if (value == null) { @@ -94,4 +107,9 @@ public class LocationConfigProperty implements MVConfigProperty { } return defaultValue; } + + @Override + public String toString() { + return LocationManipulation.strCoordsRaw(this.value); + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/MVConfigMigrator.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/MVConfigMigrator.java index 5b9e33ce..1a8dbe16 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/MVConfigMigrator.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/MVConfigMigrator.java @@ -17,8 +17,17 @@ import java.util.Arrays; import java.util.List; import java.util.logging.Level; -@SuppressWarnings("deprecation") +/* + * This is a mess, so I'm just going to suppress all warnings here. + * BEGIN CHECKSTYLE-SUPPRESSION: ALL + */ + +/** + * @deprecated This isn't used any more, is it? + */ +@Deprecated public abstract class MVConfigMigrator { + public List createdDefaults = new ArrayList(); public abstract boolean migrate(String name, File folder); @@ -60,3 +69,7 @@ public abstract class MVConfigMigrator { return oldFolder; } } + +/* + * END CHECKSTYLE-SUPPRESSION: ALL + */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/StringConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/StringConfigProperty.java index b2e67ea9..948034ce 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/StringConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/StringConfigProperty.java @@ -32,16 +32,25 @@ public class StringConfigProperty implements MVConfigProperty { this.parseValue(this.section.getString(this.configNode, defaultValue)); } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public String getValue() { return this.value; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { if (value == null) { @@ -51,21 +60,25 @@ public class StringConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return this.configNode; } - @Override - public String toString() { - return value; - } - + /** + * {@inheritDoc} + */ @Override public String getHelp() { return this.help; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(String value) { if (value == null) { @@ -75,4 +88,9 @@ public class StringConfigProperty implements MVConfigProperty { this.section.set(configNode, this.value); return true; } + + @Override + public String toString() { + return value; + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/TempStringConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/TempStringConfigProperty.java index 1369dada..dc578cf3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/TempStringConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/TempStringConfigProperty.java @@ -28,20 +28,33 @@ public class TempStringConfigProperty implements MVConfigProperty { this.method = method; } + /** + * {@inheritDoc} + */ @Override public String getName() { return this.name; } + /** + * {@inheritDoc} + */ @Override public String getValue() { return this.value; } + /** + * Gets the method used to set this {@link TempStringConfigProperty}. + * @return The name of that method. + */ public String getMethod() { return this.method; } + /** + * {@inheritDoc} + */ @Override public boolean parseValue(String value) { if (value == null) { @@ -51,21 +64,25 @@ public class TempStringConfigProperty implements MVConfigProperty { return true; } + /** + * {@inheritDoc} + */ @Override public String getConfigNode() { return ""; } - @Override - public String toString() { - return value; - } - + /** + * {@inheritDoc} + */ @Override public String getHelp() { return this.help; } + /** + * {@inheritDoc} + */ @Override public boolean setValue(String value) { if (value == null) { @@ -74,4 +91,9 @@ public class TempStringConfigProperty implements MVConfigProperty { this.value = value; return true; } + + @Override + public String toString() { + return value; + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java index 0031041a..e26acec3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java @@ -81,9 +81,11 @@ public class CannonDestination implements MVDestination { } try { + // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck Float.parseFloat(parsed.get(3)); Float.parseFloat(parsed.get(4)); Float.parseFloat(parsed.get(5)); + // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck } catch (NumberFormatException e) { return false; } @@ -151,9 +153,11 @@ public class CannonDestination implements MVDestination { this.location.setZ(coords[2]); try { + // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck this.location.setPitch(Float.parseFloat(parsed.get(3))); this.location.setYaw(Float.parseFloat(parsed.get(4))); this.speed = Math.abs(Float.parseFloat(parsed.get(5))); + // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck } catch (NumberFormatException e) { this.isValid = false; return; @@ -196,15 +200,6 @@ public class CannonDestination implements MVDestination { this.isValid = false; } - @Override - public String toString() { - if (isValid) { - return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() - + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed; - } - return "i:Invalid Destination"; - } - /** * {@inheritDoc} */ @@ -220,4 +215,13 @@ public class CannonDestination implements MVDestination { public boolean useSafeTeleporter() { return false; } + + @Override + public String toString() { + if (isValid) { + return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed; + } + return "i:Invalid Destination"; + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java index b9e78878..c8baf41d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java @@ -53,7 +53,7 @@ public class ExactDestination implements MVDestination { // Need at least: e:world:x,y,z // OR e:world:x,y,z:pitch:yaw // so basically 3 or 5 - if (!(parsed.size() == 3 || parsed.size() == 5)) { + if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck return false; } // If it's not an Exact type @@ -76,7 +76,7 @@ public class ExactDestination implements MVDestination { try { Float.parseFloat(parsed.get(3)); - Float.parseFloat(parsed.get(4)); + Float.parseFloat(parsed.get(4)); // SUPPRESS CHECKSTYLE: MagicNumberCheck } catch (NumberFormatException e) { return false; } @@ -111,7 +111,7 @@ public class ExactDestination implements MVDestination { // Need at least: e:world:x,y,z // OR e:world:x,y,z:pitch:yaw // so basically 3 or 5 - if (!(parsed.size() == 3 || parsed.size() == 5)) { + if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck this.isValid = false; return; } @@ -152,7 +152,7 @@ public class ExactDestination implements MVDestination { try { this.location.setPitch(Float.parseFloat(parsed.get(3))); - this.location.setYaw(Float.parseFloat(parsed.get(4))); + this.location.setYaw(Float.parseFloat(parsed.get(4))); // SUPPRESS CHECKSTYLE: MagicNumberCheck } catch (NumberFormatException e) { this.isValid = false; return; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/BlockSafety.java b/src/main/java/com/onarandombox/MultiverseCore/utils/BlockSafety.java index ce5cf5b2..aee6bb64 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/BlockSafety.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/BlockSafety.java @@ -106,7 +106,7 @@ public class BlockSafety { */ public Location getTopBlock(Location l) { Location check = l.clone(); - check.setY(127); + check.setY(127); // SUPPRESS CHECKSTYLE: MagicNumberCheck while (check.getY() > 0) { if (this.playerCanSpawnHereSafely(check)) { return check; @@ -124,7 +124,7 @@ public class BlockSafety { public Location getBottomBlock(Location l) { Location check = l.clone(); check.setY(0); - while (check.getY() < 127) { + while (check.getY() < 127) { // SUPPRESS CHECKSTYLE: MagicNumberCheck if (this.playerCanSpawnHereSafely(check)) { return check; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java index 5c8cdf70..132ff259 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java @@ -28,6 +28,7 @@ public class LocationManipulation { private static Map orientationInts = new HashMap(); static { + // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck orientationInts.put("n", 180); orientationInts.put("ne", 225); orientationInts.put("e", 270); @@ -39,6 +40,7 @@ public class LocationManipulation { // "freeze" the map: orientationInts = Collections.unmodifiableMap(orientationInts); + // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck } /** @@ -92,7 +94,7 @@ public class LocationManipulation { // Split the whole string, format is: // {'world', 'x,y,z'[, 'pitch', 'yaw']} String[] split = locationString.split(":"); - if (split.length < 2 || split.length > 4) { + if (split.length < 2 || split.length > 4) { // SUPPRESS CHECKSTYLE: MagicNumberCheck return null; } // Split the xyz string, format is: @@ -114,7 +116,7 @@ public class LocationManipulation { if (split.length >= 3) { yaw = (float) Double.parseDouble(split[2]); } - if (split.length == 4) { + if (split.length == 4) { // SUPPRESS CHECKSTYLE: MagicNumberCheck pitch = (float) Double.parseDouble(split[3]); } return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch); @@ -171,6 +173,7 @@ public class LocationManipulation { * @return The NESW Direction */ public static String getDirection(Location location) { + // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck double r = (location.getYaw() % 360) + 180; // Remember, these numbers are every 45 degrees with a 22.5 offset, to detect boundaries. String dir; @@ -192,6 +195,7 @@ public class LocationManipulation { dir = "nw"; else dir = "n"; + // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck return dir; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVMessaging.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVMessaging.java index 29f65587..89e6a009 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVMessaging.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVMessaging.java @@ -22,7 +22,7 @@ public class MVMessaging { public MVMessaging() { this.sentList = new HashMap(); - this.cooldown = 5000; + this.cooldown = 5000; // SUPPRESS CHECKSTYLE: MagicNumberCheck } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java index b1f59480..90e8796c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java @@ -42,6 +42,6 @@ public class MVPlayerSession { */ public boolean getTeleportable() { long time = (new Date()).getTime(); - return ((time - this.teleportLast) > this.config.getInt("portalcooldown", 5000)); + return ((time - this.teleportLast) > this.config.getInt("portalcooldown", 5000)); // SUPPRESS CHECKSTYLE: MagicNumberCheck } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/SafeTTeleporter.java b/src/main/java/com/onarandombox/MultiverseCore/utils/SafeTTeleporter.java index 66ff947b..e33bb0a9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/SafeTTeleporter.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/SafeTTeleporter.java @@ -61,8 +61,8 @@ public class SafeTTeleporter { // TODO: Make this configurable Location safe = checkAboveAndBelowLocation(l, tolerance, radius); if (safe != null) { - safe.setX(safe.getBlockX() + .5); - safe.setZ(safe.getBlockZ() + .5); + safe.setX(safe.getBlockX() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck + safe.setZ(safe.getBlockZ() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.plugin.log(Level.FINE, "Hey! I found one: " + LocationManipulation.strCoordsRaw(safe)); } else { this.plugin.log(Level.FINE, "Uh oh! No safe place found!"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java b/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java index 5b455427..683515b2 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/UpdateChecker.java @@ -18,6 +18,17 @@ import java.util.TimerTask; import java.util.logging.Logger; import java.util.regex.Pattern; +/* + * Apparently this isn't used and I don't know if we'll ever use this, + * so I'm just going to deprecate it for now and suppress the warnings. + * + * BEGIN CHECKSTYLE-SUPPRESSION: ALL + */ + +/** + * @deprecated Currently unused. + */ +@Deprecated public class UpdateChecker { public static final Logger log = Logger.getLogger("Minecraft"); @@ -104,3 +115,7 @@ public class UpdateChecker { } } + +/* + * END CHECKSTYLE-SUPPRESSION: ALL + */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteFailedException.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteFailedException.java index 996fd64f..85a803a4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteFailedException.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteFailedException.java @@ -1,5 +1,8 @@ package com.onarandombox.MultiverseCore.utils.webpaste; +/** + * Thrown when pasting failed. + */ public class PasteFailedException extends Exception { public PasteFailedException() { super(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteService.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteService.java index b3866d50..2bc9324e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteService.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteService.java @@ -37,6 +37,7 @@ public interface PasteService { * @param encodedData A URL-encoded String containing the full request to post to * the given URL. Can be the result of calling #encodeData(). * @param url The URL to which to paste. Can be the result of calling #getPostURL(). + * @throws PasteFailedException When pasting/posting the data failed. * @return The URL at which the new paste is visible. */ String postData(String encodedData, URL url) throws PasteFailedException; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteServiceFactory.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteServiceFactory.java index 5233cf48..e5a63f84 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteServiceFactory.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteServiceFactory.java @@ -1,13 +1,25 @@ package com.onarandombox.MultiverseCore.utils.webpaste; +/** + * Used to construct {@link PasteService}s. + */ public class PasteServiceFactory { private PasteServiceFactory() { } + /** + * Constructs a new {@link PasteService}. + * @param type The {@link PasteServiceType}. + * @param isPrivate Whether the new {@link PasteService} should create private pastes. + * @return The newly created {@link PasteService}. + */ public static PasteService getService(PasteServiceType type, boolean isPrivate) { switch(type) { - case PASTEBIN: return new PastebinPasteService(isPrivate); - case PASTIE: return new PastiePasteService(isPrivate); - default: return null; + case PASTEBIN: + return new PastebinPasteService(isPrivate); + case PASTIE: + return new PastiePasteService(isPrivate); + default: + return null; } } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteServiceType.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteServiceType.java index 1ac820ce..51d3089a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteServiceType.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PasteServiceType.java @@ -1,6 +1,18 @@ package com.onarandombox.MultiverseCore.utils.webpaste; +/** + * An enum containing all known {@link PasteService}s. + * + * @see PasteService + * @see PasteServiceFactory + */ public enum PasteServiceType { + /** + * @see PastebinPasteService + */ PASTEBIN, + /** + * @see PastiePasteService + */ PASTIE } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java index 1dae09c4..2eb5221c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java @@ -10,14 +10,21 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.util.regex.Pattern; +/** + * Pastes to {@code pastebin.com}. + */ public class PastebinPasteService implements PasteService { - protected boolean isPrivate; + private boolean isPrivate; public PastebinPasteService(boolean isPrivate) { this.isPrivate = isPrivate; } + /** + * {@inheritDoc} + */ + @Override public URL getPostURL() { try { return new URL("http://pastebin.com/api/api_post.php"); @@ -26,6 +33,10 @@ public class PastebinPasteService implements PasteService { } } + /** + * {@inheritDoc} + */ + @Override public String encodeData(String data) { try { String encData = URLEncoder.encode("api_dev_key", "UTF-8") + "=" + URLEncoder.encode("d61d68d31e8e0392b59b50b277411c71", "UTF-8"); @@ -39,6 +50,10 @@ public class PastebinPasteService implements PasteService { } } + /** + * {@inheritDoc} + */ + @Override public String postData(String encodedData, URL url) throws PasteFailedException { try { URLConnection conn = url.openConnection(); @@ -60,15 +75,17 @@ public class PastebinPasteService implements PasteService { throw new PasteFailedException(e); } } - + + // TODO maybe remove this? private Pattern getURLMatchingPattern() { - if(this.isPrivate) { + if (this.isPrivate) { return Pattern.compile(".*http://pastie.org/.*key=([0-9a-z]+).*"); } else { return Pattern.compile(".*http://pastie.org/([0-9]+).*"); } } + // TODO maybe remove this? private String formatURL(String pastieID) { return "http://pastie.org/" + (this.isPrivate ? "private/" : "") + pastieID; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastiePasteService.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastiePasteService.java index 19bd8994..d912edc6 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastiePasteService.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastiePasteService.java @@ -11,14 +11,21 @@ import java.net.URLEncoder; import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Pastes to {@code pastie.org}. + */ public class PastiePasteService implements PasteService { - protected boolean isPrivate; + private boolean isPrivate; public PastiePasteService(boolean isPrivate) { this.isPrivate = isPrivate; } + /** + * {@inheritDoc} + */ + @Override public URL getPostURL() { try { return new URL("http://pastie.org/pastes"); @@ -27,6 +34,10 @@ public class PastiePasteService implements PasteService { } } + /** + * {@inheritDoc} + */ + @Override public String encodeData(String data) { try { String encData = URLEncoder.encode("paste[authorization]", "UTF-8") + "=" + URLEncoder.encode("burger", "UTF-8"); // burger is magic @@ -39,6 +50,10 @@ public class PastiePasteService implements PasteService { } } + /** + * {@inheritDoc} + */ + @Override public String postData(String encodedData, URL url) throws PasteFailedException { try { URLConnection conn = url.openConnection(); @@ -53,7 +68,7 @@ public class PastiePasteService implements PasteService { Pattern pastiePattern = this.getURLMatchingPattern(); while ((line = rd.readLine()) != null) { Matcher m = pastiePattern.matcher(line); - if(m.matches()) { + if (m.matches()) { String pastieID = m.group(1); pastieUrl = this.formatURL(pastieID); } @@ -65,9 +80,9 @@ public class PastiePasteService implements PasteService { throw new PasteFailedException(e); } } - + private Pattern getURLMatchingPattern() { - if(this.isPrivate) { + if (this.isPrivate) { return Pattern.compile(".*http://pastie.org/.*key=([0-9a-z]+).*"); } else { return Pattern.compile(".*http://pastie.org/([0-9]+).*");