mirror of
https://github.com/SimplexDevelopment/SimplexCore.git
synced 2025-07-04 08:06:41 +00:00
First working version of the API
This commit is contained in:
52
src/main/java/io/github/paldiu/simplexcore/CoreState.java
Normal file
52
src/main/java/io/github/paldiu/simplexcore/CoreState.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -7,6 +7,9 @@ import io.github.paldiu.simplexcore.plugin.SimplexAddon;
|
||||
import io.github.paldiu.simplexcore.utils.Constants;
|
||||
|
||||
public final class SimplexCore extends SimplexAddon<SimplexCore> {
|
||||
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<SimplexCore> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
@ -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<? extends CommandSender> target;
|
||||
protected final TextComponentFactory factory = new TextComponentFactory();
|
||||
|
||||
private ChatUtils(Bean<? extends CommandSender> target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public static <T extends CommandSender> 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()));
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user