From d754247455c0f7ef75e2333066ca461aeaa23520 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sun, 31 Oct 2021 14:05:06 +0100 Subject: [PATCH] Makes some smaller changes Replaces the mystery code in sendMessage with translateAlternateColorCodes and removes the TODO Removes the TODO in deactivate() as it is actually necessary because fixed portals are always active Moves conflictsWithExistingGate to PortalCreator and removes the TODO for now Removes the extra spaces in >Random< Adjusts some comments Adds missing information about Economy and the requirement of UUIDs --- README.md | 19 ++++++++----- .../stargate/config/MessageSender.java | 4 +-- .../stargate/event/StargateAccessEvent.java | 2 +- .../stargate/portal/PortalActivator.java | 4 +-- .../stargate/portal/PortalCreator.java | 23 ++++++++++++++- .../stargate/portal/PortalHandler.java | 28 ++----------------- .../stargate/portal/PortalSignDrawer.java | 2 +- 7 files changed, 40 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 3a8b5fe..c4f108d 100644 --- a/README.md +++ b/README.md @@ -22,18 +22,23 @@ version of Stargate compliant with Spigot 1.17, even if it means changing the en ## Migration -This plugin should be compatible with configurations from the Stargate plugin all the way back. The nethergate.gate -file, the endgate.gate file and the watergate.gate file will be overwritten if they exist. Take a backup of the files +This plugin should be compatible with configurations from the Stargate plugin all the way back. The nethergate.gate +file, the endgate.gate file and the watergate.gate file will be overwritten if they exist. Take a backup of the files and overwrite the files after the first startup if you want to keep your custom gates. -If you have legacy gate files using the old numeric material ids, you need to change them to the new format manually. -Use F3 + H to see material ids. Use them exactly as written after "minecraft:". -The configuration will be updated to a more easily readable format, but the old configuration will be saved in case you -want to change back right away. +If you have legacy gate files using the old numeric material ids, you need to change them to the new format manually. +Use F3 + H to see material ids. Use them exactly as written after "minecraft:". The configuration will be updated to a +more easily readable format, but the old configuration will be saved in case you want to change back right away. -Permissions have had a few changes, so you should check the permissions section for any differences since you set up +Permissions have had a few changes, so you should check the permissions section for any differences since you set up permissions. +Payment to owner using Economy, through Vault, is only possible if the portal owner in the portal database is defined by +a UUID, and not a username. Right now, there is no automatic upgrade from usernames to UUID. You must either make the +stargate owner re-create the stargate or edit the file in the portals folder in a text editor. There are various ways to +find the UUID of players. You may look in the usercache.json file in the server directory or search for the username on +various websites. + # Permissions ``` diff --git a/src/main/java/net/knarcraft/stargate/config/MessageSender.java b/src/main/java/net/knarcraft/stargate/config/MessageSender.java index 2ada1f4..1507dd7 100644 --- a/src/main/java/net/knarcraft/stargate/config/MessageSender.java +++ b/src/main/java/net/knarcraft/stargate/config/MessageSender.java @@ -50,9 +50,7 @@ public final class MessageSender { if (message.isEmpty()) { return; } - //Replace color codes with green? What's the deal with the dollar sign? - //TODO: Figure out what this is actually supposed to do and do it in a better way - message = message.replaceAll("(&([a-f0-9]))", "\u00A7$2"); + message = ChatColor.translateAlternateColorCodes('&', message); if (error) { sender.sendMessage(ChatColor.RED + languageLoader.getString("prefix") + ChatColor.WHITE + message); } else { diff --git a/src/main/java/net/knarcraft/stargate/event/StargateAccessEvent.java b/src/main/java/net/knarcraft/stargate/event/StargateAccessEvent.java index 3f70dec..5b64a14 100644 --- a/src/main/java/net/knarcraft/stargate/event/StargateAccessEvent.java +++ b/src/main/java/net/knarcraft/stargate/event/StargateAccessEvent.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; /** * This event should be called whenever a player attempts to access a stargate * - *

This event is triggered whenever a player enters or activates a stargate. This event can be used to override + *

This event is triggered whenever a player enters or activates a stargate. This event can be used to override * whether the player should be allowed to access the stargate.

*/ @SuppressWarnings("unused") diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalActivator.java b/src/main/java/net/knarcraft/stargate/portal/PortalActivator.java index 3e3dd4d..481ca52 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalActivator.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalActivator.java @@ -191,9 +191,7 @@ public class PortalActivator { //Un-mark the portal as activated Stargate.getStargateConfig().getActivePortalsQueue().remove(portal); - //For a fixed gate, the destinations and the sign never really change, but at the same time, fixed gates are - // never really activated, so in theory, this check should be redundant. - //TODO: Decide if this check is really useless + //Fixed portals are active by definition, but should never be de-activated if (portal.getOptions().isFixed()) { return; } diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java b/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java index faf9b60..f041e02 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java @@ -147,7 +147,7 @@ public class PortalCreator { } //Check if a conflict exists - if (PortalHandler.conflictsWithExistingPortal(gate, portalLocation.getTopLeft(), yaw, player)) { + if (conflictsWithExistingPortal(gate, portalLocation.getTopLeft(), yaw, player)) { return null; } @@ -312,4 +312,25 @@ public class PortalCreator { } } + /** + * Checks whether the new portal conflicts with an existing portal + * + * @param gate

The gate type of the new portal

+ * @param topLeft

The top-left block of the new portal

+ * @param yaw

The yaw when looking directly outwards from the portal

+ * @param player

The player creating the new portal

+ * @return

True if a conflict was found. False otherwise

+ */ + private static boolean conflictsWithExistingPortal(Gate gate, BlockLocation topLeft, double yaw, Player player) { + for (RelativeBlockVector borderVector : gate.getLayout().getBorder()) { + BlockLocation borderBlockLocation = topLeft.getRelativeLocation(borderVector, yaw); + if (PortalHandler.getByBlock(borderBlockLocation.getBlock()) != null) { + Stargate.debug("createPortal", "Gate conflicts with existing gate"); + Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createConflict")); + return true; + } + } + return false; + } + } diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java index 8d536b5..15592b8 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java @@ -86,11 +86,11 @@ public class PortalHandler { destinations.add(portal.getName()); continue; } - //Check if this player can access the dest world + //Check if this player can access the destination world if (PermissionHelper.cannotAccessWorld(player, portal.getWorld().getName())) { continue; } - //Visible to this player. + //The portal is visible to the player if (PermissionHelper.canSeePortal(player, portal)) { destinations.add(portal.getName()); } @@ -170,30 +170,6 @@ public class PortalHandler { return gate; } - /** - * Checks whether the new portal conflicts with an existing portal - * - * @param gate

The gate type of the new portal

- * @param topLeft

The top-left block of the new portal

- * @param yaw

The yaw when looking directly outwards from the portal

- * @param player

The player creating the new portal

- * @return

True if a conflict was found. False otherwise

- */ - static boolean conflictsWithExistingPortal(Gate gate, BlockLocation topLeft, double yaw, Player player) { - //TODO: Make a quicker check. Could just check for control block conflicts if all code is changed to account for - // getting several hits at a single location when checking for the existence of a portal. May make - // everything slower overall? Would make for cooler gates though. - for (RelativeBlockVector borderVector : gate.getLayout().getBorder()) { - BlockLocation borderBlockLocation = topLeft.getRelativeLocation(borderVector, yaw); - if (getByBlock(borderBlockLocation.getBlock()) != null) { - Stargate.debug("createPortal", "Gate conflicts with existing gate"); - Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createConflict")); - return true; - } - } - return false; - } - /** * Updates the sign and open state of portals pointing at the newly created portal * diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalSignDrawer.java b/src/main/java/net/knarcraft/stargate/portal/PortalSignDrawer.java index 353bb98..a79cdb0 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalSignDrawer.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalSignDrawer.java @@ -191,7 +191,7 @@ public class PortalSignDrawer { */ private void drawFixedSign(Sign sign) { if (portal.getOptions().isRandom()) { - setLine(sign, 1, "> " + Stargate.getString("signRandom") + " <"); + setLine(sign, 1, ">" + Stargate.getString("signRandom") + "<"); } else { setLine(sign, 1, ">" + portal.getDestinationName() + "<"); }