diff --git a/.classpath b/.classpath
new file mode 100644
index 000000000..002ad570e
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
index 5c3982140..996d21d18 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,4 +33,5 @@ hs_err_pid*
.gitignore
QuickShop.iml
target/*
-build/
\ No newline at end of file
+build/
+/target/
diff --git a/.project b/.project
new file mode 100644
index 000000000..60e02fc11
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ QuickShop-Reremake
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 000000000..29abf9995
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=UTF-8
+encoding//src/test/resources=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..2f5cc74c3
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 000000000..f897a7f1c
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/src/main/java/org/maxgamer/quickshop/Util/Logger/QuickShopLogger.java b/src/main/java/org/maxgamer/quickshop/Util/Logger/QuickShopLogger.java
index 6fbd0186e..c2c7c4d37 100644
--- a/src/main/java/org/maxgamer/quickshop/Util/Logger/QuickShopLogger.java
+++ b/src/main/java/org/maxgamer/quickshop/Util/Logger/QuickShopLogger.java
@@ -29,132 +29,241 @@ import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import static org.bukkit.ChatColor.*;
+
/*
- * Code from MyPet, It is a awesome project!
+ * Originally take from Mypet which is a awesome project,
+ * directly extends from the Logger due to the colorful logging prefix.
+ *
+ * This is generally a new built logger system that
+ * rely on the Java logger to provide better customization.
+ *
+ * It is possible to switch to Log4j for better performance in the future.
*/
-public class QuickShopLogger extends PluginLogger {
+public class QuickShopLogger extends Logger {
protected boolean debugSetup = false;
- private final Map replacements = new HashMap<>();
- private static FileHandler debugLogFileHandler = null;
- private static boolean AnsiSupported = true;
- private String pluginName = "Unknown";
+
+ /**
+ * Mapping from the text pattern of Bukkit color to the corresponding text format of Ansi
+ */
+ private Map bukkitToAnsi;
+
+ // below are non-static for secret optimization
+ /**
+ * Regex that indicates the case insensitive
+ */
+ private String IGNORE_CASE;
+
+ //private FileHandler debugLogFileHandler = null;
+ private boolean AnsiSupported = true;
+ private String pluginName = "QuickShop";
- public QuickShopLogger(Plugin context) {
- super(context);
- try {
- if (Ansi.isEnabled()) {
- registerStyles();
- }
- } catch (NoClassDefFoundError e) {
- AnsiSupported = false;
- info("Your server doesn't support ANSI color, disabling color formatter...");
- }
-
-
- String prefix = context.getDescription().getPrefix();
- pluginName = prefix != null ? "[" + ChatColor.YELLOW+ prefix + ChatColor.RESET + "] " : "[" + ChatColor.YELLOW + context.getDescription().getName() + ChatColor.RESET + "] ";
- if (AnsiSupported) {
- pluginName = applyStyles(pluginName);
- }
-
- try {
- Field logger = ReflectionUtil.getField(PluginLogger.class, "pluginName");
- if (logger != null) {
- logger.set(this, pluginName);
- }
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- this.config();
- //super.setUseParentHandlers(false);
+ public QuickShopLogger(Plugin plugin) {
+ super(plugin.getClass().getCanonicalName(), null);
+
+ // Basic settings
+ setParent(plugin.getServer().getLogger());
+ setLevel(Level.ALL);
+
+ // Ansi setup
+ try {
+ if (Ansi.isEnabled())
+ registerStyles();
+ } catch (NoClassDefFoundError e) {
+ AnsiSupported = false;
+ info("Your server doesn't support ANSI color, disabled color formatter.");
+ }
+ // Logger naming
+ String prefix = plugin.getDescription().getPrefix();
+ pluginName = prefix != null ?
+ "[" + ChatColor.YELLOW + prefix + ChatColor.RESET + "] " :
+ "[" + ChatColor.YELLOW + plugin.getDescription().getName() + ChatColor.RESET + "] ";
+ pluginName = AnsiSupported ? applyStyles(pluginName) : pluginName;
+
+ this.config();
+ //super.setUseParentHandlers(false);
}
+
+ // Logging stuffs
public void log(LogRecord logRecord) {
- logRecord.setLoggerName("");
- String message = logRecord.getMessage();
- if (message != null) {
- if (logRecord.getLevel() == Level.WARNING) {
- message = ChatColor.YELLOW + message;
- }
- if (logRecord.getLevel() == Level.SEVERE) {
- message = ChatColor.RED + message;
- }
- if (AnsiSupported) {
- message = applyStyles(message);
- }
- logRecord.setMessage(message);
- }
+ logRecord.setLoggerName("");
+ String message = logRecord.getMessage();
+ if (message != null) {
+ if (logRecord.getLevel() == Level.WARNING) {
+ message = ChatColor.YELLOW + message;
+ }
+ if (logRecord.getLevel() == Level.SEVERE) {
+ message = ChatColor.RED + message;
+ }
+ if (AnsiSupported) {
+ message = applyStyles(message);
+ }
+ logRecord.setMessage(message);
+ }
- super.log(logRecord);
+ super.log(logRecord);
}
-
- public String applyStyles(String message) {
- for (ChatColor color : replacements.keySet()) {
- if (this.replacements.containsKey(color)) {
- message = message.replaceAll("(?i)" + color, this.replacements.get(color));
- } else {
- message = message.replaceAll("(?i)" + color, "");
- }
- }
- return message + Ansi.ansi().reset();
- }
-
- private void registerStyles() {
- this.replacements.put(ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString());
- this.replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString());
- this.replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString());
- this.replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString());
- this.replacements.put(ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString());
- this.replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString());
- this.replacements.put(ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString());
- this.replacements.put(ChatColor.GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString());
- this.replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString());
- this.replacements.put(ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString());
- this.replacements.put(ChatColor.GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString());
- this.replacements.put(ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString());
- this.replacements.put(ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString());
- this.replacements.put(ChatColor.LIGHT_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString());
- this.replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString());
- this.replacements.put(ChatColor.WHITE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString());
- this.replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString());
- this.replacements.put(ChatColor.BOLD, Ansi.ansi().a(Ansi.Attribute.UNDERLINE_DOUBLE).toString());
- this.replacements.put(ChatColor.STRIKETHROUGH, Ansi.ansi().a(Ansi.Attribute.STRIKETHROUGH_ON).toString());
- this.replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Ansi.Attribute.UNDERLINE).toString());
- this.replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Ansi.Attribute.ITALIC).toString());
- this.replacements.put(ChatColor.RESET, Ansi.ansi().a(Ansi.Attribute.RESET).toString());
- }
-
+
public void info(Object... params) {
- this.info(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
+ this.info(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
}
public void warning(Object... params) {
- this.warning(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
+ this.warning(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
}
public void severe(Object... params) {
- this.severe(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
+ this.severe(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
}
public void config(Object... params) {
- this.config(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
+ this.config(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
}
public void fine(Object... params) {
- this.fine(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
+ this.fine(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
}
public void finer(Object... params) {
- this.finer(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
+ this.finer(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
}
public void finest(Object... params) {
- this.finest(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
+ this.finest(Arrays.stream(params).map(String::valueOf).collect(Collectors.joining(" ")));
+ }
+
+ // Style stuffs
+ /**
+ * Apply Ansi styples to the specific message if it contains,
+ * internally converting Bukkit style color text to Ansi code.
+ * @param message to apply styles
+ * @return text maybe applied styles
+ */
+ public String applyStyles(String message) {
+ for (Entry entry : bukkitToAnsi.entrySet())
+ message = entry.getKey().matcher(message).replaceAll(entry.getValue());
+
+ return message.concat(Ansi.ansi().reset().toString());
+ }
+
+ /*
+ * This will compile patterns for Bukkit colors as the key,
+ * and stringify Ansi as the value, then register in to the system.
+ */
+ private void registerStyles() {
+ // Initial here for secert optimization
+ bukkitToAnsi = new HashMap();
+ IGNORE_CASE = "(?i)";
+
+ // Colors
+ regAnsiMapping(BLACK, Ansi.Color.BLACK);
+ regAnsiMapping(DARK_BLUE, Ansi.Color.BLUE);
+ regAnsiMapping(DARK_GREEN, Ansi.Color.GREEN);
+ regAnsiMapping(DARK_AQUA, Ansi.Color.CYAN);
+ regAnsiMapping(DARK_RED, Ansi.Color.RED);
+ regAnsiMapping(DARK_PURPLE, Ansi.Color.MAGENTA);
+ regAnsiMapping(GOLD, Ansi.Color.YELLOW);
+ regAnsiMapping(GRAY, Ansi.Color.WHITE);
+ regAnsiMapping(DARK_GRAY, Ansi.Color.BLACK, true);
+ regAnsiMapping(BLUE, Ansi.Color.BLUE, true);
+ regAnsiMapping(GREEN, Ansi.Color.GREEN, true);
+ regAnsiMapping(AQUA, Ansi.Color.CYAN, true);
+ regAnsiMapping(RED, Ansi.Color.RED, true);
+ regAnsiMapping(LIGHT_PURPLE, Ansi.Color.MAGENTA, true);
+ regAnsiMapping(YELLOW, Ansi.Color.YELLOW, true);
+ regAnsiMapping(WHITE, Ansi.Color.WHITE, true);
+
+ // Effects
+ regAnsiMapping(MAGIC, Ansi.Attribute.BLINK_SLOW);
+ regAnsiMapping(BOLD, Ansi.Attribute.UNDERLINE_DOUBLE);
+ regAnsiMapping(STRIKETHROUGH, Ansi.Attribute.STRIKETHROUGH_ON);
+ regAnsiMapping(UNDERLINE, Ansi.Attribute.UNDERLINE);
+ regAnsiMapping(ITALIC, Ansi.Attribute.ITALIC);
+ regAnsiMapping(RESET, Ansi.Attribute.RESET);
+ }
+
+ /*
+ * Register a mapping from Bukkit color to Ansi
+ */
+ private void regAnsiMapping(ChatColor bukkColor, Ansi.Color ansiColor) {
+ regAnsiMapping0(toPattern(bukkColor), toDesc(ansiColor));
+ }
+
+ /*
+ * Register a mapping from Bukkit color to Ansi
+ */
+ private void regAnsiMapping(ChatColor bukkColor, Ansi.Attribute ansiAttribute) {
+ regAnsiMapping0(toPattern(bukkColor), toDesc(ansiAttribute));
+ }
+
+ /*
+ * Register a mapping from Bukkit color to Ansi, with color option
+ */
+ private void regAnsiMapping(ChatColor bukkColor, Ansi.Color ansiColor, boolean intensity) {
+ regAnsiMapping0(toPattern(bukkColor), toDesc(ansiColor, intensity));
+ }
+
+ /*
+ * Register a mapping from the pattern of Bukkit color to the description of Ansi,
+ * and this is the genuine type for them to be registered.
+ */
+ private void regAnsiMapping0(Pattern bukkitPattern, String ansiDesc) {
+ this.bukkitToAnsi.put(bukkitPattern, ansiDesc);
+ }
+
+ /**
+ * Convert a Bukkit color to regex pattern
+ * @param bukkitColor the bukkit color
+ * @return the pattern
+ */
+ private Pattern toPattern(ChatColor bukkitColor) {
+ return Pattern.compile(IGNORE_CASE.concat(bukkitColor.toString()));
+ }
+
+ /**
+ * To populate a Ansi with a reset attribute ahead
+ * @param ansiColor
+ * @return Ansi with reset ahead
+ */
+ private Ansi resetWith(Ansi.Color ansiColor) {
+ return Ansi.ansi().a(Ansi.Attribute.RESET).fg(ansiColor);
+ }
+
+ /**
+ * Convert a Ansi to its description text
+ * @param ansiColor Ansi
+ * @param intensity Ansi color option
+ * @return stringified Ansi
+ */
+ private String toDesc(Ansi.Color ansiColor, boolean intensity) {
+ return intensity ? resetWith(ansiColor).bold().toString() : toDesc(ansiColor);
+ }
+
+ /**
+ * Convert a Ansi to its description text
+ * @param ansiColor Ansi
+ * @return stringified Ansi
+ */
+ private String toDesc(Ansi.Color ansiColor) {
+ return resetWith(ansiColor).boldOff().toString();
+ }
+
+ /**
+ * Convert a Ansi to its description text
+ * @param ansiAttribute Ansi
+ * @return stringified Ansi
+ */
+ private String toDesc(Ansi.Attribute ansiAttribute) {
+ return Ansi.ansi().a(Ansi.Attribute.RESET).toString();
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 510217968..03aadbcf7 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,7 +1,7 @@
name: ${name}
main: ${package}.${name}
version: ${project.version}
-authors: [BukkitCommonsStudio,Netherfoam, Timtower, KaiNoMood, Ghost_chu, Mgazul, TiaraRinne]
+authors: [BukkitCommonsStudio, Netherfoam, Timtower, KaiNoMood, Ghost_chu, Mgazul, TiaraRinne]
description: Economy Shops plugin
#softdepend: [Herochat, Vault, Essentials, OpenInv] OLD Remove Herochat support.