diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 893e7ac43..ad330489b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -72,6 +72,8 @@ import com.plotsquared.core.configuration.Storage; import com.plotsquared.core.configuration.caption.ChatFormatter; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.database.DBFunc; +import com.plotsquared.core.events.RemoveRoadEntityEvent; +import com.plotsquared.core.events.Result; import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.generator.SingleWorldGenerator; @@ -110,6 +112,7 @@ import com.plotsquared.core.uuid.CacheUUIDService; import com.plotsquared.core.uuid.UUIDPipeline; import com.plotsquared.core.uuid.offline.OfflineModeUUIDService; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import io.papermc.lib.PaperLib; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; @@ -818,8 +821,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (entity.hasMetadata("ps-tmp-teleport")) { continue; } - iterator.remove(); - entity.remove(); + this.removeRoadEntity(entity, iterator); } continue; } @@ -832,8 +834,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (entity.hasMetadata("ps-tmp-teleport")) { continue; } - iterator.remove(); - entity.remove(); + this.removeRoadEntity(entity, iterator); } } continue; @@ -843,7 +844,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl case "DROPPED_ITEM": if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation())) == null) { - entity.remove(); + this.removeRoadEntity(entity, iterator); } // dropped item continue; @@ -874,8 +875,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (entity.hasMetadata("ps-tmp-teleport")) { continue; } - iterator.remove(); - entity.remove(); + this.removeRoadEntity(entity, iterator); } } } @@ -980,8 +980,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (entity.hasMetadata("ps-tmp-teleport")) { continue; } - iterator.remove(); - entity.remove(); + this.removeRoadEntity(entity, iterator); } } } else { @@ -992,8 +991,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (entity.hasMetadata("ps-tmp-teleport")) { continue; } - iterator.remove(); - entity.remove(); + this.removeRoadEntity(entity, iterator); } } } @@ -1007,6 +1005,17 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl }), TaskTime.seconds(1L)); } + private void removeRoadEntity(Entity entity, Iterator entityIterator) { + RemoveRoadEntityEvent event = eventDispatcher.callRemoveRoadEntity(BukkitAdapter.adapt(entity)); + + if (event.getEventResult() == Result.DENY) { + return; + } + + entityIterator.remove(); + entity.remove(); + } + @Override public @Nullable final ChunkGenerator getDefaultWorldGenerator( diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java index d04b8db4c..e963187d1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -99,6 +99,7 @@ import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.CauldronLevelChangeEvent; import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.block.MoistureChangeEvent; import org.bukkit.event.block.SpongeAbsorbEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.projectiles.BlockProjectileSource; @@ -740,6 +741,28 @@ public class BlockEventListener implements Listener { } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onMoistureChange(MoistureChangeEvent event) { + Block block = event.getBlock(); + Location location = BukkitUtil.adapt(block.getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = area.getOwnedPlot(location); + if (plot == null) { + event.setCancelled(true); + return; + } + Material blockType = block.getType(); + if (blockType == Material.FARMLAND) { + if (!plot.getFlag(SoilDryFlag.class)) { + plot.debug("Soil could not dry because soil-dry = false"); + event.setCancelled(true); + } + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChange(BlockFromToEvent event) { Block fromBlock = event.getBlock(); diff --git a/Core/src/main/java/com/plotsquared/core/events/EntityEvent.java b/Core/src/main/java/com/plotsquared/core/events/EntityEvent.java new file mode 100644 index 000000000..5642342b6 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/events/EntityEvent.java @@ -0,0 +1,63 @@ +/* + * PlotSquared, a land and world management plugin for Minecraft. + * Copyright (C) IntellectualSites + * Copyright (C) IntellectualSites team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.events; + +import com.sk89q.worldedit.entity.Entity; +import org.checkerframework.checker.nullness.qual.NonNull; + +/** + * @since TODO + */ +public abstract class EntityEvent { + + private final Entity entity; + + private String name; + + /** + * @since TODO + */ + public EntityEvent(Entity entity) { + this.entity = entity; + } + + /** + * Obtain the entity involved in the event + * + * @return Entity + * @since TODO + */ + public Entity getEntity() { + return this.entity; + } + + /** + * Obtain the event's class name + * + * @return the event class name + * @since TODO + */ + @NonNull public String getEventName() { + if (this.name == null) { + this.name = this.getClass().getSimpleName(); + } + return this.name; + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/events/RemoveRoadEntityEvent.java b/Core/src/main/java/com/plotsquared/core/events/RemoveRoadEntityEvent.java new file mode 100644 index 000000000..aa7155cc7 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/events/RemoveRoadEntityEvent.java @@ -0,0 +1,50 @@ +/* + * PlotSquared, a land and world management plugin for Minecraft. + * Copyright (C) IntellectualSites + * Copyright (C) IntellectualSites team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.events; + +import com.sk89q.worldedit.entity.Entity; + +/** + * @since TODO + */ +public class RemoveRoadEntityEvent extends EntityEvent implements CancellablePlotEvent { + + private Result eventResult; + + /** + * RemoveRoadEntityEvent: Called when an entity on road is removed. + * + * @param entity The entity to remove + * @since TODO + */ + public RemoveRoadEntityEvent(Entity entity) { + super(entity); + } + + @Override + public Result getEventResult() { + return this.eventResult; + } + + @Override + public void setEventResult(Result eventResult) { + this.eventResult = eventResult; + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java b/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java index 26db74ff5..e61f1727d 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java +++ b/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java @@ -45,6 +45,7 @@ import com.plotsquared.core.events.PlotFlagRemoveEvent; import com.plotsquared.core.events.PlotMergeEvent; import com.plotsquared.core.events.PlotRateEvent; import com.plotsquared.core.events.PlotUnlinkEvent; +import com.plotsquared.core.events.RemoveRoadEntityEvent; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.events.post.PostPlayerAutoPlotEvent; import com.plotsquared.core.events.post.PostPlotChangeOwnerEvent; @@ -71,6 +72,7 @@ import com.plotsquared.core.plot.flag.types.BlockTypeWrapper; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -298,6 +300,12 @@ public class EventDispatcher { return event; } + public RemoveRoadEntityEvent callRemoveRoadEntity(Entity entity) { + RemoveRoadEntityEvent event = new RemoveRoadEntityEvent(entity); + eventBus.post(event); + return event; + } + public void doJoinTask(final PlotPlayer player) { if (player == null) { return; //possible future warning message to figure out where we are retrieving null diff --git a/build.gradle.kts b/build.gradle.kts index 0741fcd80..45618eb4f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -74,7 +74,7 @@ subprojects { } dependencies { - implementation(platform("com.intellectualsites.bom:bom-newest:1.22")) + implementation(platform("com.intellectualsites.bom:bom-newest:1.23")) } dependencies { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b2a4ea05b..97adf54c2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,7 +20,7 @@ squirrelid = "0.3.1" # Gradle plugins shadow = "7.1.2" grgit = "4.1.1" -spotless = "6.13.0" +spotless = "6.14.1" nexus = "1.1.0" [libraries]