From 27c2f7b9e94f8118a0e883d59b2bb840fea1ecec Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 2 Feb 2023 15:01:07 +0800 Subject: [PATCH] feat: Update to 1.16.5-R0.1-SNAPSHOT dependency --- pom.xml | 8 +- .../MultiverseCore/MultiverseCore.java | 7 +- .../queue/DummyCommandBlockSender.java | 17 +++ .../listeners/MVEntityListener.java | 5 +- .../listeners/MVPlayerListener.java | 22 +--- .../utils/BukkitTravelAgent.java | 111 ------------------ .../utils/CompatibilityLayer.java | 106 ----------------- 7 files changed, 30 insertions(+), 246 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/utils/BukkitTravelAgent.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/utils/CompatibilityLayer.java diff --git a/pom.xml b/pom.xml index 87df4183..e714385f 100644 --- a/pom.xml +++ b/pom.xml @@ -280,10 +280,10 @@ - org.bukkit - bukkit - 1.13.2-R0.1-SNAPSHOT - provided + org.spigotmc + spigot-api + 1.16.5-R0.1-SNAPSHOT + provided diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 6fda9ae9..aa952101 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -89,20 +89,19 @@ import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; import com.onarandombox.MultiverseCore.listeners.MVWorldInitListener; import com.onarandombox.MultiverseCore.listeners.MVWorldListener; import com.onarandombox.MultiverseCore.utils.AnchorManager; -import com.onarandombox.MultiverseCore.utils.CompatibilityLayer; import com.onarandombox.MultiverseCore.utils.MVEconomist; import com.onarandombox.MultiverseCore.utils.MVMessaging; import com.onarandombox.MultiverseCore.utils.MVPermissions; import com.onarandombox.MultiverseCore.utils.MVPlayerSession; import com.onarandombox.MultiverseCore.utils.MaterialConverter; -import com.onarandombox.MultiverseCore.utils.TestingMode; -import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator; import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety; import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation; import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter; +import com.onarandombox.MultiverseCore.utils.TestingMode; import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper; import com.onarandombox.MultiverseCore.utils.VaultHandler; import com.onarandombox.MultiverseCore.utils.WorldManager; +import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator; import com.pneumaticraft.commandhandler.CommandHandler; import me.main__.util.SerializationConfig.NoSuchPropertyException; import me.main__.util.SerializationConfig.SerializationConfig; @@ -257,8 +256,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { // Setup our SafeTTeleporter this.safeTTeleporter = new SimpleSafeTTeleporter(this); this.unsafeCallWrapper = new UnsafeCallWrapper(this); - // Setup our CompatibilityLayer - CompatibilityLayer.init(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/queue/DummyCommandBlockSender.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/queue/DummyCommandBlockSender.java index 7ec3dfe0..181e8e50 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/queue/DummyCommandBlockSender.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/queue/DummyCommandBlockSender.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Set; +import java.util.UUID; /** * Used by {@link CommandQueueManager}, so different commands block can be recognised as one. @@ -27,6 +28,16 @@ class DummyCommandBlockSender implements CommandSender { throw new UnsupportedOperationException(); } + @Override + public void sendMessage(@Nullable UUID uuid, @NotNull String s) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendMessage(@Nullable UUID uuid, @NotNull String[] strings) { + throw new UnsupportedOperationException(); + } + @Override public @NotNull Server getServer() { return Bukkit.getServer(); @@ -37,6 +48,12 @@ class DummyCommandBlockSender implements CommandSender { return "DummyCommandBlockSender"; } + @NotNull + @Override + public Spigot spigot() { + throw new UnsupportedOperationException(); + } + @Override public boolean isPermissionSet(@NotNull String name) { throw new UnsupportedOperationException(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java index fd81e694..509f7bbd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java @@ -11,7 +11,6 @@ import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.utils.CompatibilityLayer; import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -24,8 +23,6 @@ import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.FoodLevelChangeEvent; -import java.util.logging.Level; - /** * Multiverse's Entity {@link Listener}. */ @@ -119,7 +116,7 @@ public class MVEntityListener implements Listener { return; } if (!this.plugin.getMVConfig().isUsingDefaultPortalSearch()) { - CompatibilityLayer.setPortalSearchRadius(event, this.plugin.getMVConfig().getPortalSearchRadius()); + event.setSearchRadius(this.plugin.getMVConfig().getPortalSearchRadius()); } } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 2921f9c5..72600132 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -7,13 +7,14 @@ package com.onarandombox.MultiverseCore.listeners; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.enums.RespawnType; import com.onarandombox.MultiverseCore.event.MVRespawnEvent; -import com.onarandombox.MultiverseCore.utils.CompatibilityLayer; import com.onarandombox.MultiverseCore.utils.PermissionTools; import org.bukkit.GameMode; import org.bukkit.Location; @@ -31,9 +32,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - /** * Multiverse's {@link Listener} for players. */ @@ -70,16 +68,8 @@ public class MVPlayerListener implements Listener { return; } - RespawnType respawnType = RespawnType.OTHER; - if (event.isBedSpawn()) { - respawnType = RespawnType.BED; - } - if (CompatibilityLayer.isAnchorSpawn(event)) { - respawnType = RespawnType.ANCHOR; - } - - if (mvWorld.getBedRespawn() && (respawnType == RespawnType.BED || respawnType == RespawnType.ANCHOR)) { - Logging.fine("Spawning %s at their %s", event.getPlayer().getName(), respawnType); + if (mvWorld.getBedRespawn() && (event.isBedSpawn() || event.isAnchorSpawn())) { + Logging.fine("Spawning %s at their %s.", event.getPlayer().getName(), event.isBedSpawn() ? "BED" : "ANCHOR"); return; } @@ -313,7 +303,7 @@ public class MVPlayerListener implements Listener { + "' because enforceaccess is off."); } if (!this.plugin.getMVConfig().isUsingDefaultPortalSearch()) { - CompatibilityLayer.setPortalSearchRadius(event, this.plugin.getMVConfig().getPortalSearchRadius()); + event.setSearchRadius(this.plugin.getMVConfig().getPortalSearchRadius()); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/BukkitTravelAgent.java b/src/main/java/com/onarandombox/MultiverseCore/utils/BukkitTravelAgent.java deleted file mode 100644 index e2f658fa..00000000 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/BukkitTravelAgent.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.onarandombox.MultiverseCore.utils; - -import java.util.logging.Level; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiverseCore.destination.CannonDestination; -import org.bukkit.Location; -import org.bukkit.TravelAgent; -import org.bukkit.event.player.PlayerPortalEvent; - -public class BukkitTravelAgent implements TravelAgent { - private final MVTravelAgent agent; - - public BukkitTravelAgent(MVTravelAgent agent) { - this.agent = agent; - } - - /** - * {@inheritDoc} - */ - @Override - public BukkitTravelAgent setSearchRadius(int radius) { - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public int getSearchRadius() { - return 0; - } - - /** - * {@inheritDoc} - */ - @Override - public BukkitTravelAgent setCreationRadius(int radius) { - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public int getCreationRadius() { - return 0; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean getCanCreatePortal() { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public void setCanCreatePortal(boolean create) { - } - - /** - * {@inheritDoc} - */ - @Override - public Location findOrCreate(Location location) { - return this.getSafeLocation(); - } - - /** - * {@inheritDoc} - */ - @Override - public Location findPortal(Location location) { - return this.getSafeLocation(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean createPortal(Location location) { - return false; - } - - private Location getSafeLocation() { - // At this time, these can never use the velocity. - if (agent.destination instanceof CannonDestination) { - Logging.fine("Using Stock TP method. This cannon will have 0 velocity"); - } - SafeTTeleporter teleporter = agent.core.getSafeTTeleporter(); - Location newLoc = agent.destination.getLocation(agent.player); - if (agent.destination.useSafeTeleporter()) { - newLoc = teleporter.getSafeLocation(agent.player, agent.destination); - } - if (newLoc == null) { - return agent.player.getLocation(); - } - return newLoc; - - } - - public void setPortalEventTravelAgent(PlayerPortalEvent event) { - event.setPortalTravelAgent(this); - event.useTravelAgent(true); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/CompatibilityLayer.java b/src/main/java/com/onarandombox/MultiverseCore/utils/CompatibilityLayer.java deleted file mode 100644 index 2a83a7e2..00000000 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/CompatibilityLayer.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.onarandombox.MultiverseCore.utils; - -import com.dumptruckman.minecraft.util.Logging; -import org.bukkit.event.entity.EntityPortalEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerRespawnEvent; - -import java.lang.reflect.Method; - -/** - * Utility class to enable version specific minecraft features. - */ -public class CompatibilityLayer { - - private static Method checkAnchorSpawn; - private static boolean useTravelAgent; - private static Method playerPortalSearchRadius; - private static Method entityPortalSearchRadius; - - /** - * Initialise the reflection class, methods and fields. - */ - public static void init() { - checkAnchorSpawn = ReflectHelper.getMethod(PlayerRespawnEvent.class, "isAnchorSpawn"); - useTravelAgent = ReflectHelper.hasClass("org.bukkit.TravelAgent"); - playerPortalSearchRadius = ReflectHelper.getMethod(PlayerPortalEvent.class, "setSearchRadius", int.class); - entityPortalSearchRadius = ReflectHelper.getMethod(EntityPortalEvent.class, "setSearchRadius", int.class); - } - - /** - *

Check if the respawn point is of respawn anchor type.

- *

Introduced in minecraft 1.16

- * - * @param event A player respawn event. - * @return If the respawn location is an anchor point. - */ - public static boolean isAnchorSpawn(PlayerRespawnEvent event) { - if (checkAnchorSpawn == null) { - return false; - } - Boolean result = ReflectHelper.invokeMethod(event, checkAnchorSpawn); - if (result == null) { - Logging.warning("Unable to check if spawning at respawn anchor!"); - return false; - } - return result; - } - - /** - *

Gets if Travel Agent is supported on the server's minecraft version.

- *

Removed in minecraft 1.14

- * - * @return True if Travel Agent is supported, else false. - */ - public static boolean isUseTravelAgent() { - return useTravelAgent; - } - - /** - *

Sets search radius for a PlayerPortalEvent.

- * - *

Use travel agent if available, else using new PlayerPortalEvent.setSearchRadius(int) method - * introduced in minecraft 1.15

- * - * @param event A Player Portal Event. - * @param searchRadius Target search radius to set to. - */ - public static void setPortalSearchRadius(PlayerPortalEvent event, int searchRadius) { - if (useTravelAgent) { - event.getPortalTravelAgent().setSearchRadius(searchRadius); - event.useTravelAgent(true); - Logging.finer("Used travel agent to set player portal search radius."); - return; - } - if (playerPortalSearchRadius == null) { - Logging.warning("Unable to set player portal search radius!"); - return; - } - ReflectHelper.invokeMethod(event, playerPortalSearchRadius, searchRadius); - Logging.finer("Used new method to set player portal search radius."); - } - - /** - *

Sets search radius for a EntityPortalEvent.

- * - *

Use travel agent if available, else using new EntityPortalEvent.setSearchRadius(int) method - * introduced in minecraft 1.15

- * - * @param event A Entity Portal Event. - * @param searchRadius Target search radius to set to. - */ - public static void setPortalSearchRadius(EntityPortalEvent event, int searchRadius) { - if (useTravelAgent) { - event.getPortalTravelAgent().setSearchRadius(searchRadius); - event.useTravelAgent(true); - Logging.finer("Used travel agent to set entity portal search radius."); - return; - } - if (entityPortalSearchRadius == null) { - Logging.warning("Unable to set entity portal search radius!"); - return; - } - ReflectHelper.invokeMethod(event, entityPortalSearchRadius, searchRadius); - Logging.finer("Used new method to set entity portal search radius."); - } -}