mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2024-12-22 03:27:37 +00:00
AdminChat
This commit is contained in:
parent
e18a0c0808
commit
09699ccabb
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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<Connection> 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<Boolean> 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<Boolean> 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<Boolean> insertRow(final String table, final Object... values)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user