From cae9cb1e26cfa514e44ad641ba8fecf0ed792f86 Mon Sep 17 00:00:00 2001 From: Aria Date: Thu, 2 Mar 2023 18:43:36 -0700 Subject: [PATCH] Update more messages --- .../dev/zontreck/essentials/Messages.java | 27 +++++++++++++++++++ .../commands/teleport/TPACommand.java | 21 +++++++++------ .../commands/teleport/TPAHereCommand.java | 20 +++++++------- .../commands/teleport/TPAcceptCommand.java | 12 ++++++--- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/main/java/dev/zontreck/essentials/Messages.java b/src/main/java/dev/zontreck/essentials/Messages.java index 2ffe8dc..0133a7f 100644 --- a/src/main/java/dev/zontreck/essentials/Messages.java +++ b/src/main/java/dev/zontreck/essentials/Messages.java @@ -1,6 +1,8 @@ package dev.zontreck.essentials; import dev.zontreck.libzontreck.chat.ChatColor; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; public class Messages { public static final String ESSENTIALS_PREFIX; @@ -35,6 +37,18 @@ public class Messages { public static final String TELEPORT_REQUEST_DENIED; public static final String TELEPORT_REQUEST_CANCELLED; + public static final String TELEPORT_ACCEPT; + public static final String TELEPORT_DENY; + public static final SoundEvent TPA_SOUND; + public static final String TPA_HERE; + + public static final String PLAYER_NOT_FOUND; + public static final String NO_TP_TO_SELF; + public static final String NO_MORE_THAN_ONE_TPA; + public static final String TPA; + + public static final String TELEPORT_REQUEST_ACCEPTED; + static{ ESSENTIALS_PREFIX = "!Gray![!Dark_Green!AE!Gray!] "; @@ -74,5 +88,18 @@ public class Messages { TELEPORT_REQUEST_NOT_FOUND = ESSENTIALS_PREFIX + "!Dark_Red!The teleport request could not be found. Perhaps it already expired or was cancelled/denied already."; TELEPORT_REQUEST_DENIED = ESSENTIALS_PREFIX + "!Dark_Red!Teleport request was denied"; TELEPORT_REQUEST_CANCELLED = ESSENTIALS_PREFIX + "!Dark_Red!Teleport request was cancelled"; + TELEPORT_REQUEST_ACCEPTED = ESSENTIALS_PREFIX + "!Dark_Green!Teleport request was accepted"; + + TPA_SOUND = SoundEvents.ANVIL_FALL; + TELEPORT_ACCEPT = "!Dark_Gray![!Dark_Green!Accept!Dark_Gray!]"; + TELEPORT_DENY = "!Dark_Gray![!Dark_Red!Deny!Dark_Gray!]"; + + TPA_HERE = "[0] !Bold!!Dark_Purple!is requesting you to teleport to them!\n\n"; + + PLAYER_NOT_FOUND = ESSENTIALS_PREFIX + "!Dark_Red!Error: Player not found"; + NO_TP_TO_SELF = ESSENTIALS_PREFIX + "!Dark_Red!You cannot teleport to yourself!"; + NO_MORE_THAN_ONE_TPA = ESSENTIALS_PREFIX + "!Dark_Red!You already have a TPA Request active, wait for it to expire, or use the cancel button/command"; + + TPA = "[0] !Bold!!Dark_Purple! is requesting to teleport to you!\n\n"; } } diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TPACommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TPACommand.java index d78a27e..ed0b3b3 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TPACommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TPACommand.java @@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; +import dev.zontreck.essentials.Messages; import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.libzontreck.chat.Clickable; import dev.zontreck.libzontreck.chat.HoverTip; @@ -17,6 +18,7 @@ import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextComponent; import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.network.NetworkHooks; public class TPACommand { @@ -33,7 +35,7 @@ public class TPACommand { private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) { // Send the request to player if(serverPlayer == null){ - source.sendFailure(new TextComponent(ChatColor.DARK_RED+"Error: Player not found")); + source.sendFailure(ChatHelpers.macro(Messages.PLAYER_NOT_FOUND)); return 1; } @@ -41,7 +43,7 @@ public class TPACommand { if(play.getUUID() == serverPlayer.getUUID()){ - source.sendFailure(new TextComponent(ChatColor.DARK_RED+"You cannot teleport to yourself!")); + source.sendFailure(ChatHelpers.macro(Messages.NO_TP_TO_SELF)); return 1; } @@ -49,11 +51,11 @@ public class TPACommand { for(TeleportContainer cont2 : TeleportRegistry.get()){ if(cont2.compareTo(cont)==0){ - ChatHelpers.broadcastTo(cont.FromPlayer, new TextComponent(ChatColor.DARK_RED+ "You already have a TPA Request active, wait for it to expire, or use the cancel button/command"), source.getServer()); + ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro(Messages.NO_MORE_THAN_ONE_TPA), source.getServer()); return 0; }else { if(cont2.FromPlayer == cont.FromPlayer){ - ChatHelpers.broadcastTo(cont.FromPlayer, new TextComponent(ChatColor.DARK_RED+ "You already have a TPA Request active, wait for it to expire, or use the cancel button/command"), source.getServer()); + ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro(Messages.NO_MORE_THAN_ONE_TPA), source.getServer()); return 0; } } @@ -61,7 +63,7 @@ public class TPACommand { ClickEvent ce = Clickable.command("/tpcancel "+cont.TeleportID.toString()); - HoverEvent he = HoverTip.get(ChatColor.DARK_GREEN+"Cancel this teleport request (Not yet implemented)"); + HoverEvent he = HoverTip.get(ChatColor.DARK_GREEN+"Cancel this teleport request"); Style s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(he).withClickEvent(ce); @@ -77,15 +79,18 @@ public class TPACommand { Style s2 = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce2).withHoverEvent(he2); + + Profile p; try { p = Profile.get_profile_of(cont.FromPlayer.toString()); } catch (UserProfileNotYetExistsException e) { return 1; } - ChatHelpers.broadcastTo(cont.ToPlayer, new TextComponent(p.name_color+p.nickname + ChatColor.BOLD + ChatColor.DARK_PURPLE+" is requesting to teleport to you\n \n"). - append(new TextComponent(ChatColor.DARK_GRAY+"["+ChatColor.DARK_GREEN+"ACCEPT" + ChatColor.DARK_GRAY+"] ").setStyle(s)). - append(new TextComponent(ChatColor.DARK_GRAY + "["+ChatColor.DARK_RED+"DENY"+ChatColor.DARK_GRAY+"]").setStyle(s2)), serverPlayer.server); + serverPlayer.playSound(Messages.TPA_SOUND, 1, serverPlayer.getRandom().nextFloat()); + ChatHelpers.broadcastTo(cont.ToPlayer, ChatHelpers.macro(Messages.TPA, p.name_color+p.nickname). + append(ChatHelpers.macro(Messages.TELEPORT_ACCEPT+" ").setStyle(s)). + append(ChatHelpers.macro(Messages.TELEPORT_DENY).setStyle(s2)), serverPlayer.server); TeleportRegistry.get().add(cont); return 0; diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TPAHereCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TPAHereCommand.java index 5546942..d729fc9 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TPAHereCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TPAHereCommand.java @@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.teleport; import com.mojang.brigadier.CommandDispatcher; +import dev.zontreck.essentials.Messages; import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.libzontreck.chat.Clickable; import dev.zontreck.libzontreck.chat.HoverTip; @@ -35,11 +36,11 @@ public class TPAHereCommand { ServerPlayer play = (ServerPlayer)source.getEntity(); if(serverPlayer == null){ - source.sendFailure(new TextComponent(ChatColor.DARK_RED+"Error: Player not found")); + source.sendFailure(ChatHelpers.macro(Messages.PLAYER_NOT_FOUND)); return 1; } if(play.getUUID() == serverPlayer.getUUID()){ - source.sendFailure(new TextComponent(ChatColor.DARK_RED+"You cannot teleport to yourself!")); + source.sendFailure(ChatHelpers.macro(Messages.NO_TP_TO_SELF)); return 1; } @@ -47,11 +48,11 @@ public class TPAHereCommand { for(TeleportContainer cont2 : TeleportRegistry.get()){ if(cont2.compareTo(cont)==0){ - ChatHelpers.broadcastTo(cont.ToPlayer, new TextComponent(ChatColor.DARK_RED+ "You already have a TPA Request active, wait for it to expire, or use the cancel button/command"), source.getServer()); + ChatHelpers.broadcastTo(cont.ToPlayer, ChatHelpers.macro(Messages.NO_MORE_THAN_ONE_TPA), source.getServer()); return 0; }else { if(cont2.ToPlayer.equals(cont.ToPlayer)){ - ChatHelpers.broadcastTo(cont.FromPlayer, new TextComponent(ChatColor.DARK_RED+ "You already have a TPA Request active, wait for it to expire, or use the cancel button/command"), source.getServer()); + ChatHelpers.broadcastTo(cont.ToPlayer, ChatHelpers.macro(Messages.NO_MORE_THAN_ONE_TPA), source.getServer()); return 0; } } @@ -59,7 +60,7 @@ public class TPAHereCommand { ClickEvent ce = Clickable.command("/tpcancel "+cont.TeleportID.toString()); - HoverEvent he = HoverTip.get(ChatColor.DARK_GREEN+"Cancel this teleport request (Not yet implemented)"); + HoverEvent he = HoverTip.get(ChatColor.DARK_GREEN+"Cancel this teleport request"); Style s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(he).withClickEvent(ce); @@ -81,16 +82,17 @@ public class TPAHereCommand { } catch (UserProfileNotYetExistsException e) { return 1; } - ChatHelpers.broadcastTo(cont.FromPlayer, new TextComponent(p.name_color+p.nickname + ChatColor.BOLD + ChatColor.DARK_PURPLE+" is requesting you to teleport to them\n \n"). - append(new TextComponent(ChatColor.DARK_GRAY+"["+ChatColor.DARK_GREEN+"ACCEPT" + ChatColor.DARK_GRAY+"] ").setStyle(s)). - append(new TextComponent(ChatColor.DARK_GRAY + "["+ChatColor.DARK_RED+"DENY"+ChatColor.DARK_GRAY+"]").setStyle(s2)), serverPlayer.server); + serverPlayer.playSound(Messages.TPA_SOUND, 1, serverPlayer.getRandom().nextFloat()); + ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro(Messages.TPA_HERE, p.name_color+p.nickname). + append(ChatHelpers.macro(Messages.TELEPORT_ACCEPT+" ").setStyle(s)). + append(ChatHelpers.macro(Messages.TELEPORT_DENY).setStyle(s2)), serverPlayer.server); TeleportRegistry.get().add(cont); return 0; } private static int usage(CommandSourceStack source) { - source.sendSuccess(new TextComponent("/tpa USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"), false); + source.sendSuccess(new TextComponent("/tpahere USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpahere "+ChatColor.DARK_RED+"target_player\n"), false); return 0; } } diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TPAcceptCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TPAcceptCommand.java index ff4e9ee..9b201a6 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TPAcceptCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TPAcceptCommand.java @@ -1,5 +1,6 @@ package dev.zontreck.essentials.commands.teleport; +import java.util.Iterator; import java.util.UUID; import com.mojang.brigadier.CommandDispatcher; @@ -32,19 +33,22 @@ public class TPAcceptCommand { UUID teleporter = UUID.fromString(TPID); ServerPlayer play = (ServerPlayer)source.getEntity(); - for(TeleportContainer cont : TeleportRegistry.get()){ + Iterator it = TeleportRegistry.get().iterator(); + while(it.hasNext()) + { + TeleportContainer cont = it.next(); if(cont.TeleportID.equals(teleporter)){ // Accepting! ServerPlayer from = source.getServer().getPlayerList().getPlayer(cont.FromPlayer); ServerPlayer to = source.getServer().getPlayerList().getPlayer(cont.ToPlayer); - Component comp = new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.DARK_PURPLE+"Teleport request was accepted. Opening wormhole!"); + Component comp = ChatHelpers.macro(Messages.TELEPORT_REQUEST_ACCEPTED); ChatHelpers.broadcastTo(cont.FromPlayer, comp, source.getServer()); ChatHelpers.broadcastTo(cont.ToPlayer, comp, source.getServer()); - TeleportRegistry.get().remove(cont); + it.remove(); cont.PlayerInst = from; @@ -58,7 +62,7 @@ public class TPAcceptCommand { } } - Component comp = new TextComponent(ChatColor.DARK_RED+"The teleport was not found, perhaps the request expired or was already cancelled/denied"); + Component comp = ChatHelpers.macro(Messages.TELEPORT_REQUEST_NOT_FOUND); ChatHelpers.broadcastTo(play.getUUID(), comp, source.getServer());