From 6eaab7c7eeec1ce9b3a5c264d3add2c9dcb76d2e Mon Sep 17 00:00:00 2001 From: Aria Date: Tue, 28 Feb 2023 22:14:15 -0700 Subject: [PATCH] Move more messages into the central location --- .../dev/zontreck/essentials/Messages.java | 22 ++++++++++++++++++- .../commands/warps/RTPWarpCommand.java | 10 ++++++++- .../commands/warps/SetWarpCommand.java | 9 +++++++- .../commands/warps/WarpCommand.java | 8 +++---- .../essentials/configs/EssentialsConfig.java | 8 ++++++- .../essentials/events/WarpCreatedEvent.java | 5 +++++ 6 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/main/java/dev/zontreck/essentials/Messages.java b/src/main/java/dev/zontreck/essentials/Messages.java index 3000093..4afb9ca 100644 --- a/src/main/java/dev/zontreck/essentials/Messages.java +++ b/src/main/java/dev/zontreck/essentials/Messages.java @@ -19,10 +19,22 @@ public class Messages { public static final String WARP_ACCESS_FORMAT; public static final String PUBLIC; public static final String PRIVATE; - + + public static final String WARP_NAME_REQUIRED; + public static final String WARP_NOT_EXIST; + public static final String WARP_ATTEMPTING; + public static final String WARPING; + public static final String WARP_CREATED; + public static final String WARP_CREATE_ERROR; + public static final String WARP_RTP_CREATED; + static{ ESSENTIALS_PREFIX = "!Gray![!Dark_Green!AE!Gray!] "; + WARP_ATTEMPTING = ESSENTIALS_PREFIX + "!Dark_Green!Attempting to find a safe landing location. This may take a minute"; + WARPING = ESSENTIALS_PREFIX+"!Dark_green!Warping"; + + RTP_SEARCHING = ESSENTIALS_PREFIX + "!Dark_Purple!Searching... Attempt !Gold![0]!White!/!Dark_Red![1]"; RTP_CANCELLED = ESSENTIALS_PREFIX + "!Dark_Red!Last position was good, but another mod asked us not to send you there. This could happen with a claims mod."; RTP_ABORTED = ESSENTIALS_PREFIX + "!Dark_Red!Could not find a suitable location in [0] attempts. Giving up. [1]"; @@ -38,5 +50,13 @@ public class Messages { WARP_ACCESS_FORMAT = "!Dark_Purple!This warp is [0]"; PUBLIC = "!Dark_Green!Public"; PRIVATE = "!Dark_Red!Private"; + + WARP_NAME_REQUIRED = ESSENTIALS_PREFIX + "!Dark_Red!The warp name is required in order to warp. You can click this message to get a full list of the warps you have access to."; + WARP_NOT_EXIST = ESSENTIALS_PREFIX + "!Dark_Red!No Such Warp"; + + WARP_CREATED = ESSENTIALS_PREFIX + "!Dark_Green!Warp created successfully"; + WARP_CREATE_ERROR = ESSENTIALS_PREFIX + "!Dark_Red!Warp could not be created due to [0]"; + + WARP_RTP_CREATED = WARP_CREATED+" with RTP properties"; } } diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/RTPWarpCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/RTPWarpCommand.java index e565c0d..4d2864e 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/RTPWarpCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/RTPWarpCommand.java @@ -9,6 +9,7 @@ import com.mojang.brigadier.arguments.StringArgumentType; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.commands.teleport.TeleportDestination; +import dev.zontreck.essentials.events.WarpCreatedEvent; import dev.zontreck.essentials.warps.Warp; import dev.zontreck.essentials.warps.WarpsProvider; import dev.zontreck.libzontreck.chat.ChatColor; @@ -23,6 +24,7 @@ import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.MinecraftForge; public class RTPWarpCommand { @@ -45,10 +47,16 @@ public class RTPWarpCommand { TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); Warp warp = new Warp(p.getUUID(), string, true, true, dest); + WarpCreatedEvent event = new WarpCreatedEvent(warp); + if(MinecraftForge.EVENT_BUS.post(event)) + { + ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(ChatHelpers.macroize(Messages.WARP_CREATE_ERROR)), p.server); + return 0; + } WarpsProvider.WARPS_INSTANCE.add(warp); - ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX+ChatColor.doColors(" !Dark_Green!Random Position Teleport (RTP) Warp created successfully")), p.server); + ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(ChatHelpers.macroize(Messages.WARP_RTP_CREATED)), p.server); return 0; } diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java index 7223ba7..7c1dbcb 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/SetWarpCommand.java @@ -9,6 +9,7 @@ import com.mojang.brigadier.arguments.StringArgumentType; import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.commands.teleport.TeleportDestination; +import dev.zontreck.essentials.events.WarpCreatedEvent; import dev.zontreck.essentials.warps.Warp; import dev.zontreck.essentials.warps.WarpsProvider; import dev.zontreck.libzontreck.chat.ChatColor; @@ -23,6 +24,7 @@ import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.MinecraftForge; public class SetWarpCommand { @@ -46,9 +48,14 @@ public class SetWarpCommand { TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel()); Warp w = new Warp(p.getUUID(), string, false, true, dest); + WarpCreatedEvent event = new WarpCreatedEvent(w); + if(MinecraftForge.EVENT_BUS.post(event)){ + ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(ChatHelpers.macroize(Messages.WARP_CREATE_ERROR, event.denyReason)), p.server); + return 0; + } WarpsProvider.WARPS_INSTANCE.add(w); - ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX+ChatColor.doColors(" !Dark_Green!Warp created successfully")), p.server); + ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(ChatHelpers.macroize(Messages.WARP_CREATED)), p.server); return 0; } diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/WarpCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/WarpCommand.java index fb4a153..cadc080 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/WarpCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/WarpCommand.java @@ -64,10 +64,10 @@ public class WarpCommand { if(type == 1) { - ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX+ ChatColor.doColors(" !Dark_Green!Attempting to locate a safe location. This may take a minute or two")), p.server); + ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(ChatHelpers.macroize(Messages.WARP_ATTEMPTING)), p.server); }else{ - ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX+ ChatColor.doColors(" !Dark_Purple!Warping!")), p.server); + ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(ChatHelpers.macroize(Messages.WARPING)), p.server); } Thread tx = new Thread(new Runnable(){ @@ -92,7 +92,7 @@ public class WarpCommand { tx.start(); }catch(NoSuchWarpException e) { - ChatHelpers.broadcastTo(source.getEntity().getUUID(), new TextComponent(ChatColor.DARK_RED+"No such warp"), source.getServer()); + ChatHelpers.broadcastTo(source.getEntity().getUUID(), new TextComponent(ChatHelpers.macroize(Messages.WARP_NOT_EXIST)), source.getServer()); } catch (CommandSyntaxException e) { e.printStackTrace(); } @@ -101,7 +101,7 @@ public class WarpCommand { private static int nowarp(CommandSourceStack source) { ServerPlayer p = (ServerPlayer)source.getEntity(); - ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(ChatColor.DARK_RED + "You must supply the warp name. If you need to know what warps are available, please use the warps command, or click this message.").withStyle(Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(Clickable.command("/warps"))), source.getServer()); + ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(ChatHelpers.macroize(Messages.WARP_NAME_REQUIRED)).withStyle(Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(Clickable.command("/warps"))), source.getServer()); return 0; } diff --git a/src/main/java/dev/zontreck/essentials/configs/EssentialsConfig.java b/src/main/java/dev/zontreck/essentials/configs/EssentialsConfig.java index 5549a0c..81ff8fd 100644 --- a/src/main/java/dev/zontreck/essentials/configs/EssentialsConfig.java +++ b/src/main/java/dev/zontreck/essentials/configs/EssentialsConfig.java @@ -1,5 +1,11 @@ package dev.zontreck.essentials.configs; public class EssentialsConfig { - + // TODO: + /* + * 1. Waystone support, Issue #1 + * 2. Economy support for server owners to charge a fee to use warps and / or homes + * + * + */ } diff --git a/src/main/java/dev/zontreck/essentials/events/WarpCreatedEvent.java b/src/main/java/dev/zontreck/essentials/events/WarpCreatedEvent.java index ee007d7..d8993f4 100644 --- a/src/main/java/dev/zontreck/essentials/events/WarpCreatedEvent.java +++ b/src/main/java/dev/zontreck/essentials/events/WarpCreatedEvent.java @@ -8,6 +8,11 @@ import net.minecraftforge.eventbus.api.Event; public class WarpCreatedEvent extends Event { public Warp warp; + + /** + * Edit this value to specify a reason for cancelling the event to the end user + */ + public String denyReason = "an unknown error"; public WarpCreatedEvent(Warp w) { warp=w;