From 3af6063c992c83dcf86da0b880f441d1e1200fac Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 22 Apr 2017 02:17:52 +0200 Subject: [PATCH 1/9] Started #29, tried compile-time check, finished #29 Damn, annotation processors are complicated --- .factorypath | 2 ++ .gitignore | 1 + .settings/org.eclipse.jdt.core.prefs | 26 ++++++++------- .../javax.annotation.processing.Processor | 1 + .../buttondevteam/core/CommandCaller.java | 7 ++-- .../core/ScheduledRestartCommand.java | 17 ++-------- .../core/UpdatePluginCommand.java | 12 ++----- .../lib/AnnotationProcessor.java | 33 +++++++++++++++++++ .../buttondevteam/lib/chat/CommandClass.java | 29 ++++++++++++++++ .../java/buttondevteam/lib/chat/Format.java | 24 -------------- .../lib/chat/PlayerCommandBase.java | 16 +++++++++ .../buttondevteam/lib/chat/TBMCChatAPI.java | 5 +-- .../lib/chat/TBMCCommandBase.java | 21 +++--------- .../lib/player/ChromaGamerBase.java | 1 + .../lib/player/ChromaGamerEnforcer.java | 14 ++++++++ 15 files changed, 128 insertions(+), 81 deletions(-) create mode 100644 .factorypath create mode 100644 META-INF/services/javax.annotation.processing.Processor create mode 100644 src/main/java/buttondevteam/lib/AnnotationProcessor.java create mode 100644 src/main/java/buttondevteam/lib/chat/CommandClass.java delete mode 100644 src/main/java/buttondevteam/lib/chat/Format.java create mode 100644 src/main/java/buttondevteam/lib/chat/PlayerCommandBase.java create mode 100644 src/main/java/buttondevteam/lib/player/ChromaGamerEnforcer.java diff --git a/.factorypath b/.factorypath new file mode 100644 index 0000000..610dea5 --- /dev/null +++ b/.factorypath @@ -0,0 +1,2 @@ + + diff --git a/.gitignore b/.gitignore index 1917a1a..84dff78 100644 --- a/.gitignore +++ b/.gitignore @@ -224,3 +224,4 @@ TheButtonAutoFlair/out/artifacts/Autoflair/Autoflair.jar *.xml TBMC/ +/.apt_generated/ diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 672496e..edf183d 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,14 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.8 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.processAnnotations=enabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/META-INF/services/javax.annotation.processing.Processor b/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000..c52a464 --- /dev/null +++ b/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +buttondevteam.lib.AnnotationProcessor \ No newline at end of file diff --git a/src/main/java/buttondevteam/core/CommandCaller.java b/src/main/java/buttondevteam/core/CommandCaller.java index cb1b050..732f4ce 100644 --- a/src/main/java/buttondevteam/core/CommandCaller.java +++ b/src/main/java/buttondevteam/core/CommandCaller.java @@ -8,6 +8,8 @@ import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.PlayerCommandBase; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; @@ -69,11 +71,12 @@ public class CommandCaller implements CommandExecutor { } return true; } - if (cmd.GetModOnly() && !MainPlugin.permission.has(sender, "tbmc.admin")) { + if (cmd.getClass().getAnnotation(CommandClass.class).modOnly() + && !MainPlugin.permission.has(sender, "tbmc.admin")) { sender.sendMessage("§cYou need to be a mod to use this command."); return true; } - if (cmd.GetPlayerOnly() && !(sender instanceof Player)) { + if (cmd instanceof PlayerCommandBase && !(sender instanceof Player)) { sender.sendMessage("§cOnly ingame players can use this command."); return true; } diff --git a/src/main/java/buttondevteam/core/ScheduledRestartCommand.java b/src/main/java/buttondevteam/core/ScheduledRestartCommand.java index 77bc185..82090d2 100644 --- a/src/main/java/buttondevteam/core/ScheduledRestartCommand.java +++ b/src/main/java/buttondevteam/core/ScheduledRestartCommand.java @@ -9,8 +9,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitTask; import buttondevteam.lib.ScheduledServerRestartEvent; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCCommandBase; +@CommandClass(modOnly = true, path = "schrestart") public class ScheduledRestartCommand extends TBMCCommandBase { private static volatile int restartcounter; private static volatile BukkitTask restarttask; @@ -66,19 +68,4 @@ public class ScheduledRestartCommand extends TBMCCommandBase { "You can optionally set the amount of ticks to wait before the restart." // }; } - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return true; - } - - @Override - public String GetCommandPath() { - return "schrestart"; - } } diff --git a/src/main/java/buttondevteam/core/UpdatePluginCommand.java b/src/main/java/buttondevteam/core/UpdatePluginCommand.java index dab077e..06f5787 100644 --- a/src/main/java/buttondevteam/core/UpdatePluginCommand.java +++ b/src/main/java/buttondevteam/core/UpdatePluginCommand.java @@ -4,8 +4,10 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCCommandBase; +@CommandClass(modOnly = true) public class UpdatePluginCommand extends TBMCCommandBase { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { @@ -37,14 +39,4 @@ public class UpdatePluginCommand extends TBMCCommandBase { "To list the plugin names: /" + alias // }; } - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return true; - } } diff --git a/src/main/java/buttondevteam/lib/AnnotationProcessor.java b/src/main/java/buttondevteam/lib/AnnotationProcessor.java new file mode 100644 index 0000000..8e763ec --- /dev/null +++ b/src/main/java/buttondevteam/lib/AnnotationProcessor.java @@ -0,0 +1,33 @@ +package buttondevteam.lib; + +import java.util.List; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; + +import buttondevteam.lib.player.ChromaGamerEnforcer; + +/** * A simple session bean type annotation processor. The implementation * is based on the standard annotation processing API in Java 6. */ +@SupportedSourceVersion(SourceVersion.RELEASE_8) +public class AnnotationProcessor extends AbstractProcessor { + /** * Check if both @Stateful and @Stateless are present in an * session bean. If so, emits a warning message. */ + @Override + public boolean process(Set typeElements, RoundEnvironment roundEnv) { // TODO: SEparate JAR + Set elements = roundEnv.getElementsAnnotatedWith(ChromaGamerEnforcer.class); + for (Element element : elements) { + System.out.println("Processing " + element); + List annotationMirrors = element.getAnnotationMirrors(); + System.out.println("Annotations: " + annotationMirrors); + for (AnnotationMirror annotation : annotationMirrors) { + String type = annotation.getAnnotationType().toString(); + System.out.println("Type: " + type); + } + } + return true; // claim the annotations + } +} diff --git a/src/main/java/buttondevteam/lib/chat/CommandClass.java b/src/main/java/buttondevteam/lib/chat/CommandClass.java new file mode 100644 index 0000000..fd5ac9d --- /dev/null +++ b/src/main/java/buttondevteam/lib/chat/CommandClass.java @@ -0,0 +1,29 @@ +package buttondevteam.lib.chat; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface CommandClass { + /** + * Determines whether the command can only be used by mods and above or regular players can use it as well. + * + * @return If the command is mod only + */ + public boolean modOnly(); + + /** + * The command's path, or name if top-level command.
+ * For example:
+ * "u admin updateplugin" or "u" for the top level one
+ * The path must be lowercase!
+ * + * @return The command path, which is the command class name by default (removing any "command" from it) + */ + public String path() default ""; +} diff --git a/src/main/java/buttondevteam/lib/chat/Format.java b/src/main/java/buttondevteam/lib/chat/Format.java deleted file mode 100644 index b13d45b..0000000 --- a/src/main/java/buttondevteam/lib/chat/Format.java +++ /dev/null @@ -1,24 +0,0 @@ -package buttondevteam.lib.chat; - -public enum Format implements TellrawSerializableEnum { - Bold("bold"), Underlined("underlined"), Italic("italic"), Strikethrough("strikethrough"), Obfuscated( - "obfuscated"); - // TODO: Add format codes to /u c - private String name; - - Format(String name) { - this.name = name; - this.flag = 1 << this.ordinal(); - } - - @Override - public String getName() { - return name; - } - - private final int flag; - - public int getFlag() { - return flag; - } -} \ No newline at end of file diff --git a/src/main/java/buttondevteam/lib/chat/PlayerCommandBase.java b/src/main/java/buttondevteam/lib/chat/PlayerCommandBase.java new file mode 100644 index 0000000..66a60b9 --- /dev/null +++ b/src/main/java/buttondevteam/lib/chat/PlayerCommandBase.java @@ -0,0 +1,16 @@ +package buttondevteam.lib.chat; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public abstract class PlayerCommandBase extends TBMCCommandBase { + public abstract boolean OnCommand(Player player, String alias, String[] args); + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + if (sender instanceof Player) + return OnCommand((Player) sender, alias, args); + sender.sendMessage("§cYou need to be a player to use this command."); + return true; + } +} diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index b6317ee..0babdb8 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -61,9 +61,10 @@ public class TBMCChatAPI { }; for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) { if (cmd.GetCommandPath().startsWith(command + " ")) { - if (cmd.GetPlayerOnly() && !(sender instanceof Player)) + if (cmd instanceof PlayerCommandBase && !(sender instanceof Player)) continue; - if (cmd.GetModOnly() && !MainPlugin.permission.has(sender, "tbmc.admin")) + if (cmd.getClass().getAnnotation(CommandClass.class).modOnly() + && !MainPlugin.permission.has(sender, "tbmc.admin")) continue; int ind = cmd.GetCommandPath().indexOf(' ', command.length() + 2); if (ind >= 0) { diff --git a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java index 111e057..2c0cff4 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java @@ -27,24 +27,13 @@ public abstract class TBMCCommandBase { * * @return The command path, which is the command class name by default (removing any "command" from it) */ - public String GetCommandPath() { - return getClass().getSimpleName().toLowerCase().replace("command", ""); + public final String GetCommandPath() { + if (!getClass().isAnnotationPresent(CommandClass.class)) + throw new RuntimeException("No @Command annotation on command class " + getClass().getSimpleName() + "!"); + String path = getClass().getAnnotation(CommandClass.class).path(); + return path.length() == 0 ? getClass().getSimpleName().toLowerCase().replace("command", "") : path; } - /** - * Determines whether the command can only be used as a player, or command blocks or the console can use it as well. - * - * @return If the command is player only - */ - public abstract boolean GetPlayerOnly(); - - /** - * Determines whether the command can only be used by mods or regular players can use it as well. - * - * @return If the command is mod only - */ - public abstract boolean GetModOnly(); - Plugin plugin; // Used By TBMCChatAPI public final Plugin getPlugin() { // Used by CommandCaller (ButtonChat) diff --git a/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java b/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java index 944b676..d22d120 100644 --- a/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java +++ b/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java @@ -9,6 +9,7 @@ import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import buttondevteam.lib.TBMCCoreAPI; +@ChromaGamerEnforcer public abstract class ChromaGamerBase implements AutoCloseable { public static final String TBMC_PLAYERS_DIR = "TBMC/players/"; diff --git a/src/main/java/buttondevteam/lib/player/ChromaGamerEnforcer.java b/src/main/java/buttondevteam/lib/player/ChromaGamerEnforcer.java new file mode 100644 index 0000000..35ffdf4 --- /dev/null +++ b/src/main/java/buttondevteam/lib/player/ChromaGamerEnforcer.java @@ -0,0 +1,14 @@ +package buttondevteam.lib.player; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.TYPE) +@Inherited +public @interface ChromaGamerEnforcer { + +} From 672fab2d1b2cc6f4abb673ff8d7f8b86a0817818 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 22 Apr 2017 23:17:58 +0200 Subject: [PATCH 2/9] Fixed POM stuff --- pom.xml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 8609c02..ba1b5fd 100644 --- a/pom.xml +++ b/pom.xml @@ -9,12 +9,6 @@ src/main/java - - src - - **/*.java - - src/main/resources @@ -34,6 +28,7 @@ 1.8 1.8 + -proc:none @@ -76,7 +71,7 @@ target - resources + src/main/resources @@ -114,7 +109,7 @@ - org.apache.commons + commons-io commons-io 1.3.2 provided From bcf8cc4e991fe402a5593c3b2b9bdd236f88b96f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 23 Apr 2017 02:12:56 +0200 Subject: [PATCH 3/9] Probably mostly added support for ButtonChat cmds It's a whole different story --- .../buttondevteam/core/CommandCaller.java | 6 ---- .../lib/chat/OptionallyPlayerCommandBase.java | 30 +++++++++++++++++++ .../chat/OptionallyPlayerCommandClass.java | 20 +++++++++++++ .../lib/chat/PlayerCommandBase.java | 2 +- .../buttondevteam/lib/chat/TBMCChatAPI.java | 2 +- .../lib/chat/TBMCCommandBase.java | 25 ++++++++++++++-- 6 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 src/main/java/buttondevteam/lib/chat/OptionallyPlayerCommandBase.java create mode 100644 src/main/java/buttondevteam/lib/chat/OptionallyPlayerCommandClass.java diff --git a/src/main/java/buttondevteam/core/CommandCaller.java b/src/main/java/buttondevteam/core/CommandCaller.java index 732f4ce..42b5866 100644 --- a/src/main/java/buttondevteam/core/CommandCaller.java +++ b/src/main/java/buttondevteam/core/CommandCaller.java @@ -5,11 +5,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; -import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.PlayerCommandBase; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; @@ -76,10 +74,6 @@ public class CommandCaller implements CommandExecutor { sender.sendMessage("§cYou need to be a mod to use this command."); return true; } - if (cmd instanceof PlayerCommandBase && !(sender instanceof Player)) { - sender.sendMessage("§cOnly ingame players can use this command."); - return true; - } final String[] cmdargs = args.length > 0 ? Arrays.copyOfRange(args, args.length - argc, args.length) : args; try { if (!cmd.OnCommand(sender, alias, cmdargs)) { diff --git a/src/main/java/buttondevteam/lib/chat/OptionallyPlayerCommandBase.java b/src/main/java/buttondevteam/lib/chat/OptionallyPlayerCommandBase.java new file mode 100644 index 0000000..889cf76 --- /dev/null +++ b/src/main/java/buttondevteam/lib/chat/OptionallyPlayerCommandBase.java @@ -0,0 +1,30 @@ +package buttondevteam.lib.chat; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import buttondevteam.lib.TBMCCoreAPI; + +public abstract class OptionallyPlayerCommandBase extends TBMCCommandBase { + public boolean OnCommand(Player player, String alias, String[] args) { + if (getClass().isAnnotationPresent(OptionallyPlayerCommandClass.class) + && getClass().getAnnotation(OptionallyPlayerCommandClass.class).playerOnly()) + TBMCCoreAPI.SendException("Error while executing command " + getClass().getSimpleName() + "!", + new Exception( + "The PlayerCommand annotation is present and set to playerOnly but the Player overload isn't overriden!")); + return true; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + if (sender instanceof Player) + return OnCommand((Player) sender, alias, args); + if (!getClass().isAnnotationPresent(OptionallyPlayerCommandClass.class) + || !getClass().getAnnotation(OptionallyPlayerCommandClass.class).playerOnly()) + TBMCCoreAPI.SendException("Error while executing command " + getClass().getSimpleName() + "!", + new Exception( + "Command class doesn't override the CommandSender overload and no PlayerCommandClass annotation is present or playerOnly is false!")); + sender.sendMessage("§cYou need to be a player to use this command."); + return true; + } +} diff --git a/src/main/java/buttondevteam/lib/chat/OptionallyPlayerCommandClass.java b/src/main/java/buttondevteam/lib/chat/OptionallyPlayerCommandClass.java new file mode 100644 index 0000000..6cfd977 --- /dev/null +++ b/src/main/java/buttondevteam/lib/chat/OptionallyPlayerCommandClass.java @@ -0,0 +1,20 @@ +package buttondevteam.lib.chat; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Only needed to use with {@link OptionallyPlayerCommandBase} command classes + * + * @author NorbiPeti + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface OptionallyPlayerCommandClass { + public boolean playerOnly(); +} diff --git a/src/main/java/buttondevteam/lib/chat/PlayerCommandBase.java b/src/main/java/buttondevteam/lib/chat/PlayerCommandBase.java index 66a60b9..3b30ff5 100644 --- a/src/main/java/buttondevteam/lib/chat/PlayerCommandBase.java +++ b/src/main/java/buttondevteam/lib/chat/PlayerCommandBase.java @@ -7,7 +7,7 @@ public abstract class PlayerCommandBase extends TBMCCommandBase { public abstract boolean OnCommand(Player player, String alias, String[] args); @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { + public final boolean OnCommand(CommandSender sender, String alias, String[] args) { if (sender instanceof Player) return OnCommand((Player) sender, alias, args); sender.sendMessage("§cYou need to be a player to use this command."); diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index 0babdb8..a55dad0 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -61,7 +61,7 @@ public class TBMCChatAPI { }; for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) { if (cmd.GetCommandPath().startsWith(command + " ")) { - if (cmd instanceof PlayerCommandBase && !(sender instanceof Player)) + if (cmd.isPlayerOnly() && !(sender instanceof Player)) continue; if (cmd.getClass().getAnnotation(CommandClass.class).modOnly() && !MainPlugin.permission.has(sender, "tbmc.admin")) diff --git a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java index 2c0cff4..157dd1f 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java @@ -1,5 +1,7 @@ package buttondevteam.lib.chat; +import java.util.function.Function; + import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; @@ -30,8 +32,19 @@ public abstract class TBMCCommandBase { public final String GetCommandPath() { if (!getClass().isAnnotationPresent(CommandClass.class)) throw new RuntimeException("No @Command annotation on command class " + getClass().getSimpleName() + "!"); - String path = getClass().getAnnotation(CommandClass.class).path(); - return path.length() == 0 ? getClass().getSimpleName().toLowerCase().replace("command", "") : path; + Function, String> getFromClass = cl -> getClass().getSimpleName().toLowerCase() + .replace("commandbase", "").replace("command", ""); + String path = getClass().getAnnotation(CommandClass.class).path(), prevpath = path; // TODO: Check if annotation exists (No @Inherited?) + for (Class cl = getClass().getSuperclass(); cl != null + && !cl.getName().equals(TBMCCommandBase.class.getName()); cl = cl.getSuperclass()) { + //com.sun.xml.internal.bind.v2.TODO.prototype(); + String newpath = cl.getAnnotation(CommandClass.class).path(); + if (newpath.length() == 0) + newpath = getFromClass.apply(cl); + if (!newpath.equals(prevpath)) + path = (prevpath = newpath) + " " + path; + } + return path.length() == 0 ? getFromClass.apply(getClass()) : path; } Plugin plugin; // Used By TBMCChatAPI @@ -39,4 +52,12 @@ public abstract class TBMCCommandBase { public final Plugin getPlugin() { // Used by CommandCaller (ButtonChat) return plugin; } + + public final boolean isPlayerOnly() { + return this instanceof PlayerCommandBase ? true + : this instanceof OptionallyPlayerCommandBase + ? getClass().isAnnotationPresent(OptionallyPlayerCommandClass.class) + ? getClass().getAnnotation(OptionallyPlayerCommandClass.class).playerOnly() : true + : false; + } } From 308006d624c38c127b6b9b92054925fc53e10c0a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 30 Apr 2017 00:35:42 +0200 Subject: [PATCH 4/9] Chat channel improved, tried a bunch of ideas --- .../java/buttondevteam/core/MainPlugin.java | 55 +------- .../java/buttondevteam/lib/chat/Channel.java | 123 ++++++++++++++++-- .../lib/chat/ChatChannelRegisterEvent.java | 27 ++++ .../buttondevteam/lib/chat/TBMCChatAPI.java | 10 ++ 4 files changed, 159 insertions(+), 56 deletions(-) create mode 100644 src/main/java/buttondevteam/lib/chat/ChatChannelRegisterEvent.java diff --git a/src/main/java/buttondevteam/core/MainPlugin.java b/src/main/java/buttondevteam/core/MainPlugin.java index 9d48e81..df3f0ca 100644 --- a/src/main/java/buttondevteam/core/MainPlugin.java +++ b/src/main/java/buttondevteam/core/MainPlugin.java @@ -1,22 +1,21 @@ package buttondevteam.core; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; +import java.util.ArrayList; import java.util.logging.Logger; import org.bukkit.Bukkit; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scoreboard.Scoreboard; + +import com.palmergames.bukkit.towny.Towny; +import com.palmergames.bukkit.towny.object.Nation; +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.TownyUniverse; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.TBMCChatAPI; -import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.TBMCPlayerBase; import net.milkbowl.vault.permission.Permission; @@ -27,7 +26,6 @@ public class MainPlugin extends JavaPlugin { private PluginDescriptionFile pdfFile; private Logger logger; - private int C = 0, keep = 0; @Override public void onEnable() { @@ -43,45 +41,6 @@ public class MainPlugin extends JavaPlugin { TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class); logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ")."); - Arrays.stream(new File(ChromaGamerBase.TBMC_PLAYERS_DIR).listFiles(f -> !f.isDirectory())).map(f -> { - YamlConfiguration yc = new YamlConfiguration(); - try { - yc.load(f); - } catch (IOException | InvalidConfigurationException e) { - TBMCCoreAPI.SendException("Error while converting player data!", e); - } - f.delete(); - return yc; - }).forEach(yc -> { - try { - int flairtime = yc.getInt("flairtime"), fcount = yc.getInt("fcount"), fdeaths = yc.getInt("fdeaths"); - String flairstate = yc.getString("flairstate"); - List usernames = yc.getStringList("usernames"); - boolean flaircheater = yc.getBoolean("flaircheater"); - final String uuid = yc.getString("uuid"); - C++; - if ((fcount == 0 || fdeaths == 0) - && (flairstate == null || "NoComment".equals(flairstate) || flairtime <= 0)) - return; // Those who received no Fs yet will also get their stats reset if no flair - final File file = new File(ChromaGamerBase.TBMC_PLAYERS_DIR + "minecraft", uuid + ".yml"); - YamlConfiguration targetyc = YamlConfiguration.loadConfiguration(file); - targetyc.set("PlayerName", yc.getString("playername")); - targetyc.set("minecraft_id", uuid); - ConfigurationSection bc = targetyc.createSection("ButtonChat"); - bc.set("FlairTime", "NoComment".equals(flairstate) ? -3 : flairtime); // FlairTimeNone: -3 - bc.set("FCount", fcount); - bc.set("FDeaths", fdeaths); - bc.set("FlairState", flairstate); - bc.set("UserNames", usernames); - bc.set("FlairCheater", flaircheater); - targetyc.save(file); - keep++; - } catch (Exception e) { - TBMCCoreAPI.SendException("Error while converting player data!", e); - } - }); - Bukkit.getScheduler().runTask(this, () -> logger.info("Converted " + keep + " player data from " + C)); - //TODO: Remove once ran it at least once } @Override diff --git a/src/main/java/buttondevteam/lib/chat/Channel.java b/src/main/java/buttondevteam/lib/chat/Channel.java index 5a257a4..178a4fe 100644 --- a/src/main/java/buttondevteam/lib/chat/Channel.java +++ b/src/main/java/buttondevteam/lib/chat/Channel.java @@ -2,26 +2,60 @@ package buttondevteam.lib.chat; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; +import com.palmergames.bukkit.towny.object.Nation; +import com.palmergames.bukkit.towny.object.Resident; +import com.palmergames.bukkit.towny.object.Town; + +import buttondevteam.core.MainPlugin; public class Channel { public final String DisplayName; public final Color color; - public final String Command; + public final String ID; + /** + * Filters both the sender and the targets + */ + public final Function filteranderrormsg; private static List channels = new ArrayList<>(); - public Channel(String displayname, Color color, String command) { + /** + * Creates a channel. + * + * @param displayname + * The name that should appear at the start of the message + * @param color + * The default color of the messages sent in the channel + * @param command + * The command to be used for the channel without /. For example "mod". It's also used for scoreboard objective names. + * @param filteranderrormsg + * Checks all senders against the criteria provided here and sends the message returned if it has an index - otherwise displays the error.
+ * May be null to send to everyone. + */ + public Channel(String displayname, Color color, String command, + Function filteranderrormsg) { DisplayName = displayname; this.color = color; - Command = command; + ID = command; + this.filteranderrormsg = filteranderrormsg; } static { - channels.add(GlobalChat = new Channel("§fg§f", Color.White, "g")); - channels.add(TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc")); - channels.add(NationChat = new Channel("§6NC§f", Color.Gold, "nc")); - channels.add(AdminChat = new Channel("§cADMIN§f", Color.Red, "a")); - channels.add(ModChat = new Channel("§9MOD§f", Color.Blue, "mod")); + RegisterChannel(GlobalChat = new Channel("§fg§f", Color.White, "g", null)); + RegisterChannel(TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); + RegisterChannel(NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true))); + RegisterChannel(AdminChat = new Channel("§cADMIN§f", Color.Red, "a", s -> s.isOp() ? new RecipientTestResult(0) + : new RecipientTestResult("You need to be an admin to use this channel."))); + RegisterChannel(ModChat = new Channel("§9MOD§f", Color.Blue, "mod", + s -> s.isOp() || (s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, "mod")) + ? new RecipientTestResult(0) // + : new RecipientTestResult("You need to be a mod to use this channel."))); } public static List getChannels() { @@ -33,4 +67,77 @@ public class Channel { public static Channel NationChat; public static Channel AdminChat; public static Channel ModChat; + + static void RegisterChannel(Channel channel) { + channels.add(channel); + Bukkit.getPluginManager().callEvent(new ChatChannelRegisterEvent(channel)); + } + + /** + * Return the error message for the message sender if they can't send it and the score + */ + private static RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) { + if (!(sender instanceof Player)) + return new RecipientTestResult("§cYou are not a player!"); + try { + Resident resident = MainPlugin.TU.getResidentMap().get(sender.getName().toLowerCase()); + if (resident != null && resident.getModes().contains("spy")) + return null; + /* + * p.sendMessage(String.format("[SPY-%s] - %s: %s", channel.DisplayName, ((Player) sender).getDisplayName(), message)); + */ + Town town = null; + if (resident != null && resident.hasTown()) + town = resident.getTown(); + if (town == null) + return new RecipientTestResult("You aren't in a town."); + Nation nation = null; + int index = -1; // TODO: Move all this to the event in ButtonChat along with the channel definitions and make scores only for the sender... + if (nationchat) { + if (town.hasNation()) + nation = town.getNation(); + if (nation == null) + return new RecipientTestResult("Your town isn't in a nation."); + index = MainPlugin.Nations.indexOf(nation); + if (index < 0) { + MainPlugin.Nations.add(nation); + index = MainPlugin.Nations.size() - 1; + } + } else { + index = MainPlugin.Towns.indexOf(town); + if (index < 0) { + MainPlugin.Towns.add(town); + index = MainPlugin.Towns.size() - 1; + } + } + return new RecipientTestResult(index); + } catch (NotRegisteredException e) { + return new RecipientTestResult("You (probably) aren't knwon by Towny! (Not in a town)"); + } + } + + public static class RecipientTestResult { + public String errormessage; + public int score; + + /** + * Creates a result that indicates an error + * + * @param errormessage + * The error message to show the sender if they don't meet the criteria. + */ + public RecipientTestResult(String errormessage) { + this.errormessage = errormessage; + } + + /** + * Creates a result that indicates a success + * + * @param score + * The score that identifies the target group. For example, the index of the town or nation to send to. + */ + public RecipientTestResult(int score) { + this.score = score; + } // TODO: Set score of players, if they get one, otherwise (on error) set score to -1 + } } diff --git a/src/main/java/buttondevteam/lib/chat/ChatChannelRegisterEvent.java b/src/main/java/buttondevteam/lib/chat/ChatChannelRegisterEvent.java new file mode 100644 index 0000000..d10c54b --- /dev/null +++ b/src/main/java/buttondevteam/lib/chat/ChatChannelRegisterEvent.java @@ -0,0 +1,27 @@ +package buttondevteam.lib.chat; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ChatChannelRegisterEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + + private Channel channel; + + public ChatChannelRegisterEvent(Channel channel) { + this.channel = channel; + } + + public Channel getChannel() { + return channel; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index a55dad0..cbad418 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -215,4 +215,14 @@ public class TBMCChatAPI { Bukkit.getPluginManager().callEvent(event); return event.isCancelled(); } + + /** + * Register a chat channel. See {@link Channel#Channel(String, Color, String, java.util.function.Function)} for details. + * + * @param channel + * A new {@link Channel} to register + */ + public static void RegisterChatChannel(Channel channel) { + Channel.RegisterChannel(channel); + } } From 9a61047cd270fb57d54a4ec525418eb0f56e9ff2 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 6 May 2017 19:55:21 +0200 Subject: [PATCH 5/9] Chat channels probably done, needs testing --- .../java/buttondevteam/lib/TBMCChatEvent.java | 30 ++++++++++- .../java/buttondevteam/lib/chat/Channel.java | 51 +------------------ .../buttondevteam/lib/chat/TBMCChatAPI.java | 18 ++++++- 3 files changed, 47 insertions(+), 52 deletions(-) diff --git a/src/main/java/buttondevteam/lib/TBMCChatEvent.java b/src/main/java/buttondevteam/lib/TBMCChatEvent.java index 21c84b3..192b7c1 100644 --- a/src/main/java/buttondevteam/lib/TBMCChatEvent.java +++ b/src/main/java/buttondevteam/lib/TBMCChatEvent.java @@ -6,7 +6,14 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.Channel.RecipientTestResult; +/** + * Make sure to only send the message to users who {@link #shouldSendTo(CommandSender)} returns true. + * + * @author NorbiPeti + * + */ public class TBMCChatEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); @@ -14,11 +21,13 @@ public class TBMCChatEvent extends Event implements Cancellable { private CommandSender sender; private String message; private boolean cancelled; + private int score; - public TBMCChatEvent(CommandSender sender, Channel channel, String message) { + public TBMCChatEvent(CommandSender sender, Channel channel, String message, int score) { this.sender = sender; this.channel = channel; this.message = message; // TODO: Message object with data? + this.score = score; } /* @@ -56,4 +65,23 @@ public class TBMCChatEvent extends Event implements Cancellable { this.cancelled = cancelled; } + /** + * Note: Errors are sent to the sender automatically + */ + public boolean shouldSendTo(CommandSender sender) { + if (channel.filteranderrormsg == null) + return true; + RecipientTestResult result = channel.filteranderrormsg.apply(sender); + return result.errormessage == null && score == result.score; + } + + /** + * Note: Errors are sent to the sender automatically + */ + public int getMCScore(CommandSender sender) { + if (channel.filteranderrormsg == null) + return 0; + RecipientTestResult result = channel.filteranderrormsg.apply(sender); + return result.errormessage == null ? result.score : -1; + } } diff --git a/src/main/java/buttondevteam/lib/chat/Channel.java b/src/main/java/buttondevteam/lib/chat/Channel.java index 178a4fe..8054baf 100644 --- a/src/main/java/buttondevteam/lib/chat/Channel.java +++ b/src/main/java/buttondevteam/lib/chat/Channel.java @@ -35,7 +35,7 @@ public class Channel { * @param command * The command to be used for the channel without /. For example "mod". It's also used for scoreboard objective names. * @param filteranderrormsg - * Checks all senders against the criteria provided here and sends the message returned if it has an index - otherwise displays the error.
+ * Checks all senders against the criteria provided here and sends the message if the index matches the sender's - if no score at all, displays the error.
* May be null to send to everyone. */ public Channel(String displayname, Color color, String command, @@ -48,8 +48,6 @@ public class Channel { static { RegisterChannel(GlobalChat = new Channel("§fg§f", Color.White, "g", null)); - RegisterChannel(TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); - RegisterChannel(NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true))); RegisterChannel(AdminChat = new Channel("§cADMIN§f", Color.Red, "a", s -> s.isOp() ? new RecipientTestResult(0) : new RecipientTestResult("You need to be an admin to use this channel."))); RegisterChannel(ModChat = new Channel("§9MOD§f", Color.Blue, "mod", @@ -63,8 +61,6 @@ public class Channel { } public static Channel GlobalChat; - public static Channel TownChat; - public static Channel NationChat; public static Channel AdminChat; public static Channel ModChat; @@ -73,49 +69,6 @@ public class Channel { Bukkit.getPluginManager().callEvent(new ChatChannelRegisterEvent(channel)); } - /** - * Return the error message for the message sender if they can't send it and the score - */ - private static RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) { - if (!(sender instanceof Player)) - return new RecipientTestResult("§cYou are not a player!"); - try { - Resident resident = MainPlugin.TU.getResidentMap().get(sender.getName().toLowerCase()); - if (resident != null && resident.getModes().contains("spy")) - return null; - /* - * p.sendMessage(String.format("[SPY-%s] - %s: %s", channel.DisplayName, ((Player) sender).getDisplayName(), message)); - */ - Town town = null; - if (resident != null && resident.hasTown()) - town = resident.getTown(); - if (town == null) - return new RecipientTestResult("You aren't in a town."); - Nation nation = null; - int index = -1; // TODO: Move all this to the event in ButtonChat along with the channel definitions and make scores only for the sender... - if (nationchat) { - if (town.hasNation()) - nation = town.getNation(); - if (nation == null) - return new RecipientTestResult("Your town isn't in a nation."); - index = MainPlugin.Nations.indexOf(nation); - if (index < 0) { - MainPlugin.Nations.add(nation); - index = MainPlugin.Nations.size() - 1; - } - } else { - index = MainPlugin.Towns.indexOf(town); - if (index < 0) { - MainPlugin.Towns.add(town); - index = MainPlugin.Towns.size() - 1; - } - } - return new RecipientTestResult(index); - } catch (NotRegisteredException e) { - return new RecipientTestResult("You (probably) aren't knwon by Towny! (Not in a town)"); - } - } - public static class RecipientTestResult { public String errormessage; public int score; @@ -138,6 +91,6 @@ public class Channel { */ public RecipientTestResult(int score) { this.score = score; - } // TODO: Set score of players, if they get one, otherwise (on error) set score to -1 + } } } diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index cbad418..5dd1bdf 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -20,6 +20,7 @@ import buttondevteam.core.CommandCaller; import buttondevteam.core.MainPlugin; import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.Channel.RecipientTestResult; public class TBMCChatAPI { @@ -200,7 +201,7 @@ public class TBMCChatAPI { } /** - * Sends a chat message to Minecraft + * Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}. * * @param channel * The channel to send to @@ -211,7 +212,20 @@ public class TBMCChatAPI { * @return The event cancelled state */ public static boolean SendChatMessage(Channel channel, CommandSender sender, String message) { - TBMCChatEvent event = new TBMCChatEvent(sender, channel, message); + if (!Channel.getChannels().contains(channel)) + throw new RuntimeException("Channel " + channel.DisplayName + " not registered!"); + int score; + if (channel.filteranderrormsg == null) + score = -1; + else { + RecipientTestResult result = channel.filteranderrormsg.apply(sender); + if (result.errormessage != null) { + sender.sendMessage("§c" + result.errormessage); + return true; + } + score = result.score; + } + TBMCChatEvent event = new TBMCChatEvent(sender, channel, message, score); Bukkit.getPluginManager().callEvent(event); return event.isCancelled(); } From f5ce88faf69683eb0284351267af68b7e22eb12b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 7 May 2017 01:08:13 +0200 Subject: [PATCH 6/9] Fixed channels a bit --- .../java/buttondevteam/core/MainPlugin.java | 23 +++++++++++-------- .../java/buttondevteam/core/TestPrepare.java | 5 ++++ .../java/buttondevteam/lib/chat/Channel.java | 17 -------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/main/java/buttondevteam/core/MainPlugin.java b/src/main/java/buttondevteam/core/MainPlugin.java index df3f0ca..b8ae2da 100644 --- a/src/main/java/buttondevteam/core/MainPlugin.java +++ b/src/main/java/buttondevteam/core/MainPlugin.java @@ -1,21 +1,16 @@ package buttondevteam.core; -import java.util.ArrayList; import java.util.logging.Logger; -import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scoreboard.Scoreboard; - -import com.palmergames.bukkit.towny.Towny; -import com.palmergames.bukkit.towny.object.Nation; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; - import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.TBMCChatAPI; +import buttondevteam.lib.chat.Channel.RecipientTestResult; import buttondevteam.lib.player.TBMCPlayerBase; import net.milkbowl.vault.permission.Permission; @@ -40,7 +35,15 @@ public class MainPlugin extends JavaPlugin { TBMCChatAPI.AddCommand(this, ScheduledRestartCommand.class); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class); - logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ")."); + TBMCChatAPI.RegisterChatChannel(Channel.GlobalChat = new Channel("§fg§f", Color.White, "g", null)); + TBMCChatAPI.RegisterChatChannel( + Channel.AdminChat = new Channel("§cADMIN§f", Color.Red, "a", s -> s.isOp() ? new RecipientTestResult(0) + : new RecipientTestResult("You need to be an admin to use this channel."))); + TBMCChatAPI.RegisterChatChannel(Channel.ModChat = new Channel("§9MOD§f", Color.Blue, "mod", + s -> s.isOp() || (s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, "mod")) + ? new RecipientTestResult(0) // + : new RecipientTestResult("You need to be a mod to use this channel."))); + logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ") Test: " + Test + "."); } @Override diff --git a/src/main/java/buttondevteam/core/TestPrepare.java b/src/main/java/buttondevteam/core/TestPrepare.java index e135a6a..027128b 100644 --- a/src/main/java/buttondevteam/core/TestPrepare.java +++ b/src/main/java/buttondevteam/core/TestPrepare.java @@ -11,6 +11,10 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.Color; +import buttondevteam.lib.chat.TBMCChatAPI; + public class TestPrepare { public static void PrepareServer() { Bukkit.setServer(Mockito.mock(Server.class, new Answer() { @@ -34,5 +38,6 @@ public class TestPrepare { return cl.isAssignableFrom(invocation.getMethod().getReturnType()); } })); + TBMCChatAPI.RegisterChatChannel(Channel.GlobalChat = new Channel("§fg§f", Color.White, "g", null)); } } diff --git a/src/main/java/buttondevteam/lib/chat/Channel.java b/src/main/java/buttondevteam/lib/chat/Channel.java index 8054baf..cfb86a7 100644 --- a/src/main/java/buttondevteam/lib/chat/Channel.java +++ b/src/main/java/buttondevteam/lib/chat/Channel.java @@ -6,13 +6,6 @@ import java.util.function.Function; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Nation; -import com.palmergames.bukkit.towny.object.Resident; -import com.palmergames.bukkit.towny.object.Town; - -import buttondevteam.core.MainPlugin; public class Channel { public final String DisplayName; @@ -46,16 +39,6 @@ public class Channel { this.filteranderrormsg = filteranderrormsg; } - static { - RegisterChannel(GlobalChat = new Channel("§fg§f", Color.White, "g", null)); - RegisterChannel(AdminChat = new Channel("§cADMIN§f", Color.Red, "a", s -> s.isOp() ? new RecipientTestResult(0) - : new RecipientTestResult("You need to be an admin to use this channel."))); - RegisterChannel(ModChat = new Channel("§9MOD§f", Color.Blue, "mod", - s -> s.isOp() || (s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, "mod")) - ? new RecipientTestResult(0) // - : new RecipientTestResult("You need to be a mod to use this channel."))); - } - public static List getChannels() { return channels; } From acebf37359d249f9dc42dcda93a9afafa070b0ed Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 13 May 2017 16:08:45 +0200 Subject: [PATCH 7/9] Addede chat preprocess event --- .../lib/TBMCChatPreprocessEvent.java | 68 +++++++++++++++++++ .../buttondevteam/lib/chat/TBMCChatAPI.java | 7 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/main/java/buttondevteam/lib/TBMCChatPreprocessEvent.java diff --git a/src/main/java/buttondevteam/lib/TBMCChatPreprocessEvent.java b/src/main/java/buttondevteam/lib/TBMCChatPreprocessEvent.java new file mode 100644 index 0000000..8f8f9d2 --- /dev/null +++ b/src/main/java/buttondevteam/lib/TBMCChatPreprocessEvent.java @@ -0,0 +1,68 @@ +package buttondevteam.lib; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import buttondevteam.lib.chat.Channel; + +/** + * Can be used to change messages before it's sent. + * + * @author NorbiPeti + * + */ +public class TBMCChatPreprocessEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + + private Channel channel; + private CommandSender sender; + private String message; + private boolean cancelled; + + public TBMCChatPreprocessEvent(CommandSender sender, Channel channel, String message) { + this.sender = sender; + this.channel = channel; + this.message = message; // TODO: Message object with data? + } + + /* + * public TBMCPlayer getPlayer() { return TBMCPlayer.getPlayer(sender); // TODO: Get Chroma user } + */ + + public Channel getChannel() { + return channel; + } + + public CommandSender getSender() { + return sender; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } +} diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index 5dd1bdf..86e7c37 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -19,6 +19,7 @@ import org.reflections.util.ConfigurationBuilder; import buttondevteam.core.CommandCaller; import buttondevteam.core.MainPlugin; import buttondevteam.lib.TBMCChatEvent; +import buttondevteam.lib.TBMCChatPreprocessEvent; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.Channel.RecipientTestResult; @@ -214,6 +215,10 @@ public class TBMCChatAPI { public static boolean SendChatMessage(Channel channel, CommandSender sender, String message) { if (!Channel.getChannels().contains(channel)) throw new RuntimeException("Channel " + channel.DisplayName + " not registered!"); + TBMCChatPreprocessEvent eventPre = new TBMCChatPreprocessEvent(sender, channel, message); + Bukkit.getPluginManager().callEvent(eventPre); + if (eventPre.isCancelled()) + return true; int score; if (channel.filteranderrormsg == null) score = -1; @@ -225,7 +230,7 @@ public class TBMCChatAPI { } score = result.score; } - TBMCChatEvent event = new TBMCChatEvent(sender, channel, message, score); + TBMCChatEvent event = new TBMCChatEvent(sender, channel, eventPre.getMessage(), score); Bukkit.getPluginManager().callEvent(event); return event.isCancelled(); } From 4a5479b0271884dc7367cb3d78fded722b9b065d Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 14 May 2017 01:13:34 +0200 Subject: [PATCH 8/9] COMMANDS WORK - YE #29 --- .../buttondevteam/core/CommandCaller.java | 30 +++++------ .../java/buttondevteam/lib/TBMCCoreAPI.java | 53 +++++++++++-------- .../buttondevteam/lib/chat/CommandClass.java | 12 +++++ .../buttondevteam/lib/chat/TBMCChatAPI.java | 28 ++++++---- .../lib/chat/TBMCCommandBase.java | 46 +++++++++++----- 5 files changed, 104 insertions(+), 65 deletions(-) diff --git a/src/main/java/buttondevteam/core/CommandCaller.java b/src/main/java/buttondevteam/core/CommandCaller.java index 42b5866..50a65a9 100644 --- a/src/main/java/buttondevteam/core/CommandCaller.java +++ b/src/main/java/buttondevteam/core/CommandCaller.java @@ -13,42 +13,36 @@ import buttondevteam.lib.chat.TBMCCommandBase; public class CommandCaller implements CommandExecutor { - private static final String REGISTER_ERROR_MSG = "An error occured while registering commands"; - private CommandCaller() { } private static CommandCaller instance; - public static void RegisterCommand(TBMCCommandBase cmd) { + public static void RegisterCommand(TBMCCommandBase cmd) throws Exception { if (instance == null) instance = new CommandCaller(); - if (cmd.GetCommandPath() == null) { - TBMCCoreAPI.SendException(REGISTER_ERROR_MSG, - new Exception("Command " + cmd.getClass().getSimpleName() + " has no command path!")); - return; - } - if (cmd.getPlugin() == null) { - TBMCCoreAPI.SendException(REGISTER_ERROR_MSG, - new Exception("Command " + cmd.GetCommandPath() + " has no plugin!")); - return; - } + String topcmd = cmd.GetCommandPath(); + if (topcmd == null) + throw new Exception("Command " + cmd.getClass().getSimpleName() + " has no command path!"); + if (cmd.getPlugin() == null) + throw new Exception("Command " + cmd.GetCommandPath() + " has no plugin!"); int i; - String topcmd; - if ((i = (topcmd = cmd.GetCommandPath()).indexOf(' ')) != -1) // Get top-level command - topcmd = cmd.GetCommandPath().substring(0, i); + if ((i = topcmd.indexOf(' ')) != -1) // Get top-level command + topcmd = topcmd.substring(0, i); { PluginCommand pc = ((JavaPlugin) cmd.getPlugin()).getCommand(topcmd); if (pc == null) - TBMCCoreAPI.SendException(REGISTER_ERROR_MSG, new Exception("Top level command " + topcmd - + " not registered in plugin.yml for plugin: " + cmd.getPlugin().getName())); + throw new Exception("Top level command " + topcmd + " not registered in plugin.yml for plugin: " + + cmd.getPlugin().getName()); else pc.setExecutor(instance); + System.out.println("Executor set"); } } @Override public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { + System.out.println("onCommand called"); String path = command.getName().toLowerCase(); for (String arg : args) path += " " + arg; diff --git a/src/main/java/buttondevteam/lib/TBMCCoreAPI.java b/src/main/java/buttondevteam/lib/TBMCCoreAPI.java index 469095e..a80923c 100644 --- a/src/main/java/buttondevteam/lib/TBMCCoreAPI.java +++ b/src/main/java/buttondevteam/lib/TBMCCoreAPI.java @@ -201,8 +201,10 @@ public class TBMCCoreAPI { SendUnsentExceptions(); TBMCExceptionEvent event = new TBMCExceptionEvent(sourcemsg, e); Bukkit.getPluginManager().callEvent(event); - if (!event.isHandled()) - exceptionsToSend.put(sourcemsg, e); + synchronized (exceptionsToSend) { + if (!event.isHandled()) + exceptionsToSend.put(sourcemsg, e); + } Bukkit.getLogger().warning(sourcemsg); e.printStackTrace(); if (debugPotato) { @@ -212,7 +214,6 @@ public class TBMCCoreAPI { devsOnline.add(player); } } - ; if (!devsOnline.isEmpty()) { DebugPotato potato = new DebugPotato() .setMessage(new String[] { // @@ -234,8 +235,10 @@ public class TBMCCoreAPI { SendUnsentDebugMessages(); TBMCDebugMessageEvent event = new TBMCDebugMessageEvent(debugMessage); Bukkit.getPluginManager().callEvent(event); - if (!event.isSent()) - debugMessagesToSend.add(debugMessage); + synchronized (debugMessagesToSend) { + if (!event.isSent()) + debugMessagesToSend.add(debugMessage); + } } /** @@ -258,28 +261,32 @@ public class TBMCCoreAPI { * Send exceptions that haven't been sent (their events didn't get handled). This method is used by the DiscordPlugin's ready event */ public static void SendUnsentExceptions() { - if (exceptionsToSend.size() > 20) { - exceptionsToSend.clear(); // Don't call more and more events if all the handler plugins are unloaded - Bukkit.getLogger().warning("Unhandled exception list is over 20! Clearing!"); - } - for (Entry entry : exceptionsToSend.entrySet()) { - TBMCExceptionEvent event = new TBMCExceptionEvent(entry.getKey(), entry.getValue()); - Bukkit.getPluginManager().callEvent(event); - if (event.isHandled()) - exceptionsToSend.remove(entry.getKey()); + synchronized (exceptionsToSend) { + if (exceptionsToSend.size() > 20) { + exceptionsToSend.clear(); // Don't call more and more events if all the handler plugins are unloaded + Bukkit.getLogger().warning("Unhandled exception list is over 20! Clearing!"); + } + for (Entry entry : exceptionsToSend.entrySet()) { + TBMCExceptionEvent event = new TBMCExceptionEvent(entry.getKey(), entry.getValue()); + Bukkit.getPluginManager().callEvent(event); + if (event.isHandled()) + exceptionsToSend.remove(entry.getKey()); + } } } public static void SendUnsentDebugMessages() { - if (debugMessagesToSend.size() > 20) { - debugMessagesToSend.clear(); // Don't call more and more DebugMessages if all the handler plugins are unloaded - Bukkit.getLogger().warning("Unhandled Debug Message list is over 20! Clearing!"); - } - for (String message : debugMessagesToSend) { - TBMCDebugMessageEvent event = new TBMCDebugMessageEvent(message); - Bukkit.getPluginManager().callEvent(event); - if (event.isSent()) - debugMessagesToSend.remove(message); + synchronized (debugMessagesToSend) { + if (debugMessagesToSend.size() > 20) { + debugMessagesToSend.clear(); // Don't call more and more DebugMessages if all the handler plugins are unloaded + Bukkit.getLogger().warning("Unhandled Debug Message list is over 20! Clearing!"); + } + for (String message : debugMessagesToSend) { + TBMCDebugMessageEvent event = new TBMCDebugMessageEvent(message); + Bukkit.getPluginManager().callEvent(event); + if (event.isSent()) + debugMessagesToSend.remove(message); + } } } diff --git a/src/main/java/buttondevteam/lib/chat/CommandClass.java b/src/main/java/buttondevteam/lib/chat/CommandClass.java index fd5ac9d..1a49d87 100644 --- a/src/main/java/buttondevteam/lib/chat/CommandClass.java +++ b/src/main/java/buttondevteam/lib/chat/CommandClass.java @@ -6,6 +6,13 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Abstract classes with no {@link CommandClass} annotations will be ignored. Classes that are not abstract or have the annotation will be included in the command path unless + * {@link #excludeFromPath()} is true. + * + * @author NorbiPeti + * + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Inherited @@ -26,4 +33,9 @@ public @interface CommandClass { * @return The command path, which is the command class name by default (removing any "command" from it) */ public String path() default ""; + + /** + * Exclude this class from the path. Useful if more commands share some property but aren't subcommands of a common command. See {@link CommandClass} for more details. + */ + public boolean excludeFromPath() default false; } diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index 86e7c37..50b0086 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -4,6 +4,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.Map.Entry; import java.util.Set; import java.util.function.Consumer; @@ -61,20 +62,20 @@ public class TBMCChatAPI { cmds.add("§6---- Subcommands ----"); cmds.add(cmd); }; - for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) { - if (cmd.GetCommandPath().startsWith(command + " ")) { - if (cmd.isPlayerOnly() && !(sender instanceof Player)) + for (Entry cmd : TBMCChatAPI.GetCommands().entrySet()) { + if (cmd.getKey().startsWith(command + " ")) { + if (cmd.getValue().isPlayerOnly() && !(sender instanceof Player)) continue; if (cmd.getClass().getAnnotation(CommandClass.class).modOnly() && !MainPlugin.permission.has(sender, "tbmc.admin")) continue; - int ind = cmd.GetCommandPath().indexOf(' ', command.length() + 2); + int ind = cmd.getKey().indexOf(' ', command.length() + 2); if (ind >= 0) { - String newcmd = cmd.GetCommandPath().substring(0, ind); + String newcmd = cmd.getKey().substring(0, ind); if (!cmds.contains("/" + newcmd)) addToCmds.accept("/" + newcmd); } else - addToCmds.accept("/" + cmd.GetCommandPath()); + addToCmds.accept("/" + cmd.getKey()); } } return cmds.toArray(new String[cmds.size()]); @@ -99,15 +100,22 @@ public class TBMCChatAPI { * @param acmdclass * A command's class to get the package name for commands. The provided class's package and subpackages are scanned for commands. */ - public static void AddCommands(JavaPlugin plugin, Class acmdclass) { - plugin.getLogger().info("Registering commands for " + plugin.getName()); + public static synchronized void AddCommands(JavaPlugin plugin, Class acmdclass) { + plugin.getLogger().info("Registering commands from " + acmdclass.getPackage().getName()); Reflections rf = new Reflections(new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage(acmdclass.getPackage().getName(), plugin.getClass().getClassLoader())) + .addUrls( + ClasspathHelper.forClass(OptionallyPlayerCommandBase.class, + OptionallyPlayerCommandBase.class.getClassLoader()), + ClasspathHelper.forClass(PlayerCommandBase.class, PlayerCommandBase.class.getClassLoader())) // http://stackoverflow.com/questions/12917417/using-reflections-for-finding-the-transitive-subtypes-of-a-class-when-not-all .addClassLoader(plugin.getClass().getClassLoader()).addScanners(new SubTypesScanner())); Set> cmds = rf.getSubTypesOf(TBMCCommandBase.class); for (Class cmd : cmds) { try { + if (!cmd.getPackage().getName().startsWith(acmdclass.getPackage().getName())) + continue; // It keeps including the commands from here + //System.out.println("Class found: " + cmd.getName()); if (Modifier.isAbstract(cmd.getModifiers())) continue; TBMCCommandBase c = cmd.newInstance(); @@ -116,9 +124,7 @@ public class TBMCChatAPI { continue; commands.put(c.GetCommandPath(), c); CommandCaller.RegisterCommand(c); - } catch (InstantiationException e) { - TBMCCoreAPI.SendException("An error occured while registering command " + cmd.getName(), e); - } catch (IllegalAccessException e) { + } catch (Exception e) { TBMCCoreAPI.SendException("An error occured while registering command " + cmd.getName(), e); } } diff --git a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java index 157dd1f..e751a9a 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java @@ -5,9 +5,11 @@ import java.util.function.Function; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; +import javassist.Modifier; + /** * Extend this class to create new TBMCCommand and use {@link TBMCChatAPI#AddCommand(org.bukkit.plugin.java.JavaPlugin, TBMCCommandBase)} to add it. Note: The command path (command name - * and subcommand arguments) will be the class name by default, removing any "command" from it. To change it (especially for subcommands), override {@link #GetCommandPath()}. + * and subcommand arguments) will be the class name by default, removing any "command" from it. To change it (especially for subcommands), use the path field in the {@link CommandClass} annotation. * * @author Norbi * @@ -15,36 +17,54 @@ import org.bukkit.plugin.Plugin; public abstract class TBMCCommandBase { public TBMCCommandBase() { + path = getcmdpath(); } public abstract boolean OnCommand(CommandSender sender, String alias, String[] args); public abstract String[] GetHelpText(String alias); + private String path = null; + /** * The command's path, or name if top-level command.
* For example:
* "u admin updateplugin" or "u" for the top level one
* The path must be lowercase!
+ * Abstract classes with no {@link CommandClass} annotations will be ignored. * - * @return The command path, which is the command class name by default (removing any "command" from it) + * @return The command path, which is the command class name by default (removing any "command" from it) - Change via the {@link CommandClass} annotation */ public final String GetCommandPath() { + return path; + } + + private final String getcmdpath() { if (!getClass().isAnnotationPresent(CommandClass.class)) - throw new RuntimeException("No @Command annotation on command class " + getClass().getSimpleName() + "!"); - Function, String> getFromClass = cl -> getClass().getSimpleName().toLowerCase() - .replace("commandbase", "").replace("command", ""); - String path = getClass().getAnnotation(CommandClass.class).path(), prevpath = path; // TODO: Check if annotation exists (No @Inherited?) + throw new RuntimeException( + "No @CommandClass annotation on command class " + getClass().getSimpleName() + "!"); + Function, String> getFromClass = cl -> cl.getSimpleName().toLowerCase().replace("commandbase", "") // <-- ... + .replace("command", ""); + String path = getClass().getAnnotation(CommandClass.class).path(), + prevpath = path = path.length() == 0 ? getFromClass.apply(getClass()) : path; + // System.out.println("Path: " + (path.length() == 0 ? getFromClass.apply(getClass()) : path)) for (Class cl = getClass().getSuperclass(); cl != null - && !cl.getName().equals(TBMCCommandBase.class.getName()); cl = cl.getSuperclass()) { - //com.sun.xml.internal.bind.v2.TODO.prototype(); - String newpath = cl.getAnnotation(CommandClass.class).path(); - if (newpath.length() == 0) + && !cl.getPackage().getName().equals(TBMCCommandBase.class.getPackage().getName()); cl = cl + .getSuperclass()) { // + String newpath; + if (!cl.isAnnotationPresent(CommandClass.class) + || (newpath = cl.getAnnotation(CommandClass.class).path()).length() == 0 + || newpath.equals(prevpath)) { + if (Modifier.isAbstract(cl.getModifiers()) && (!cl.isAnnotationPresent(CommandClass.class)) + || cl.getAnnotation(CommandClass.class).excludeFromPath()) // <-- + continue; newpath = getFromClass.apply(cl); - if (!newpath.equals(prevpath)) - path = (prevpath = newpath) + " " + path; + } + path = (prevpath = newpath) + " " + path; + // System.out.println("Path: " + (path.length() == 0 ? getFromClass.apply(cl) : path)); } - return path.length() == 0 ? getFromClass.apply(getClass()) : path; + //System.out.println("Path: " + path); + return path; } Plugin plugin; // Used By TBMCChatAPI From 36b3c1895d22094a8e80428ad74f5f421d4b91ef Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 14 May 2017 01:24:30 +0200 Subject: [PATCH 9/9] Thought I changed the DiscordPlugin too - AW Cleaned code a bit YEEHAW --- src/main/java/buttondevteam/core/CommandCaller.java | 2 -- .../java/buttondevteam/core/ScheduledRestartCommand.java | 7 ------- src/main/java/buttondevteam/core/TestPrepare.java | 2 -- src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java | 1 - src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java | 3 --- src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java | 3 --- 6 files changed, 18 deletions(-) diff --git a/src/main/java/buttondevteam/core/CommandCaller.java b/src/main/java/buttondevteam/core/CommandCaller.java index 50a65a9..2b27f9e 100644 --- a/src/main/java/buttondevteam/core/CommandCaller.java +++ b/src/main/java/buttondevteam/core/CommandCaller.java @@ -36,13 +36,11 @@ public class CommandCaller implements CommandExecutor { + cmd.getPlugin().getName()); else pc.setExecutor(instance); - System.out.println("Executor set"); } } @Override public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { - System.out.println("onCommand called"); String path = command.getName().toLowerCase(); for (String arg : args) path += " " + arg; diff --git a/src/main/java/buttondevteam/core/ScheduledRestartCommand.java b/src/main/java/buttondevteam/core/ScheduledRestartCommand.java index 82090d2..b80c2de 100644 --- a/src/main/java/buttondevteam/core/ScheduledRestartCommand.java +++ b/src/main/java/buttondevteam/core/ScheduledRestartCommand.java @@ -34,11 +34,7 @@ public class ScheduledRestartCommand extends TBMCCommandBase { restartbar = Bukkit.createBossBar("Server restart in " + ticks / 20f, BarColor.RED, BarStyle.SOLID, BarFlag.DARKEN_SKY); restartbar.setProgress(1); - // System.out.println("Progress: " + restartbar.getProgress()); Bukkit.getOnlinePlayers().stream().forEach(p -> restartbar.addPlayer(p)); - /* - * System.out.println( "Players: " + restartbar.getPlayers().stream().map(p -> p.getName()).collect(Collectors.joining(", "))); - */ sender.sendMessage("Scheduled restart in " + ticks / 20f); ScheduledServerRestartEvent e = new ScheduledServerRestartEvent(ticks); Bukkit.getPluginManager().callEvent(e); @@ -52,9 +48,6 @@ public class ScheduledRestartCommand extends TBMCCommandBase { Bukkit.broadcastMessage("§c-- The server is restarting in " + restartcounter / 20 + " seconds!"); restartbar.setProgress(restartcounter / (double) restarttime); restartbar.setTitle(String.format("Server restart in %f.2", restartcounter / 20f)); - /* - * if (restartcounter % 20 == 0) System.out.println("Progress: " + restartbar.getProgress()); - */ restartcounter--; }, 1, 1); return true; diff --git a/src/main/java/buttondevteam/core/TestPrepare.java b/src/main/java/buttondevteam/core/TestPrepare.java index 027128b..3b6c837 100644 --- a/src/main/java/buttondevteam/core/TestPrepare.java +++ b/src/main/java/buttondevteam/core/TestPrepare.java @@ -21,8 +21,6 @@ public class TestPrepare { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - // System.out.println("Return type: " + invocation.getMethod().getReturnType()); - // System.out.println(String.class.isAssignableFrom(invocation.getMethod().getReturnType())); if (returns(invocation, String.class)) return "test"; if (returns(invocation, Logger.class)) diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index 50b0086..943de8d 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -115,7 +115,6 @@ public class TBMCChatAPI { try { if (!cmd.getPackage().getName().startsWith(acmdclass.getPackage().getName())) continue; // It keeps including the commands from here - //System.out.println("Class found: " + cmd.getName()); if (Modifier.isAbstract(cmd.getModifiers())) continue; TBMCCommandBase c = cmd.newInstance(); diff --git a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java index e751a9a..086f15d 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java @@ -47,7 +47,6 @@ public abstract class TBMCCommandBase { .replace("command", ""); String path = getClass().getAnnotation(CommandClass.class).path(), prevpath = path = path.length() == 0 ? getFromClass.apply(getClass()) : path; - // System.out.println("Path: " + (path.length() == 0 ? getFromClass.apply(getClass()) : path)) for (Class cl = getClass().getSuperclass(); cl != null && !cl.getPackage().getName().equals(TBMCCommandBase.class.getPackage().getName()); cl = cl .getSuperclass()) { // @@ -61,9 +60,7 @@ public abstract class TBMCCommandBase { newpath = getFromClass.apply(cl); } path = (prevpath = newpath) + " " + path; - // System.out.println("Path: " + (path.length() == 0 ? getFromClass.apply(cl) : path)); } - //System.out.println("Path: " + path); return path; } diff --git a/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java b/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java index e4f38c2..c1e3400 100644 --- a/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java +++ b/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java @@ -74,17 +74,14 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase { public static T getPlayer(UUID uuid, Class cl) { if (playermap.containsKey(uuid + "-" + cl.getSimpleName())) return (T) playermap.get(uuid + "-" + cl.getSimpleName()); - // System.out.println("A"); try { T player; if (playermap.containsKey(uuid + "-" + TBMCPlayer.class.getSimpleName())) { - // System.out.println("B"); - Don't program when tired player = cl.newInstance(); player.plugindata = playermap.get(uuid + "-" + TBMCPlayer.class.getSimpleName()).plugindata; playermap.put(uuid + "-" + cl.getSimpleName(), player); // It will get removed on player quit } else player = ChromaGamerBase.getUser(uuid.toString(), cl); - // System.out.println("C"); player.uuid = uuid; return player; } catch (Exception e) {