From 6c18f2582085345a8d5e0d4b93dc57fb2c639c3e Mon Sep 17 00:00:00 2001 From: Paldiu Date: Thu, 4 Feb 2021 09:38:44 -0600 Subject: [PATCH] First working version of the API --- pom.xml | 2 +- .../github/paldiu/simplexcore/CoreState.java | 52 ++++++++++++++ .../paldiu/simplexcore/SimplexCore.java | 29 +++++++- .../paldiu/simplexcore/chat/ChatUtils.java | 39 ++++++++++ .../paldiu/simplexcore/chat/Messages.java | 19 +++++ .../chat/TextComponentFactory.java | 72 +++++++++++++++++++ target/classes/plugin.yml | 4 +- target/maven-archiver/pom.properties | 4 +- .../compile/default-compile/createdFiles.lst | 10 ++- .../compile/default-compile/inputFiles.lst | 10 ++- 10 files changed, 229 insertions(+), 12 deletions(-) create mode 100644 src/main/java/io/github/paldiu/simplexcore/CoreState.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/chat/ChatUtils.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/chat/Messages.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/chat/TextComponentFactory.java diff --git a/pom.xml b/pom.xml index 2077802..5ee7f7f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.paldiu.simplexcore SimplexCore - 1.0.0-BLEEDING + 1.1.0-EDGE jar SimplexCore diff --git a/src/main/java/io/github/paldiu/simplexcore/CoreState.java b/src/main/java/io/github/paldiu/simplexcore/CoreState.java new file mode 100644 index 0000000..999f9f0 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/CoreState.java @@ -0,0 +1,52 @@ +package io.github.paldiu.simplexcore; + +import io.github.paldiu.simplexcore.utils.Constants; +import org.bukkit.Bukkit; + +public class CoreState { + enum State { + ON, + DEBUG, + SUSPENDED, + VOLATILE + } + + public State getState() { + if (SimplexCore.isDebug()) { + return State.DEBUG; + } + + if (Constants.getPlugin().isEnabled()) { + return State.ON; + } + + if (SimplexCore.isSuspended()) { + return State.SUSPENDED; + } + + return State.VOLATILE; + } + + String message; + + public CoreState() { + switch (getState()) { + case ON: + message = "The Core is currently ON"; + break; + case SUSPENDED: + message = "The Core is currently SUSPENDED. Please report this to the developer."; + break; + case DEBUG: + message = "The Core is currently in DEBUG mode. Do not use this if you don't know what you're doing."; + break; + case VOLATILE: + message = "The Core state is currently unknown! Please report this to the developer!"; + break; + } + } + + public String getMessage() { + return message; + } +} \ No newline at end of file diff --git a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java index c6baf24..d9f6441 100644 --- a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java +++ b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java @@ -7,6 +7,9 @@ import io.github.paldiu.simplexcore.plugin.SimplexAddon; import io.github.paldiu.simplexcore.utils.Constants; public final class SimplexCore extends SimplexAddon { + protected static boolean debug = false; + protected static boolean suspended = false; + @Override public SimplexCore getPlugin() { return this; @@ -14,13 +17,33 @@ public final class SimplexCore extends SimplexAddon { @Override public void start() { - Constants.getRegistry().register(this); - Constants.getCommandLoader().classpath(Command_info.class).load(); - SimplexListener.register(new ServerPluginListener(), this); + try { + Constants.getRegistry().register(this); + Constants.getCommandLoader().classpath(Command_info.class).load(); + SimplexListener.register(new ServerPluginListener(), this); + } catch (Exception ex) { + suspended = true; + // TODO: Write an output to a file with why it suspended. + } + + CoreState state = new CoreState(); + Constants.getLogger().info(state.getMessage()); } @Override public void stop() { } + + public static void setDebug(boolean enable) { + debug = enable; + } + + public static boolean isDebug() { + return debug; + } + + public static boolean isSuspended() { + return suspended; + } } \ No newline at end of file diff --git a/src/main/java/io/github/paldiu/simplexcore/chat/ChatUtils.java b/src/main/java/io/github/paldiu/simplexcore/chat/ChatUtils.java new file mode 100644 index 0000000..3f65167 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/chat/ChatUtils.java @@ -0,0 +1,39 @@ +package io.github.paldiu.simplexcore.chat; + +import io.github.paldiu.simplexcore.utils.Bean; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.command.CommandSender; + +public final class ChatUtils { + protected final Bean target; + protected final TextComponentFactory factory = new TextComponentFactory(); + + private ChatUtils(Bean target) { + this.target = target; + } + + public static ChatUtils target(T target) { + return new ChatUtils(new Bean<>(target)); + } + + public void msg(String message) { + target.get().sendMessage(message); + } + + public void msg(TextComponent component) { + target.get().sendMessage(component); + } + + public void err(Messages message) { + target.get().sendMessage(message.getMessage()); + } + + public void color(String message) { + target.get().sendMessage(factory.colorize(message)); + } + + public void color(TextComponent component) { + target.get().sendMessage(factory.colorize(component.getText())); + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/chat/Messages.java b/src/main/java/io/github/paldiu/simplexcore/chat/Messages.java new file mode 100644 index 0000000..0368310 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/chat/Messages.java @@ -0,0 +1,19 @@ +package io.github.paldiu.simplexcore.chat; + +public enum Messages { + NO_PERMS("You do not have permission to use this command!"), + DISCORD("https://discord.gg/"), + BAN("You have been permanently banned from this server."), + KICK("You have been kicked by a moderator."), + AFK_KICK("You were kicked to ensure space for active players."); + + Messages(String message) { + this.message = message; + } + + String message; + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/chat/TextComponentFactory.java b/src/main/java/io/github/paldiu/simplexcore/chat/TextComponentFactory.java new file mode 100644 index 0000000..a65bfb9 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/chat/TextComponentFactory.java @@ -0,0 +1,72 @@ +package io.github.paldiu.simplexcore.chat; + +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.chat.hover.content.Text; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class TextComponentFactory { + @NotNull + public TextComponent textComponent(@NotNull String message) { + TextComponent component = new TextComponent(); + component.setText(message); + return component; + } + + @NotNull + public TextComponent clickableComponent(@NotNull String message, @NotNull String clickAction, @NotNull ClickEvent.Action actionType) { + TextComponent comp = new TextComponent(); + ClickEvent onClick = new ClickEvent(actionType, clickAction); + comp.setText(message); + comp.setClickEvent(onClick); + return comp; + } + + @NotNull + public TextComponent coloredComponent(@NotNull String message, @Nullable ChatColor color) { + TextComponent component = new TextComponent(); + if (color != null) component.setColor(color); + component.setText(message); + return component; + } + + @NotNull + public TextComponent clickableColored(@NotNull String message, @NotNull String clickMessage, @NotNull ClickEvent.Action actionType, @Nullable ChatColor color) { + TextComponent comp = new TextComponent(); + ClickEvent onClick = new ClickEvent(actionType, clickMessage); + if (color != null) comp.setColor(color); + comp.setText(message); + comp.setClickEvent(onClick); + return comp; + } + + @NotNull + public TextComponent addColor(@NotNull TextComponent component, @NotNull ChatColor color) { + component.setColor(color); + return component; + } + + @NotNull + public TextComponent resetColor(@NotNull TextComponent component) { + component.setColor(ChatColor.RESET); + return component; + } + + @NotNull + public TextComponent hoverableText(@NotNull String message, @NotNull String hoverMessage, @NotNull HoverEvent.Action action) { + TextComponent comp = new TextComponent(); + comp.setText(message); + Text text = new Text(hoverMessage); + HoverEvent event = new HoverEvent(action, text); + comp.setHoverEvent(event); + return comp; + } + + @NotNull + public String colorize(@NotNull String message) { + return ChatColor.translateAlternateColorCodes('&', message); + } +} diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml index 6597f32..f03e8d9 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -1,6 +1,6 @@ name: SimplexCore -version: 1.0.0-BLEEDING -main: pw.coomer.simplexcore.SimplexCore +version: 1.1.0-EDGE +main: io.github.paldiu.simplexcore.SimplexCore api-version: 1.16 prefix: Simplex authors: [ Paldiu ] diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index 9246faa..f612b42 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Wed Jan 27 08:29:34 CST 2021 +#Sat Jan 30 08:40:18 CST 2021 groupId=io.github.paldiu.simplexcore artifactId=SimplexCore -version=1.0.0-BLEEDING +version=1.1.0-EDGE diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index f23d571..5caf416 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,17 +1,23 @@ +io\github\paldiu\simplexcore\command\SimplexCommand.class io\github\paldiu\simplexcore\command\defaults\Command_info.class +io\github\paldiu\simplexcore\listener\ServerPluginListener.class io\github\paldiu\simplexcore\command\CommandLoader.class io\github\paldiu\simplexcore\math\Size.class -io\github\paldiu\simplexcore\command\CommandBase.class io\github\paldiu\simplexcore\command\CommandInfo.class io\github\paldiu\simplexcore\plugin\AddonRegistry.class io\github\paldiu\simplexcore\command\CommandLoader$Registry.class io\github\paldiu\simplexcore\utils\Constants$TimeValues.class io\github\paldiu\simplexcore\utils\Bean.class io\github\paldiu\simplexcore\utils\Constants.class +io\github\paldiu\simplexcore\config\YamlFactory.class +io\github\paldiu\simplexcore\future\SimplexTask.class +io\github\paldiu\simplexcore\config\JsonFactory.class +io\github\paldiu\simplexcore\plugin\SimplexAddon.class io\github\paldiu\simplexcore\SimplexCore.class io\github\paldiu\simplexcore\utils\Trio.class +io\github\paldiu\simplexcore\listener\SimplexListener.class io\github\paldiu\simplexcore\plugin\AddonManager.class io\github\paldiu\simplexcore\math\Cuboid.class -io\github\paldiu\simplexcore\plugin\Addon.class io\github\paldiu\simplexcore\command\defaults\DefaultCommand.class io\github\paldiu\simplexcore\utils\Utilities.class +io\github\paldiu\simplexcore\chat\TextComponentFactory.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index f737540..db78614 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1,11 +1,17 @@ +C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\listener\ServerPluginListener.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\utils\Utilities.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\CommandInfo.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\plugin\AddonManager.java +C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\defaults\DefaultCommand.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\math\Size.java +C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\plugin\SimplexAddon.java +C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\future\SimplexTask.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\utils\Trio.java -C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\CommandBase.java -C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\plugin\Addon.java +C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\config\YamlFactory.java +C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\config\JsonFactory.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\plugin\AddonRegistry.java +C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\SimplexCommand.java +C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\listener\SimplexListener.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\utils\Bean.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\CommandLoader.java C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\defaults\Command_info.java