diff --git a/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java b/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java index ba1670b..e698dc5 100644 --- a/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java +++ b/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java @@ -1,6 +1,6 @@ package me.totalfreedom.corvo; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import org.bukkit.plugin.java.JavaPlugin; public class Corvo extends JavaPlugin @@ -8,18 +8,18 @@ public class Corvo extends JavaPlugin @Override public void onDisable() { - CommonsBase.getInstance() - .getRegistrations() - .getModuleRegistry() - .removeModule(this); + Patchwork.getInstance() + .getRegistrations() + .getModuleRegistry() + .removeModule(this); } @Override public void onEnable() { - CommonsBase.getInstance() - .getRegistrations() - .getModuleRegistry() - .addModule(this); + Patchwork.getInstance() + .getRegistrations() + .getModuleRegistry() + .addModule(this); } } diff --git a/Datura/src/main/java/me/totalfreedom/datura/Datura.java b/Datura/src/main/java/me/totalfreedom/datura/Datura.java index da40da4..4680a03 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/Datura.java +++ b/Datura/src/main/java/me/totalfreedom/datura/Datura.java @@ -1,6 +1,6 @@ package me.totalfreedom.datura; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.datura.punishment.Cager; import me.totalfreedom.datura.punishment.Halter; import me.totalfreedom.datura.punishment.Locker; @@ -20,19 +20,19 @@ public class Datura extends JavaPlugin @Override public void onEnable() { - CommonsBase.getInstance() - .getRegistrations() - .getModuleRegistry() - .addModule(this); + Patchwork.getInstance() + .getRegistrations() + .getModuleRegistry() + .addModule(this); - CommonsBase.getInstance() - .getRegistrations() - .getServiceTaskRegistry() - .registerService(SubscriptionProvider.syncService(this, locker)); - CommonsBase.getInstance() - .getRegistrations() - .getServiceTaskRegistry() - .registerService(SubscriptionProvider.syncService(this, cager)); + Patchwork.getInstance() + .getRegistrations() + .getServiceTaskRegistry() + .registerService(SubscriptionProvider.syncService(this, locker)); + Patchwork.getInstance() + .getRegistrations() + .getServiceTaskRegistry() + .registerService(SubscriptionProvider.syncService(this, cager)); Bukkit.getPluginManager() .registerEvents(halter, this); diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/AdminChatCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/AdminChatCommand.java new file mode 100644 index 0000000..966d2bd --- /dev/null +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/AdminChatCommand.java @@ -0,0 +1,31 @@ +package me.totalfreedom.datura.cmd; + +import me.totalfreedom.command.Commander; +import me.totalfreedom.command.annotation.Base; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +public class AdminChatCommand extends Commander +{ + + /** + * Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the + * command. + *

+ * This constructor will automatically register all subcommands and completions for this command. It will also + * automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations. + * + * @param plugin The plugin which contains this command. + */ + protected AdminChatCommand(@NotNull final JavaPlugin plugin) + { + super(plugin); + } + + @Base + public void onAdminChat(final CommandSender sender) { + + } +} diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java b/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java index a2ccc5d..affa495 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java +++ b/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java @@ -1,6 +1,6 @@ package me.totalfreedom.datura.perms; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.security.Group; import me.totalfreedom.security.Node; import net.kyori.adventure.text.Component; @@ -41,7 +41,7 @@ public class FreedomGroup implements Group this.isDefault = isDefault; this.isHidden = isHidden; this.permissions = new HashSet<>(); - this.attachment = new PermissionAttachment(CommonsBase.getInstance(), this); + this.attachment = new PermissionAttachment(Patchwork.getInstance(), this); } @Override diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java b/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java index 3f1510f..a055351 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java +++ b/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java @@ -1,6 +1,6 @@ package me.totalfreedom.datura.perms; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.datura.Datura; import me.totalfreedom.datura.user.SimpleUserData; import me.totalfreedom.security.Node; @@ -42,11 +42,11 @@ public class FreedomUser implements User this.permissions = new HashSet<>(); this.displayName = player.displayName(); - final Datura datura = CommonsBase.getInstance() - .getRegistrations() - .getModuleRegistry() - .getProvider(Datura.class) - .getModule(); + final Datura datura = Patchwork.getInstance() + .getRegistrations() + .getModuleRegistry() + .getProvider(Datura.class) + .getModule(); UserData data = SimpleUserData.fromSQL(datura.getSQL(), uuid.toString()); @@ -57,10 +57,10 @@ public class FreedomUser implements User this.userData = data; - CommonsBase.getInstance() - .getRegistrations() - .getUserRegistry() - .registerUserData(this, userData); + Patchwork.getInstance() + .getRegistrations() + .getUserRegistry() + .registerUserData(this, userData); } @Override @@ -96,7 +96,7 @@ public class FreedomUser implements User @Override public boolean addPermission(final Node node) { - final PermissionAttachment attachment = addAttachment(CommonsBase.getInstance(), node.key(), node.value()); + final PermissionAttachment attachment = addAttachment(Patchwork.getInstance(), node.key(), node.value()); bukkitAttachments.put(node, attachment); return permissions().add(node); } diff --git a/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java b/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java index 52920aa..5b3ef49 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java +++ b/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java @@ -1,6 +1,6 @@ package me.totalfreedom.datura.punishment; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.service.Service; import me.totalfreedom.utils.ShapeUtils; import org.bukkit.Bukkit; @@ -32,7 +32,7 @@ public class Cager extends Service this.cagedPlayers = new HashSet<>(); this.cageLocations = new HashMap<>(); Bukkit.getPluginManager() - .registerEvents(new CageListener(), CommonsBase.getInstance()); + .registerEvents(new CageListener(), Patchwork.getInstance()); } /** diff --git a/Datura/src/main/java/me/totalfreedom/datura/punishment/Locker.java b/Datura/src/main/java/me/totalfreedom/datura/punishment/Locker.java index 9e1e027..c459037 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/punishment/Locker.java +++ b/Datura/src/main/java/me/totalfreedom/datura/punishment/Locker.java @@ -1,6 +1,6 @@ package me.totalfreedom.datura.punishment; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.service.Service; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -35,10 +35,10 @@ public class Locker extends Service @Override public void tick() { - lockedPlayers.removeIf(uuid -> !CommonsBase.getInstance() - .getServer() - .getOfflinePlayer(uuid) - .isOnline()); + lockedPlayers.removeIf(uuid -> !Patchwork.getInstance() + .getServer() + .getOfflinePlayer(uuid) + .isOnline()); for (final UUID uuid : lockedPlayers) { diff --git a/Datura/src/main/java/me/totalfreedom/datura/sql/MySQL.java b/Datura/src/main/java/me/totalfreedom/datura/sql/MySQL.java index 9446e08..ae2debf 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/sql/MySQL.java +++ b/Datura/src/main/java/me/totalfreedom/datura/sql/MySQL.java @@ -1,6 +1,6 @@ package me.totalfreedom.datura.sql; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.sql.SQL; import me.totalfreedom.utils.container.Identity; @@ -75,9 +75,9 @@ public class MySQL implements SQL throw new CompletionException("Failed to prepare statement: " + query + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Patchwork.getInstance() + .getExecutor() + .getAsync()); } private CompletableFuture getConnection() @@ -92,9 +92,9 @@ public class MySQL implements SQL throw new CompletionException("Failed to connect to the database: " + url.toString() + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Patchwork.getInstance() + .getExecutor() + .getAsync()); } @Override @@ -112,9 +112,9 @@ public class MySQL implements SQL "Failed to retrieve a result set from query: " + query + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Patchwork.getInstance() + .getExecutor() + .getAsync()); } @Override @@ -131,9 +131,9 @@ public class MySQL implements SQL throw new CompletionException("Failed to execute update: " + query + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Patchwork.getInstance() + .getExecutor() + .getAsync()); } @Override @@ -150,9 +150,9 @@ public class MySQL implements SQL throw new CompletionException("Failed to execute statement: " + query + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Patchwork.getInstance() + .getExecutor() + .getAsync()); } @Override @@ -194,26 +194,26 @@ public class MySQL implements SQL ex); } return null; - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Patchwork.getInstance() + .getExecutor() + .getAsync()); } public CompletableFuture updateColumn(final String table, final String column, final Object value, final String key, final Identity identity) { return executeUpdate("UPDATE ? SET ? = ? WHERE ? = ?", table, column, value, key, identity.getId()) - .thenApplyAsync(result -> result > 0, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + .thenApplyAsync(result -> result > 0, Patchwork.getInstance() + .getExecutor() + .getAsync()); } public CompletableFuture deleteRow(final String table, final String key, final Identity identity) { return executeUpdate("DELETE FROM ? WHERE ? = ?", table, key, identity.getId()) - .thenApplyAsync(result -> result > 0, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + .thenApplyAsync(result -> result > 0, Patchwork.getInstance() + .getExecutor() + .getAsync()); } public CompletableFuture insertRow(final String table, final Object... values) diff --git a/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java b/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java index 014876c..4a391c6 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java +++ b/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java @@ -1,8 +1,9 @@ package me.totalfreedom.datura.user; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.datura.event.UserDataUpdateEvent; import me.totalfreedom.datura.perms.FreedomUser; +import me.totalfreedom.display.adminchat.AdminChatFormat; import me.totalfreedom.security.Group; import me.totalfreedom.sql.SQL; import me.totalfreedom.user.User; @@ -29,6 +30,8 @@ public class SimpleUserData implements UserData private boolean canInteract; private AtomicLong balance; private boolean transactionsFrozen; + private boolean hasCustomACFormat = false; + private String customACFormat; public SimpleUserData(final Player player) { @@ -36,9 +39,9 @@ public class SimpleUserData implements UserData this.username = player.getName(); this.user = new FreedomUser(player); - CommonsBase.getInstance() - .getEventBus() - .addEvent(event); + Patchwork.getInstance() + .getEventBus() + .addEvent(event); } private SimpleUserData( @@ -59,6 +62,7 @@ public class SimpleUserData implements UserData this.canInteract = canInteract; this.balance = new AtomicLong(balance); this.transactionsFrozen = transactionsFrozen; + this.customACFormat = AdminChatFormat.DEFAULT.serialize(); } public static SimpleUserData fromSQL(final SQL sql, final String uuid) @@ -81,10 +85,10 @@ public class SimpleUserData implements UserData throw new IllegalStateException("Player should be online but they are not!"); final User user = new FreedomUser(player); - final Group group = CommonsBase.getInstance() - .getRegistrations() - .getGroupRegistry() - .getGroup(g); + final Group group = Patchwork.getInstance() + .getRegistrations() + .getGroupRegistry() + .getGroup(g); final long playtime = result.getLong("playtime"); final boolean canInteract = result.getBoolean("canInteract"); @@ -113,9 +117,9 @@ public class SimpleUserData implements UserData if (player == null) throw new IllegalStateException("Player should be online but they are not!"); return new SimpleUserData(player); - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()) + }, Patchwork.getInstance() + .getExecutor() + .getAsync()) .join(); } @@ -219,4 +223,23 @@ public class SimpleUserData implements UserData { return balance.addAndGet(-amount); } + + @Override + public boolean hasCustomACFormat() + { + return hasCustomACFormat; + } + + @Override + public void setCustomACFormat(final String format) + { + this.hasCustomACFormat = format.equals(AdminChatFormat.DEFAULT.serialize()); + this.customACFormat = format; + } + + @Override + public AdminChatFormat getCustomACFormat() + { + return AdminChatFormat.deserialize(customACFormat); + } } diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java b/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java index 18dc7fb..a4eda38 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java @@ -1,6 +1,6 @@ package me.totalfreedom.fossil; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.base.Registration; import me.totalfreedom.fossil.trail.Trailer; import me.totalfreedom.service.SubscriptionProvider; @@ -9,8 +9,8 @@ import org.bukkit.plugin.java.JavaPlugin; public class Fossil extends JavaPlugin { private final Trailer trailer = new Trailer(); - private final Registration registration = CommonsBase.getInstance() - .getRegistrations(); + private final Registration registration = Patchwork.getInstance() + .getRegistrations(); @Override public void onEnable() diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadHolder.java b/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadHolder.java index cd4842e..7af351b 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadHolder.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadHolder.java @@ -1,6 +1,6 @@ package me.totalfreedom.fossil.bouncypads; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.fossil.Fossil; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -33,7 +33,7 @@ public class PadHolder implements Listener public PadHolder() { Bukkit.getPluginManager() - .registerEvents(this, CommonsBase + .registerEvents(this, Patchwork .getInstance() .getRegistrations() .getModuleRegistry() diff --git a/Patchwork/src/main/java/me/totalfreedom/base/CommonsBase.java b/Patchwork/src/main/java/me/totalfreedom/base/Patchwork.java similarity index 94% rename from Patchwork/src/main/java/me/totalfreedom/base/CommonsBase.java rename to Patchwork/src/main/java/me/totalfreedom/base/Patchwork.java index 69bade0..2ee663b 100644 --- a/Patchwork/src/main/java/me/totalfreedom/base/CommonsBase.java +++ b/Patchwork/src/main/java/me/totalfreedom/base/Patchwork.java @@ -9,7 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin; /** * The base class for Patchwork. */ -public class CommonsBase extends JavaPlugin +public class Patchwork extends JavaPlugin { /** * The {@link EventBus} for this plugin. @@ -30,9 +30,9 @@ public class CommonsBase extends JavaPlugin * * @return the plugin instance */ - public static CommonsBase getInstance() + public static Patchwork getInstance() { - return JavaPlugin.getPlugin(CommonsBase.class); + return JavaPlugin.getPlugin(Patchwork.class); } @Override diff --git a/Patchwork/src/main/java/me/totalfreedom/base/Registration.java b/Patchwork/src/main/java/me/totalfreedom/base/Registration.java index e697fe9..db58a4f 100644 --- a/Patchwork/src/main/java/me/totalfreedom/base/Registration.java +++ b/Patchwork/src/main/java/me/totalfreedom/base/Registration.java @@ -12,7 +12,7 @@ import me.totalfreedom.data.UserRegistry; *
* Registries such as {@link ModuleRegistry} and {@link ServiceTaskRegistry} can be found as final objects in this * class. These registries should only ever be accessed through the single Registration object in CommonsBase using - * {@link CommonsBase#getRegistrations()} + * {@link Patchwork#getRegistrations()} */ public class Registration { diff --git a/Patchwork/src/main/java/me/totalfreedom/base/Shortcuts.java b/Patchwork/src/main/java/me/totalfreedom/base/Shortcuts.java index 2194026..d3d7bf7 100644 --- a/Patchwork/src/main/java/me/totalfreedom/base/Shortcuts.java +++ b/Patchwork/src/main/java/me/totalfreedom/base/Shortcuts.java @@ -10,6 +10,6 @@ public final class Shortcuts } public static ModuleProvider provideModule(final Class pluginClass) { - return CommonsBase.getInstance().getRegistrations().getModuleRegistry().getProvider(pluginClass); + return Patchwork.getInstance().getRegistrations().getModuleRegistry().getProvider(pluginClass); } } diff --git a/Patchwork/src/main/java/me/totalfreedom/display/adminchat/ACFormatBuilder.java b/Patchwork/src/main/java/me/totalfreedom/display/adminchat/ACFormatBuilder.java new file mode 100644 index 0000000..b676936 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/display/adminchat/ACFormatBuilder.java @@ -0,0 +1,119 @@ +package me.totalfreedom.display.adminchat; + +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; + +public class ACFormatBuilder +{ + private char openTag = '['; + private char closeTag = ']'; + private TextColor prefixColor = NamedTextColor.DARK_RED; + private TextColor bracketColor = NamedTextColor.WHITE; + private TextColor nameColor = NamedTextColor.AQUA; + private TextColor rankColor = NamedTextColor.GOLD; + private String prefix = "Admin"; + private String chatSplitter = ">>"; + + private ACFormatBuilder() + { + + } + + public static ACFormatBuilder format() + { + return new ACFormatBuilder(); + } + + public ACFormatBuilder openBracket(final char openTag) + { + this.openTag = openTag; + return this; + } + + public ACFormatBuilder closeBracket(final char closeTag) + { + this.closeTag = closeTag; + return this; + } + + public ACFormatBuilder prefixColor(final TextColor prefixColor) + { + this.prefixColor = prefixColor; + return this; + } + + public ACFormatBuilder bracketColor(final TextColor bracketColor) + { + this.bracketColor = bracketColor; + return this; + } + + public ACFormatBuilder prefix(final String prefix) + { + this.prefix = prefix; + return this; + } + + public ACFormatBuilder chatSplitter(final String chatSplitter) + { + this.chatSplitter = chatSplitter; + return this; + } + + public ACFormatBuilder nameColor(final TextColor nameColor) + { + this.nameColor = nameColor; + return this; + } + + public ACFormatBuilder rankColor(final TextColor rankColor) + { + this.rankColor = rankColor; + return this; + } + + String openBracket() + { + return String.valueOf(openTag); + } + + String closeBracket() + { + return String.valueOf(closeTag); + } + + TextColor prefixColor() + { + return prefixColor; + } + + TextColor bracketColor() + { + return bracketColor; + } + + TextColor nameColor() + { + return nameColor; + } + + TextColor rankColor() + { + return rankColor; + } + + String prefix() + { + return prefix; + } + + String chatSplitter() + { + return chatSplitter; + } + + public AdminChatFormat build() + { + return new AdminChatFormat(this); + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/display/adminchat/AdminChatDisplay.java b/Patchwork/src/main/java/me/totalfreedom/display/adminchat/AdminChatDisplay.java new file mode 100644 index 0000000..06ec6d9 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/display/adminchat/AdminChatDisplay.java @@ -0,0 +1,97 @@ +package me.totalfreedom.display.adminchat; + +import io.papermc.paper.event.player.AsyncChatEvent; +import me.totalfreedom.base.Patchwork; +import me.totalfreedom.base.Shortcuts; +import me.totalfreedom.data.UserRegistry; +import me.totalfreedom.user.UserData; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +public class AdminChatDisplay +{ + private final Map adminChatFormat = new HashMap<>(); + private final Set toggledChat = new HashSet<>(); + + public AdminChatDisplay() { + new ACListener(this); + } + + public void addPlayer(final Player player, final AdminChatFormat format) + { + adminChatFormat.put(player.getUniqueId(), format); + } + + public void removePlayer(final Player player) + { + adminChatFormat.remove(player.getUniqueId()); + } + + public boolean hasPlayer(final Player player) + { + return adminChatFormat.containsKey(player.getUniqueId()); + } + + public void updateFormat(final Player player, final AdminChatFormat newFormat) + { + adminChatFormat.put(player.getUniqueId(), newFormat); + } + + public AdminChatFormat getFormat(final Player player) + { + return adminChatFormat.get(player.getUniqueId()); + } + + public Set getPlayers() + { + return adminChatFormat.keySet(); + } + + public Map getAdminChatFormat() + { + return adminChatFormat; + } + + public static final class ACListener implements Listener + { + private final AdminChatDisplay display; + + public ACListener(final AdminChatDisplay display) + { + this.display = display; + Bukkit.getPluginManager() + .registerEvents(this, Shortcuts.provideModule(Patchwork.class) + .getModule()); + } + + @EventHandler + public void playerChat(final AsyncChatEvent event) { + if (display.getPlayers().contains(event.getPlayer().getUniqueId())) { + event.setCancelled(true); + + } + } + + @EventHandler + public void playerJoin(final PlayerJoinEvent event) { + final Player player = event.getPlayer(); + if (player.hasPermission("patchwork.adminchat")) { + final UserData data = Patchwork.getInstance().getRegistrations().getUserRegistry().fromPlayer(player); + if (data.hasCustomACFormat()) { + display.addPlayer(player, data.getCustomACFormat()); + } else { + display.addPlayer(player, AdminChatFormat.DEFAULT); + } + } + } + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/display/adminchat/AdminChatFormat.java b/Patchwork/src/main/java/me/totalfreedom/display/adminchat/AdminChatFormat.java new file mode 100644 index 0000000..b8dd757 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/display/adminchat/AdminChatFormat.java @@ -0,0 +1,97 @@ +package me.totalfreedom.display.adminchat; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public final class AdminChatFormat +{ + public static final AdminChatFormat DEFAULT = ACFormatBuilder.format() + .build(); + private final Component prefix; + private final Component userName; + private final Component rank; + private final Component chatSplitter; + private final Component fullFormat; + + + AdminChatFormat(final ACFormatBuilder builder) + { + this.prefix = Component.text(builder.openBracket(), builder.bracketColor()) + .append(Component.text(builder.prefix(), builder.prefixColor())) + .append(Component.text(builder.closeBracket(), builder.bracketColor())); + this.userName = Component.text("%name%", builder.nameColor()); + this.rank = Component.text(builder.openBracket(), builder.bracketColor()) + .append(Component.text("%rank%", builder.rankColor())) + .append(Component.text(builder.closeBracket(), builder.bracketColor())); + this.chatSplitter = Component.text(builder.chatSplitter(), NamedTextColor.WHITE); + + this.fullFormat = prefix.append(Component.space()) + .append(userName) + .append(Component.space()) + .append(rank) + .append(Component.space()) + .append(chatSplitter) + .append(Component.space()); + } + + public static AdminChatFormat deserialize(final String serialized) + { + final Component dez = LegacyComponentSerializer.legacyAmpersand() + .deserialize(serialized); + final Component prefix = dez.children() + .get(0); + final Component userName = dez.children() + .get(1); + final Component rank = dez.children() + .get(2); + final Component chatSplitter = dez.children() + .get(3); + + return ACFormatBuilder.format() + .prefix(((TextComponent) prefix).content()) + .prefixColor(prefix.color()) + .nameColor(userName.color()) + .rankColor(rank.color()) + .chatSplitter(((TextComponent) chatSplitter).content()) + .build(); + } + + public Component getPrefix() + { + return prefix; + } + + public Component getUserName() + { + return userName; + } + + public Component getRank() + { + return rank; + } + + public Component getFullFormat() + { + return fullFormat; + } + + public Component format(final String name, final String rank) + { + return fullFormat.replaceText(b -> + { + b.matchLiteral("%name%") + .replacement(name); + b.matchLiteral("%rank%") + .replacement(rank); + }); + } + + public String serialize() + { + return LegacyComponentSerializer.legacyAmpersand() + .serialize(fullFormat); + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/event/EventBus.java b/Patchwork/src/main/java/me/totalfreedom/event/EventBus.java index 67b8514..e012d6f 100644 --- a/Patchwork/src/main/java/me/totalfreedom/event/EventBus.java +++ b/Patchwork/src/main/java/me/totalfreedom/event/EventBus.java @@ -1,7 +1,7 @@ package me.totalfreedom.event; import me.totalfreedom.api.Context; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.service.Service; import java.util.HashSet; @@ -9,11 +9,11 @@ import java.util.Set; public class EventBus extends Service { - private final CommonsBase plugin; + private final Patchwork plugin; private final Set eventSet = new HashSet<>(); private final SubscriptionBox runningSubscriptions = new SubscriptionBox<>(); - public EventBus(final CommonsBase plugin) + public EventBus(final Patchwork plugin) { super("event_bus"); this.plugin = plugin; @@ -57,7 +57,7 @@ public class EventBus extends Service runningSubscriptions.removeSubscription(subscription); } - public CommonsBase getCommonsBase() + public Patchwork getCommonsBase() { return plugin; } diff --git a/Patchwork/src/main/java/me/totalfreedom/security/Groups.java b/Patchwork/src/main/java/me/totalfreedom/security/Groups.java new file mode 100644 index 0000000..2f92fa3 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/security/Groups.java @@ -0,0 +1,30 @@ +package me.totalfreedom.security; + +public enum Groups +{ + NON_OP("patchwork.group.non-op"), + OP("patchwork.group.op"), + SUPER_ADMIN("patchwork.group.super"), + SENIOR_ADMIN("patchwork.group.senior"), + DEVELOPER("patchwork.group.dev"), + EXECUTIVE("patchwork.group.exec"), + OWNER("patchwork.group.owner"); + + private final String permission; + + Groups(final String permission) + { + this.permission = permission; + } + + public String getPermission() + { + return this.permission; + } + + @Override + public String toString() + { + return this.permission; + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java b/Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java index f090314..2b52f4e 100644 --- a/Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java +++ b/Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java @@ -1,6 +1,6 @@ package me.totalfreedom.service; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -29,9 +29,9 @@ public class FreedomExecutor public FreedomExecutor() { syncExecutor = r -> Bukkit.getScheduler() - .runTask(CommonsBase.getInstance(), r); + .runTask(Patchwork.getInstance(), r); asyncExecutor = r -> Bukkit.getScheduler() - .runTaskAsynchronously(CommonsBase.getInstance(), r); + .runTaskAsynchronously(Patchwork.getInstance(), r); } /** diff --git a/Patchwork/src/main/java/me/totalfreedom/shop/ReactionTask.java b/Patchwork/src/main/java/me/totalfreedom/shop/ReactionTask.java index cceb27e..f27f5c6 100644 --- a/Patchwork/src/main/java/me/totalfreedom/shop/ReactionTask.java +++ b/Patchwork/src/main/java/me/totalfreedom/shop/ReactionTask.java @@ -1,7 +1,7 @@ package me.totalfreedom.shop; import io.papermc.paper.event.player.AsyncChatEvent; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import me.totalfreedom.display.BossBarDisplay; import me.totalfreedom.display.BossBarTimer; import me.totalfreedom.economy.EconomicEntity; @@ -36,7 +36,7 @@ public class ReactionTask extends Task implements Listener } final BossBarTimer timer = new BossBarTimer(bossBarDisplay, reaction.getReactionDuration()); - timer.runTaskTimer(CommonsBase.getInstance(), 0L, timer.getInterval()); + timer.runTaskTimer(Patchwork.getInstance(), 0L, timer.getInterval()); } @EventHandler @@ -45,10 +45,10 @@ public class ReactionTask extends Task implements Listener if (event.message() .equals(reaction.getReactionMessage())) { - final EconomicEntity entity = CommonsBase.getInstance() - .getRegistrations() - .getUserRegistry() - .getUser(event.getPlayer()); + final EconomicEntity entity = Patchwork.getInstance() + .getRegistrations() + .getUserRegistry() + .getUser(event.getPlayer()); reaction.onReact(entity); } diff --git a/Patchwork/src/main/java/me/totalfreedom/user/UserData.java b/Patchwork/src/main/java/me/totalfreedom/user/UserData.java index 2cfb8d1..a2c4b4a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/user/UserData.java +++ b/Patchwork/src/main/java/me/totalfreedom/user/UserData.java @@ -1,5 +1,6 @@ package me.totalfreedom.user; +import me.totalfreedom.display.adminchat.AdminChatFormat; import me.totalfreedom.economy.EconomicEntityData; import me.totalfreedom.security.Group; import org.jetbrains.annotations.NotNull; @@ -30,4 +31,10 @@ public interface UserData extends EconomicEntityData boolean canInteract(); void setInteractionState(boolean canInteract); + + boolean hasCustomACFormat(); + + void setCustomACFormat(final String customACFormat); + + AdminChatFormat getCustomACFormat(); } diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/kyori/KyoriConstants.java b/Patchwork/src/main/java/me/totalfreedom/utils/kyori/KyoriConstants.java index 0ffbe29..aa33c59 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/kyori/KyoriConstants.java +++ b/Patchwork/src/main/java/me/totalfreedom/utils/kyori/KyoriConstants.java @@ -1,6 +1,6 @@ package me.totalfreedom.utils.kyori; -import me.totalfreedom.base.CommonsBase; +import me.totalfreedom.base.Patchwork; import net.kyori.adventure.chat.ChatType; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -24,7 +24,7 @@ public final class KyoriConstants /** * A singleton {@link ChatType.Bound} for the Patchwork plugin. */ - public static final ChatType.Bound PATCHWORK = fromPlugin(CommonsBase.class); + public static final ChatType.Bound PATCHWORK = fromPlugin(Patchwork.class); private KyoriConstants() {