AdminChat

This commit is contained in:
Paul Reilly 2023-06-20 09:24:28 -05:00
parent e18a0c0808
commit 09699ccabb
23 changed files with 507 additions and 103 deletions

View File

@ -1,6 +1,6 @@
package me.totalfreedom.corvo; package me.totalfreedom.corvo;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class Corvo extends JavaPlugin public class Corvo extends JavaPlugin
@ -8,7 +8,7 @@ public class Corvo extends JavaPlugin
@Override @Override
public void onDisable() public void onDisable()
{ {
CommonsBase.getInstance() Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getModuleRegistry() .getModuleRegistry()
.removeModule(this); .removeModule(this);
@ -17,7 +17,7 @@ public class Corvo extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
CommonsBase.getInstance() Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getModuleRegistry() .getModuleRegistry()
.addModule(this); .addModule(this);

View File

@ -1,6 +1,6 @@
package me.totalfreedom.datura; 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.Cager;
import me.totalfreedom.datura.punishment.Halter; import me.totalfreedom.datura.punishment.Halter;
import me.totalfreedom.datura.punishment.Locker; import me.totalfreedom.datura.punishment.Locker;
@ -20,16 +20,16 @@ public class Datura extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
CommonsBase.getInstance() Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getModuleRegistry() .getModuleRegistry()
.addModule(this); .addModule(this);
CommonsBase.getInstance() Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getServiceTaskRegistry() .getServiceTaskRegistry()
.registerService(SubscriptionProvider.syncService(this, locker)); .registerService(SubscriptionProvider.syncService(this, locker));
CommonsBase.getInstance() Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getServiceTaskRegistry() .getServiceTaskRegistry()
.registerService(SubscriptionProvider.syncService(this, cager)); .registerService(SubscriptionProvider.syncService(this, cager));

View File

@ -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.
* <p>
* 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) {
}
}

View File

@ -1,6 +1,6 @@
package me.totalfreedom.datura.perms; package me.totalfreedom.datura.perms;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import me.totalfreedom.security.Group; import me.totalfreedom.security.Group;
import me.totalfreedom.security.Node; import me.totalfreedom.security.Node;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -41,7 +41,7 @@ public class FreedomGroup implements Group
this.isDefault = isDefault; this.isDefault = isDefault;
this.isHidden = isHidden; this.isHidden = isHidden;
this.permissions = new HashSet<>(); this.permissions = new HashSet<>();
this.attachment = new PermissionAttachment(CommonsBase.getInstance(), this); this.attachment = new PermissionAttachment(Patchwork.getInstance(), this);
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package me.totalfreedom.datura.perms; package me.totalfreedom.datura.perms;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import me.totalfreedom.datura.Datura; import me.totalfreedom.datura.Datura;
import me.totalfreedom.datura.user.SimpleUserData; import me.totalfreedom.datura.user.SimpleUserData;
import me.totalfreedom.security.Node; import me.totalfreedom.security.Node;
@ -42,7 +42,7 @@ public class FreedomUser implements User
this.permissions = new HashSet<>(); this.permissions = new HashSet<>();
this.displayName = player.displayName(); this.displayName = player.displayName();
final Datura datura = CommonsBase.getInstance() final Datura datura = Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getModuleRegistry() .getModuleRegistry()
.getProvider(Datura.class) .getProvider(Datura.class)
@ -57,7 +57,7 @@ public class FreedomUser implements User
this.userData = data; this.userData = data;
CommonsBase.getInstance() Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getUserRegistry() .getUserRegistry()
.registerUserData(this, userData); .registerUserData(this, userData);
@ -96,7 +96,7 @@ public class FreedomUser implements User
@Override @Override
public boolean addPermission(final Node node) 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); bukkitAttachments.put(node, attachment);
return permissions().add(node); return permissions().add(node);
} }

View File

@ -1,6 +1,6 @@
package me.totalfreedom.datura.punishment; package me.totalfreedom.datura.punishment;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import me.totalfreedom.service.Service; import me.totalfreedom.service.Service;
import me.totalfreedom.utils.ShapeUtils; import me.totalfreedom.utils.ShapeUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -32,7 +32,7 @@ public class Cager extends Service
this.cagedPlayers = new HashSet<>(); this.cagedPlayers = new HashSet<>();
this.cageLocations = new HashMap<>(); this.cageLocations = new HashMap<>();
Bukkit.getPluginManager() Bukkit.getPluginManager()
.registerEvents(new CageListener(), CommonsBase.getInstance()); .registerEvents(new CageListener(), Patchwork.getInstance());
} }
/** /**

View File

@ -1,6 +1,6 @@
package me.totalfreedom.datura.punishment; package me.totalfreedom.datura.punishment;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import me.totalfreedom.service.Service; import me.totalfreedom.service.Service;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -35,7 +35,7 @@ public class Locker extends Service
@Override @Override
public void tick() public void tick()
{ {
lockedPlayers.removeIf(uuid -> !CommonsBase.getInstance() lockedPlayers.removeIf(uuid -> !Patchwork.getInstance()
.getServer() .getServer()
.getOfflinePlayer(uuid) .getOfflinePlayer(uuid)
.isOnline()); .isOnline());

View File

@ -1,6 +1,6 @@
package me.totalfreedom.datura.sql; package me.totalfreedom.datura.sql;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import me.totalfreedom.sql.SQL; import me.totalfreedom.sql.SQL;
import me.totalfreedom.utils.container.Identity; import me.totalfreedom.utils.container.Identity;
@ -75,7 +75,7 @@ public class MySQL implements SQL
throw new CompletionException("Failed to prepare statement: " throw new CompletionException("Failed to prepare statement: "
+ query + "\n", ex); + query + "\n", ex);
} }
}, CommonsBase.getInstance() }, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@ -92,7 +92,7 @@ public class MySQL implements SQL
throw new CompletionException("Failed to connect to the database: " throw new CompletionException("Failed to connect to the database: "
+ url.toString() + "\n", ex); + url.toString() + "\n", ex);
} }
}, CommonsBase.getInstance() }, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@ -112,7 +112,7 @@ public class MySQL implements SQL
"Failed to retrieve a result set from query: " "Failed to retrieve a result set from query: "
+ query + "\n", ex); + query + "\n", ex);
} }
}, CommonsBase.getInstance() }, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@ -131,7 +131,7 @@ public class MySQL implements SQL
throw new CompletionException("Failed to execute update: " throw new CompletionException("Failed to execute update: "
+ query + "\n", ex); + query + "\n", ex);
} }
}, CommonsBase.getInstance() }, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@ -150,7 +150,7 @@ public class MySQL implements SQL
throw new CompletionException("Failed to execute statement: " throw new CompletionException("Failed to execute statement: "
+ query + "\n", ex); + query + "\n", ex);
} }
}, CommonsBase.getInstance() }, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@ -194,7 +194,7 @@ public class MySQL implements SQL
ex); ex);
} }
return null; return null;
}, CommonsBase.getInstance() }, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@ -203,7 +203,7 @@ public class MySQL implements SQL
final String key, final Identity identity) final String key, final Identity identity)
{ {
return executeUpdate("UPDATE ? SET ? = ? WHERE ? = ?", table, column, value, key, identity.getId()) return executeUpdate("UPDATE ? SET ? = ? WHERE ? = ?", table, column, value, key, identity.getId())
.thenApplyAsync(result -> result > 0, CommonsBase.getInstance() .thenApplyAsync(result -> result > 0, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@ -211,7 +211,7 @@ public class MySQL implements SQL
public CompletableFuture<Boolean> deleteRow(final String table, final String key, final Identity identity) public CompletableFuture<Boolean> deleteRow(final String table, final String key, final Identity identity)
{ {
return executeUpdate("DELETE FROM ? WHERE ? = ?", table, key, identity.getId()) return executeUpdate("DELETE FROM ? WHERE ? = ?", table, key, identity.getId())
.thenApplyAsync(result -> result > 0, CommonsBase.getInstance() .thenApplyAsync(result -> result > 0, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }

View File

@ -1,8 +1,9 @@
package me.totalfreedom.datura.user; 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.event.UserDataUpdateEvent;
import me.totalfreedom.datura.perms.FreedomUser; import me.totalfreedom.datura.perms.FreedomUser;
import me.totalfreedom.display.adminchat.AdminChatFormat;
import me.totalfreedom.security.Group; import me.totalfreedom.security.Group;
import me.totalfreedom.sql.SQL; import me.totalfreedom.sql.SQL;
import me.totalfreedom.user.User; import me.totalfreedom.user.User;
@ -29,6 +30,8 @@ public class SimpleUserData implements UserData
private boolean canInteract; private boolean canInteract;
private AtomicLong balance; private AtomicLong balance;
private boolean transactionsFrozen; private boolean transactionsFrozen;
private boolean hasCustomACFormat = false;
private String customACFormat;
public SimpleUserData(final Player player) public SimpleUserData(final Player player)
{ {
@ -36,7 +39,7 @@ public class SimpleUserData implements UserData
this.username = player.getName(); this.username = player.getName();
this.user = new FreedomUser(player); this.user = new FreedomUser(player);
CommonsBase.getInstance() Patchwork.getInstance()
.getEventBus() .getEventBus()
.addEvent(event); .addEvent(event);
} }
@ -59,6 +62,7 @@ public class SimpleUserData implements UserData
this.canInteract = canInteract; this.canInteract = canInteract;
this.balance = new AtomicLong(balance); this.balance = new AtomicLong(balance);
this.transactionsFrozen = transactionsFrozen; this.transactionsFrozen = transactionsFrozen;
this.customACFormat = AdminChatFormat.DEFAULT.serialize();
} }
public static SimpleUserData fromSQL(final SQL sql, final String uuid) public static SimpleUserData fromSQL(final SQL sql, final String uuid)
@ -81,7 +85,7 @@ public class SimpleUserData implements UserData
throw new IllegalStateException("Player should be online but they are not!"); throw new IllegalStateException("Player should be online but they are not!");
final User user = new FreedomUser(player); final User user = new FreedomUser(player);
final Group group = CommonsBase.getInstance() final Group group = Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getGroupRegistry() .getGroupRegistry()
.getGroup(g); .getGroup(g);
@ -113,7 +117,7 @@ public class SimpleUserData implements UserData
if (player == null) throw new IllegalStateException("Player should be online but they are not!"); if (player == null) throw new IllegalStateException("Player should be online but they are not!");
return new SimpleUserData(player); return new SimpleUserData(player);
}, CommonsBase.getInstance() }, Patchwork.getInstance()
.getExecutor() .getExecutor()
.getAsync()) .getAsync())
.join(); .join();
@ -219,4 +223,23 @@ public class SimpleUserData implements UserData
{ {
return balance.addAndGet(-amount); 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);
}
} }

View File

@ -1,6 +1,6 @@
package me.totalfreedom.fossil; package me.totalfreedom.fossil;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import me.totalfreedom.base.Registration; import me.totalfreedom.base.Registration;
import me.totalfreedom.fossil.trail.Trailer; import me.totalfreedom.fossil.trail.Trailer;
import me.totalfreedom.service.SubscriptionProvider; import me.totalfreedom.service.SubscriptionProvider;
@ -9,7 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class Fossil extends JavaPlugin public class Fossil extends JavaPlugin
{ {
private final Trailer trailer = new Trailer(); private final Trailer trailer = new Trailer();
private final Registration registration = CommonsBase.getInstance() private final Registration registration = Patchwork.getInstance()
.getRegistrations(); .getRegistrations();
@Override @Override

View File

@ -1,6 +1,6 @@
package me.totalfreedom.fossil.bouncypads; package me.totalfreedom.fossil.bouncypads;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import me.totalfreedom.fossil.Fossil; import me.totalfreedom.fossil.Fossil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -33,7 +33,7 @@ public class PadHolder implements Listener
public PadHolder() public PadHolder()
{ {
Bukkit.getPluginManager() Bukkit.getPluginManager()
.registerEvents(this, CommonsBase .registerEvents(this, Patchwork
.getInstance() .getInstance()
.getRegistrations() .getRegistrations()
.getModuleRegistry() .getModuleRegistry()

View File

@ -9,7 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin;
/** /**
* The base class for Patchwork. * The base class for Patchwork.
*/ */
public class CommonsBase extends JavaPlugin public class Patchwork extends JavaPlugin
{ {
/** /**
* The {@link EventBus} for this plugin. * The {@link EventBus} for this plugin.
@ -30,9 +30,9 @@ public class CommonsBase extends JavaPlugin
* *
* @return the plugin instance * @return the plugin instance
*/ */
public static CommonsBase getInstance() public static Patchwork getInstance()
{ {
return JavaPlugin.getPlugin(CommonsBase.class); return JavaPlugin.getPlugin(Patchwork.class);
} }
@Override @Override

View File

@ -12,7 +12,7 @@ import me.totalfreedom.data.UserRegistry;
* <br> * <br>
* Registries such as {@link ModuleRegistry} and {@link ServiceTaskRegistry} can be found as final objects in this * 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 * 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 public class Registration
{ {

View File

@ -10,6 +10,6 @@ public final class Shortcuts
} }
public static <T extends JavaPlugin> ModuleProvider<T> provideModule(final Class<T> pluginClass) { public static <T extends JavaPlugin> ModuleProvider<T> provideModule(final Class<T> pluginClass) {
return CommonsBase.getInstance().getRegistrations().getModuleRegistry().getProvider(pluginClass); return Patchwork.getInstance().getRegistrations().getModuleRegistry().getProvider(pluginClass);
} }
} }

View File

@ -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);
}
}

View File

@ -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<UUID, AdminChatFormat> adminChatFormat = new HashMap<>();
private final Set<UUID> 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<UUID> getPlayers()
{
return adminChatFormat.keySet();
}
public Map<UUID, AdminChatFormat> 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);
}
}
}
}
}

View File

@ -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);
}
}

View File

@ -1,7 +1,7 @@
package me.totalfreedom.event; package me.totalfreedom.event;
import me.totalfreedom.api.Context; import me.totalfreedom.api.Context;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import me.totalfreedom.service.Service; import me.totalfreedom.service.Service;
import java.util.HashSet; import java.util.HashSet;
@ -9,11 +9,11 @@ import java.util.Set;
public class EventBus extends Service public class EventBus extends Service
{ {
private final CommonsBase plugin; private final Patchwork plugin;
private final Set<FEvent> eventSet = new HashSet<>(); private final Set<FEvent> eventSet = new HashSet<>();
private final SubscriptionBox<?> runningSubscriptions = new SubscriptionBox<>(); private final SubscriptionBox<?> runningSubscriptions = new SubscriptionBox<>();
public EventBus(final CommonsBase plugin) public EventBus(final Patchwork plugin)
{ {
super("event_bus"); super("event_bus");
this.plugin = plugin; this.plugin = plugin;
@ -57,7 +57,7 @@ public class EventBus extends Service
runningSubscriptions.removeSubscription(subscription); runningSubscriptions.removeSubscription(subscription);
} }
public CommonsBase getCommonsBase() public Patchwork getCommonsBase()
{ {
return plugin; return plugin;
} }

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
package me.totalfreedom.service; package me.totalfreedom.service;
import me.totalfreedom.base.CommonsBase; import me.totalfreedom.base.Patchwork;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -29,9 +29,9 @@ public class FreedomExecutor
public FreedomExecutor() public FreedomExecutor()
{ {
syncExecutor = r -> Bukkit.getScheduler() syncExecutor = r -> Bukkit.getScheduler()
.runTask(CommonsBase.getInstance(), r); .runTask(Patchwork.getInstance(), r);
asyncExecutor = r -> Bukkit.getScheduler() asyncExecutor = r -> Bukkit.getScheduler()
.runTaskAsynchronously(CommonsBase.getInstance(), r); .runTaskAsynchronously(Patchwork.getInstance(), r);
} }
/** /**

View File

@ -1,7 +1,7 @@
package me.totalfreedom.shop; package me.totalfreedom.shop;
import io.papermc.paper.event.player.AsyncChatEvent; 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.BossBarDisplay;
import me.totalfreedom.display.BossBarTimer; import me.totalfreedom.display.BossBarTimer;
import me.totalfreedom.economy.EconomicEntity; import me.totalfreedom.economy.EconomicEntity;
@ -36,7 +36,7 @@ public class ReactionTask extends Task implements Listener
} }
final BossBarTimer timer = new BossBarTimer(bossBarDisplay, reaction.getReactionDuration()); final BossBarTimer timer = new BossBarTimer(bossBarDisplay, reaction.getReactionDuration());
timer.runTaskTimer(CommonsBase.getInstance(), 0L, timer.getInterval()); timer.runTaskTimer(Patchwork.getInstance(), 0L, timer.getInterval());
} }
@EventHandler @EventHandler
@ -45,7 +45,7 @@ public class ReactionTask extends Task implements Listener
if (event.message() if (event.message()
.equals(reaction.getReactionMessage())) .equals(reaction.getReactionMessage()))
{ {
final EconomicEntity entity = CommonsBase.getInstance() final EconomicEntity entity = Patchwork.getInstance()
.getRegistrations() .getRegistrations()
.getUserRegistry() .getUserRegistry()
.getUser(event.getPlayer()); .getUser(event.getPlayer());

View File

@ -1,5 +1,6 @@
package me.totalfreedom.user; package me.totalfreedom.user;
import me.totalfreedom.display.adminchat.AdminChatFormat;
import me.totalfreedom.economy.EconomicEntityData; import me.totalfreedom.economy.EconomicEntityData;
import me.totalfreedom.security.Group; import me.totalfreedom.security.Group;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -30,4 +31,10 @@ public interface UserData extends EconomicEntityData
boolean canInteract(); boolean canInteract();
void setInteractionState(boolean canInteract); void setInteractionState(boolean canInteract);
boolean hasCustomACFormat();
void setCustomACFormat(final String customACFormat);
AdminChatFormat getCustomACFormat();
} }

View File

@ -1,6 +1,6 @@
package me.totalfreedom.utils.kyori; 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.chat.ChatType;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
@ -24,7 +24,7 @@ public final class KyoriConstants
/** /**
* A singleton {@link ChatType.Bound} for the Patchwork plugin. * 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() private KyoriConstants()
{ {