From 494523e65df55e01d84e48c705f7ae297854b288 Mon Sep 17 00:00:00 2001 From: Daniel V Date: Fri, 1 Mar 2024 14:20:10 -0500 Subject: [PATCH] Fix compatibility with hardcore mode on lower versions. --- .../comatibility/VersionCompatibility.java | 19 +++++++++++++++ .../impl/OneSeventeenCompatibility.java | 24 +++++++++++++++++++ .../commands/sub/ImportCommand.java | 2 +- .../player/PlayerTeleportListener.java | 4 ++-- .../phantomworlds/world/PhantomWorld.java | 2 ++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/lokka30/phantomworlds/comatibility/VersionCompatibility.java b/src/main/java/me/lokka30/phantomworlds/comatibility/VersionCompatibility.java index 966c340..8fb0346 100644 --- a/src/main/java/me/lokka30/phantomworlds/comatibility/VersionCompatibility.java +++ b/src/main/java/me/lokka30/phantomworlds/comatibility/VersionCompatibility.java @@ -18,6 +18,7 @@ */ import org.bukkit.NamespacedKey; +import org.bukkit.World; import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; @@ -58,4 +59,22 @@ default List potionEffectSuggestions() { default PotionEffectType findType(final String effectType) { return PotionEffectType.getByKey(NamespacedKey.fromString(effectType)); } + + /** + * Used to check if world is hardcore or not. + * @param world The world to check. + * @return True if hardcore, otherwise false. + */ + default boolean hardcore(final World world) { + return world.isHardcore(); + } + + /** + * Used to apply the hardcore value to the world. + * @param world The world to apply to. + * @param hardcore Hardcore value to set for the world. + */ + default void applyHardcore(World world, final boolean hardcore) { + world.setHardcore(hardcore); + } } \ No newline at end of file diff --git a/src/main/java/me/lokka30/phantomworlds/comatibility/impl/OneSeventeenCompatibility.java b/src/main/java/me/lokka30/phantomworlds/comatibility/impl/OneSeventeenCompatibility.java index 70ea519..4939213 100644 --- a/src/main/java/me/lokka30/phantomworlds/comatibility/impl/OneSeventeenCompatibility.java +++ b/src/main/java/me/lokka30/phantomworlds/comatibility/impl/OneSeventeenCompatibility.java @@ -18,6 +18,7 @@ */ import me.lokka30.phantomworlds.comatibility.VersionCompatibility; +import org.bukkit.World; import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; @@ -64,4 +65,27 @@ public List potionEffectSuggestions() { public PotionEffectType findType(String effectType) { return PotionEffectType.getByName(effectType); } + + /** + * Used to check if world is hardcore or not. + * + * @param world The world to check. + * + * @return True if hardcore, otherwise false. + */ + @Override + public boolean hardcore(World world) { + return false; + } + + /** + * Used to apply the hardcore value to the world. + * + * @param world The world to apply to. + * @param hardcore Hardcore value to set for the world. + */ + @Override + public void applyHardcore(World world, boolean hardcore) { + //do nothing, not applicable to these versions. + } } \ No newline at end of file diff --git a/src/main/java/me/lokka30/phantomworlds/commands/sub/ImportCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/sub/ImportCommand.java index 712549b..3aedc34 100644 --- a/src/main/java/me/lokka30/phantomworlds/commands/sub/ImportCommand.java +++ b/src/main/java/me/lokka30/phantomworlds/commands/sub/ImportCommand.java @@ -63,7 +63,7 @@ public static void onCommand(final CommandSender sender, final World world) { final PhantomWorld pworld = new PhantomWorld( world.getName(), world.getEnvironment(), world.canGenerateStructures(), null, - null, world.isHardcore(), world.getSeed(), world.getWorldType(), world.getAllowMonsters(), + null, PhantomWorlds.compatibility().hardcore(world), world.getSeed(), world.getWorldType(), world.getAllowMonsters(), world.getAllowAnimals(), world.getKeepSpawnInMemory(), world.getPVP(), world.getDifficulty(), GameMode.SURVIVAL ); pworld.save(); diff --git a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerTeleportListener.java b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerTeleportListener.java index 36423cb..e6d33ae 100644 --- a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerTeleportListener.java +++ b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerTeleportListener.java @@ -56,9 +56,9 @@ public void onPortal(PlayerTeleportEvent event) { event.setCancelled(true); } - if(!event.getPlayer().isOp() && event.getPlayer().hasPermission("phantomworlds.world.deny." + event.getTo().getWorld().getName())) { + /*if(!event.getPlayer().isOp() && event.getPlayer().hasPermission("phantomworlds.world.deny." + event.getTo().getWorld().getName())) { event.setCancelled(true); - } + }*/ if(plugin.worldManager.tpAwaiting.containsKey(event.getPlayer().getUniqueId())) { if(event.isCancelled()) { diff --git a/src/main/java/me/lokka30/phantomworlds/world/PhantomWorld.java b/src/main/java/me/lokka30/phantomworlds/world/PhantomWorld.java index 6e3bb20..eb1b85b 100644 --- a/src/main/java/me/lokka30/phantomworlds/world/PhantomWorld.java +++ b/src/main/java/me/lokka30/phantomworlds/world/PhantomWorld.java @@ -121,6 +121,8 @@ public void create() { world.setKeepSpawnInMemory(keepSpawnInMemory); world.setPVP(allowPvP); world.setDifficulty(difficulty); + + PhantomWorlds.compatibility().applyHardcore(world, hardcore); } public void save() {