mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-06-26 19:44:27 +00:00
AdminChat
This commit is contained in:
@ -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
|
@ -12,7 +12,7 @@ import me.totalfreedom.data.UserRegistry;
|
||||
* <br>
|
||||
* 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
|
||||
{
|
||||
|
@ -10,6 +10,6 @@ public final class Shortcuts
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<FEvent> 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;
|
||||
}
|
||||
|
30
Patchwork/src/main/java/me/totalfreedom/security/Groups.java
Normal file
30
Patchwork/src/main/java/me/totalfreedom/security/Groups.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
|
Reference in New Issue
Block a user