entry : map.entrySet()) {
valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()});
}
+
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
}
}
@@ -735,6 +759,7 @@ public JsonObjectBuilder appendField(String key, String value) {
if (value == null) {
throw new IllegalArgumentException("JSON value must not be null");
}
+
appendFieldUnescaped(key, "\"" + escape(value) + "\"");
return this;
}
@@ -762,6 +787,7 @@ public JsonObjectBuilder appendField(String key, JsonObject object) {
if (object == null) {
throw new IllegalArgumentException("JSON object must not be null");
}
+
appendFieldUnescaped(key, object.toString());
return this;
}
@@ -777,10 +803,10 @@ public JsonObjectBuilder appendField(String key, String[] values) {
if (values == null) {
throw new IllegalArgumentException("JSON values must not be null");
}
- String escapedValues =
- Arrays.stream(values)
- .map(value -> "\"" + escape(value) + "\"")
- .collect(Collectors.joining(","));
+
+ String escapedValues = Arrays.stream(values)
+ .map(value -> "\"" + escape(value) + "\"")
+ .collect(Collectors.joining(","));
appendFieldUnescaped(key, "[" + escapedValues + "]");
return this;
}
@@ -796,6 +822,7 @@ public JsonObjectBuilder appendField(String key, int[] values) {
if (values == null) {
throw new IllegalArgumentException("JSON values must not be null");
}
+
String escapedValues =
Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
appendFieldUnescaped(key, "[" + escapedValues + "]");
@@ -813,6 +840,7 @@ public JsonObjectBuilder appendField(String key, JsonObject[] values) {
if (values == null) {
throw new IllegalArgumentException("JSON values must not be null");
}
+
String escapedValues =
Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
appendFieldUnescaped(key, "[" + escapedValues + "]");
@@ -829,12 +857,15 @@ private void appendFieldUnescaped(String key, String escapedValue) {
if (builder == null) {
throw new IllegalStateException("JSON has already been built");
}
+
if (key == null) {
throw new IllegalArgumentException("JSON key must not be null");
}
+
if (hasAtLeastOneField) {
builder.append(",");
}
+
builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
hasAtLeastOneField = true;
}
@@ -848,13 +879,14 @@ public JsonObject build() {
if (builder == null) {
throw new IllegalStateException("JSON has already been built");
}
+
JsonObject object = new JsonObject(builder.append("}").toString());
builder = null;
return object;
}
/**
- * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
+ * Escapes the given string like stated in ....
*
* This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
* Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
@@ -878,6 +910,7 @@ private static String escape(String value) {
builder.append(c);
}
}
+
return builder.toString();
}
@@ -902,4 +935,4 @@ public String toString() {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/com/gmail/justbru00/epic/rename/multiversion/ServerVersion.java b/src/com/gmail/justbru00/epic/rename/multiversion/ServerVersion.java
index 3aeb104..290107f 100644
--- a/src/com/gmail/justbru00/epic/rename/multiversion/ServerVersion.java
+++ b/src/com/gmail/justbru00/epic/rename/multiversion/ServerVersion.java
@@ -3,6 +3,7 @@
*
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.multiversion;
import com.gmail.justbru00.epic.rename.utils.v3.Messager;
@@ -20,26 +21,62 @@ public ServerVersion(int major, int minor, int patch) {
}
public boolean isAtLeast(int major, int minor, int patch) {
- if (this.major > major) return true;
- if (this.major < major) return false;
- if (this.minor > minor) return true;
- if (this.minor < minor) return false;
+ if (this.major > major) {
+ return true;
+ }
+
+ if (this.major < major) {
+ return false;
+ }
+
+ if (this.minor > minor) {
+ return true;
+ }
+
+ if (this.minor < minor) {
+ return false;
+ }
+
return this.patch >= patch;
}
public boolean isLessThan(int major, int minor, int patch) {
- if (this.major < major) return true;
- if (this.major > major) return false;
- if (this.minor < minor) return true;
- if (this.minor > minor) return false;
+ if (this.major < major) {
+ return true;
+ }
+
+ if (this.major > major) {
+ return false;
+ }
+
+ if (this.minor < minor) {
+ return true;
+ }
+
+ if (this.minor > minor) {
+ return false;
+ }
+
return this.patch < patch;
}
public boolean isLessThanOrEqualTo(int major, int minor, int patch) {
- if (this.major < major) return true;
- if (this.major > major) return false;
- if (this.minor < minor) return true;
- if (this.minor > minor) return false;
+ if (this.major < major) {
+ return true;
+ }
+
+ if (this.major > major) {
+ return false;
+ }
+
+ if (this.minor < minor) {
+ return true;
+ }
+
+ if (this.minor > minor) {
+ return false;
+ }
+
return this.patch <= patch;
}
diff --git a/src/com/gmail/justbru00/epic/rename/tabcompleters/EpicRenameTabCompleter.java b/src/com/gmail/justbru00/epic/rename/tabcompleters/EpicRenameTabCompleter.java
index 6a11b3b..e40b42a 100644
--- a/src/com/gmail/justbru00/epic/rename/tabcompleters/EpicRenameTabCompleter.java
+++ b/src/com/gmail/justbru00/epic/rename/tabcompleters/EpicRenameTabCompleter.java
@@ -8,9 +8,9 @@
import org.bukkit.command.TabCompleter;
public class EpicRenameTabCompleter implements TabCompleter {
-
- private ArrayList epicrenameFirstArgumentList = new ArrayList();
- private ArrayList empty = new ArrayList();
+
+ private final ArrayList epicrenameFirstArgumentList = new ArrayList<>();
+ private final ArrayList empty = new ArrayList<>();
public EpicRenameTabCompleter() {
epicrenameFirstArgumentList.add("help");
@@ -19,31 +19,30 @@ public EpicRenameTabCompleter() {
epicrenameFirstArgumentList.add("debug");
epicrenameFirstArgumentList.add("version");
}
-
+
@Override
public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
-
+
if (!command.getName().equalsIgnoreCase("epicrename")) {
return null;
}
-
+
if (args.length == 1) {
if (!args[0].equals("")) {
- ArrayList completion = new ArrayList();
-
+ ArrayList completion = new ArrayList<>();
+
for (String first : epicrenameFirstArgumentList) {
if (first.toLowerCase().startsWith(args[0].toLowerCase())) {
completion.add(first);
}
}
-
+
return completion;
} else {
return epicrenameFirstArgumentList;
}
}
-
+
return empty;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/tabcompleters/ExportTabCompleter.java b/src/com/gmail/justbru00/epic/rename/tabcompleters/ExportTabCompleter.java
index d18af74..3c6103d 100644
--- a/src/com/gmail/justbru00/epic/rename/tabcompleters/ExportTabCompleter.java
+++ b/src/com/gmail/justbru00/epic/rename/tabcompleters/ExportTabCompleter.java
@@ -8,10 +8,10 @@
import org.bukkit.command.TabCompleter;
public class ExportTabCompleter implements TabCompleter {
-
- private ArrayList exportFirstArgumentList = new ArrayList();
- private ArrayList empty = new ArrayList();
-
+
+ private final ArrayList exportFirstArgumentList = new ArrayList<>();
+ private final ArrayList empty = new ArrayList<>();
+
public ExportTabCompleter() {
exportFirstArgumentList.add("hand");
exportFirstArgumentList.add("inventory");
@@ -22,24 +22,23 @@ public List onTabComplete(CommandSender sender, Command command, String
if (!command.getName().equalsIgnoreCase("export")) {
return null;
}
-
+
if (args.length == 1) {
if (!args[0].equals("")) {
ArrayList completion = new ArrayList();
-
+
for (String first : exportFirstArgumentList) {
if (first.toLowerCase().startsWith(args[0].toLowerCase())) {
completion.add(first);
}
}
-
+
return completion;
} else {
return exportFirstArgumentList;
}
}
-
+
return empty;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericNoArgsTabCompleter.java b/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericNoArgsTabCompleter.java
index 4d86419..08eff76 100644
--- a/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericNoArgsTabCompleter.java
+++ b/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericNoArgsTabCompleter.java
@@ -8,21 +8,20 @@
import org.bukkit.command.TabCompleter;
public class GenericNoArgsTabCompleter implements TabCompleter {
-
- private ArrayList empty = new ArrayList();
- private String commandName;
-
+
+ private final ArrayList empty = new ArrayList<>();
+ private final String commandName;
+
public GenericNoArgsTabCompleter(String _commandName) {
commandName = _commandName;
}
-
+
@Override
public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (!command.getName().equalsIgnoreCase(commandName)) {
return null;
}
-
+
return empty;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericOneArgTabCompleter.java b/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericOneArgTabCompleter.java
index a2070ad..8e05e7c 100644
--- a/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericOneArgTabCompleter.java
+++ b/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericOneArgTabCompleter.java
@@ -9,28 +9,27 @@
public class GenericOneArgTabCompleter implements TabCompleter {
- private ArrayList empty = new ArrayList();
- private ArrayList firstArgument = new ArrayList();
- private String commandName;
-
+ private final ArrayList empty = new ArrayList<>();
+ private final ArrayList firstArgument = new ArrayList<>();
+ private final String commandName;
+
public GenericOneArgTabCompleter(String _commandName, String _firstArgument) {
firstArgument.add(_firstArgument);
commandName = _commandName;
}
-
+
@Override
public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (!command.getName().equalsIgnoreCase(commandName)) {
return null;
}
-
+
if (args.length == 1) {
if (args[0].equals("")) {
return firstArgument;
}
}
-
+
return empty;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericTwoArgTabCompleter.java b/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericTwoArgTabCompleter.java
index c1defe3..1764aa8 100644
--- a/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericTwoArgTabCompleter.java
+++ b/src/com/gmail/justbru00/epic/rename/tabcompleters/GenericTwoArgTabCompleter.java
@@ -9,36 +9,35 @@
public class GenericTwoArgTabCompleter implements TabCompleter {
- private ArrayList empty = new ArrayList();
- private ArrayList firstArgument = new ArrayList();
- private ArrayList secondArgument = new ArrayList();
- private String commandName;
-
+ private final ArrayList empty = new ArrayList<>();
+ private final ArrayList firstArgument = new ArrayList<>();
+ private final ArrayList secondArgument = new ArrayList<>();
+ private final String commandName;
+
public GenericTwoArgTabCompleter(String _commandName, String _firstArgument, String _secondArgument) {
firstArgument.add(_firstArgument);
secondArgument.add(_secondArgument);
commandName = _commandName;
}
-
+
@Override
public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (!command.getName().equalsIgnoreCase(commandName)) {
return null;
}
-
+
if (args.length == 1) {
if (args[0].equals("")) {
return firstArgument;
}
}
-
+
if (args.length == 2) {
if (args[1].equals("")) {
return secondArgument;
}
}
-
+
return empty;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/tabcompleters/ImportTabCompleter.java b/src/com/gmail/justbru00/epic/rename/tabcompleters/ImportTabCompleter.java
index 3b92d8f..4735229 100644
--- a/src/com/gmail/justbru00/epic/rename/tabcompleters/ImportTabCompleter.java
+++ b/src/com/gmail/justbru00/epic/rename/tabcompleters/ImportTabCompleter.java
@@ -8,19 +8,19 @@
import org.bukkit.command.TabCompleter;
public class ImportTabCompleter implements TabCompleter {
-
- private ArrayList importFirstArgumentList = new ArrayList();
- private ArrayList importHandInventorySecondArgumentList = new ArrayList();
- private ArrayList importRawSecondArgumentList = new ArrayList();
- private ArrayList empty = new ArrayList();
-
+
+ private final ArrayList importFirstArgumentList = new ArrayList<>();
+ private final ArrayList importHandInventorySecondArgumentList = new ArrayList<>();
+ private final ArrayList importRawSecondArgumentList = new ArrayList<>();
+ private final ArrayList empty = new ArrayList<>();
+
public ImportTabCompleter() {
importFirstArgumentList.add("hand");
importFirstArgumentList.add("inventory");
importFirstArgumentList.add("raw");
-
+
importHandInventorySecondArgumentList.add("");
-
+
importRawSecondArgumentList.add("");
}
@@ -28,60 +28,59 @@ public ImportTabCompleter() {
public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (!command.getName().equalsIgnoreCase("import")) {
return null;
- }
-
- if (args.length == 1) {
+ }
+
+ if (args.length == 1) {
if (!args[0].equals("")) {
- ArrayList completion = new ArrayList();
-
+ ArrayList completion = new ArrayList<>();
+
for (String first : importFirstArgumentList) {
if (first.toLowerCase().startsWith(args[0].toLowerCase())) {
completion.add(first);
}
}
-
- return completion;
+
+ return completion;
} else {
return importFirstArgumentList;
}
} else if (args.length == 2) {
if (!args[1].equals("")) {
- if (args[0].toLowerCase().equals("hand") || args[0].toLowerCase().equals("inventory")) {
- ArrayList completion = new ArrayList();
-
+ if (args[0].equalsIgnoreCase("hand") || args[0].equalsIgnoreCase("inventory")) {
+ ArrayList completion = new ArrayList<>();
+
for (String second : importHandInventorySecondArgumentList) {
if (second.toLowerCase().startsWith(args[1].toLowerCase())) {
completion.add(second);
}
}
-
- return completion;
- } else if (args[0].toLowerCase().equals("raw")) {
- ArrayList completion = new ArrayList();
-
+
+ return completion;
+ } else if (args[0].equalsIgnoreCase("raw")) {
+ ArrayList completion = new ArrayList<>();
+
for (String second : importRawSecondArgumentList) {
if (second.toLowerCase().startsWith(args[1].toLowerCase())) {
completion.add(second);
}
}
-
+
return completion;
} else {
return empty;
}
} else {
// No text in second argument yet
- if (args[0].toLowerCase().equals("hand") || args[0].toLowerCase().equals("inventory")) {
+ if (args[0].equalsIgnoreCase("hand") || args[0].equalsIgnoreCase("inventory")) {
return importHandInventorySecondArgumentList;
- } else if (args[0].toLowerCase().equals("raw")) {
+ } else if (args[0].equalsIgnoreCase("raw")) {
return importRawSecondArgumentList;
} else {
return empty;
}
}
}
-
+
return empty;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/test/ConfigUpdaterConverter.java b/src/com/gmail/justbru00/epic/rename/test/ConfigUpdaterConverter.java
index 9628e8d..5f11a46 100644
--- a/src/com/gmail/justbru00/epic/rename/test/ConfigUpdaterConverter.java
+++ b/src/com/gmail/justbru00/epic/rename/test/ConfigUpdaterConverter.java
@@ -4,6 +4,7 @@
import org.bukkit.configuration.file.YamlConfiguration;
public class ConfigUpdaterConverter {
+
public static void main(String[] args) throws InvalidConfigurationException {
YamlConfiguration config = new YamlConfiguration();
config.loadFromString("rename:\r\n" +
@@ -144,10 +145,9 @@ public static void main(String[] args) throws InvalidConfigurationException {
" \r\n" +
"exploit_prevention:\r\n" +
" no_grindstone_with_glowing_items: '&cYou cannot use a grindstone on a glowing item. Please remove glow from the item first with /removeglow.' ");
-
+
for (String key : config.getRoot().getKeys(true)) {
System.out.println("updateMessagesYmlString(\"" + key + "\", \"" + config.getString(key) + "\");");
- //updateMessagesYmlString("rename.blacklisted_material_found", "&cSorry that material is blacklisted.");
}
}
}
diff --git a/src/com/gmail/justbru00/epic/rename/test/FormattingCodeCounterTest.java b/src/com/gmail/justbru00/epic/rename/test/FormattingCodeCounterTest.java
index 5a3d9f6..98216a1 100644
--- a/src/com/gmail/justbru00/epic/rename/test/FormattingCodeCounterTest.java
+++ b/src/com/gmail/justbru00/epic/rename/test/FormattingCodeCounterTest.java
@@ -5,24 +5,21 @@
public class FormattingCodeCounterTest {
public static void main(String[] args) {
- if (test()) {
- System.out.println("TEST PASSED");
- } else {
- System.out.println("TEST FAILED");
- }
+ if (test()) {
+ System.out.println("TEST PASSED");
+ } else {
+ System.out.println("TEST FAILED");
+ }
}
+
/**
- *
+ *
* @return True if test is successful
*/
public static boolean test() {
String test = "&b&lTesting the counter&. &k";
int codes = 3;
-
- if (codes == FormattingCodeCounter.getAmountOfColorCodes(test, '&')) {
- return true;
- }
-
- return false;
+
+ return codes == FormattingCodeCounter.getAmountOfColorCodes(test, '&');
}
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/Blacklists.java b/src/com/gmail/justbru00/epic/rename/utils/v3/Blacklists.java
index edb3ffe..6ec5c92 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/Blacklists.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/Blacklists.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import java.util.List;
@@ -17,7 +18,7 @@
public class Blacklists {
// VERSION 3
-
+
/**
* Issue #81
* Checks if the name of the item is one of the ones from the config.
@@ -27,28 +28,23 @@ public class Blacklists {
*/
public static boolean checkExistingName(Player p) {
Debug.send("[Blacklists#checkExistingName(Player)] Method called");
-
+
if (RenameUtil.getInHand(p).getType() == Material.AIR || RenameUtil.getInHand(p) == null) {
Debug.send("[Blacklists#checkExistingName(Player)] Item was AIR or NULL");
return true;
}
-
+
String itemName = RenameUtil.getInHand(p).getItemMeta().getDisplayName();
itemName = ChatColor.stripColor(itemName);
-
- if (itemName == null) {
- Debug.send("[Blacklists#checkExistingName(Player)] Item existing name was NULL");
- return true;
- }
-
+
for (String blacklistedString : Main.getInstance().getConfig().getStringList("blacklists.existingname")) {
if (blacklistedString != null) {
-
+
blacklistedString = ChatColor.stripColor(Messager.color(blacklistedString));
-
- if (itemName.toLowerCase().contains(blacklistedString.toLowerCase())) {
+
+ if (itemName.toLowerCase().contains(blacklistedString.toLowerCase())) {
Debug.send("[Blacklists#checkExistingName(Player)] Name contained '" + blacklistedString + "'");
-
+
if (p.hasPermission("epicrename.bypass.existingname")) {
// Player has bypass permission
Debug.send("[Blacklists#checkExistingName(Player)] Player had the epicrename.bypass.existingname permission.");
@@ -57,17 +53,17 @@ public static boolean checkExistingName(Player p) {
} else {
Debug.send("Bypass messages are disabled.");
}
- return true;
- }
-
- return false;
- }
- }
+ return true;
+ }
+
+ return false;
+ }
+ }
}
-
+
return true;
}
-
+
/**
* Issue #81
* Checks if the lore of the item is one of the ones from the config file.
@@ -77,27 +73,27 @@ public static boolean checkExistingName(Player p) {
*/
public static boolean checkExistingLore(Player p) {
Debug.send("[Blacklists#checkExistingLore(Player)] Method called");
-
+
if (RenameUtil.getInHand(p).getType() == Material.AIR || RenameUtil.getInHand(p) == null) {
Debug.send("[Blacklists#checkExistingLore(Player)] Item was AIR or NULL");
return true;
}
-
+
List loreLines = RenameUtil.getInHand(p).getItemMeta().getLore();
-
+
if (loreLines == null) {
Debug.send("[Blacklists#checkExistingLore(Player)] Lore from existing item was NULL");
return true;
}
-
+
for (String loreLine : loreLines) {
loreLine = ChatColor.stripColor(loreLine);
-
+
for (String blacklistedString : Main.getInstance().getConfig().getStringList("blacklists.existingloreline")) {
if (blacklistedString != null) {
-
+
blacklistedString = ChatColor.stripColor(Messager.color(blacklistedString));
-
+
if (loreLine.toLowerCase().contains(blacklistedString.toLowerCase())) {
Debug.send("[Blacklists#checkExistingLore(Player)] Lore Line: '"+ loreLine + "' contained '" + blacklistedString + "'");
if (p.hasPermission("epicrename.bypass.existinglore")) {
@@ -110,23 +106,23 @@ public static boolean checkExistingLore(Player p) {
}
return true;
}
-
+
return false;
}
}
}
}
-
+
return true;
}
-
+
/**
- *
+ *
* @param m The Material from the {@link CommandExecutor}. This will also check is the player has the bypass permission. It will message the player.
* @return True if NO blacklisted material found. False if a blacklisted material is FOUND.
*/
public static boolean checkMaterialBlacklist(Material m, Player p) {
-
+
// Issue #74
if (p.hasPermission("epicrename.bypass.materialblacklist")) {
Debug.send("Player just bypassed the material blacklist.");
@@ -135,10 +131,11 @@ public static boolean checkMaterialBlacklist(Material m, Player p) {
} else {
Debug.send("Bypass messages are disabled.");
}
+
return true;
}
// End issue #74
-
+
for (String s : Main.getInstance().getConfig().getStringList("blacklists.material")) {
if (s != null) {
if (m == Material.getMaterial(s)) {
@@ -147,16 +144,17 @@ public static boolean checkMaterialBlacklist(Material m, Player p) {
}
}
}
+
return true;
}
/**
- *
+ *
* @param args The arguments from the {@link CommandExecutor}. This will also check is the player has the bypass permission. It will message the player.
* @return True if NO blacklisted word found. False if a blacklisted word is FOUND.
*/
public static boolean checkTextBlacklist(String[] args, Player p) {
-
+
// Issue #74
if (p.hasPermission("epicrename.bypass.textblacklist")) {
Debug.send("Player just bypassed the text blacklist.");
@@ -170,21 +168,21 @@ public static boolean checkTextBlacklist(String[] args, Player p) {
}
// End issue #74
- StringBuilder builder = new StringBuilder("");
- String completeArgs = "";
-
+ StringBuilder builder = new StringBuilder();
+ String completeArgs;
+
for (String item : args) {
- builder.append(item + " ");
+ builder.append(item).append(" ");
}
-
+
completeArgs = builder.toString().trim();
if (Main.getInstance().getConfig().getBoolean("replace_underscores")) {
completeArgs = completeArgs.replace("_", " ");
Debug.send("Replaced the underscores.");
}
-
+
completeArgs = ChatColor.stripColor(Messager.color(completeArgs));
-
+
for (String s : Main.getInstance().getConfig().getStringList("blacklists.text")) {
if (s != null) {
if (completeArgs.toLowerCase().contains(s.toLowerCase())) {
@@ -196,5 +194,4 @@ public static boolean checkTextBlacklist(String[] args, Player p) {
return true;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/CharLimit.java b/src/com/gmail/justbru00/epic/rename/utils/v3/CharLimit.java
index d2879e9..1114848 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/CharLimit.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/CharLimit.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import org.bukkit.ChatColor;
@@ -15,28 +16,27 @@
*/
public class CharLimit {
-
/**
* @param checking The {@link String[]} that we are checking.
* @param player The {@link Player} who sent the command.
* @return TRUE if ok. FALSE if too many chars.
*/
public static boolean checkCharLimit(String[] checking, Player player) { // VERISON 3.0
- StringBuilder builder = new StringBuilder("");
- String completeArgs = "";
-
+ StringBuilder builder = new StringBuilder();
+ String completeArgs;
+
for (String item : checking) {
- builder.append(item + " ");
+ builder.append(item).append(" ");
}
-
+
completeArgs = builder.toString();
completeArgs = ChatColor.stripColor(Messager.color(completeArgs));
-
+
if (!Main.getInstance().getConfig().getBoolean("rename_character_limit.enabled")) {
Debug.send("Character Limit is disabled.");
return true;
}
-
+
if (player.hasPermission("epicrename.bypass.charlimit")) {
Debug.send("Player bypassed char limit");
if (!Main.getBooleanFromConfig("disable_bypass_messages")) { // Issue #107
@@ -44,17 +44,18 @@ public static boolean checkCharLimit(String[] checking, Player player) { // VERI
} else {
Debug.send("Bypass messages are disabled.");
} // End Issue #107
+
return true;
}
-
+
if (completeArgs.length() > getCharLimit()) {
Debug.send("Player failed char limit.");
return false;
}
-
+
return true;
}
-
+
public static int getCharLimit() {
return Main.getInstance().getConfig().getInt("rename_character_limit.limit");
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/Debug.java b/src/com/gmail/justbru00/epic/rename/utils/v3/Debug.java
index 41e91cb..e97b9d3 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/Debug.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/Debug.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import org.bukkit.Bukkit;
@@ -19,7 +20,7 @@ public static void send(String msg) {
}
}
}
-
+
public static void sendPlain(String msg) {
if (Main.debug) {
Bukkit.broadcastMessage(Messager.color(Main.prefix + "&8[&cDebug&8] &f") + msg);
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/EconomyManager.java b/src/com/gmail/justbru00/epic/rename/utils/v3/EconomyManager.java
index de9cd9d..5d064b0 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/EconomyManager.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/EconomyManager.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import org.bukkit.entity.Player;
@@ -22,31 +23,33 @@ public class EconomyManager {
* @return The {@link EcoMessage}
*/
public static EcoMessage takeMoney(Player player, EpicRenameCommands erc){
-
- if (Main.USE_ECO == false) {
+
+ if (!Main.USE_ECO) {
return EcoMessage.ECO_DISABLED;
}
-
+
if (player.hasPermission("epicrename.bypass.costs.*")) {
if (!Main.getBooleanFromConfig("disable_bypass_messages")) { // Issue #195
Messager.msgPlayer(Main.getMsgFromConfig("economy.bypass"), player);
}
+
return EcoMessage.ECO_BYPASS;
}
-
+
if (erc == EpicRenameCommands.RENAME) {
-
+
if (player.hasPermission("epicrename.bypass.costs.rename")) {
if (!Main.getBooleanFromConfig("disable_bypass_messages")) { // Issue #195
Messager.msgPlayer(Main.getMsgFromConfig("economy.bypass"), player);
}
+
return EcoMessage.ECO_BYPASS;
}
-
+
EconomyResponse r = Main.econ.withdrawPlayer(player, Main.getInstance().getConfig().getInt("economy.costs.rename"));
-
+
Debug.send("Value from config was: " + Main.getInstance().getConfig().getInt("economy.costs.rename"));
-
+
if (r.transactionSuccess()) {
Messager.msgPlayer(formatMsg(Main.getMsgFromConfig("economy.transaction_success"), r), player);
return EcoMessage.SUCCESS;
@@ -54,18 +57,18 @@ public static EcoMessage takeMoney(Player player, EpicRenameCommands erc){
Messager.msgPlayer(formatMsg(Main.getMsgFromConfig("economy.transaction_error"), r), player);
return EcoMessage.TRANSACTION_ERROR;
}
-
+
} else if (erc == EpicRenameCommands.LORE) {
-
+
if (player.hasPermission("epicrename.bypass.costs.lore")) {
if (!Main.getBooleanFromConfig("disable_bypass_messages")) { // Issue #195
Messager.msgPlayer(Main.getMsgFromConfig("economy.bypass"), player);
}
return EcoMessage.ECO_BYPASS;
}
-
+
EconomyResponse r = Main.econ.withdrawPlayer(player, Main.getInstance().getConfig().getInt("economy.costs.lore"));
-
+
if (r.transactionSuccess()) {
Messager.msgPlayer(formatMsg(Main.getMsgFromConfig("economy.transaction_success"), r), player);
return EcoMessage.SUCCESS;
@@ -74,16 +77,16 @@ public static EcoMessage takeMoney(Player player, EpicRenameCommands erc){
return EcoMessage.TRANSACTION_ERROR;
}
} else if (erc == EpicRenameCommands.GLOW) { // ISSUE #101
-
+
if (player.hasPermission("epicrename.bypass.costs.glow")) {
if (!Main.getBooleanFromConfig("disable_bypass_messages")) { // Issue #195
Messager.msgPlayer(Main.getMsgFromConfig("economy.bypass"), player);
}
return EcoMessage.ECO_BYPASS;
}
-
+
EconomyResponse r = Main.econ.withdrawPlayer(player, Main.getInstance().getConfig().getInt("economy.costs.glow"));
-
+
if (r.transactionSuccess()) {
Messager.msgPlayer(formatMsg(Main.getMsgFromConfig("economy.transaction_success"), r), player);
return EcoMessage.SUCCESS;
@@ -92,10 +95,10 @@ public static EcoMessage takeMoney(Player player, EpicRenameCommands erc){
return EcoMessage.TRANSACTION_ERROR;
}
} // END ISSUE #101
-
+
return EcoMessage.UNHANDLED;
}
-
+
/**
* Formats the message with the {cost} and {error} variables.
* @param msg The message you want to replace the variables in.
@@ -103,9 +106,9 @@ public static EcoMessage takeMoney(Player player, EpicRenameCommands erc){
* @return The formated string with the variables replaced.
*/
public static String formatMsg(String msg, EconomyResponse r) {
-
+
msg = msg.replace("{cost}", String.valueOf(r.amount));
-
+
if (!r.transactionSuccess()) {
if (r.errorMessage != null) {
msg = msg.replace("{error}", r.errorMessage);
@@ -113,8 +116,7 @@ public static String formatMsg(String msg, EconomyResponse r) {
msg = msg.replace("{error}", "Economy error message was null. Maybe try checking your balance?");
}
}
-
+
return msg;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/EpicRenameOnlineAPI.java b/src/com/gmail/justbru00/epic/rename/utils/v3/EpicRenameOnlineAPI.java
index c5d7369..c7b2342 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/EpicRenameOnlineAPI.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/EpicRenameOnlineAPI.java
@@ -1,16 +1,17 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Optional;
import javax.net.ssl.HttpsURLConnection;
@@ -21,40 +22,37 @@
/**
* Created for issue #105, #106
- *
+ *
* @author Justin Brubaker
*
*/
public class EpicRenameOnlineAPI {
-
+
private static final String POST_URL = "https://epicrename.com/api/v1/export";
/**
- * Attempts to GET raw text from a URL. If the URL is a pastebin link such as
- * https://pastebin.com/e5mwvrJ8 then the method will convert that link to
- * https://pastebin.com/raw/e5mwvrJ8 If the URL is not a pastebin link then it
- * will just attempt to get raw text.
- *
- * This method attempts to connect with HTTPS if possible.
- *
- * @param url
- * @return The text retrieved from the server
- * @throws IOException
- */
+ * Attempts to GET raw text from a URL. If the URL is a pastebin link such as
+ * ... then the method will cthat link to
+ * https://pastebin.com/raw/e5mwvrJ8 If the URL is not a pastebin link then it
+ * will just attempt to get raw text.
+ * This method attempts to connect with HTTPS if possible.
+ *
+ * @return The text retrieved from the server
+ */
public static Optional getTextFromURL(String url) throws IOException, EpicRenameOnlineExpiredException, EpicRenameOnlineNotFoundException {
Main.setEpicRenameOnlineFeaturesUsedBefore(true);
if (url.contains("https://pastebin.com/") && !url.contains("raw/")) {
- String newUrl = "";
+ String newUrl;
- newUrl = url.substring(21, url.length());
+ newUrl = url.substring(21);
newUrl = "https://pastebin.com/raw/VALUE".replace("VALUE", newUrl);
url = newUrl;
Debug.send("[EpicRenameOnlineAPI] New URL is: " + url);
}
- URL urlObj = null;
- String textData = null;
+ URL urlObj;
+ String textData;
urlObj = new URL(url);
@@ -68,25 +66,26 @@ public static Optional getTextFromURL(String url) throws IOException, Ep
httpsConn.setInstanceFollowRedirects(false);
httpsConn.setRequestProperty("Connection", "close");
httpsConn.connect();
-
- BufferedReader in = null;
+
+ BufferedReader in;
String inputLine;
- StringBuffer response = new StringBuffer();
+ StringBuilder response = new StringBuilder();
if (httpsConn.getResponseCode() >= 200 && httpsConn.getResponseCode() < 300) {
// Attempt to get raw text data
- in = new BufferedReader(new InputStreamReader(httpsConn.getInputStream(), "UTF-8"));
+ in = new BufferedReader(new InputStreamReader(httpsConn.getInputStream(), StandardCharsets.UTF_8));
} else {
- in = new BufferedReader(new InputStreamReader(httpsConn.getErrorStream(), "UTF-8"));
+ in = new BufferedReader(new InputStreamReader(httpsConn.getErrorStream(), StandardCharsets.UTF_8));
}
while ((inputLine = in.readLine()) != null) {
- response.append(inputLine + "\n");
+ response.append(inputLine).append("\n");
}
+
in.close();
textData = response.toString();
-
+
if (textData.startsWith("ERROR:")) {
if (textData.startsWith("ERROR: 404 - Not Found." ) && textData.contains("Link has expired")) {
// Link expired on EpicRenameOnline server
@@ -96,24 +95,22 @@ public static Optional getTextFromURL(String url) throws IOException, Ep
throw new EpicRenameOnlineNotFoundException();
}
}
-
- if(textData.trim().equalsIgnoreCase("") || textData == null) {
- return Optional.ofNullable(null);
+
+ if (textData.trim().equalsIgnoreCase("")) {
+ return Optional.empty();
}
- return Optional.ofNullable(textData);
+ return Optional.of(textData);
}
/**
- * Pastes the data provided directly to https://epicrename.com/
- *
- * @param data The text to paste.
- * @return The response from EpicRenameOnline. This can be a link to the paste or an
- * error message beginning with "ERROR:"
- * @throws IOException
- * @throws MalformedURLException
- */
- public static String paste(String data) throws MalformedURLException, IOException {
+ * Pastes the data provided directly to ...
+ *
+ * @param data The text to paste.
+ * @return The response from EpicRenameOnline. This can be a link to the paste or an
+ * error message beginning with "ERROR:"
+ */
+ public static String paste(String data) throws IOException {
String response = post(data);
Main.setEpicRenameOnlineFeaturesUsedBefore(true);
@@ -122,14 +119,11 @@ public static String paste(String data) throws MalformedURLException, IOExceptio
/**
* Posts text data to EpicRenameOnline.
- *
- * @param data
+ *
* @return If this contains "ERROR: " then the post failed.
- * @throws IOException
- * @throws MalformedURLException
*/
- private static String post(String data) throws IOException, MalformedURLException {
- URL formattedUrl = null;
+ private static String post(String data) throws IOException {
+ URL formattedUrl;
formattedUrl = new URL(POST_URL);
Debug.send("[EpicRenameOnlineAPI] Attempting to POST.");
@@ -141,12 +135,12 @@ private static String post(String data) throws IOException, MalformedURLExceptio
httpsCon.setReadTimeout(1000);
httpsCon.setRequestMethod("POST");
- OutputStreamWriter out = new OutputStreamWriter(httpsCon.getOutputStream(), "UTF-8");
+ OutputStreamWriter out = new OutputStreamWriter(httpsCon.getOutputStream(), StandardCharsets.UTF_8);
out.write(data);
out.flush();
out.close();
- BufferedReader reader = new BufferedReader(new InputStreamReader(httpsCon.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(httpsCon.getInputStream(), StandardCharsets.UTF_8));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
@@ -155,6 +149,7 @@ private static String post(String data) throws IOException, MalformedURLExceptio
}
builder.append(line);
}
+
reader.close();
String response = builder.toString();
@@ -167,5 +162,4 @@ private static String post(String data) throws IOException, MalformedURLExceptio
return response;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/FormattingCodeCounter.java b/src/com/gmail/justbru00/epic/rename/utils/v3/FormattingCodeCounter.java
index ea26376..2dbe135 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/FormattingCodeCounter.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/FormattingCodeCounter.java
@@ -7,18 +7,18 @@
import com.gmail.justbru00.epic.rename.main.v3.Main;
public class FormattingCodeCounter {
-
+
/**
* Checks if the given string has too many formatting codes.
* @return True if the max. is not reached. False if the max. has been reached.
*/
public static boolean checkMaxColorCodes(Player p, String valueToCheck, EpicRenameCommands cmd, boolean sendBypassMsg) {
-
+
if (!Main.getInstance().getConfig().getBoolean("formatting_code_limit.enabled")) {
Debug.send("[FormattingCodeCounter#checkMaxColorCodes] Formatting code limits are disabled.");
return true;
}
-
+
if (p.hasPermission("epicrename.bypass.formattingcodemax")) {
if (sendBypassMsg) {
if (!Main.getBooleanFromConfig("disable_bypass_messages")) { // Issue #107
@@ -27,32 +27,28 @@ public static boolean checkMaxColorCodes(Player p, String valueToCheck, EpicRena
Debug.send("Bypass messages are disabled.");
} // End Issue #107
}
-
+
Debug.send("[FormattingCodeCounter#checkMaxColorCodes] Formatting code limit bypassed");
return true;
}
-
+
int numOfCodes = getAmountOfColorCodes(valueToCheck, '&');
Debug.send("[FormattingCodeCounter#checkMaxColorCodes] Number of formatting codes: " + numOfCodes);
-
- if (numOfCodes > Main.getInstance().getConfig().getInt("formatting_code_limit." + EpicRenameCommands.getStringName(cmd) + ".max")) {
- return false;
- }
-
- return true;
- }
-
+
+ return numOfCodes <= Main.getInstance().getConfig().getInt("formatting_code_limit." + EpicRenameCommands.getStringName(cmd) + ".max");
+ }
+
/**
* Checks if the given string has too few formatting codes.
* @return True if the min. is reached. False if the min. has not been reached.
*/
public static boolean checkMinColorCodes(Player p, String valueToCheck, EpicRenameCommands cmd, boolean sendBypassMsg) {
-
+
if (!Main.getInstance().getConfig().getBoolean("formatting_code_limit.enabled")) {
Debug.send("[FormattingCodeCounter#checkMinColorCodes] Formatting code limits are disabled.");
return true;
}
-
+
if (p.hasPermission("epicrename.bypass.formattingcodemin")) {
if (sendBypassMsg) {
if (!Main.getBooleanFromConfig("disable_bypass_messages")) { // Issue #107
@@ -61,19 +57,17 @@ public static boolean checkMinColorCodes(Player p, String valueToCheck, EpicRena
Debug.send("Bypass messages are disabled.");
} // End Issue #107
}
+
Debug.send("[FormattingCodeCounter#checkMinColorCodes] Formatting code limit bypassed.");
return true;
}
-
+
int numOfCodes = getAmountOfColorCodes(valueToCheck, '&');
Debug.send("[FormattingCodeCounter#checkMinColorCodes] Number of formatting codes: " + numOfCodes);
-
- if (numOfCodes < Main.getInstance().getConfig().getInt("formatting_code_limit." + EpicRenameCommands.getStringName(cmd) + ".min")) {
- return false;
- }
- return true;
- }
-
+
+ return numOfCodes >= Main.getInstance().getConfig().getInt("formatting_code_limit." + EpicRenameCommands.getStringName(cmd) + ".min");
+ }
+
/**
* Counts how many formatting codes are in the given String.
* @return The amount of formatting codes in the string.
@@ -81,9 +75,9 @@ public static boolean checkMinColorCodes(Player p, String valueToCheck, EpicRena
public static int getAmountOfColorCodes(String valueToCountCodesIn, char colorCodeChar) {
int colorCodes = 0;
char[] array = valueToCountCodesIn.toCharArray();
-
+
for (int i = 0; i < array.length; i++) {
-
+
if (array[i] == colorCodeChar) {
// Might be a color code
if (array.length != i + 1) { // Prevent error with color code character at end of string
@@ -95,23 +89,21 @@ public static int getAmountOfColorCodes(String valueToCountCodesIn, char colorCo
}
}
}
-
+
// Issue #167 - Count hex color codes as well.
int numberOfHexColorCodes = valueToCountCodesIn.split("([A-Fa-f0-9]{6})").length - 1;
-
+
Debug.send("[FormattingCodeCounter#getAmountOfColorCodes] numberOfHexColorCodes = " + numberOfHexColorCodes);
-
+
if (numberOfHexColorCodes > 0) {
colorCodes = colorCodes + numberOfHexColorCodes;
}
-
+
return colorCodes;
}
-
+
/**
* Sends the minimum not reached message for the specified command.
- * @param p
- * @param erc
*/
public static void sendMinNotReachedMsg(Player p, EpicRenameCommands erc) {
if (erc.equals(EpicRenameCommands.RENAME) || erc.equals(EpicRenameCommands.LORE)
@@ -119,7 +111,7 @@ public static void sendMinNotReachedMsg(Player p, EpicRenameCommands erc) {
String msgFromConfig = Main.getMsgFromConfig("format_code_limit.min_not_reached");
FileConfiguration config = Main.getInstance().getConfig();
int minimum = config.getInt("formatting_code_limit." + EpicRenameCommands.getStringName(erc) + ".min");
-
+
msgFromConfig = msgFromConfig.replace("{min}", String.valueOf(minimum));
Messager.msgPlayer(msgFromConfig, p);
} else {
@@ -127,11 +119,9 @@ public static void sendMinNotReachedMsg(Player p, EpicRenameCommands erc) {
+ " config.yml version 8 only supports those commands.");
}
}
-
+
/**
* Sends the maximum reached message for the specified command.
- * @param p
- * @param erc
*/
public static void sendMaxReachedMsg(Player p, EpicRenameCommands erc) {
if (erc.equals(EpicRenameCommands.RENAME) || erc.equals(EpicRenameCommands.LORE)
@@ -139,7 +129,7 @@ public static void sendMaxReachedMsg(Player p, EpicRenameCommands erc) {
String msgFromConfig = Main.getMsgFromConfig("format_code_limit.max_reached");
FileConfiguration config = Main.getInstance().getConfig();
int minimum = config.getInt("formatting_code_limit." + EpicRenameCommands.getStringName(erc) + ".max");
-
+
msgFromConfig = msgFromConfig.replace("{max}", String.valueOf(minimum));
Messager.msgPlayer(msgFromConfig, p);
} else {
@@ -147,5 +137,4 @@ public static void sendMaxReachedMsg(Player p, EpicRenameCommands erc) {
+ " config.yml version 8 only supports those commands.");
}
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/FormattingPermManager.java b/src/com/gmail/justbru00/epic/rename/utils/v3/FormattingPermManager.java
index 3245001..1a00b92 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/FormattingPermManager.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/FormattingPermManager.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import org.bukkit.entity.Player;
@@ -23,13 +24,14 @@ public class FormattingPermManager {
* @return True if the player has permission. False if the player doesn't have permission.
*/
public static boolean checkPerms(EpicRenameCommands erc, String[] args, Player p) {
- StringBuilder builder = new StringBuilder("");
+ StringBuilder builder = new StringBuilder();
for (String item : args) {
- builder.append(item + " ");
+ builder.append(item).append(" ");
}
+
return checkPerms(erc, builder.toString().trim(), p);
}
-
+
/**
* Checks the provided players permissions for the color codes in their proposed text.
* @param erc The command this text will be used for.
@@ -43,7 +45,7 @@ public static boolean checkPerms(EpicRenameCommands erc, String unformattedStrin
Messager.msgPlayer(Main.getMsgFromConfig("format_code_permission.&x_color_code_blocked").replace("{code}", "&x"), p);
return false;
}
-
+
for (String code : FORMAT_CODES) {
String perm = FORMAT_PERM.replace("{CMD}", EpicRenameCommands.getStringName(erc)).replace("{CODE}", code);
if (unformattedString.toLowerCase().contains("&" + code)) {
@@ -55,7 +57,7 @@ public static boolean checkPerms(EpicRenameCommands erc, String unformattedStrin
}
}
}
-
+
// ISSUE #150
if (unformattedString.matches(".*[0-9a-fA-F]{6}.*")) {
String perm = FORMAT_PERM.replace("{CMD}", EpicRenameCommands.getStringName(erc)).replace("{CODE}", "hex");
@@ -66,7 +68,7 @@ public static boolean checkPerms(EpicRenameCommands erc, String unformattedStrin
return false;
}
}
-
+
return true;
}
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/GlowingUtil.java b/src/com/gmail/justbru00/epic/rename/utils/v3/GlowingUtil.java
index baee6d8..804d4b6 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/GlowingUtil.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/GlowingUtil.java
@@ -50,12 +50,10 @@ public static ItemStack addGlowingToItemModern(ItemStack itemStack) {
return itemStack;
}
- @Deprecated
/**
- *
- * @param itemStack
* @return ItemStack with glowing removed or null if item is not glowing
*/
+ @Deprecated
public static ItemStack removeGlowingFromItemLegacy(ItemStack itemStack) {
ItemMeta im = itemStack.getItemMeta();
@@ -86,8 +84,6 @@ public static ItemStack removeGlowingFromItemLegacy(ItemStack itemStack) {
}
/**
- *
- * @param itemStack
* @return ItemStack with glowing removed or null if item is not glowing
*/
public static ItemStack removeGlowingFromItemModern(ItemStack itemStack) {
@@ -213,5 +209,4 @@ public static ItemStack convertLegacyGlowingToModern(ItemStack itemStack) {
public static boolean isLegacyToModernConversionEnabled() {
return Main.getBooleanFromConfig("convert_legacy_glowing_to_modern_glowing");
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/ItemSerialization.java b/src/com/gmail/justbru00/epic/rename/utils/v3/ItemSerialization.java
index 4034401..890ed55 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/ItemSerialization.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/ItemSerialization.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import org.bukkit.configuration.InvalidConfigurationException;
@@ -19,18 +20,17 @@ public class ItemSerialization {
/**
* @author Justin Brubaker
* @param inv Inventory to convert to string.
- * @return
*/
public static String toString(Inventory inv) {
YamlConfiguration config = new YamlConfiguration();
-
+
for (int i = 0; i < inv.getSize(); i++) {
config.set(String.valueOf(i), inv.getItem(i));
}
-
+
return config.saveToString();
}
-
+
/**
* This method will completely clear the players inventory.
* @author Justin Brubaker
@@ -40,7 +40,7 @@ public static String toString(Inventory inv) {
public static void fillInventoryFromString(String s, Player p) {
Inventory inv = p.getInventory();
inv.clear();
-
+
YamlConfiguration config = new YamlConfiguration();
try {
config.loadFromString(s);
@@ -48,16 +48,14 @@ public static void fillInventoryFromString(String s, Player p) {
e.printStackTrace();
return;
}
-
+
for (int i = 0; i < inv.getSize(); i++) {
inv.setItem(i, config.getItemStack(String.valueOf(i), null));
}
}
-
+
/**
* Single {@link ItemStack} to a {@link String}
- * @param is
- * @return
*/
public static String toString(ItemStack is) {
return toString(is, "i");
@@ -65,22 +63,19 @@ public static String toString(ItemStack is) {
/**
* Single {@link ItemStack} from a {@link String}
- * @param string
- * @return
*/
public static ItemStack toItem(String string) {
return toItem(string, "i");
}
/**
- * This code is from Hellgast23's comment at
- * https://www.spigotmc.org/threads/serializing-itemstack-to-string.80233/#post-889181
- *
- * @author Hellgast23
- * @param itemStack
- * @param key The name of the configuration section.
- * @return A string of text that contains item information.
- */
+ * This code is from Hellgast23's comment at
+ * ...
+ *
+ * @author Hellgast23
+ * @param key The name of the configuration section.
+ * @return A string of text that contains item information.
+ */
private static String toString(ItemStack itemStack, String key) {
YamlConfiguration config = new YamlConfiguration();
config.set(key, itemStack);
@@ -90,10 +85,8 @@ private static String toString(ItemStack itemStack, String key) {
/**
* This code is from Hellgast23's comment at
* https://www.spigotmc.org/threads/serializing-itemstack-to-string.80233/#post-889181
- *
+ *
* @author Hellgast23
- * @param stringBlob
- * @return
*/
private static ItemStack toItem(String string, String key) {
YamlConfiguration config = new YamlConfiguration();
@@ -103,7 +96,7 @@ private static ItemStack toItem(String string, String key) {
e.printStackTrace();
return null;
}
+
return config.getItemStack(key, null);
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/LoreUtil.java b/src/com/gmail/justbru00/epic/rename/utils/v3/LoreUtil.java
index 0bbda74..00f4be8 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/LoreUtil.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/LoreUtil.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import java.util.ArrayList;
@@ -24,7 +25,7 @@ public class LoreUtil {
@SuppressWarnings("deprecation")
public static void setLoreLine(int lineNumber, Player player, String[] args) {
Debug.send("LoreUtil#setLoreLine() start.");
- StringBuilder builder = new StringBuilder("");
+ StringBuilder builder = new StringBuilder();
ItemStack inHand = RenameUtil.getInHand(player);
@@ -45,13 +46,13 @@ public static void setLoreLine(int lineNumber, Player player, String[] args) {
Messager.msgPlayer(Main.getMsgFromConfig("setloreline.blacklisted_material_found"), player);
return;
}
-
+
// Check Existing Name Blacklist #81
if (!Blacklists.checkExistingName(player)) {
Messager.msgPlayer(Main.getMsgFromConfig("setloreline.blacklisted_existing_name_found"), player);
return;
}
-
+
// Check Existing Lore Blacklist #81
if (!Blacklists.checkExistingLore(player)) {
Messager.msgPlayer(Main.getMsgFromConfig("setloreline.blacklisted_existing_lore_found"), player);
@@ -63,29 +64,29 @@ public static void setLoreLine(int lineNumber, Player player, String[] args) {
// FormattingPermManager handles the message.
return;
}
-
+
lineNumber = lineNumber - 1;
for (int i = 1; i < args.length; i++) {
- builder.append(args[i] + " ");
+ builder.append(args[i]).append(" ");
}
String loreToBeSet = builder.toString().trim();
Debug.send("Text to set is: " + loreToBeSet);
-
+
// Issue #32
if (!FormattingCodeCounter.checkMinColorCodes(player, loreToBeSet, EpicRenameCommands.SETLORELINE, true)) {
FormattingCodeCounter.sendMinNotReachedMsg(player, EpicRenameCommands.SETLORELINE);
return;
}
-
+
if (!FormattingCodeCounter.checkMaxColorCodes(player, loreToBeSet, EpicRenameCommands.SETLORELINE, true)) {
FormattingCodeCounter.sendMaxReachedMsg(player, EpicRenameCommands.SETLORELINE);
return;
}
// End Issue #32
-
- List newLore = new ArrayList();
+
+ List newLore = new ArrayList<>();
loreToBeSet = Messager.color(loreToBeSet);
@@ -114,9 +115,8 @@ public static void setLoreLine(int lineNumber, Player player, String[] args) {
Debug.send("oldLore has: " + item);
}
- for (int i = 0; i < oldLore.size(); i++) { // Fill new lore with old stuff
- newLore.add(oldLore.get(i));
- }
+ // Fill new lore with old stuff
+ newLore.addAll(oldLore);
// Debug
if (Main.debug)
@@ -130,17 +130,7 @@ public static void setLoreLine(int lineNumber, Player player, String[] args) {
newLore.set(lineNumber, loreToBeSet);
}
-
- im.setLore(newLore);
- inHand.setItemMeta(im);
- if (Main.USE_NEW_GET_HAND) {
- player.getInventory().setItemInMainHand(inHand);
- } else {
- player.setItemInHand(inHand);
- }
- Messager.msgPlayer(Main.getMsgFromConfig("setloreline.success"), player);
-
- } else { // Item has no lore
+ } else { // Item has no lore
Debug.send("Item has no lore D:");
for (int i = 0; i <= lineNumber; i++) {
@@ -151,25 +141,23 @@ public static void setLoreLine(int lineNumber, Player player, String[] args) {
newLore.set(lineNumber, loreToBeSet);
- im.setLore(newLore);
- inHand.setItemMeta(im);
- if (Main.USE_NEW_GET_HAND) {
- player.getInventory().setItemInMainHand(inHand);
- } else {
- player.setItemInHand(inHand);
- }
- Messager.msgPlayer(Main.getMsgFromConfig("setloreline.success"), player);
- }
+ }
- }
+ im.setLore(newLore);
+ inHand.setItemMeta(im);
+ if (Main.USE_NEW_GET_HAND) {
+ player.getInventory().setItemInMainHand(inHand);
+ } else {
+ player.setItemInHand(inHand);
+ }
+
+ Messager.msgPlayer(Main.getMsgFromConfig("setloreline.success"), player);
+ }
- @SuppressWarnings("deprecation")
/**
* Handles the lore command.
- *
- * @param args
- * @param player
*/
+ @SuppressWarnings("deprecation")
public static void loreHandle(String[] args, Player player) {
if (Blacklists.checkTextBlacklist(args, player)) {
Debug.send("[LoreUtil] Passed Text Blacklist");
@@ -184,37 +172,38 @@ public static void loreHandle(String[] args, Player player) {
Debug.send("[LoreUtil] Passed FormattingPermManager#checkPerms()");
boolean firstLine = true;
-
+
// Issue #32
for (String line : LoreUtil.buildLoreFromArgs(args, false)) {
-
+
if (!FormattingCodeCounter.checkMinColorCodes(player, line, EpicRenameCommands.LORE, firstLine)) {
FormattingCodeCounter.sendMinNotReachedMsg(player, EpicRenameCommands.LORE);
return;
}
-
+
if (!FormattingCodeCounter.checkMaxColorCodes(player, line, EpicRenameCommands.LORE, firstLine)) {
FormattingCodeCounter.sendMaxReachedMsg(player, EpicRenameCommands.LORE);
return;
- }
+ }
+
firstLine = false;
}
Debug.send("[LoreUtil] Passed FormattingCodeCounter min and max");
// End Issue #32
-
- ItemStack inHand = RenameUtil.getInHand(player);
- if (inHand.getType() != Material.AIR) {
+ ItemStack toLore = RenameUtil.getInHand(player);
+
+ if (toLore.getType() != Material.AIR) {
Debug.send("[LoreUtil] Passed Air check");
- if (MaterialPermManager.checkPerms(EpicRenameCommands.LORE, inHand, player)) {
+ if (MaterialPermManager.checkPerms(EpicRenameCommands.LORE, toLore, player)) {
EcoMessage ecoStatus = EconomyManager.takeMoney(player, EpicRenameCommands.LORE);
if (ecoStatus == EcoMessage.TRANSACTION_ERROR) {
return;
}
-
+
// Add experience cost option #121
XpMessage xpStatus = XpCostManager.takeXp(player, EpicRenameCommands.LORE);
@@ -222,58 +211,46 @@ public static void loreHandle(String[] args, Player player) {
return;
}
- ItemStack toLore = inHand;
- ItemMeta toLoreMeta = toLore.getItemMeta();
+ ItemMeta toLoreMeta = toLore.getItemMeta();
toLoreMeta.setLore(LoreUtil.buildLoreFromArgs(args, true));
toLore.setItemMeta(toLoreMeta);
if (Main.USE_NEW_GET_HAND) { // Use 1.9+ method
player.getInventory().setItemInMainHand(toLore);
- Messager.msgPlayer(Main.getMsgFromConfig("lore.success"), player);
- return;
- } else { // Use older method.
+ } else { // Use older method.
player.setItemInHand(toLore);
- Messager.msgPlayer(Main.getMsgFromConfig("lore.success"), player);
- return;
- }
-
- } else {
+ }
+ Messager.msgPlayer(Main.getMsgFromConfig("lore.success"), player);
+ } else {
Messager.msgPlayer(Main.getMsgFromConfig("lore.no_permission_for_material"),
player);
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("lore.cannot_lore_air"), player);
- return;
}
} else {
// FormattingPermManager handles the message.
- return;
}
} else {
// Existing lore
Messager.msgPlayer(Main.getMsgFromConfig("lore.blacklisted_existing_lore_found"), player);
- return;
}
} else {
// Existing name
Messager.msgPlayer(Main.getMsgFromConfig("lore.blacklisted_existing_name_found"), player);
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("lore.blacklisted_material_found"), player);
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("lore.blacklisted_word_found"), player);
- return;
}
}
/**
* Takes the command args and changes them to a ArrayList with multiple lines
* and color
- *
+ *
* @param args
* The args you want to change.
* @return An ArrayList with line breaks at every '|'
@@ -281,15 +258,16 @@ public static void loreHandle(String[] args, Player player) {
public static List buildLoreFromArgs(String[] args, boolean enablePrefixSuffix) {
List toBeLore = new ArrayList();
- StringBuilder builder = new StringBuilder("");
- String completeArgs = "";
+ StringBuilder builder = new StringBuilder();
+ String completeArgs;
for (String item : args) { // Closes #68
if (Main.getInstance().getConfig().getBoolean("replace_underscores")) {
item = item.replace("_", " ");
Debug.send("Replaced the underscores.");
}
- builder.append(item + " ");
+
+ builder.append(item).append(" ");
} // End closes #68
// Add .trim() to fix ISSUE #135
@@ -307,10 +285,10 @@ public static List buildLoreFromArgs(String[] args, boolean enablePrefix
}
}
- toBeLore.add(completeArgs.substring(lastBreak, completeArgs.length()));
+ toBeLore.add(completeArgs.substring(lastBreak));
+
+ List loreToReturn = new ArrayList<>();
- List loreToReturn = new ArrayList();
-
// ISSUE #185
String eachLinePrefix = "";
String eachLineSuffix = "";
@@ -319,11 +297,11 @@ public static List buildLoreFromArgs(String[] args, boolean enablePrefix
eachLinePrefix = config.getString("command_argument.prefixes.lore.each_line", "");
eachLineSuffix = config.getString("command_argument.suffixes.lore.each_line", "");
}
-
+
if (!eachLinePrefix.equalsIgnoreCase("")) {
eachLinePrefix = Messager.color(eachLinePrefix);
}
-
+
if (!eachLineSuffix.equalsIgnoreCase("")) {
eachLineSuffix = Messager.color(eachLineSuffix);
}
@@ -335,5 +313,4 @@ public static List buildLoreFromArgs(String[] args, boolean enablePrefix
return loreToReturn;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/MaterialPermManager.java b/src/com/gmail/justbru00/epic/rename/utils/v3/MaterialPermManager.java
index d947eae..059a29f 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/MaterialPermManager.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/MaterialPermManager.java
@@ -8,7 +8,7 @@
public class MaterialPermManager {
public static final String MATERIAL_PERM = "epicrename.{CMD}.material.{MATERIAL}";
-
+
/**
* Checks if the player has permission for the material provided.
* @param erc The command that is being performed.
@@ -20,14 +20,12 @@ public static boolean checkPerms(EpicRenameCommands erc, ItemStack toCheck, Play
// New Permission Checks
String newPerm = MATERIAL_PERM.replace("{CMD}", EpicRenameCommands.getStringName(erc)).replace("{MATERIAL}", toCheck.getType().toString());
String allNewPerm = MATERIAL_PERM.replace("{CMD}", EpicRenameCommands.getStringName(erc)).replace("{MATERIAL}", "*");
-
- //Debug.send("[MaterialPermManager] NewPerm: " + newPerm + " allNewPerm: " + allNewPerm);
-
+
if (p.hasPermission(allNewPerm)) {
Debug.send("[MaterialPermManager] The player has permission. Perm: " + allNewPerm);
return true;
}
-
+
if (p.hasPermission(newPerm)) {
Debug.send("[MaterialPermManager] The player has permission. Perm: " + newPerm);
return true;
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/Messager.java b/src/com/gmail/justbru00/epic/rename/utils/v3/Messager.java
index 0e271ec..831f552 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/Messager.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/Messager.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
- */
+ */
+
package com.gmail.justbru00.epic.rename.utils.v3;
import java.awt.Color;
@@ -20,41 +21,39 @@
import net.md_5.bungee.api.chat.TextComponent;
/**
- *
+ *
* @author Justin Brubaker
*
*/
public class Messager {
-
+
private static final Pattern RGB_PATTERN = Pattern.compile("(&)?([0-9a-fA-F]{6})");
private static final Pattern X_PATTERN = Pattern.compile("&[xX]&([A-Fa-f0-9])&([A-Fa-f0-9])&([A-Fa-f0-9])&([A-Fa-f0-9])&([A-Fa-f0-9])&([A-Fa-f0-9])");
-
+
public static String color(String uncolored) {
if (Main.MC_VERSION == null) {
return ChatColor.translateAlternateColorCodes('&', uncolored);
}
-
+
if (Main.MC_VERSION.equals(MCVersion.ONE_DOT_SIXTEEN_OR_NEWER) || Main.MC_VERSION.equals(MCVersion.ONE_DOT_TWENTY_DOT_FIVE_OR_NEWER)) {
return ChatColor.translateAlternateColorCodes('&', convertHexColorCodes(uncolored));
}
-
+
return ChatColor.translateAlternateColorCodes('&', uncolored);
}
-
+
/**
* ISSUE #150
* Converts hex color codes.
- * @param uncolored
- * @return
*/
public static String convertHexColorCodes(String uncolored) {
StringBuffer builder = new StringBuffer();
-
+
Matcher matcher = RGB_PATTERN.matcher(uncolored);
-
- while(matcher.find()) {
+
+ while (matcher.find()) {
boolean escaped = (matcher.group(1) != null);
-
+
if (!escaped) {
try {
String hexColorCode = matcher.group(2);
@@ -64,13 +63,15 @@ public static String convertHexColorCodes(String uncolored) {
//Ignore
}
}
+
matcher.appendReplacement(builder, "$2");
}
+
matcher.appendTail(builder);
return builder.toString();
}
-
+
/**
* @throws NumberFormatException If the provided hex color code is incorrect or if the version less than 1.16.
*/
@@ -82,62 +83,60 @@ public static String parseHexColor(String hexColor) throws NumberFormatException
if (hexColor.startsWith("#")) {
hexColor = hexColor.substring(1);
}
-
+
if (hexColor.length() != 6) {
throw new NumberFormatException("Invalid Length");
}
-
+
Color.decode("#" + hexColor);
-
+
StringBuilder assembledColorCode = new StringBuilder();
-
+
assembledColorCode.append("\u00a7x");
-
+
for (char curChar : hexColor.toCharArray()) {
assembledColorCode.append("\u00a7").append(curChar);
}
-
+
return assembledColorCode.toString();
}
-
+
public static void msgConsole(String msg) {
msg = VariableReplacer.replace(msg);
-
+
if (Main.clogger != null) {
Main.clogger.sendMessage(Main.prefix + Messager.color(msg));
} else {
Main.log.info(ChatColor.stripColor(Messager.color(msg)));
}
}
-
+
public static void msgPlayer(String msg, Player player) {
msg = VariableReplacer.replace(msg);
player.sendMessage(Main.prefix + Messager.color(msg));
}
-
+
public static void msgPlayerPlain(String msg, Player player) {
msg = VariableReplacer.replace(msg);
player.sendMessage(Main.prefix + msg);
}
-
+
/**
* Sends a message from the provided messages.yml path to the provided sender.
- * @param msgPath
- * @param sender
*/
public static void msgSenderWithConfigMsg(String msgPath, CommandSender sender) {
String msg = Main.getMsgFromConfig(msgPath);
msg = VariableReplacer.replace(msg);
sender.sendMessage(Main.prefix + Messager.color(msg));
}
-
+
public static void msgSender(String msg, CommandSender sender) {
msg = VariableReplacer.replace(msg);
sender.sendMessage(Main.prefix + Messager.color(msg));
}
-
+
/**
- *
+ *
* @param uncoloredChatMessage The chat message to send.
* @param suggestedCommand The command to suggest with / included
* @param player The player to send the suggestion to.
@@ -145,19 +144,16 @@ public static void msgSender(String msg, CommandSender sender) {
public static void sendCommandSuggestionToPlayer(String uncoloredChatMessage, String suggestedCommand, Player player) {
String colored = Main.prefix + Messager.color(uncoloredChatMessage);
TextComponent component = new TextComponent(TextComponent.fromLegacyText(colored));
-
+
component.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggestedCommand));
-
+
player.spigot().sendMessage(component);
}
-
+
/**
- * Code from: https://www.spigotmc.org/threads/reverse-translatealternatecolorcodes.453480/#post-3888824
- * @author Schottky
- * @param textToReverse
- * @param altChar
- * @return
- */
+ * Code from: ...
+ * @author Schottky
+ */
public static String reverseSectionSignTo(String textToReverse, char altChar) {
char[] chars = textToReverse.toCharArray();
@@ -170,15 +166,13 @@ public static String reverseSectionSignTo(String textToReverse, char altChar) {
return new String(chars);
}
-
+
/**
- * Reverses text with &x&1&2&3&4&5&6 color codes back to
- * Thanks to Elementeral for the code inspiration: https://www.spigotmc.org/threads/hex-color-code-translate.449748/#post-3867804
- * @param textToReverse
- * @return
- */
+ * Reverses text with &x&1&2&3&4&5&6 color codes back to
+ * Thanks to Elementeral for the code inspiration: ...
+ */
public static String reverseFromXToHex(String textToReverse) {
-
+
Matcher matcher = X_PATTERN.matcher(textToReverse);
StringBuffer buffer = new StringBuffer(textToReverse.length() + 4 * 8);
while (matcher.find()) {
@@ -196,6 +190,7 @@ public static String reverseFromXToHex(String textToReverse) {
group5.charAt(0) +
group6.charAt(0));
}
+
return matcher.appendTail(buffer).toString();
}
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/PluginFile.java b/src/com/gmail/justbru00/epic/rename/utils/v3/PluginFile.java
index 4f0628d..f4c722c 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/PluginFile.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/PluginFile.java
@@ -10,11 +10,11 @@
import org.bukkit.plugin.java.JavaPlugin;
public class PluginFile extends YamlConfiguration {
-
- private File file;
- private String defaults;
- private JavaPlugin plugin;
-
+
+ private final File file;
+ private final String defaults;
+ private final JavaPlugin plugin;
+
/**
* Creates new PluginFile, without defaults
* @param plugin - Your plugin
@@ -23,7 +23,7 @@ public class PluginFile extends YamlConfiguration {
public PluginFile(JavaPlugin plugin, String fileName) {
this(plugin, fileName, null);
}
-
+
/**
* Creates new PluginFile, with defaults
* @param plugin - Your plugin
@@ -36,14 +36,14 @@ public PluginFile(JavaPlugin plugin, String fileName, String defaultsName) {
this.file = new File(plugin.getDataFolder(), fileName);
reload();
}
-
+
/**
* Reload configuration
*/
public void reload() {
-
+
if (!file.exists()) {
-
+
try {
file.getParentFile().mkdirs();
file.createNewFile();
@@ -51,51 +51,42 @@ public void reload() {
if (defaults != null) {
InputStreamReader reader = new InputStreamReader(plugin.getResource(defaults));
FileConfiguration defaultsConfig = YamlConfiguration.loadConfiguration(reader);
-
+
setDefaults(defaultsConfig);
options().copyDefaults(true);
-
-
+
reader.close();
save();
options().copyDefaults(false);
}
-
+
} catch (IOException exception) {
exception.printStackTrace();
plugin.getLogger().severe("Error while creating file " + file.getName());
}
-
}
-
+
try {
load(file);
} catch (IOException exception) {
exception.printStackTrace();
plugin.getLogger().severe("Error while loading file " + file.getName());
-
} catch (InvalidConfigurationException exception) {
exception.printStackTrace();
plugin.getLogger().severe("Error while loading file " + file.getName());
-
}
-
}
-
+
/**
* Save configuration
*/
public void save() {
-
try {
options().indent(2);
save(file);
-
} catch (IOException exception) {
exception.printStackTrace();
plugin.getLogger().severe("Error while saving file " + file.getName());
}
-
}
-
-}
\ No newline at end of file
+}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/RenameUtil.java b/src/com/gmail/justbru00/epic/rename/utils/v3/RenameUtil.java
index 7f9a471..077367b 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/RenameUtil.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/RenameUtil.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import org.bukkit.Material;
@@ -21,7 +22,7 @@ public class RenameUtil {
// VERSION 3
/**
- *
+ *
* @param player The {@link Player} who sent the command.
* @param args The arguments of the command sent to the {@link CommandExecutor}
* @param erc The command that called this method.
@@ -48,100 +49,88 @@ public static void renameHandle(Player player, String[] args, EpicRenameCommands
Debug.send("[RenameUtil] Passed Format Permissions Check.");
if (inHand.getType() != Material.AIR) { // Check != Air
if (MaterialPermManager.checkPerms(erc, inHand, player)) { // Check for per material permissions
-
- StringBuilder builder = new StringBuilder("");
- String completeArgs = "";
+
+ StringBuilder builder = new StringBuilder();
+ String completeArgs;
for (String item : args) {
- builder.append(item + " ");
+ builder.append(item).append(" ");
}
-
+
completeArgs = builder.toString().trim();
-
+
if (Main.getInstance().getConfig().getBoolean("replace_underscores")) {
completeArgs = completeArgs.replace("_", " ");
Debug.send("[RenameUtil] Replaced the underscores.");
}
-
+
// Issue #32
if (!FormattingCodeCounter.checkMinColorCodes(player, completeArgs, erc, true)) {
FormattingCodeCounter.sendMinNotReachedMsg(player, erc);
return;
}
+
Debug.send("[RenameUtil] Passed FormattingCodeCounter Minimum Check.");
-
+
if (!FormattingCodeCounter.checkMaxColorCodes(player, completeArgs, erc, true)) {
FormattingCodeCounter.sendMaxReachedMsg(player, erc);
return;
}
+
Debug.send("[RenameUtil] Passed FormattingCodeCounter Maximum Check.");
// End Issue #32
completeArgs = Messager.color(Main.getInstance().getConfig().getString("command_argument.prefixes.rename")
+ completeArgs + Main.getInstance().getConfig().getString("command_argument.suffixes.rename"));
-
+
EcoMessage ecoStatus = EconomyManager.takeMoney(player, EpicRenameCommands.RENAME);
if (ecoStatus == EcoMessage.TRANSACTION_ERROR) {
return;
}
-
+
// Add experience cost option #121
XpMessage xpStatus = XpCostManager.takeXp(player, EpicRenameCommands.RENAME);
if (xpStatus == XpMessage.TRANSACTION_ERROR) {
return;
}
-
+
String oldName = inHand.getItemMeta().getDisplayName();
if (Main.USE_NEW_GET_HAND) { // Use 1.9+ method
player.getInventory().setItemInMainHand(RenameUtil.renameItemStack(player, completeArgs, inHand));
- Messager.msgPlayer(VariableReplacer.replaceRenameSuccessVariables(Main.getMsgFromConfig("rename.success"),
- oldName, completeArgs), player);
- Messager.msgConsole(VariableReplacer.replaceRenameLogVariables(Main.getMsgFromConfig("rename.log"),
- player.getName(), oldName, completeArgs));
- return;
- } else { // Use older method.
+ } else { // Use older method.
player.setItemInHand(RenameUtil.renameItemStack(player, completeArgs, inHand));
- Messager.msgPlayer(VariableReplacer.replaceRenameSuccessVariables(Main.getMsgFromConfig("rename.success"),
- oldName, completeArgs), player);
- Messager.msgConsole(VariableReplacer.replaceRenameLogVariables(Main.getMsgFromConfig("rename.log"),
- player.getName(), oldName, completeArgs));
- return;
- }
- } else {
+ }
+ Messager.msgPlayer(VariableReplacer.replaceRenameSuccessVariables(Main.getMsgFromConfig("rename.success"),
+ oldName, completeArgs), player);
+ Messager.msgConsole(VariableReplacer.replaceRenameLogVariables(Main.getMsgFromConfig("rename.log"),
+ player.getName(), oldName, completeArgs));
+ } else {
Messager.msgPlayer(
Main.getMsgFromConfig("rename.no_permission_for_material"), player);
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("rename.cannot_rename_air"), player);
- return;
}
} else {
// Message handled by FormattingPermManager
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("rename_character_limit.name_too_long"), player);
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("rename.blacklisted_existing_lore_found"), player);
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("rename.blacklisted_existing_name_found"), player);
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("rename.blacklisted_material_found"), player);
- return;
}
} else {
Messager.msgPlayer(Main.getMsgFromConfig("rename.blacklisted_word_found"), player);
- return;
}
} else {
Debug.send(
@@ -150,24 +139,22 @@ public static void renameHandle(Player player, String[] args, EpicRenameCommands
}
/**
- *
+ *
* @param player
* The {@link Player} who ran the command.
- * @param args
- * The arguments of the command.
* @param toRename
* The {@link ItemStack} that is being renamed.
* @return The renamed {@link ItemStack}.
*/
public static ItemStack renameItemStack(Player player, String completeArgs, ItemStack toRename) {
-
+
// ISSUE #130
if (Main.getInstance().getConfig().getBoolean("add_trailing_space_to_rename")) {
completeArgs = completeArgs + " ";
Debug.send("[RenameUtil] Added trailing space to rename arguments.");
}
// END ISSUE #130
-
+
// ISSUE #137
if (Main.getInstance().getConfig().getBoolean("add_leading_space_to_rename")) {
completeArgs = " " + completeArgs;
@@ -187,7 +174,7 @@ public static ItemStack renameItemStack(Player player, String completeArgs, Item
/**
* This method gets the item in the players main hand. It will use the correct
* method for the server version it is running on.
- *
+ *
* @param player
* The player to get the item from.
* @return The item stack in the players hand.
@@ -198,9 +185,7 @@ public static ItemStack getInHand(Player player) {
if (Main.USE_NEW_GET_HAND) {
returning = player.getInventory().getItemInMainHand();
- return returning;
- } else {
-
+ } else {
try {
returning = player.getItemInHand();
} catch (Exception e) {
@@ -209,9 +194,8 @@ public static ItemStack getInHand(Player player) {
Messager.msgConsole(
"&cProblem while getting the ItemStack inHand. Failed at player.getItemInHand() Server version problem?");
}
+ }
- return returning;
- }
- }
-
+ return returning;
+ }
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/VariableReplacer.java b/src/com/gmail/justbru00/epic/rename/utils/v3/VariableReplacer.java
index 8798f62..5be28da 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/VariableReplacer.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/VariableReplacer.java
@@ -1,42 +1,36 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import com.gmail.justbru00.epic.rename.main.v3.Main;
public class VariableReplacer {
-
+
// Variables: {char} {version}
public static String replace(String toReplace) {
-
+
toReplace = toReplace.replace("{char}", "" + CharLimit.getCharLimit());
toReplace = toReplace.replace("{version}", Main.PLUGIN_VERSION);
-
+
return toReplace;
}
-
+
/**
* Replaces {player}, {previous_name}, {new_name} and depreciated {name}
- * @param toReplace
- * @return
*/
public static String replaceRenameLogVariables(String toReplace, String playerUsername, String oldName, String completeArgs) {
return replaceRenameSuccessVariables(toReplace.replace("{player}", playerUsername), oldName, completeArgs);
}
-
+
/**
* Replaces {previous_name}, {new_name} and depreciated {name}
- * @param toReplace
- * @param oldName
- * @param completeArgs
- * @return
*/
public static String replaceRenameSuccessVariables(String toReplace, String oldName, String completeArgs) {
return toReplace.replace("{previous_name}", oldName).replace("{new_name}", completeArgs).replace("{name}", completeArgs);
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/WorldChecker.java b/src/com/gmail/justbru00/epic/rename/utils/v3/WorldChecker.java
index a6a7490..921a16d 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/WorldChecker.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/WorldChecker.java
@@ -15,25 +15,25 @@ public class WorldChecker {
* @return True if the world is okay false if the world is disabled.
*/
public static boolean checkWorld(Player p) {
-
+
if (!Main.getInstance().getConfig().getBoolean("per_world")) {
Debug.send("Per world is disabled.");
return true;
}
-
+
Location l = p.getLocation();
-
+
List worlds;
worlds = Main.getInstance().getConfig().getStringList("enabled_worlds");
-
+
for (String s : worlds) {
if (l.getWorld().getName().equals(s)) {
Debug.send("In an enabled world");
return true;
}
}
+
Debug.send("In a disabled world.");
return false;
}
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/XpCostManager.java b/src/com/gmail/justbru00/epic/rename/utils/v3/XpCostManager.java
index 3ebb65e..c627811 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/XpCostManager.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/XpCostManager.java
@@ -1,8 +1,9 @@
/**
* @author Justin "JustBru00" Brubaker
- *
+ *
* This is licensed under the MPL Version 2.0. See license info in LICENSE.txt
*/
+
package com.gmail.justbru00.epic.rename.utils.v3;
import org.bukkit.entity.Player;
@@ -21,26 +22,26 @@ public class XpCostManager {
*/
public static XpMessage takeXp(Player player, EpicRenameCommands erc){
- if (Main.USE_XP_COST == false) {
+ if (!Main.USE_XP_COST) {
return XpMessage.XP_DISABLED;
}
-
+
if (player.hasPermission("epicrename.bypass.costs.*")) {
Messager.msgPlayer(Main.getMsgFromConfig("xp.bypass"), player);
return XpMessage.XP_BYPASS;
}
-
+
if (erc == EpicRenameCommands.RENAME) {
-
+
if (player.hasPermission("epicrename.bypass.costs.rename")) {
Messager.msgPlayer(Main.getMsgFromConfig("xp.bypass"), player);
return XpMessage.XP_BYPASS;
}
-
+
XpResponse r = withdraw(player, Main.getInstance().getConfig().getInt("xp.costs.rename"));
-
+
Debug.send("Value from config was: " + Main.getInstance().getConfig().getInt("xp.costs.rename"));
-
+
if (r.isTransactionSuccess()) {
Messager.msgPlayer(formatMsg(Main.getMsgFromConfig("xp.transaction_success"), r), player);
return XpMessage.SUCCESS;
@@ -48,15 +49,16 @@ public static XpMessage takeXp(Player player, EpicRenameCommands erc){
Messager.msgPlayer(formatMsg(Main.getMsgFromConfig("xp.transaction_error"), r), player);
return XpMessage.TRANSACTION_ERROR;
}
-
+
} else if (erc == EpicRenameCommands.LORE) {
-
+
if (player.hasPermission("epicrename.bypass.costs.lore")) {
Messager.msgPlayer(Main.getMsgFromConfig("xp.bypass"), player);
return XpMessage.XP_BYPASS;
}
+
XpResponse r = withdraw(player, Main.getInstance().getConfig().getInt("xp.costs.lore"));
-
+
if (r.isTransactionSuccess()) {
Messager.msgPlayer(formatMsg(Main.getMsgFromConfig("xp.transaction_success"), r), player);
return XpMessage.SUCCESS;
@@ -65,14 +67,14 @@ public static XpMessage takeXp(Player player, EpicRenameCommands erc){
return XpMessage.TRANSACTION_ERROR;
}
} else if (erc == EpicRenameCommands.GLOW) {
-
+
if (player.hasPermission("epicrename.bypass.costs.glow")) {
Messager.msgPlayer(Main.getMsgFromConfig("economy.bypass"), player);
return XpMessage.XP_BYPASS;
}
-
+
XpResponse r = withdraw(player, Main.getInstance().getConfig().getInt("xp.costs.glow"));
-
+
if (r.isTransactionSuccess()) {
Messager.msgPlayer(formatMsg(Main.getMsgFromConfig("xp.transaction_success"), r), player);
return XpMessage.SUCCESS;
@@ -81,10 +83,10 @@ public static XpMessage takeXp(Player player, EpicRenameCommands erc){
return XpMessage.TRANSACTION_ERROR;
}
}
-
+
return XpMessage.UNHANDLED;
}
-
+
/**
* Formats the message with the {cost} and {error} variables.
* @param msg The message you want to replace the variables in.
@@ -92,43 +94,43 @@ public static XpMessage takeXp(Player player, EpicRenameCommands erc){
* @return The formated string with the variables replaced.
*/
public static String formatMsg(String msg, XpResponse r) {
-
+
msg = msg.replace("{cost}", String.valueOf(r.getXpAmount()));
-
- if (!r.isTransactionSuccess()) msg = msg.replace("{error}", r.getErrorMessage());
+
+ if (!r.isTransactionSuccess()) {
+ msg = msg.replace("{error}", r.getErrorMessage());
+ }
+
return msg;
}
+
/**
* Attempts to withdraw XP from the player.
* Will check if the player even has enough before attempting to withdraw.
- * @param p
- * @param xpCost
- * @return An {@link XpResponse} with the outcome of this attempted withdraw.
+ * @return An {@link XpResponse} with the outcome of this withdraw attempt.
*/
public static XpResponse withdraw(Player p, Integer xpCost) {
- Integer totalXp = getTotalExperience(p);
+ int totalXp = getTotalExperience(p);
XpResponse r = new XpResponse();
r.setXpAmount(xpCost);
-
+
if (totalXp < xpCost) {
r.setTransactionSuccess(false);
r.setErrorMessage("Not enough experience.");
return r;
}
-
+
totalXp = totalXp - xpCost;
setTotalExperience(p, totalXp);
r.setTransactionSuccess(true);
-
+
return r;
}
-
+
/**
- * From @Djaytan on spigotmc.org.
- * https://www.spigotmc.org/threads/solved-setting-and-getting-a-players-current-experience-points-not-levels.72804/#post-3466821
- * @param level
- * @return
- */
+ * From @Djaytan on spigotmc.org.
+ * ...
+ */
public static int getTotalExperience(int level) {
int xp = 0;
@@ -139,28 +141,25 @@ public static int getTotalExperience(int level) {
} else if (level > 30) {
xp = (int) Math.round(((4.5 * Math.pow(level, 2) - 162.5 * level + 2220)));
}
+
return xp;
}
/**
- * From @Djaytan on spigotmc.org.
- * https://www.spigotmc.org/threads/solved-setting-and-getting-a-players-current-experience-points-not-levels.72804/#post-3466821
- * @param player
- * @return
- */
+ * From @Djaytan on spigotmc.org.
+ * ...
+ */
public static int getTotalExperience(Player player) {
return Math.round(player.getExp() * player.getExpToLevel()) + getTotalExperience(player.getLevel());
}
/**
* From @Djaytan on spigotmc.org
- * https://www.spigotmc.org/threads/solved-setting-and-getting-a-players-current-experience-points-not-levels.72804/#post-3466821
- * @param player
- * @param amount
+ * ...
*/
public static void setTotalExperience(Player player, int amount) {
- int level = 0;
- int xp = 0;
+ int level;
+ int xp;
float a = 0;
float b = 0;
float c = -amount;
@@ -177,12 +176,11 @@ public static void setTotalExperience(Player player, int amount) {
b = -162.5f;
c += 2220;
}
+
level = (int) Math.floor((-b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a));
xp = amount - getTotalExperience(level);
player.setLevel(level);
player.setExp(0);
player.giveExp(xp);
}
-
-
}
diff --git a/src/com/gmail/justbru00/epic/rename/utils/v3/XpResponse.java b/src/com/gmail/justbru00/epic/rename/utils/v3/XpResponse.java
index e15c6b9..86abce8 100644
--- a/src/com/gmail/justbru00/epic/rename/utils/v3/XpResponse.java
+++ b/src/com/gmail/justbru00/epic/rename/utils/v3/XpResponse.java
@@ -5,14 +5,14 @@ public class XpResponse {
private String errorMessage;
private Integer xpAmount;
private boolean transactionSuccess;
-
+
public XpResponse(String _errorMessage, boolean _transactionSuccess, Integer _xpAmount) {
super();
transactionSuccess = _transactionSuccess;
errorMessage = _errorMessage;
xpAmount = _xpAmount;
}
-
+
public XpResponse() {
super();
}
@@ -40,5 +40,4 @@ public void setXpAmount(Integer xpAmount) {
public void setTransactionSuccess(boolean transactionSuccess) {
this.transactionSuccess = transactionSuccess;
}
-
}
diff --git a/src/plugin.yml b/src/plugin.yml
index 47e28ae..63e06b7 100644
--- a/src/plugin.yml
+++ b/src/plugin.yml
@@ -5,6 +5,7 @@ description: Performs different item modifications with easy to use commands.
authors: [Justin Brubaker,JustBru00,jayoevans]
softdepend: [Vault]
api-version: 1.13
+folia-supported: true
commands:
rename: