Add nick and prefix commands
This commit is contained in:
parent
05b7d0e38f
commit
40288b1a92
8 changed files with 175 additions and 0 deletions
|
@ -6,12 +6,17 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import dev.zontreck.ase.guis.ChestGUI;
|
import dev.zontreck.ase.guis.ChestGUI;
|
||||||
import dev.zontreck.ase.guis.PrimitiveAction;
|
import dev.zontreck.ase.guis.PrimitiveAction;
|
||||||
import dev.zontreck.ase.guis.PrimitiveItem;
|
import dev.zontreck.ase.guis.PrimitiveItem;
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
public class EventsHandler implements Listener {
|
public class EventsHandler implements Listener {
|
||||||
|
|
||||||
|
@ -30,6 +35,42 @@ public class EventsHandler implements Listener {
|
||||||
AriasServerEssentials.cachedPlayerData.remove(id);
|
AriasServerEssentials.cachedPlayerData.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public static void onChat(AsyncChatEvent ev) {
|
||||||
|
Player sender = ev.getPlayer();
|
||||||
|
Component message = ev.message();
|
||||||
|
|
||||||
|
// Get player's saved data
|
||||||
|
SavedData playerData = AriasServerEssentials.getPlayerData(sender.getUniqueId().toString());
|
||||||
|
String nickname = playerData.profile.nickname;
|
||||||
|
String prefix = playerData.profile.prefix;
|
||||||
|
|
||||||
|
// Fallbacks
|
||||||
|
if (nickname == null || nickname.isEmpty()) {
|
||||||
|
nickname = sender.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefix == null) {
|
||||||
|
prefix = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the chat format: [prefix] [nickname/username]: message
|
||||||
|
Component prefixComponent = Component.text(prefix, NamedTextColor.GRAY);
|
||||||
|
Component nameComponent = Component.text(nickname, NamedTextColor.YELLOW);
|
||||||
|
Component colonComponent = Component.text(": ", NamedTextColor.GRAY);
|
||||||
|
|
||||||
|
Component finalMessage = Component.empty()
|
||||||
|
.append(prefixComponent)
|
||||||
|
.append(Component.space())
|
||||||
|
.append(nameComponent)
|
||||||
|
.append(colonComponent)
|
||||||
|
.append(message)
|
||||||
|
.hoverEvent(HoverEvent.showText(Component.text("Username: " + sender.getName())));
|
||||||
|
|
||||||
|
ev.setCancelled(true); // Cancel the original message
|
||||||
|
ev.viewers().forEach(viewer -> viewer.sendMessage(finalMessage));
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public static void onPlayerInteractGUI(InventoryClickEvent ice) {
|
public static void onPlayerInteractGUI(InventoryClickEvent ice) {
|
||||||
// Get the player who clicked
|
// Get the player who clicked
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package dev.zontreck.ase.commands;
|
package dev.zontreck.ase.commands;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
|
||||||
|
@ -10,6 +12,8 @@ import dev.zontreck.ase.commands.homes.SetHomeCommand;
|
||||||
import dev.zontreck.ase.commands.misc.BroadcastCommand;
|
import dev.zontreck.ase.commands.misc.BroadcastCommand;
|
||||||
import dev.zontreck.ase.commands.misc.CloseInvCommand;
|
import dev.zontreck.ase.commands.misc.CloseInvCommand;
|
||||||
import dev.zontreck.ase.commands.misc.CreditsCommand;
|
import dev.zontreck.ase.commands.misc.CreditsCommand;
|
||||||
|
import dev.zontreck.ase.commands.misc.NickCommand;
|
||||||
|
import dev.zontreck.ase.commands.misc.PrefixCommand;
|
||||||
import dev.zontreck.ase.commands.misc.PronounsCommand;
|
import dev.zontreck.ase.commands.misc.PronounsCommand;
|
||||||
import dev.zontreck.ase.commands.misc.ShareItemCommand;
|
import dev.zontreck.ase.commands.misc.ShareItemCommand;
|
||||||
import dev.zontreck.ase.commands.tpa.TPACancelCommand;
|
import dev.zontreck.ase.commands.tpa.TPACancelCommand;
|
||||||
|
@ -202,5 +206,29 @@ public class CommandRegistry {
|
||||||
PlayerPronouns.TheyThem)))
|
PlayerPronouns.TheyThem)))
|
||||||
|
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
cmds.register(Commands.literal("nick")
|
||||||
|
.requires(x -> x.getSender().isPermissionSet(NickCommand.PERMISSION))
|
||||||
|
.then(Commands.argument("nick", StringArgumentType.string())
|
||||||
|
.executes(ctx -> NickCommand.execute(ctx.getSource(),
|
||||||
|
StringArgumentType.getString(ctx, "nick"))))
|
||||||
|
|
||||||
|
.build());
|
||||||
|
|
||||||
|
cmds.register(Commands.literal("prefix")
|
||||||
|
.requires(x -> x.getSender().isPermissionSet(PrefixCommand.PERMISSION))
|
||||||
|
.then(Commands.argument("prefix", StringArgumentType.word())
|
||||||
|
.executes(ctx -> PrefixCommand.execute(ctx.getSource(),
|
||||||
|
(Player) ctx.getSource().getSender(),
|
||||||
|
StringArgumentType.getString(ctx, "prefix"))))
|
||||||
|
.then(Commands.argument("target", ArgumentTypes.player())
|
||||||
|
.requires(x -> x.getSender().isOp())
|
||||||
|
.executes(ctx -> PrefixCommand.execute(ctx.getSource(),
|
||||||
|
ctx.getArgument("target",
|
||||||
|
PlayerSelectorArgumentResolver.class)
|
||||||
|
.resolve(ctx.getSource()).getFirst(),
|
||||||
|
StringArgumentType.getString(ctx, "prefix"))))
|
||||||
|
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package dev.zontreck.ase.commands.misc;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
|
||||||
|
import dev.zontreck.ase.AriasServerEssentials;
|
||||||
|
import dev.zontreck.ase.SavedData;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
public class NickCommand {
|
||||||
|
public static final String PERMISSION = "ase.commands.nick";
|
||||||
|
|
||||||
|
public static int execute(CommandSourceStack ctx, String nickname) {
|
||||||
|
Player player = (Player) ctx.getSender();
|
||||||
|
SavedData data = AriasServerEssentials.getPlayerData(player.getUniqueId().toString());
|
||||||
|
|
||||||
|
data.profile.nickname = nickname;
|
||||||
|
data.save(player.getUniqueId().toString());
|
||||||
|
|
||||||
|
player.sendMessage(Component.text("Your nickname has been updated!", NamedTextColor.DARK_GREEN));
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package dev.zontreck.ase.commands.misc;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
|
||||||
|
import dev.zontreck.ase.AriasServerEssentials;
|
||||||
|
import dev.zontreck.ase.SavedData;
|
||||||
|
import dev.zontreck.ase.utils.ProfileUtils;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
public class PrefixCommand {
|
||||||
|
public static final String PERMISSION = "ase.commands.prefix";
|
||||||
|
|
||||||
|
public static int execute(CommandSourceStack ctx, Player target, String prefix) {
|
||||||
|
SavedData data = AriasServerEssentials.getPlayerData(target.getUniqueId().toString());
|
||||||
|
|
||||||
|
data.profile.prefix = prefix;
|
||||||
|
data.save(target.getUniqueId().toString());
|
||||||
|
|
||||||
|
ctx.getSender()
|
||||||
|
.sendMessage(Component.text("Prefix for '", NamedTextColor.DARK_GREEN)
|
||||||
|
.append(Component.text(ProfileUtils.getPlayerNickname(target), NamedTextColor.YELLOW)
|
||||||
|
.append(Component.text("' has been updated.", NamedTextColor.DARK_GREEN))));
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,11 +5,13 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||||
public class PlayerProfile {
|
public class PlayerProfile {
|
||||||
public PlayerPronouns pronouns = PlayerPronouns.TheyThem;
|
public PlayerPronouns pronouns = PlayerPronouns.TheyThem;
|
||||||
public String nickname = "";
|
public String nickname = "";
|
||||||
|
public String prefix = "";
|
||||||
|
|
||||||
public ConfigurationSection serialize(ConfigurationSection parent) {
|
public ConfigurationSection serialize(ConfigurationSection parent) {
|
||||||
ConfigurationSection profile = parent.createSection("profile");
|
ConfigurationSection profile = parent.createSection("profile");
|
||||||
profile.set("nickname", nickname);
|
profile.set("nickname", nickname);
|
||||||
profile.set("pronouns", pronouns.name());
|
profile.set("pronouns", pronouns.name());
|
||||||
|
profile.set("prefix", prefix);
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +20,7 @@ public class PlayerProfile {
|
||||||
if (section == null)
|
if (section == null)
|
||||||
return new PlayerProfile();
|
return new PlayerProfile();
|
||||||
String nick = "";
|
String nick = "";
|
||||||
|
String prefix = "";
|
||||||
PlayerPronouns pronouns = PlayerPronouns.TheyThem;
|
PlayerPronouns pronouns = PlayerPronouns.TheyThem;
|
||||||
if (section.contains("nickname")) {
|
if (section.contains("nickname")) {
|
||||||
nick = section.getString("nickname");
|
nick = section.getString("nickname");
|
||||||
|
@ -27,9 +30,14 @@ public class PlayerProfile {
|
||||||
pronouns = PlayerPronouns.valueOf(section.getString("pronouns"));
|
pronouns = PlayerPronouns.valueOf(section.getString("pronouns"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (section.contains("prefix")) {
|
||||||
|
prefix = section.getString("prefix");
|
||||||
|
}
|
||||||
|
|
||||||
PlayerProfile profile = new PlayerProfile();
|
PlayerProfile profile = new PlayerProfile();
|
||||||
profile.nickname = nick;
|
profile.nickname = nick;
|
||||||
profile.pronouns = pronouns;
|
profile.pronouns = pronouns;
|
||||||
|
profile.prefix = prefix;
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
15
src/main/java/dev/zontreck/ase/utils/ProfileUtils.java
Normal file
15
src/main/java/dev/zontreck/ase/utils/ProfileUtils.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package dev.zontreck.ase.utils;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import dev.zontreck.ase.AriasServerEssentials;
|
||||||
|
|
||||||
|
public class ProfileUtils {
|
||||||
|
public static String getPlayerPrefix(Player player) {
|
||||||
|
return AriasServerEssentials.getPlayerData(player.getUniqueId().toString()).profile.prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPlayerNickname(Player player) {
|
||||||
|
return AriasServerEssentials.getPlayerData(player.getUniqueId().toString()).profile.nickname;
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,6 +66,12 @@ commands:
|
||||||
pronouns:
|
pronouns:
|
||||||
description: Update your pronouns!
|
description: Update your pronouns!
|
||||||
usage: "- /pronouns [sheher,hehim,theythem] -"
|
usage: "- /pronouns [sheher,hehim,theythem] -"
|
||||||
|
nick:
|
||||||
|
description: Change nickname
|
||||||
|
usage: "- /nick [nickname] -"
|
||||||
|
prefix:
|
||||||
|
description: Change prefix
|
||||||
|
usage: "- /prefix [optional:player] [prefix]"
|
||||||
permissions:
|
permissions:
|
||||||
ase.commands.*:
|
ase.commands.*:
|
||||||
description: Allow all commands
|
description: Allow all commands
|
||||||
|
@ -88,6 +94,7 @@ permissions:
|
||||||
ase.commands.warps: true
|
ase.commands.warps: true
|
||||||
ase.commands.editwarp: true
|
ase.commands.editwarp: true
|
||||||
ase.commands.pronouns: true
|
ase.commands.pronouns: true
|
||||||
|
ase.commands.nick: true
|
||||||
ase.commands.home:
|
ase.commands.home:
|
||||||
description: Allows usage of the /home command
|
description: Allows usage of the /home command
|
||||||
default: true
|
default: true
|
||||||
|
@ -148,3 +155,9 @@ permissions:
|
||||||
ase.commands.pronouns:
|
ase.commands.pronouns:
|
||||||
description: Allow usage of /pronouns
|
description: Allow usage of /pronouns
|
||||||
default: true
|
default: true
|
||||||
|
ase.commands.nick:
|
||||||
|
description: Allow changing nickname
|
||||||
|
default: true
|
||||||
|
ase.commands.prefix:
|
||||||
|
description: Allow changing prefix
|
||||||
|
default: false
|
||||||
|
|
|
@ -66,6 +66,12 @@ commands:
|
||||||
pronouns:
|
pronouns:
|
||||||
description: Update your pronouns!
|
description: Update your pronouns!
|
||||||
usage: "- /pronouns [sheher,hehim,theythem] -"
|
usage: "- /pronouns [sheher,hehim,theythem] -"
|
||||||
|
nick:
|
||||||
|
description: Change nickname
|
||||||
|
usage: "- /nick [nickname] -"
|
||||||
|
prefix:
|
||||||
|
description: Change prefix
|
||||||
|
usage: "- /prefix [optional:player] [prefix]"
|
||||||
permissions:
|
permissions:
|
||||||
ase.commands.*:
|
ase.commands.*:
|
||||||
description: Allow all commands
|
description: Allow all commands
|
||||||
|
@ -88,6 +94,7 @@ permissions:
|
||||||
ase.commands.warps: true
|
ase.commands.warps: true
|
||||||
ase.commands.editwarp: true
|
ase.commands.editwarp: true
|
||||||
ase.commands.pronouns: true
|
ase.commands.pronouns: true
|
||||||
|
ase.commands.nick: true
|
||||||
ase.commands.home:
|
ase.commands.home:
|
||||||
description: Allows usage of the /home command
|
description: Allows usage of the /home command
|
||||||
default: true
|
default: true
|
||||||
|
@ -148,3 +155,9 @@ permissions:
|
||||||
ase.commands.pronouns:
|
ase.commands.pronouns:
|
||||||
description: Allow usage of /pronouns
|
description: Allow usage of /pronouns
|
||||||
default: true
|
default: true
|
||||||
|
ase.commands.nick:
|
||||||
|
description: Allow changing nickname
|
||||||
|
default: true
|
||||||
|
ase.commands.prefix:
|
||||||
|
description: Allow changing prefix
|
||||||
|
default: false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue