From ca7ef8266d08615201823da1d2b97b5e19569ba6 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Thu, 9 Nov 2023 17:42:35 +0800 Subject: [PATCH] PlotSquared: Don't allow changing time of Plot Worlds --- .../plotsquared/PlotSquaredIntegration.java | 8 ++++++ .../PlotSquaredIntegrationImpl.java | 25 ++++++++++++++++++- .../axiom/packet/SetTimePacketListener.java | 6 +++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegration.java b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegration.java index 22ff051..2ebc218 100644 --- a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegration.java +++ b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegration.java @@ -2,6 +2,7 @@ package com.moulberry.axiom.integration.plotsquared; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -22,4 +23,11 @@ public class PlotSquaredIntegration { return PlotSquaredIntegrationImpl.canPlaceBlock(player, loc); } + public static boolean isPlotWorld(World world) { + if (!Bukkit.getPluginManager().isPluginEnabled("PlotSquared")) { + return true; + } + return PlotSquaredIntegrationImpl.isPlotWorld(world); + } + } diff --git a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java index 70057f6..7f2cfd7 100644 --- a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java +++ b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java @@ -2,6 +2,7 @@ package com.moulberry.axiom.integration.plotsquared; import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; @@ -12,11 +13,12 @@ import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.types.BlockTypeWrapper; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BlockType; -import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.List; +import java.util.WeakHashMap; /* * PlotSquared, a land and world management plugin for Minecraft. @@ -114,4 +116,25 @@ public class PlotSquaredIntegrationImpl { return pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_ROAD, true); } + private static final WeakHashMap plotWorldCache = new WeakHashMap<>(); + static boolean isPlotWorld(World world) { + if (plotWorldCache.containsKey(world)) { + return plotWorldCache.get(world); + } + + boolean isPlotWorld = false; + + String worldName = world.getName(); + for (String plotWorld : PlotSquared.get().getPlotAreaManager().getAllWorlds()) { + if (plotWorld.equals(worldName)) { + isPlotWorld = true; + break; + } + } + + plotWorldCache.put(world, isPlotWorld); + return isPlotWorld; + + } + } diff --git a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java index 9ec6def..38a3a25 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java @@ -3,6 +3,7 @@ package com.moulberry.axiom.packet; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.event.AxiomModifyWorldEvent; import com.moulberry.axiom.event.AxiomTimeChangeEvent; +import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import io.netty.buffer.Unpooled; import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; @@ -44,6 +45,11 @@ public class SetTimePacketListener implements PluginMessageListener { return; } + // Don't allow on plot worlds + if (PlotSquaredIntegration.isPlotWorld(player.getWorld())) { + return; + } + // Call time change event AxiomTimeChangeEvent timeChangeEvent = new AxiomTimeChangeEvent(player, time, freezeTime); Bukkit.getPluginManager().callEvent(timeChangeEvent);