From ea6a2d33dce31a1558b96d45237a5dfef685362e Mon Sep 17 00:00:00 2001 From: Yomamaeatstoes Date: Mon, 25 Dec 2023 21:16:34 -0500 Subject: [PATCH 01/50] Reimplement Folia Support. --- config/checkstyle/import-control.xml | 1 + gradle.properties | 2 +- worldguard-bukkit/build.gradle.kts | 8 ++++ .../bukkit/BukkitRegionContainer.java | 6 ++- .../worldguard/bukkit/WorldGuardPlugin.java | 37 ++++++++++++++++--- .../listener/EventAbstractionListener.java | 13 ++++++- .../bukkit/listener/PlayerMoveListener.java | 6 ++- .../bukkit/session/BukkitSessionManager.java | 10 ++++- .../bukkit/util/report/SchedulerReport.java | 28 ++++++++------ .../src/main/resources/plugin.yml | 1 + 10 files changed, 88 insertions(+), 24 deletions(-) diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index b00f80c27..979fc3b63 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -11,6 +11,7 @@ + diff --git a/gradle.properties b/gradle.properties index 2c13f50cb..b5d88d32c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.sk89q.worldguard -version=7.1.0-SNAPSHOT +version=7.1.0-SNAPSHOT-Custom-Folia diff --git a/worldguard-bukkit/build.gradle.kts b/worldguard-bukkit/build.gradle.kts index 5a03aa8aa..c2ba9bc37 100644 --- a/worldguard-bukkit/build.gradle.kts +++ b/worldguard-bukkit/build.gradle.kts @@ -12,6 +12,10 @@ repositories { name = "paper" url = uri("https://repo.papermc.io/repository/maven-public/") } + maven { + name = "devmart-other" + url = uri("https://nexuslite.gcnt.net/repos/other/") + } } configurations { @@ -26,6 +30,7 @@ dependencies { } "api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false } "implementation"("com.google.guava:guava:${Versions.GUAVA}") + "implementation"("com.tcoded:FoliaLib:0.2.3") "compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false } "shadeOnly"("io.papermc:paperlib:1.0.8") "shadeOnly"("org.bstats:bstats-bukkit:3.0.1") @@ -61,6 +66,9 @@ tasks.named("shadowJar") { relocate ("co.aikar.timings.lib", "com.sk89q.worldguard.bukkit.timingslib") { include(dependency("co.aikar:minecraft-timings")) } + relocate ("com.tcoded.folialib", "com.sk89q.worldguard.bukkit.folialib") { + include(dependency("com.tcoded:FoliaLib")) + } } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java index 79d7b3446..0f5e6ed09 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java @@ -40,6 +40,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; @@ -94,7 +95,10 @@ public void onChunkUnload(ChunkUnloadEvent event) { } }, plugin); - Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, cache::invalidateAll, CACHE_INVALIDATION_INTERVAL, CACHE_INVALIDATION_INTERVAL); + int interval = CACHE_INVALIDATION_INTERVAL * 50; + plugin.foliaLib.getImpl().runTimerAsync(cache::invalidateAll, interval, interval, TimeUnit.MILLISECONDS); + +// Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, cache::invalidateAll, CACHE_INVALIDATION_INTERVAL, CACHE_INVALIDATION_INTERVAL); } public void shutdown() { diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 3ba997921..9c44f62b7 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -75,6 +75,7 @@ import com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.util.logging.RecordMessagePrefixer; +import com.tcoded.folialib.FoliaLib; import org.bstats.bukkit.Metrics; import org.bstats.charts.DrilldownPie; import org.bstats.charts.SimplePie; @@ -96,6 +97,7 @@ import java.io.InputStream; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -111,6 +113,9 @@ public class WorldGuardPlugin extends JavaPlugin { private static final int BSTATS_PLUGIN_ID = 3283; + + public FoliaLib foliaLib; + /** * Construct objects. Actual loading occurs when the plugin is enabled, so * this merely instantiates the objects. @@ -138,6 +143,10 @@ public static WorldGuardPlugin inst() { */ @Override public void onEnable() { + + // FoliaLib Util + foliaLib = new FoliaLib(this); + // Catch bad things being done by naughty plugins that include WorldGuard's classes ClassSourceValidator verifier = new ClassSourceValidator(this); verifier.reportMismatches(ImmutableList.of(WorldGuard.class, ProtectedRegion.class, Flag.class)); @@ -164,7 +173,9 @@ public void onEnable() { reg.register(GeneralCommands.class); } - getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY); + int runDelayMs = BukkitSessionManager.RUN_DELAY * 50; + foliaLib.getImpl().runTimer(sessionManager, runDelayMs, runDelayMs, TimeUnit.MILLISECONDS); +// getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY); // Register events getServer().getPluginManager().registerEvents(sessionManager, this); @@ -205,12 +216,25 @@ public void onEnable() { } worldListener.registerEvents(); - Bukkit.getScheduler().runTask(this, () -> { + if (foliaLib.isFolia()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) { - ProcessPlayerEvent event = new ProcessPlayerEvent(player); - Events.fire(event); + foliaLib.getImpl().runAtEntity(player, new Runnable() { + @Override + public void run() { + ProcessPlayerEvent event = new ProcessPlayerEvent(player); + Events.fire(event); + } + }); } - }); + } + else { + Bukkit.getScheduler().runTask(this, () -> { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + ProcessPlayerEvent event = new ProcessPlayerEvent(player); + Events.fire(event); + } + }); + } ((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).setInitialized(true); ((SimpleDomainRegistry) WorldGuard.getInstance().getDomainRegistry()).setInitialized(true); @@ -266,7 +290,8 @@ private void setupCustomCharts(Metrics metrics) { @Override public void onDisable() { WorldGuard.getInstance().disable(); - this.getServer().getScheduler().cancelTasks(this); +// this.getServer().getScheduler().cancelTasks(this); + foliaLib.getImpl().cancelAllTasks(); } @Override diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index d35483d43..27e75bb79 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -152,6 +152,7 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; public class EventAbstractionListener extends AbstractListener { @@ -990,8 +991,16 @@ public void onInventoryMoveItem(InventoryMoveItemEvent event) { handleInventoryHolderUse(event, cause, targetHolder); if (event.isCancelled() && causeHolder instanceof Hopper && wcfg.breakDeniedHoppers) { - Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), - () -> ((Hopper) causeHolder).getBlock().breakNaturally()); + Hopper hopperCauseHolder = (Hopper) causeHolder; + Location location = hopperCauseHolder.getLocation(); + + getPlugin().foliaLib.getImpl().runAtLocationLater(location, () -> { + Block block = location.getBlock(); + if (block.getType() == Material.HOPPER) { + block.breakNaturally(); + } + }, 50, TimeUnit.MILLISECONDS); + } else { entry.setCancelled(event.isCancelled()); } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java index 0db9cf825..786666ad7 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java @@ -42,6 +42,7 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.util.Vector; import org.spigotmc.event.entity.EntityMountEvent; +import java.util.concurrent.TimeUnit; public class PlayerMoveListener extends AbstractListener { @@ -132,7 +133,10 @@ public void onPlayerMove(PlayerMoveEvent event) { player.teleport(override.clone().add(0, 1, 0)); - Bukkit.getScheduler().runTaskLater(getPlugin(), () -> player.teleport(override.clone().add(0, 1, 0)), 1); + getPlugin().foliaLib.getImpl().runAtEntityLater(player, () -> { + player.teleport(override.clone().add(0, 1, 0)); + }, 50, TimeUnit.MILLISECONDS); +// Bukkit.getScheduler().runTaskLater(getPlugin(), () -> player.teleport(override.clone().add(0, 1, 0)), 1); } } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java index df589cbc0..6d6ba51f6 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java @@ -28,6 +28,8 @@ import com.sk89q.worldguard.bukkit.util.Entities; import com.sk89q.worldguard.session.AbstractSessionManager; import com.sk89q.worldguard.session.Session; +import com.tcoded.folialib.FoliaLib; +import com.tcoded.folialib.impl.ServerImplementation; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -68,7 +70,13 @@ public void onPlayerProcess(ProcessPlayerEvent event) { public void run() { for (Player player : Bukkit.getServer().getOnlinePlayers()) { LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); - get(localPlayer).tick(localPlayer); + Session session = get(localPlayer); + + FoliaLib foliaLib = WorldGuardPlugin.inst().foliaLib; + ServerImplementation impl = foliaLib.getImpl(); + + if (foliaLib.isFolia()) impl.runAtEntity(player, () -> session.tick(localPlayer)); + else session.tick(localPlayer); } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java index d897162cf..81da20ec2 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java @@ -24,6 +24,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.sk89q.worldedit.util.report.DataReport; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -52,19 +53,22 @@ public Optional load(Class clazz) throws Exception { public SchedulerReport() { super("Scheduler"); - List tasks = Bukkit.getServer().getScheduler().getPendingTasks(); + append("Error", "MODDED FOLIA VERSION - DO NOT REPORT TO WORLDGUARD"); - append("Pending Task Count", tasks.size()); - - for (BukkitTask task : tasks) { - Class taskClass = getTaskClass(task); - - DataReport report = new DataReport("Task: #" + task.getTaskId()); - report.append("Owner", task.getOwner().getName()); - report.append("Runnable", taskClass != null ? taskClass.getName() : ""); - report.append("Synchronous?", task.isSync()); - append(report.getTitle(), report); - } +// List tasks = Bukkit.getServer().getScheduler().getPendingTasks(); +//// WorldGuardPlugin.inst().foliaLib.getImpl(). +// +// append("Pending Task Count", tasks.size()); +// +// for (BukkitTask task : tasks) { +// Class taskClass = getTaskClass(task); +// +// DataReport report = new DataReport("Task: #" + task.getTaskId()); +// report.append("Owner", task.getOwner().getName()); +// report.append("Runnable", taskClass != null ? taskClass.getName() : ""); +// report.append("Synchronous?", task.isSync()); +// append(report.getTitle(), report); +// } } @SuppressWarnings("unchecked") diff --git a/worldguard-bukkit/src/main/resources/plugin.yml b/worldguard-bukkit/src/main/resources/plugin.yml index 223be72f7..2c7bf9d34 100644 --- a/worldguard-bukkit/src/main/resources/plugin.yml +++ b/worldguard-bukkit/src/main/resources/plugin.yml @@ -4,3 +4,4 @@ version: "${internalVersion}" depend: [WorldEdit] softdepend: [CommandBook] api-version: "1.20" +folia-supported: true \ No newline at end of file From 50e4f4a6a13141dee3e4ec82a54f4c3602c93189 Mon Sep 17 00:00:00 2001 From: Yomamaeatstoes <114538961+Yomamaeatstoes@users.noreply.github.com> Date: Mon, 25 Dec 2023 22:42:41 -0500 Subject: [PATCH 02/50] Update README.md Tag --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index a2fea6cfb..a895e1f93 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,11 @@ Please read CONTRIBUTING.md for important guidelines to follow. Submissions must be licensed under the GNU Lesser General Public License v3. +# Folia Inquisitors +[Folia-Inquisitors](https://github.com/orgs/Folia-Inquisitors/repositories) +[TechnicallyCoded](https://github.com/TechnicallyCoded) +[Yomamaeatstoes](https://github.com/Yomamaeatstoes) + Links ----- From b658d97d956312df5b9a0a75ccec0b9fceb78a74 Mon Sep 17 00:00:00 2001 From: Loving11ish Date: Sun, 28 Jan 2024 23:41:21 +0000 Subject: [PATCH 03/50] Updated FoliaLib dependency. Fixed ProcessPlayerEvent scheduler in WorldGuardPlugin.java. Fixed cancelling of Bukkit tasks if not running on Folia. Made SessionManager task async. Updated PaperAPI to 1.20.2. Fixed plugin.yml formatting. Updated README.md to reflect new project member(@Loving11ish). --- README.md | 3 ++ gradle.properties | 2 +- worldguard-bukkit/build.gradle.kts | 6 +-- .../bukkit/BukkitRegionContainer.java | 2 +- .../worldguard/bukkit/WorldGuardPlugin.java | 48 +++++++++++-------- .../listener/EventAbstractionListener.java | 2 +- .../bukkit/listener/PlayerMoveListener.java | 2 +- .../bukkit/session/BukkitSessionManager.java | 4 +- .../bukkit/util/report/SchedulerReport.java | 3 +- .../src/main/resources/plugin.yml | 2 +- 10 files changed, 43 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a895e1f93..10091e9bd 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,12 @@ Please read CONTRIBUTING.md for important guidelines to follow. Submissions must be licensed under the GNU Lesser General Public License v3. # Folia Inquisitors +This Folia support is maintained by the following organizations and people: + [Folia-Inquisitors](https://github.com/orgs/Folia-Inquisitors/repositories) [TechnicallyCoded](https://github.com/TechnicallyCoded) [Yomamaeatstoes](https://github.com/Yomamaeatstoes) +[Loving11ish](https://github.com/Loving11ish) Links ----- diff --git a/gradle.properties b/gradle.properties index b5d88d32c..2c13f50cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.sk89q.worldguard -version=7.1.0-SNAPSHOT-Custom-Folia +version=7.1.0-SNAPSHOT diff --git a/worldguard-bukkit/build.gradle.kts b/worldguard-bukkit/build.gradle.kts index c2ba9bc37..fd517be2f 100644 --- a/worldguard-bukkit/build.gradle.kts +++ b/worldguard-bukkit/build.gradle.kts @@ -24,13 +24,13 @@ configurations { dependencies { "api"(project(":worldguard-core")) - "compileOnly"("io.papermc.paper:paper-api:1.20-R0.1-SNAPSHOT") - "runtimeOnly"("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") { + "compileOnly"("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT") + "runtimeOnly"("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") { exclude("junit", "junit") } "api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false } "implementation"("com.google.guava:guava:${Versions.GUAVA}") - "implementation"("com.tcoded:FoliaLib:0.2.3") + "implementation"("com.tcoded:FoliaLib:0.3.1") "compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false } "shadeOnly"("io.papermc:paperlib:1.0.8") "shadeOnly"("org.bstats:bstats-bukkit:3.0.1") diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java index 0f5e6ed09..065fa0d98 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java @@ -96,7 +96,7 @@ public void onChunkUnload(ChunkUnloadEvent event) { }, plugin); int interval = CACHE_INVALIDATION_INTERVAL * 50; - plugin.foliaLib.getImpl().runTimerAsync(cache::invalidateAll, interval, interval, TimeUnit.MILLISECONDS); + plugin.getFoliaLib().getImpl().runTimerAsync(cache::invalidateAll, interval, interval, TimeUnit.MILLISECONDS); // Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, cache::invalidateAll, CACHE_INVALIDATION_INTERVAL, CACHE_INVALIDATION_INTERVAL); } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 9c44f62b7..0741415a3 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -114,7 +114,7 @@ public class WorldGuardPlugin extends JavaPlugin { private static final int BSTATS_PLUGIN_ID = 3283; - public FoliaLib foliaLib; + private FoliaLib foliaLib; /** * Construct objects. Actual loading occurs when the plugin is enabled, so @@ -174,7 +174,7 @@ public void onEnable() { } int runDelayMs = BukkitSessionManager.RUN_DELAY * 50; - foliaLib.getImpl().runTimer(sessionManager, runDelayMs, runDelayMs, TimeUnit.MILLISECONDS); + foliaLib.getImpl().runTimerAsync(sessionManager, runDelayMs, runDelayMs, TimeUnit.MILLISECONDS); // getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY); // Register events @@ -216,25 +216,28 @@ public void onEnable() { } worldListener.registerEvents(); - if (foliaLib.isFolia()) { - for (Player player : Bukkit.getServer().getOnlinePlayers()) { - foliaLib.getImpl().runAtEntity(player, new Runnable() { - @Override - public void run() { - ProcessPlayerEvent event = new ProcessPlayerEvent(player); - Events.fire(event); - } - }); - } - } - else { - Bukkit.getScheduler().runTask(this, () -> { - for (Player player : Bukkit.getServer().getOnlinePlayers()) { - ProcessPlayerEvent event = new ProcessPlayerEvent(player); - Events.fire(event); - } + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + foliaLib.getImpl().runAtEntity(player, (task) -> { + ProcessPlayerEvent event = new ProcessPlayerEvent(player); + Events.fire(event); }); } +// if (foliaLib.isFolia()) { +// for (Player player : Bukkit.getServer().getOnlinePlayers()) { +// foliaLib.getImpl().runAtEntity(player, (task) -> { +// ProcessPlayerEvent event = new ProcessPlayerEvent(player); +// Events.fire(event); +// }); +// } +// } +// else { +// Bukkit.getScheduler().runTask(this, () -> { +// for (Player player : Bukkit.getServer().getOnlinePlayers()) { +// ProcessPlayerEvent event = new ProcessPlayerEvent(player); +// Events.fire(event); +// } +// }); +// } ((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).setInitialized(true); ((SimpleDomainRegistry) WorldGuard.getInstance().getDomainRegistry()).setInitialized(true); @@ -290,7 +293,9 @@ private void setupCustomCharts(Metrics metrics) { @Override public void onDisable() { WorldGuard.getInstance().disable(); -// this.getServer().getScheduler().cancelTasks(this); + if (!foliaLib.isFolia()) { + this.getServer().getScheduler().cancelTasks(this); + } foliaLib.getImpl().cancelAllTasks(); } @@ -551,4 +556,7 @@ public PlayerMoveListener getPlayerMoveListener() { return playerMoveListener; } + public FoliaLib getFoliaLib() { + return foliaLib; + } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 27e75bb79..d91baf1dc 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -994,7 +994,7 @@ public void onInventoryMoveItem(InventoryMoveItemEvent event) { Hopper hopperCauseHolder = (Hopper) causeHolder; Location location = hopperCauseHolder.getLocation(); - getPlugin().foliaLib.getImpl().runAtLocationLater(location, () -> { + getPlugin().getFoliaLib().getImpl().runAtLocationLater(location, () -> { Block block = location.getBlock(); if (block.getType() == Material.HOPPER) { block.breakNaturally(); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java index 786666ad7..5bc4c2fbe 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java @@ -133,7 +133,7 @@ public void onPlayerMove(PlayerMoveEvent event) { player.teleport(override.clone().add(0, 1, 0)); - getPlugin().foliaLib.getImpl().runAtEntityLater(player, () -> { + getPlugin().getFoliaLib().getImpl().runAtEntityLater(player, () -> { player.teleport(override.clone().add(0, 1, 0)); }, 50, TimeUnit.MILLISECONDS); // Bukkit.getScheduler().runTaskLater(getPlugin(), () -> player.teleport(override.clone().add(0, 1, 0)), 1); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java index 6d6ba51f6..21168afcf 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java @@ -72,10 +72,10 @@ public void run() { LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); Session session = get(localPlayer); - FoliaLib foliaLib = WorldGuardPlugin.inst().foliaLib; + FoliaLib foliaLib = WorldGuardPlugin.inst().getFoliaLib(); ServerImplementation impl = foliaLib.getImpl(); - if (foliaLib.isFolia()) impl.runAtEntity(player, () -> session.tick(localPlayer)); + if (foliaLib.isFolia()) impl.runAtEntity(player, (task) -> session.tick(localPlayer)); else session.tick(localPlayer); } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java index 81da20ec2..e2557786e 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java @@ -25,6 +25,7 @@ import com.google.common.cache.LoadingCache; import com.sk89q.worldedit.util.report.DataReport; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.tcoded.folialib.wrapper.task.WrappedTask; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -53,7 +54,7 @@ public Optional load(Class clazz) throws Exception { public SchedulerReport() { super("Scheduler"); - append("Error", "MODDED FOLIA VERSION - DO NOT REPORT TO WORLDGUARD"); + append("Error", "FOLIA VERSION - PLEASE REPORT TO WORLDGUARD"); // List tasks = Bukkit.getServer().getScheduler().getPendingTasks(); //// WorldGuardPlugin.inst().foliaLib.getImpl(). diff --git a/worldguard-bukkit/src/main/resources/plugin.yml b/worldguard-bukkit/src/main/resources/plugin.yml index 2c7bf9d34..cdee59d2b 100644 --- a/worldguard-bukkit/src/main/resources/plugin.yml +++ b/worldguard-bukkit/src/main/resources/plugin.yml @@ -4,4 +4,4 @@ version: "${internalVersion}" depend: [WorldEdit] softdepend: [CommandBook] api-version: "1.20" -folia-supported: true \ No newline at end of file +folia-supported: true From 13682383c886dce39ed1865e0e5d8992825e37dc Mon Sep 17 00:00:00 2001 From: Loving11ish Date: Tue, 6 Feb 2024 02:37:45 +0000 Subject: [PATCH 04/50] Updated FoliaLib dependency. Added new Folia task methods to SchedulerReport.java. Re-added Bukkit task reports in SchedulerReport.java. --- worldguard-bukkit/build.gradle.kts | 2 +- .../bukkit/util/report/SchedulerReport.java | 87 +++++++++++++++---- 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/worldguard-bukkit/build.gradle.kts b/worldguard-bukkit/build.gradle.kts index fd517be2f..a940eaaab 100644 --- a/worldguard-bukkit/build.gradle.kts +++ b/worldguard-bukkit/build.gradle.kts @@ -30,7 +30,7 @@ dependencies { } "api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false } "implementation"("com.google.guava:guava:${Versions.GUAVA}") - "implementation"("com.tcoded:FoliaLib:0.3.1") + "implementation"("com.tcoded:FoliaLib:0.3.2") "compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false } "shadeOnly"("io.papermc:paperlib:1.0.8") "shadeOnly"("org.bstats:bstats-bukkit:3.0.1") diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java index e2557786e..23cee36be 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/report/SchedulerReport.java @@ -25,9 +25,8 @@ import com.google.common.cache.LoadingCache; import com.sk89q.worldedit.util.report.DataReport; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.tcoded.folialib.FoliaLib; import com.tcoded.folialib.wrapper.task.WrappedTask; -import org.bukkit.Bukkit; -import org.bukkit.scheduler.BukkitTask; import javax.annotation.Nullable; import java.lang.reflect.Field; @@ -37,6 +36,8 @@ public class SchedulerReport extends DataReport { + private FoliaLib foliaLib = WorldGuardPlugin.inst().getFoliaLib(); + private LoadingCache, Optional> taskFieldCache = CacheBuilder.newBuilder() .build(new CacheLoader, Optional>() { @Override @@ -51,30 +52,78 @@ public Optional load(Class clazz) throws Exception { } }); + private LoadingCache, Optional> foliaTaskFieldCache = CacheBuilder.newBuilder() + .build(new CacheLoader, Optional>() { + @Override + public Optional load(Class clazz) throws Exception { + try { + Field field = clazz.getDeclaredField("run"); + field.setAccessible(true); + return Optional.ofNullable(field); + } catch (NoSuchFieldException ignored) { + return Optional.empty(); + } + } + }); + public SchedulerReport() { super("Scheduler"); - append("Error", "FOLIA VERSION - PLEASE REPORT TO WORLDGUARD"); - -// List tasks = Bukkit.getServer().getScheduler().getPendingTasks(); -//// WorldGuardPlugin.inst().foliaLib.getImpl(). -// -// append("Pending Task Count", tasks.size()); -// -// for (BukkitTask task : tasks) { -// Class taskClass = getTaskClass(task); -// -// DataReport report = new DataReport("Task: #" + task.getTaskId()); -// report.append("Owner", task.getOwner().getName()); -// report.append("Runnable", taskClass != null ? taskClass.getName() : ""); -// report.append("Synchronous?", task.isSync()); -// append(report.getTitle(), report); -// } + List tasks = foliaLib.getImpl().getAllTasks(); + + append("Pending Task Count", tasks.size()); + + for (WrappedTask task : tasks) { + Object handle = getTaskHandle(task); + Class taskClass; + if (foliaLib.isFolia()) { + taskClass = getFoliaTaskClass(handle); + } else { + taskClass = getBukkitTaskClass(handle); + } + + DataReport report = new DataReport("Task: #" + handle.hashCode()); + report.append("Owner", task.getOwningPlugin().getName()); + report.append("Runnable", taskClass != null ? taskClass.getName() : ""); + report.append("Synchronous?", !task.isAsync()); + append(report.getTitle(), report); + } + } + + private Object getTaskHandle(WrappedTask task) { + try { + Field field = task.getClass().getDeclaredField("task"); + field.setAccessible(true); + return field.get(task); + } catch (IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + return null; + } + } + + @SuppressWarnings("unchecked") + @Nullable + private Class getFoliaTaskClass(Object task) { + try { + Class clazz = task.getClass(); + Set> classes = (Set) TypeToken.of(clazz).getTypes().rawTypes(); + + for (Class type : classes) { + Optional field = foliaTaskFieldCache.getUnchecked(type); + if (field.isPresent()) { + Object res = field.get().get(task); + return res == null ? null : res.getClass(); + } + } + } catch (IllegalAccessException | NoClassDefFoundError ignored) { + } + + return null; } @SuppressWarnings("unchecked") @Nullable - private Class getTaskClass(BukkitTask task) { + private Class getBukkitTaskClass(Object task) { try { Class clazz = task.getClass(); Set> classes = (Set) TypeToken.of(clazz).getTypes().rawTypes(); From 65431c7df86ad8041b9292250c030206a83e22f6 Mon Sep 17 00:00:00 2001 From: aurora Date: Sun, 12 May 2024 10:13:22 +0200 Subject: [PATCH 05/50] Fix fire placement by blocks when fire-spread is set to deny Fixes #2070 --- .../worldguard/bukkit/listener/RegionProtectionListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index 9ec21272d..e562a3bee 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -173,7 +173,7 @@ public void onPlaceBlock(final PlaceBlockEvent event) { /* Flint and steel, fire charge, etc. */ if (Materials.isFire(type)) { Block block = event.getCause().getFirstBlock(); - boolean fire = block != null && Materials.isFire(type); + boolean fire = block != null && Materials.isFire(block.getType()); boolean lava = block != null && Materials.isLava(block.getType()); List flags = new ArrayList<>(); flags.add(Flags.BLOCK_PLACE); From d9424b1c71303394e25c50f2409799a9a3db5187 Mon Sep 17 00:00:00 2001 From: wizjany Date: Tue, 14 May 2024 18:11:53 -0400 Subject: [PATCH 06/50] Release 7.0.10. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4a297c651..83224209c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.sk89q.worldguard -version=7.0.10-SNAPSHOT +version=7.0.10 From 6f5501f7be86a3e3324c67a393d03ce0dae74570 Mon Sep 17 00:00:00 2001 From: wizjany Date: Tue, 14 May 2024 18:14:06 -0400 Subject: [PATCH 07/50] Bump to snapshot. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 83224209c..b3cb7fcd5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.sk89q.worldguard -version=7.0.10 +version=7.0.11-SNAPSHOT From d6ef5e9398b4f1fa24574d362137b9cf49788122 Mon Sep 17 00:00:00 2001 From: Joo200 Date: Fri, 17 May 2024 18:05:16 +0200 Subject: [PATCH 08/50] Remove adventure snapshot repository --- worldguard-bukkit/build.gradle.kts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/worldguard-bukkit/build.gradle.kts b/worldguard-bukkit/build.gradle.kts index ed1cdd272..12096fbc4 100644 --- a/worldguard-bukkit/build.gradle.kts +++ b/worldguard-bukkit/build.gradle.kts @@ -12,11 +12,6 @@ repositories { name = "paper" url = uri("https://repo.papermc.io/repository/maven-public/") } - maven { - // TODO: Remove this once paper updated to adventure release - name = "adventure-snapshots" - url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") - } } configurations { From 8b7729e0e809ae033c9a8c4e027b49596c2d915e Mon Sep 17 00:00:00 2001 From: aurora <21148213+aurorasmiles@users.noreply.github.com> Date: Thu, 23 May 2024 19:05:29 +0200 Subject: [PATCH 09/50] Fix silent flag for gameplay commands (#2081) * Fix silent flag for gameplay commands This issue has been fixed in CommandBook with https://github.com/EngineHub/CommandBook/commit/644803182ed1765a9862d0a0cd0d3763d399efee but never in WorldGuard. Co-authored-by: Wyatt Childers * codestyle --- .../worldguard/commands/GeneralCommands.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java b/worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java index 1b8fffcef..1111355a9 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java @@ -70,7 +70,7 @@ public void god(CommandContext args, Actor sender) throws CommandException, Auth // Keep track of this included = true; - } else { + } else if (!args.hasFlag('s')) { player.print("God enabled by " + sender.getDisplayName() + "."); } @@ -79,7 +79,7 @@ public void god(CommandContext args, Actor sender) throws CommandException, Auth // The player didn't receive any items, then we need to send the // user a message so s/he know that something is indeed working - if (!included && args.hasFlag('s')) { + if (!included) { sender.print("Players now have god mode."); } } @@ -113,7 +113,7 @@ public void ungod(CommandContext args, Actor sender) throws CommandException, Au // Keep track of this included = true; - } else { + } else if (!args.hasFlag('s')) { player.print("God disabled by " + sender.getDisplayName() + "."); } @@ -122,7 +122,7 @@ public void ungod(CommandContext args, Actor sender) throws CommandException, Au // The player didn't receive any items, then we need to send the // user a message so s/he know that something is indeed working - if (!included && args.hasFlag('s')) { + if (!included) { sender.print("Players no longer have god mode."); } } @@ -158,7 +158,7 @@ public void heal(CommandContext args, Actor sender) throws CommandException, Aut // Keep track of this included = true; - } else { + } else if (!args.hasFlag('s')) { player.print("Healed by " + sender.getDisplayName() + "."); } @@ -166,7 +166,7 @@ public void heal(CommandContext args, Actor sender) throws CommandException, Aut // The player didn't receive any items, then we need to send the // user a message so s/he know that something is indeed working - if (!included && args.hasFlag('s')) { + if (!included) { sender.print("Players healed."); } } @@ -199,7 +199,7 @@ public void slay(CommandContext args, Actor sender) throws CommandException, Aut // Keep track of this included = true; - } else { + } else if (!args.hasFlag('s')) { player.print("Slain by " + sender.getDisplayName() + "."); } @@ -207,7 +207,7 @@ public void slay(CommandContext args, Actor sender) throws CommandException, Aut // The player didn't receive any items, then we need to send the // user a message so s/he know that something is indeed working - if (!included && args.hasFlag('s')) { + if (!included) { sender.print("Players slain."); } } From ead1e1b77c7f58da711b06d7cfc5d6bb83ad6a66 Mon Sep 17 00:00:00 2001 From: Joni Aromaa Date: Fri, 24 May 2024 15:48:08 +0100 Subject: [PATCH 10/50] Fix checking bypass on initialize (#2082) * Fix checking bypass on initialize * Add SessionManager#createSession back as deprecated --- .../session/AbstractSessionManager.java | 29 ++++++++++++++----- .../com/sk89q/worldguard/session/Session.java | 10 +++++++ .../worldguard/session/SessionManager.java | 2 ++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java index 68bfac198..0f9a05882 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java @@ -19,6 +19,7 @@ package com.sk89q.worldguard.session; +import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -67,10 +68,9 @@ public abstract class AbstractSessionManager implements SessionManager { .expireAfterWrite(2, TimeUnit.SECONDS) .build(CacheLoader.from(tuple -> BYPASS_PERMISSION_TEST.test(tuple.getWorld(), tuple.getPlayer()))); - private final LoadingCache sessions = CacheBuilder.newBuilder() + private final Cache sessions = CacheBuilder.newBuilder() .expireAfterAccess(SESSION_LIFETIME, TimeUnit.MINUTES) - .build(CacheLoader.from(key -> - createSession(key.playerRef.get()))); + .build(); private boolean hasCustom = false; private List> handlers = new LinkedList<>(); @@ -152,7 +152,7 @@ public boolean hasBypass(LocalPlayer player, World world) { @Override public void resetState(LocalPlayer player) { checkNotNull(player, "player"); - @Nullable Session session = sessions.getIfPresent(new CacheKey(player)); + @Nullable Session session = getIfPresentInternal(new CacheKey(player)); if (session != null) { session.resetState(player); } @@ -161,22 +161,35 @@ public void resetState(LocalPlayer player) { @Override @Nullable public Session getIfPresent(LocalPlayer player) { - return sessions.getIfPresent(new CacheKey(player)); + return getIfPresentInternal(new CacheKey(player)); + } + + private Session getIfPresentInternal(CacheKey cacheKey) { + @Nullable Session session = sessions.getIfPresent(cacheKey); + if (session != null) { + session.ensureInitialized(cacheKey.playerRef.get(), this::initializeSession); + return session; + } + return null; } @Override public Session get(LocalPlayer player) { - return sessions.getUnchecked(new CacheKey(player)); + Session session = sessions.asMap().computeIfAbsent(new CacheKey(player), (k) -> new Session(this)); + session.ensureInitialized(player, this::initializeSession); + return session; } @Override public Session createSession(LocalPlayer player) { - Session session = new Session(this); + return get(player); + } + + private void initializeSession(Session session, LocalPlayer player) { for (Handler.Factory factory : handlers) { session.register(factory.create(session)); } session.initialize(player); - return session; } protected static final class CacheKey { diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/Session.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/Session.java index cdc8401a3..adde86dbe 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/Session.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/Session.java @@ -38,6 +38,7 @@ import java.util.HashMap; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.BiConsumer; import static com.google.common.base.Preconditions.checkNotNull; @@ -52,6 +53,7 @@ public class Session { private Location lastValid; private Set lastRegionSet; private final AtomicBoolean needRefresh = new AtomicBoolean(false); + private boolean initialized; /** * Create a new session. @@ -120,6 +122,14 @@ public void initialize(LocalPlayer player) { } } + synchronized void ensureInitialized(LocalPlayer player, BiConsumer initializer) { + if (initialized) { + return; + } + initialized = true; + initializer.accept(this, player); + } + /** * Uninitialize the session. * diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/SessionManager.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/SessionManager.java index bd34f7ec2..fce2bf340 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/SessionManager.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/SessionManager.java @@ -95,7 +95,9 @@ public interface SessionManager { * * @param player The player * @return The new session + * @deprecated Use {@link SessionManager#get} instead */ + @Deprecated Session createSession(LocalPlayer player); /** From 27f009594aff84b7506466c709e593035a3c6902 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 16 Jun 2024 21:48:35 -0400 Subject: [PATCH 11/50] Fix compilation for MC 1.21. Nothing tested yet. --- worldguard-bukkit/build.gradle.kts | 4 ++-- .../main/java/com/sk89q/worldguard/bukkit/util/Materials.java | 1 - worldguard-bukkit/src/main/resources/plugin.yml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/worldguard-bukkit/build.gradle.kts b/worldguard-bukkit/build.gradle.kts index 12096fbc4..6b0e5d5ec 100644 --- a/worldguard-bukkit/build.gradle.kts +++ b/worldguard-bukkit/build.gradle.kts @@ -20,8 +20,8 @@ configurations { dependencies { "api"(project(":worldguard-core")) - "compileOnly"("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT") - "runtimeOnly"("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT") { + "compileOnly"("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") + "runtimeOnly"("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") { exclude("junit", "junit") } "api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 6cdd49245..bff3fd35e 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -864,7 +864,6 @@ private static void putMaterialTag(Tag tag, Integer value) { putMaterialTag(Tag.ALL_SIGNS, 0); putMaterialTag(Tag.SMALL_FLOWERS, 0); putMaterialTag(Tag.BEDS, MODIFIED_ON_RIGHT); - putMaterialTag(Tag.ITEMS_MUSIC_DISCS, 0); putMaterialTag(Tag.ITEMS_BANNERS, 0); putMaterialTag(Tag.FENCE_GATES, MODIFIED_ON_RIGHT); putMaterialTag(Tag.FENCES, 0); diff --git a/worldguard-bukkit/src/main/resources/plugin.yml b/worldguard-bukkit/src/main/resources/plugin.yml index 223be72f7..bccbfe3b5 100644 --- a/worldguard-bukkit/src/main/resources/plugin.yml +++ b/worldguard-bukkit/src/main/resources/plugin.yml @@ -3,4 +3,4 @@ main: com.sk89q.worldguard.bukkit.WorldGuardPlugin version: "${internalVersion}" depend: [WorldEdit] softdepend: [CommandBook] -api-version: "1.20" +api-version: "1.21" From 2bd426baf86cc9e41ba17d54e8b4994dd61bd6bf Mon Sep 17 00:00:00 2001 From: Joo200 Date: Mon, 17 Jun 2024 20:00:03 +0200 Subject: [PATCH 12/50] Update Materials.java with 1.21 tags and materials --- .../worldguard/bukkit/util/Materials.java | 125 +++++++++++------- 1 file changed, 77 insertions(+), 48 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index bff3fd35e..9a831ee61 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -22,7 +22,9 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.sk89q.worldguard.protection.flags.Flags; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.Tag; import org.bukkit.entity.EntityType; import org.bukkit.potion.PotionEffect; @@ -80,6 +82,10 @@ private static void putMaterialTag(Tag tag, Integer value) { ENTITY_ITEMS.put(EntityType.ARMOR_STAND, Material.ARMOR_STAND); ENTITY_ITEMS.put(EntityType.END_CRYSTAL, Material.END_CRYSTAL); + // preset some tags to a default value, override some of them: + putMaterialTag(Tag.DOORS, MODIFIED_ON_RIGHT); + putMaterialTag(Tag.TRAPDOORS, MODIFIED_ON_RIGHT); + MATERIAL_FLAGS.put(Material.AIR, 0); MATERIAL_FLAGS.put(Material.STONE, 0); MATERIAL_FLAGS.put(Material.GRASS_BLOCK, 0); @@ -150,12 +156,6 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.CAKE, MODIFIED_ON_RIGHT); MATERIAL_FLAGS.put(Material.REPEATER, MODIFIED_ON_RIGHT); // MATERIAL_FLAGS.put(Material.STAINED_GLASS, 0); - MATERIAL_FLAGS.put(Material.ACACIA_TRAPDOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.BIRCH_TRAPDOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.DARK_OAK_TRAPDOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.JUNGLE_TRAPDOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.OAK_TRAPDOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.SPRUCE_TRAPDOOR, MODIFIED_ON_RIGHT); MATERIAL_FLAGS.put(Material.INFESTED_STONE, 0); MATERIAL_FLAGS.put(Material.INFESTED_STONE_BRICKS, 0); MATERIAL_FLAGS.put(Material.INFESTED_MOSSY_STONE_BRICKS, 0); @@ -227,11 +227,6 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.IRON_TRAPDOOR, 0); MATERIAL_FLAGS.put(Material.RED_SANDSTONE, 0); MATERIAL_FLAGS.put(Material.RED_SANDSTONE_STAIRS, 0); - MATERIAL_FLAGS.put(Material.SPRUCE_DOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.BIRCH_DOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.JUNGLE_DOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.ACACIA_DOOR, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.DARK_OAK_DOOR, MODIFIED_ON_RIGHT); MATERIAL_FLAGS.put(Material.DIRT_PATH, 0); MATERIAL_FLAGS.put(Material.CHORUS_PLANT, 0); @@ -247,7 +242,7 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.PURPUR_SLAB, 0); MATERIAL_FLAGS.put(Material.STRUCTURE_BLOCK, MODIFIED_ON_LEFT | MODIFIED_ON_RIGHT); MATERIAL_FLAGS.put(Material.REPEATING_COMMAND_BLOCK, MODIFIED_ON_RIGHT); - MATERIAL_FLAGS.put(Material.CHAIN_COMMAND_BLOCK , MODIFIED_ON_RIGHT); + MATERIAL_FLAGS.put(Material.CHAIN_COMMAND_BLOCK, MODIFIED_ON_RIGHT); MATERIAL_FLAGS.put(Material.MAGMA_BLOCK, 0); MATERIAL_FLAGS.put(Material.NETHER_WART_BLOCK, 0); @@ -677,7 +672,6 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.CRIMSON_FUNGUS, 0); MATERIAL_FLAGS.put(Material.CRIMSON_NYLIUM, 0); MATERIAL_FLAGS.put(Material.CRIMSON_ROOTS, 0); - MATERIAL_FLAGS.put(Material.CRIMSON_TRAPDOOR, MODIFIED_ON_RIGHT); MATERIAL_FLAGS.put(Material.CRYING_OBSIDIAN, 0); MATERIAL_FLAGS.put(Material.GILDED_BLACKSTONE, 0); MATERIAL_FLAGS.put(Material.LODESTONE, 0); @@ -718,7 +712,6 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.WARPED_FUNGUS_ON_A_STICK, 0); MATERIAL_FLAGS.put(Material.WARPED_NYLIUM, 0); MATERIAL_FLAGS.put(Material.WARPED_ROOTS, 0); - MATERIAL_FLAGS.put(Material.WARPED_TRAPDOOR, MODIFIED_ON_RIGHT); MATERIAL_FLAGS.put(Material.WARPED_WART_BLOCK, 0); MATERIAL_FLAGS.put(Material.WEEPING_VINES, 0); MATERIAL_FLAGS.put(Material.WEEPING_VINES_PLANT, 0); @@ -843,9 +836,46 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.ARMADILLO_SCUTE, 0); MATERIAL_FLAGS.put(Material.WOLF_ARMOR, 0); - // Generated via tag - putMaterialTag(Tag.WOODEN_DOORS, MODIFIED_ON_RIGHT); - putMaterialTag(Tag.WOODEN_TRAPDOORS, MODIFIED_ON_RIGHT); + // 1.21 + MATERIAL_FLAGS.put(Material.CHISELED_TUFF, 0); + MATERIAL_FLAGS.put(Material.POLISHED_TUFF, 0); + MATERIAL_FLAGS.put(Material.TUFF_BRICKS, 0); + MATERIAL_FLAGS.put(Material.CHISELED_TUFF_BRICKS, 0); + MATERIAL_FLAGS.put(Material.HEAVY_CORE, 0); + MATERIAL_FLAGS.put(Material.CHISELED_COPPER, 0); + MATERIAL_FLAGS.put(Material.EXPOSED_CHISELED_COPPER, 0); + MATERIAL_FLAGS.put(Material.WEATHERED_CHISELED_COPPER, 0); + MATERIAL_FLAGS.put(Material.OXIDIZED_CHISELED_COPPER, 0); + MATERIAL_FLAGS.put(Material.WAXED_CHISELED_COPPER, 0); + MATERIAL_FLAGS.put(Material.WAXED_EXPOSED_CHISELED_COPPER, 0); + MATERIAL_FLAGS.put(Material.WAXED_WEATHERED_CHISELED_COPPER, 0); + MATERIAL_FLAGS.put(Material.WAXED_OXIDIZED_CHISELED_COPPER, 0); + MATERIAL_FLAGS.put(Material.CRAFTER, 0); + MATERIAL_FLAGS.put(Material.FLOW_BANNER_PATTERN, 0); + MATERIAL_FLAGS.put(Material.GUSTER_BANNER_PATTERN, 0); + MATERIAL_FLAGS.put(Material.COPPER_GRATE, 0); + MATERIAL_FLAGS.put(Material.WEATHERED_COPPER_GRATE, 0); + MATERIAL_FLAGS.put(Material.EXPOSED_COPPER_GRATE, 0); + MATERIAL_FLAGS.put(Material.OXIDIZED_COPPER_GRATE, 0); + MATERIAL_FLAGS.put(Material.WAXED_COPPER_GRATE, 0); + MATERIAL_FLAGS.put(Material.WAXED_WEATHERED_COPPER_GRATE, 0); + MATERIAL_FLAGS.put(Material.WAXED_EXPOSED_COPPER_GRATE, 0); + MATERIAL_FLAGS.put(Material.WAXED_OXIDIZED_COPPER_GRATE, 0); + MATERIAL_FLAGS.put(Material.COPPER_BULB, 0); + MATERIAL_FLAGS.put(Material.WEATHERED_COPPER_BULB, 0); + MATERIAL_FLAGS.put(Material.EXPOSED_COPPER_BULB, 0); + MATERIAL_FLAGS.put(Material.OXIDIZED_COPPER_BULB, 0); + MATERIAL_FLAGS.put(Material.WAXED_COPPER_BULB, 0); + MATERIAL_FLAGS.put(Material.WAXED_WEATHERED_COPPER_BULB, 0); + MATERIAL_FLAGS.put(Material.WAXED_EXPOSED_COPPER_BULB, 0); + MATERIAL_FLAGS.put(Material.WAXED_OXIDIZED_COPPER_BULB, 0); + MATERIAL_FLAGS.put(Material.TRIAL_SPAWNER, 0); + MATERIAL_FLAGS.put(Material.TRIAL_KEY, 0); + MATERIAL_FLAGS.put(Material.OMINOUS_TRIAL_KEY, 0); + MATERIAL_FLAGS.put(Material.VAULT, 0); + MATERIAL_FLAGS.put(Material.OMINOUS_BOTTLE, 0); + MATERIAL_FLAGS.put(Material.BREEZE_ROD, 0); + putMaterialTag(Tag.SHULKER_BOXES, MODIFIED_ON_RIGHT); putMaterialTag(Tag.ITEMS_BOATS, 0); putMaterialTag(Tag.BANNERS, 0); @@ -902,6 +932,9 @@ private static void putMaterialTag(Tag tag, Integer value) { if (isSpawnEgg(material)) { MATERIAL_FLAGS.put(material, 0); } + if (material.name().startsWith("MUSIC_DISC_")) { + MATERIAL_FLAGS.put(material, 0); + } if (!MATERIAL_FLAGS.containsKey(material)) { logger.fine("Missing material definition for " + (material.isBlock() ? "block " : "item ") + material.name()); } @@ -909,15 +942,15 @@ private static void putMaterialTag(Tag tag, Integer value) { // DAMAGE_EFFECTS.add(PotionEffectType.SPEED); DAMAGE_EFFECTS.add(PotionEffectType.SLOWNESS); -// DAMAGE_EFFECTS.add(PotionEffectType.FAST_DIGGING); +// DAMAGE_EFFECTS.add(PotionEffectType.HASTE); DAMAGE_EFFECTS.add(PotionEffectType.MINING_FATIGUE); -// DAMAGE_EFFECTS.add(PotionEffectType.INCREASE_DAMAGE); -// DAMAGE_EFFECTS.add(PotionEffectType.HEAL); +// DAMAGE_EFFECTS.add(PotionEffectType.STRENGTH); +// DAMAGE_EFFECTS.add(PotionEffectType.INSTANT_HEALTH); DAMAGE_EFFECTS.add(PotionEffectType.INSTANT_DAMAGE); -// DAMAGE_EFFECTS.add(PotionEffectType.JUMP); +// DAMAGE_EFFECTS.add(PotionEffectType.JUMP_BOOST); DAMAGE_EFFECTS.add(PotionEffectType.NAUSEA); // DAMAGE_EFFECTS.add(PotionEffectType.REGENERATION); -// DAMAGE_EFFECTS.add(PotionEffectType.DAMAGE_RESISTANCE); +// DAMAGE_EFFECTS.add(PotionEffectType.RESISTANCE); // DAMAGE_EFFECTS.add(PotionEffectType.FIRE_RESISTANCE); // DAMAGE_EFFECTS.add(PotionEffectType.WATER_BREATHING); // DAMAGE_EFFECTS.add(PotionEffectType.INVISIBILITY); @@ -940,6 +973,11 @@ private static void putMaterialTag(Tag tag, Integer value) { DAMAGE_EFFECTS.add(PotionEffectType.BAD_OMEN); // DAMAGE_EFFECTS.add(PotionEffectType.HERO_OF_THE_VILLAGE); DAMAGE_EFFECTS.add(PotionEffectType.DARKNESS); + DAMAGE_EFFECTS.add(PotionEffectType.TRIAL_OMEN); + DAMAGE_EFFECTS.add(PotionEffectType.WIND_CHARGED); + DAMAGE_EFFECTS.add(PotionEffectType.WEAVING); + DAMAGE_EFFECTS.add(PotionEffectType.OOZING); + DAMAGE_EFFECTS.add(PotionEffectType.INFESTED); } private Materials() { @@ -1139,10 +1177,11 @@ public static EntityType getEntitySpawnEgg(Material material) { case ALLAY_SPAWN_EGG -> EntityType.ALLAY; case ARMADILLO_SPAWN_EGG -> EntityType.ARMADILLO; case AXOLOTL_SPAWN_EGG -> EntityType.AXOLOTL; - case SPIDER_SPAWN_EGG -> EntityType.SPIDER; case BAT_SPAWN_EGG -> EntityType.BAT; case BEE_SPAWN_EGG -> EntityType.BEE; case BLAZE_SPAWN_EGG -> EntityType.BLAZE; + case BOGGED_SPAWN_EGG -> EntityType.BOGGED; + case BREEZE_SPAWN_EGG -> EntityType.BREEZE; case CAT_SPAWN_EGG -> EntityType.CAT; case CAMEL_SPAWN_EGG -> EntityType.CAMEL; case CAVE_SPIDER_SPAWN_EGG -> EntityType.CAVE_SPIDER; @@ -1192,6 +1231,7 @@ public static EntityType getEntitySpawnEgg(Material material) { case SLIME_SPAWN_EGG -> EntityType.SLIME; case SNIFFER_SPAWN_EGG -> EntityType.SNIFFER; case SNOW_GOLEM_SPAWN_EGG -> EntityType.SNOW_GOLEM; + case SPIDER_SPAWN_EGG -> EntityType.SPIDER; case SQUID_SPAWN_EGG -> EntityType.SQUID; case STRAY_SPAWN_EGG -> EntityType.STRAY; case STRIDER_SPAWN_EGG -> EntityType.STRIDER; @@ -1366,15 +1406,13 @@ public static boolean hasDamageEffect(Collection effects) { * @return true if equippable armor */ public static boolean isArmor(Material type) { + if (Tag.ITEMS_HEAD_ARMOR.isTagged(type) || Tag.ITEMS_CHEST_ARMOR.isTagged(type) || + Tag.ITEMS_LEG_ARMOR.isTagged(type) || Tag.ITEMS_FOOT_ARMOR.isTagged(type) || + Tag.ITEMS_SKULLS.isTagged(type)) { + return true; + } return switch (type) { - case LEATHER_HELMET, LEATHER_CHESTPLATE, LEATHER_LEGGINGS, LEATHER_BOOTS, - CHAINMAIL_HELMET, CHAINMAIL_CHESTPLATE, CHAINMAIL_LEGGINGS, CHAINMAIL_BOOTS, - IRON_HELMET, IRON_CHESTPLATE, IRON_LEGGINGS, IRON_BOOTS, - DIAMOND_HELMET, DIAMOND_CHESTPLATE, DIAMOND_LEGGINGS, DIAMOND_BOOTS, - GOLDEN_HELMET, GOLDEN_CHESTPLATE, GOLDEN_LEGGINGS, GOLDEN_BOOTS, - NETHERITE_HELMET, NETHERITE_CHESTPLATE, NETHERITE_LEGGINGS, NETHERITE_BOOTS, - TURTLE_HELMET, ELYTRA -> - true; + case CARVED_PUMPKIN, ELYTRA -> true; default -> false; }; } @@ -1465,27 +1503,18 @@ public static boolean isToolApplicable(Material toolMaterial, Material targetMat public static boolean isFire(Material type) { return type == Material.FIRE || type == Material.SOUL_FIRE; } - + public static boolean isWaxedCopper(Material type) { - return switch (type) { - case WAXED_COPPER_BLOCK, WAXED_EXPOSED_COPPER, WAXED_WEATHERED_COPPER, WAXED_OXIDIZED_COPPER, - WAXED_CUT_COPPER, WAXED_EXPOSED_CUT_COPPER, WAXED_WEATHERED_CUT_COPPER, - WAXED_OXIDIZED_CUT_COPPER, WAXED_CUT_COPPER_STAIRS, WAXED_EXPOSED_CUT_COPPER_STAIRS, - WAXED_WEATHERED_CUT_COPPER_STAIRS, WAXED_OXIDIZED_CUT_COPPER_STAIRS, WAXED_CUT_COPPER_SLAB, - WAXED_EXPOSED_CUT_COPPER_SLAB, WAXED_WEATHERED_CUT_COPPER_SLAB, WAXED_OXIDIZED_CUT_COPPER_SLAB -> - true; - default -> false; - }; + // copied from the MaterialTags class in Paper + return type.name().startsWith("WAXED_") && type.name().contains("COPPER"); } - + public static boolean isUnwaxedCopper(Material type) { + // copied from the MaterialTags class in Paper return switch (type) { - case COPPER_BLOCK, EXPOSED_COPPER, WEATHERED_COPPER, OXIDIZED_COPPER, CUT_COPPER, - EXPOSED_CUT_COPPER, WEATHERED_CUT_COPPER, OXIDIZED_CUT_COPPER, CUT_COPPER_STAIRS, - EXPOSED_CUT_COPPER_STAIRS, WEATHERED_CUT_COPPER_STAIRS, OXIDIZED_CUT_COPPER_STAIRS, - CUT_COPPER_SLAB, EXPOSED_CUT_COPPER_SLAB, WEATHERED_CUT_COPPER_SLAB, OXIDIZED_CUT_COPPER_SLAB -> - true; - default -> false; + case COPPER_BLOCK, CHISELED_COPPER, COPPER_DOOR, COPPER_TRAPDOOR, COPPER_GRATE, COPPER_BULB -> true; + default -> type.name().startsWith("EXPOSED_") || type.name().startsWith("WEATHERED_") || + type.name().startsWith("OXIDIZED_") || type.name().startsWith("CUT_COPPER"); }; } From 7783e9ae3ba734f021fb5fb80eaf680273140ae7 Mon Sep 17 00:00:00 2001 From: Lennart <1535717+lenis0012@users.noreply.github.com> Date: Wed, 19 Jun 2024 18:00:35 +0200 Subject: [PATCH 13/50] Fix ItemStack conversion on block place on MC 1.21 (#2093) * Fix ItemStack conversion on block place This issue is present in 1.21 because some materials do not convert 1:1 to item types. This throws an exception in the ItemStack constructor. Example: WALL_TORCH is a valid block but not a valid item, only TORCH is a valid item. So, use the item in hand instead, creating a copy with quantity set to 1, for issueing the use item event. * Use ItemStack as-is. Closes #2092. --------- Co-authored-by: wizjany --- .../worldguard/bukkit/listener/EventAbstractionListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index e39a4c3cf..8f13d13d1 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -218,8 +218,8 @@ public void onBlockPlace(BlockPlaceEvent event) { Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), previousState.getLocation(), previousState.getType())); } - if (!event.isCancelled()) { - ItemStack itemStack = new ItemStack(event.getBlockPlaced().getType(), 1); + ItemStack itemStack = event.getItemInHand(); + if (!event.isCancelled() && !itemStack.isEmpty()) { Events.fireToCancel(event, new UseItemEvent(event, create(event.getPlayer()), event.getPlayer().getWorld(), itemStack)); } From 6898ad8674d9b329f407088162dc6234403fcc8d Mon Sep 17 00:00:00 2001 From: Joo200 Date: Sat, 22 Jun 2024 15:08:10 +0200 Subject: [PATCH 14/50] Fix ItemStack conversion for spigot compatibility --- .../worldguard/bukkit/listener/EventAbstractionListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 8f13d13d1..43f2bfaf5 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -219,7 +219,7 @@ public void onBlockPlace(BlockPlaceEvent event) { } ItemStack itemStack = event.getItemInHand(); - if (!event.isCancelled() && !itemStack.isEmpty()) { + if (!event.isCancelled() && itemStack.getType() != Material.AIR) { Events.fireToCancel(event, new UseItemEvent(event, create(event.getPlayer()), event.getPlayer().getWorld(), itemStack)); } From 887f3bfaec8b4806947627c1354d843eb9f8ad9b Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 4 Jun 2024 06:45:22 +0200 Subject: [PATCH 15/50] Special handling for WindCharges --- .../bukkit/listener/EventAbstractionListener.java | 5 +++++ .../bukkit/listener/WorldGuardEntityListener.java | 11 +++++++++++ .../com/sk89q/worldguard/bukkit/util/Materials.java | 1 + .../com/sk89q/worldguard/protection/flags/Flags.java | 1 + 4 files changed, 18 insertions(+) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 43f2bfaf5..c0a692d38 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -79,6 +79,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import org.bukkit.entity.ThrownPotion; +import org.bukkit.entity.WindCharge; import org.bukkit.entity.minecart.HopperMinecart; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -357,6 +358,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { @EventHandler(ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); + if (entity instanceof WindCharge) { + Events.fireBulkEventToCancel(event, new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); + return; + } Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); if (entity instanceof Creeper) { Cause.untrackParentCause(entity); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 7ea3bf477..ab1bdf501 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -60,6 +60,7 @@ import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; +import org.bukkit.entity.WindCharge; import org.bukkit.entity.Wither; import org.bukkit.entity.WitherSkull; import org.bukkit.entity.Wolf; @@ -522,6 +523,16 @@ public void onEntityExplode(EntityExplodeEvent event) { } } } + } else if (ent instanceof WindCharge) { + if (wcfg.useRegions) { + for (Block block : event.blockList()) { + if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.WIND_CHARGE_BURST)) { + event.blockList().clear(); + event.setCancelled(true); + return; + } + } + } } else { // unhandled entity if (wcfg.blockOtherExplosions) { diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 9a831ee61..cc0540ae4 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -835,6 +835,7 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.ARMADILLO_SCUTE, 0); MATERIAL_FLAGS.put(Material.WOLF_ARMOR, 0); + MATERIAL_FLAGS.put(Material.WIND_CHARGE, 0); // 1.21 MATERIAL_FLAGS.put(Material.CHISELED_TUFF, 0); diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java index 24cc675ed..5702cfe15 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java @@ -93,6 +93,7 @@ public final class Flags { public static final StateFlag ENDERDRAGON_BLOCK_DAMAGE = register(new StateFlag("enderdragon-block-damage", true)); public static final StateFlag GHAST_FIREBALL = register(new StateFlag("ghast-fireball", true)); public static final StateFlag OTHER_EXPLOSION = register(new StateFlag("other-explosion", true)); + public static final StateFlag WIND_CHARGE_BURST = register(new StateFlag("wind-charge-burst", true)); public static final StateFlag WITHER_DAMAGE = register(new StateFlag("wither-damage", true)); public static final StateFlag ENDER_BUILD = register(new StateFlag("enderman-grief", true)); public static final StateFlag SNOWMAN_TRAILS = register(new StateFlag("snowman-trails", true)); From 8aa37e389dbee587d756ce2118a5553880e1a1fe Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 4 Jun 2024 08:06:56 +0200 Subject: [PATCH 16/50] Do not call as a bulk event, because it has to check every blocks type --- .../bukkit/listener/EventAbstractionListener.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index c0a692d38..33ac09366 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -152,6 +152,7 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; @@ -359,7 +360,16 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); if (entity instanceof WindCharge) { - Events.fireBulkEventToCancel(event, new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); + Iterator it = event.blockList().iterator(); + while (it.hasNext()) { + Block block = it.next(); + UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), block); + useEvent.setSilent(true); + Bukkit.getServer().getPluginManager().callEvent(useEvent); + if (useEvent.isCancelled()) { + it.remove(); + } + } return; } Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); From 83298796aba69bb686f11d2e03b1156e2c42ad28 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Tue, 25 Jun 2024 21:38:22 +0200 Subject: [PATCH 17/50] WindCharge -> AbstractWindCharge --- .../worldguard/bukkit/listener/EventAbstractionListener.java | 4 ++-- .../worldguard/bukkit/listener/WorldGuardEntityListener.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 33ac09366..64e7a7280 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -65,6 +65,7 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.type.Dispenser; +import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; @@ -79,7 +80,6 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import org.bukkit.entity.ThrownPotion; -import org.bukkit.entity.WindCharge; import org.bukkit.entity.minecart.HopperMinecart; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -359,7 +359,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { @EventHandler(ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); - if (entity instanceof WindCharge) { + if (entity instanceof AbstractWindCharge) { Iterator it = event.blockList().iterator(); while (it.hasNext()) { Block block = it.next(); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index ab1bdf501..b04d56b4e 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -44,6 +44,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Creeper; import org.bukkit.entity.EnderCrystal; @@ -60,7 +61,6 @@ import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; -import org.bukkit.entity.WindCharge; import org.bukkit.entity.Wither; import org.bukkit.entity.WitherSkull; import org.bukkit.entity.Wolf; @@ -523,7 +523,7 @@ public void onEntityExplode(EntityExplodeEvent event) { } } } - } else if (ent instanceof WindCharge) { + } else if (ent instanceof AbstractWindCharge) { if (wcfg.useRegions) { for (Block block : event.blockList()) { if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.WIND_CHARGE_BURST)) { From a5ea5115f95657d940b43dd83cdf5b81caaeabb1 Mon Sep 17 00:00:00 2001 From: Joo200 Date: Wed, 26 Jun 2024 22:30:33 +0200 Subject: [PATCH 18/50] Fix UseBlockFlag for multiple uses at the same time, add windburst-flag --- .../com/sk89q/worldguard/bukkit/BukkitUtil.java | 17 ----------------- .../bukkit/listener/BlacklistListener.java | 6 +++--- .../listener/BuildPermissionListener.java | 10 ++++++---- .../listener/EventAbstractionListener.java | 15 ++++----------- .../listener/RegionProtectionListener.java | 4 ++-- .../listener/WorldGuardEntityListener.java | 11 ----------- .../sk89q/worldguard/bukkit/util/Materials.java | 2 +- 7 files changed, 16 insertions(+), 49 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java index c290b7cfe..2d43d2080 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java @@ -55,23 +55,6 @@ public static int getPotionEffectBits(ItemStack item) { return item.getDurability() & 0x3F; } - /** - * Get a blacklist target for the given block. - * - * @param block the block - * @param effectiveMaterial The effective material, if different - * @return a target - */ - public static Target createTarget(Block block, Material effectiveMaterial) { - checkNotNull(block); - checkNotNull(block.getType()); - if (block.getType() == effectiveMaterial) { - return createTarget(block.getType()); - } else { - return createTarget(effectiveMaterial); - } - } - /** * Get a blacklist target for the given block. * diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java index bfb569f5a..3b9077175 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BlacklistListener.java @@ -96,7 +96,7 @@ public void onBreakBlock(final BreakBlockEvent event) { event.filter(target -> { if (!wcfg.getBlacklist().check( new BlockBreakBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), - createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)) { + createTarget(target.getBlock())), false, false)) { return false; } else if (!wcfg.getBlacklist().check( new ItemDestroyWithBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), @@ -124,7 +124,7 @@ public void onPlaceBlock(final PlaceBlockEvent event) { final LocalPlayer localPlayer = getPlugin().wrapPlayer(player); event.filter(target -> wcfg.getBlacklist().check(new BlockPlaceBlacklistEvent( - localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)); + localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false)); } @EventHandler(ignoreCancelled = true) @@ -143,7 +143,7 @@ public void onUseBlock(final UseBlockEvent event) { final LocalPlayer localPlayer = getPlugin().wrapPlayer(player); event.filter(target -> wcfg.getBlacklist().check(new BlockInteractBlacklistEvent( - localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)); + localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false)); } @EventHandler(ignoreCancelled = true) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BuildPermissionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BuildPermissionListener.java index 2ad78b4b1..7958b685c 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BuildPermissionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/BuildPermissionListener.java @@ -101,12 +101,14 @@ public void onUseBlock(final UseBlockEvent event) { if (rootCause instanceof Player) { final Player player = (Player) rootCause; - final Material material = event.getEffectiveMaterial(); - if (!hasBuildPermission(player, "block." + material.name().toLowerCase() + ".interact") - && !hasBuildPermission(player, "block.interact." + material.name().toLowerCase())) { + boolean blocked = event.filter(loc -> { + String blacklistName = loc.getBlock().getType().name().toLowerCase(); + return hasBuildPermission(player, "block." + blacklistName + ".interact") || + hasBuildPermission(player, "block.interact." + blacklistName); + }, true); + if (blocked && !event.isSilent()) { tellErrorMessage(player, event.getWorld()); - event.setCancelled(true); } } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 64e7a7280..14c49c2ad 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -152,7 +152,6 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; @@ -360,16 +359,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); if (entity instanceof AbstractWindCharge) { - Iterator it = event.blockList().iterator(); - while (it.hasNext()) { - Block block = it.next(); - UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), block); - useEvent.setSilent(true); - Bukkit.getServer().getPluginManager().callEvent(useEvent); - if (useEvent.isCancelled()) { - it.remove(); - } - } + UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR); + useEvent.getRelevantFlags().add(Flags.WIND_CHARGE_BURST); + useEvent.setSilent(true); + Events.fireBulkEventToCancel(event, useEvent); return; } Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index e562a3bee..4a86df3f4 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -244,13 +244,13 @@ public void onUseBlock(final UseBlockEvent event) { if (!isRegionSupportEnabled(event.getWorld())) return; // Region support disabled if (isWhitelisted(event.getCause(), event.getWorld(), false)) return; // Whitelisted cause - final Material type = event.getEffectiveMaterial(); final RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); final RegionAssociable associable = createRegionAssociable(event.getCause()); event.filter((Predicate) target -> { boolean canUse; String what; + final Material type = target.getBlock().getType(); /* Saplings, etc. */ if (Materials.isConsideredBuildingIfUsed(type)) { @@ -278,7 +278,7 @@ public void onUseBlock(final UseBlockEvent event) { what = "sleep"; /* Respawn Anchors */ - } else if(type == Material.RESPAWN_ANCHOR) { + } else if(target.getBlock().getType() == Material.RESPAWN_ANCHOR) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.RESPAWN_ANCHORS)); what = "use anchors"; diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index b04d56b4e..7ea3bf477 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -44,7 +44,6 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; -import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Creeper; import org.bukkit.entity.EnderCrystal; @@ -523,16 +522,6 @@ public void onEntityExplode(EntityExplodeEvent event) { } } } - } else if (ent instanceof AbstractWindCharge) { - if (wcfg.useRegions) { - for (Block block : event.blockList()) { - if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.WIND_CHARGE_BURST)) { - event.blockList().clear(); - event.setCancelled(true); - return; - } - } - } } else { // unhandled entity if (wcfg.blockOtherExplosions) { diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index cc0540ae4..787f78369 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -835,7 +835,6 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.ARMADILLO_SCUTE, 0); MATERIAL_FLAGS.put(Material.WOLF_ARMOR, 0); - MATERIAL_FLAGS.put(Material.WIND_CHARGE, 0); // 1.21 MATERIAL_FLAGS.put(Material.CHISELED_TUFF, 0); @@ -876,6 +875,7 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.VAULT, 0); MATERIAL_FLAGS.put(Material.OMINOUS_BOTTLE, 0); MATERIAL_FLAGS.put(Material.BREEZE_ROD, 0); + MATERIAL_FLAGS.put(Material.WIND_CHARGE, 0); putMaterialTag(Tag.SHULKER_BOXES, MODIFIED_ON_RIGHT); putMaterialTag(Tag.ITEMS_BOATS, 0); From af645ea2e468f0bf2450fe6610071d38342fb0ce Mon Sep 17 00:00:00 2001 From: Joo200 Date: Wed, 26 Jun 2024 22:34:29 +0200 Subject: [PATCH 19/50] Cleanup code --- .../worldguard/bukkit/listener/RegionProtectionListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index 4a86df3f4..f5942d753 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -278,7 +278,7 @@ public void onUseBlock(final UseBlockEvent event) { what = "sleep"; /* Respawn Anchors */ - } else if(target.getBlock().getType() == Material.RESPAWN_ANCHOR) { + } else if(type == Material.RESPAWN_ANCHOR) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.RESPAWN_ANCHORS)); what = "use anchors"; From b269d7e264eb5846e0b69f7df1523e2f4d5d07c4 Mon Sep 17 00:00:00 2001 From: wizjany Date: Wed, 26 Jun 2024 18:17:55 -0400 Subject: [PATCH 20/50] Handle vaults as use, crafters as chest-access. --- .../java/com/sk89q/worldguard/bukkit/util/Materials.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 787f78369..231a0bbe1 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -22,9 +22,7 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.sk89q.worldguard.protection.flags.Flags; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.Tag; import org.bukkit.entity.EntityType; import org.bukkit.potion.PotionEffect; @@ -872,7 +870,7 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.TRIAL_SPAWNER, 0); MATERIAL_FLAGS.put(Material.TRIAL_KEY, 0); MATERIAL_FLAGS.put(Material.OMINOUS_TRIAL_KEY, 0); - MATERIAL_FLAGS.put(Material.VAULT, 0); + MATERIAL_FLAGS.put(Material.VAULT, MODIFIED_ON_RIGHT); MATERIAL_FLAGS.put(Material.OMINOUS_BOTTLE, 0); MATERIAL_FLAGS.put(Material.BREEZE_ROD, 0); MATERIAL_FLAGS.put(Material.WIND_CHARGE, 0); @@ -1165,6 +1163,7 @@ public static boolean isInventoryBlock(Material material) { || material == Material.BLAST_FURNACE || material == Material.SMOKER || material == Material.CHISELED_BOOKSHELF + || material == Material.CRAFTER || Tag.ITEMS_CHEST_BOATS.isTagged(material) || Tag.SHULKER_BOXES.isTagged(material); } @@ -1324,7 +1323,7 @@ public static boolean isUseFlagApplicable(Material material) { } return switch (material) { case LEVER, LECTERN, ENCHANTING_TABLE, BELL, LOOM, - CARTOGRAPHY_TABLE, STONECUTTER, GRINDSTONE -> true; + CARTOGRAPHY_TABLE, STONECUTTER, GRINDSTONE, VAULT -> true; default -> false; }; } From a801a9d67a3563a8f1e1c17b724eda0b8f62b700 Mon Sep 17 00:00:00 2001 From: wizjany Date: Wed, 26 Jun 2024 18:50:12 -0400 Subject: [PATCH 21/50] Release 7.0.11-beta1. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index b3cb7fcd5..5516b2bd5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.sk89q.worldguard -version=7.0.11-SNAPSHOT +version=7.0.11-beta1 From fa357f46816eba773278a65aadfc7fd64d1a361c Mon Sep 17 00:00:00 2001 From: wizjany Date: Wed, 26 Jun 2024 18:58:10 -0400 Subject: [PATCH 22/50] Back to snapshot. Idk why we even to this for betas, they're not getting a maven release. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5516b2bd5..b3cb7fcd5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.sk89q.worldguard -version=7.0.11-beta1 +version=7.0.11-SNAPSHOT From c6fbfb87a377d624c5cf14d6fa46e543799949b1 Mon Sep 17 00:00:00 2001 From: CyberFlame Date: Fri, 5 Jul 2024 02:21:57 +1200 Subject: [PATCH 23/50] remove double space --- .../src/main/java/com/sk89q/worldguard/session/Session.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/Session.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/Session.java index adde86dbe..f52f00cc7 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/Session.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/Session.java @@ -112,7 +112,7 @@ public void initialize(LocalPlayer player) { disableBypass = cfg.disableDefaultBypass; if (cfg.announceBypassStatus && player.hasPermission("worldguard.region.toggle-bypass")) { player.printInfo(TextComponent.of( - "You are " + (disableBypass ? "not" : "") + " bypassing region protection. " + + "You are " + (disableBypass ? "not " : "") + "bypassing region protection. " + "You can toggle this with /rg bypass", TextColor.DARK_PURPLE)); } From 574921089b192354c1eedeecd8e7cb0d559752c4 Mon Sep 17 00:00:00 2001 From: aurora Date: Tue, 2 Jul 2024 14:47:57 +0200 Subject: [PATCH 24/50] Port build-logic from WorldEdit --- .travis.yml | 8 - build-logic/build.gradle.kts | 34 ++++ build-logic/settings.gradle.kts | 9 + .../buildlogic.artifactory-root.gradle.kts | 32 +++ .../buildlogic.artifactory-sub.gradle.kts | 10 + .../kotlin/buildlogic.common-java.gradle.kts | 81 ++++++++ .../main/kotlin/buildlogic.common.gradle.kts | 69 +++++++ .../buildlogic.core-and-platform.gradle.kts | 23 +++ .../main/kotlin/buildlogic.libs.gradle.kts | 182 ++++++++++++++++++ .../kotlin/buildlogic.platform.gradle.kts | 39 ++++ .../kotlin/buildlogic/CommonJavaExtension.kt | 7 + .../main/kotlin/buildlogic/GradleExtras.kt | 24 +++ build.gradle.kts | 22 +-- buildSrc/build.gradle.kts | 29 --- buildSrc/src/main/kotlin/ArtifactoryConfig.kt | 40 ---- buildSrc/src/main/kotlin/CommonConfig.kt | 38 ---- buildSrc/src/main/kotlin/GradleExtras.kt | 12 -- buildSrc/src/main/kotlin/LibsConfig.kt | 171 ---------------- buildSrc/src/main/kotlin/PlatformConfig.kt | 113 ----------- buildSrc/src/main/kotlin/Versions.kt | 10 - gradle.properties | 2 + gradle/gradle-daemon-jvm.properties | 2 + gradle/libs.versions.toml | 76 ++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 36 +++- worldguard-bukkit/build.gradle.kts | 74 +++---- worldguard-core/build.gradle.kts | 51 ++++- worldguard-libs/build.gradle.kts | 2 +- worldguard-libs/bukkit/build.gradle.kts | 1 - worldguard-libs/core/build.gradle.kts | 20 +- 30 files changed, 719 insertions(+), 500 deletions(-) delete mode 100644 .travis.yml create mode 100644 build-logic/build.gradle.kts create mode 100644 build-logic/settings.gradle.kts create mode 100644 build-logic/src/main/kotlin/buildlogic.artifactory-root.gradle.kts create mode 100644 build-logic/src/main/kotlin/buildlogic.artifactory-sub.gradle.kts create mode 100644 build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts create mode 100644 build-logic/src/main/kotlin/buildlogic.common.gradle.kts create mode 100644 build-logic/src/main/kotlin/buildlogic.core-and-platform.gradle.kts create mode 100644 build-logic/src/main/kotlin/buildlogic.libs.gradle.kts create mode 100644 build-logic/src/main/kotlin/buildlogic.platform.gradle.kts create mode 100644 build-logic/src/main/kotlin/buildlogic/CommonJavaExtension.kt create mode 100644 build-logic/src/main/kotlin/buildlogic/GradleExtras.kt delete mode 100644 buildSrc/build.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/ArtifactoryConfig.kt delete mode 100644 buildSrc/src/main/kotlin/CommonConfig.kt delete mode 100644 buildSrc/src/main/kotlin/GradleExtras.kt delete mode 100644 buildSrc/src/main/kotlin/LibsConfig.kt delete mode 100644 buildSrc/src/main/kotlin/PlatformConfig.kt delete mode 100644 buildSrc/src/main/kotlin/Versions.kt create mode 100644 gradle/gradle-daemon-jvm.properties create mode 100644 gradle/libs.versions.toml delete mode 100644 worldguard-libs/bukkit/build.gradle.kts diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2cbac18ad..000000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: java -dist: trusty -jdk: - - oraclejdk11 -notifications: - email: false -before_install: chmod +x gradlew -script: ./gradlew build -S diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 000000000..178689749 --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() + maven { + name = "EngineHub Repository" + url = uri("https://maven.enginehub.org/repo/") + } +} + +dependencies { + implementation(gradleApi()) + implementation(libs.licenser) + implementation(libs.grgit) + implementation(libs.shadow) + implementation(libs.jfrog.buildinfo) + implementation(libs.paperweight) + implementation(libs.gson) + + constraints { + val asmVersion = "[${libs.versions.minimumAsm.get()},)" + implementation("org.ow2.asm:asm:$asmVersion") { + because("Need Java 21 support in shadow") + } + implementation("org.ow2.asm:asm-commons:$asmVersion") { + because("Need Java 21 support in shadow") + } + implementation("org.vafer:jdependency:[${libs.versions.minimumJdependency.get()},)") { + because("Need Java 21 support in shadow") + } + } +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 000000000..aa5e146f1 --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,9 @@ +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +rootProject.name = "build-logic" diff --git a/build-logic/src/main/kotlin/buildlogic.artifactory-root.gradle.kts b/build-logic/src/main/kotlin/buildlogic.artifactory-root.gradle.kts new file mode 100644 index 000000000..698fb424b --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.artifactory-root.gradle.kts @@ -0,0 +1,32 @@ +import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention +import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask + +plugins { + id("com.jfrog.artifactory") +} + +val ARTIFACTORY_CONTEXT_URL = "artifactory_contextUrl" +val ARTIFACTORY_USER = "artifactory_user" +val ARTIFACTORY_PASSWORD = "artifactory_password" + +if (!project.hasProperty(ARTIFACTORY_CONTEXT_URL)) ext[ARTIFACTORY_CONTEXT_URL] = "http://localhost" +if (!project.hasProperty(ARTIFACTORY_USER)) ext[ARTIFACTORY_USER] = "guest" +if (!project.hasProperty(ARTIFACTORY_PASSWORD)) ext[ARTIFACTORY_PASSWORD] = "" + +configure { + setContextUrl("${project.property(ARTIFACTORY_CONTEXT_URL)}") + clientConfig.publisher.run { + repoKey = when { + "${project.version}".contains("SNAPSHOT") -> "libs-snapshot-local" + else -> "libs-release-local" + } + username = "${project.property(ARTIFACTORY_USER)}" + password = "${project.property(ARTIFACTORY_PASSWORD)}" + isMaven = true + isIvy = false + } +} + +tasks.named("artifactoryPublish") { + isSkip = true +} diff --git a/build-logic/src/main/kotlin/buildlogic.artifactory-sub.gradle.kts b/build-logic/src/main/kotlin/buildlogic.artifactory-sub.gradle.kts new file mode 100644 index 000000000..966409761 --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.artifactory-sub.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("com.jfrog.artifactory") +} + +// Artifactory eagerly evaluates publications, so this must run after all changes to artifacts are done +afterEvaluate { + tasks.named("artifactoryPublish") { + publications("maven") + } +} diff --git a/build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts b/build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts new file mode 100644 index 000000000..2271301f2 --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts @@ -0,0 +1,81 @@ +import buildlogic.getLibrary +import buildlogic.stringyLibs + +plugins { + id("eclipse") + id("idea") + id("checkstyle") + id("buildlogic.common") +} + +val commonJava = extensions.create("commonJava") +commonJava.banSlf4j.convention(true) + +tasks + .withType() + .matching { it.name == "compileJava" || it.name == "compileTestJava" } + .configureEach { + val disabledLint = listOf( + "processing", "path", "fallthrough", "serial", "overloads", + ) + options.release.set(21) + options.compilerArgs.addAll(listOf("-Xlint:all") + disabledLint.map { "-Xlint:-$it" }) + options.isDeprecation = true + options.encoding = "UTF-8" + options.compilerArgs.add("-parameters") + //options.compilerArgs.add("-Werror") + } + +configure { + configFile = rootProject.file("config/checkstyle/checkstyle.xml") + toolVersion = "10.16.0" +} + +tasks.withType().configureEach { + useJUnitPlatform() +} + +dependencies { + "compileOnly"(stringyLibs.getLibrary("jsr305")) + "testImplementation"(platform(stringyLibs.getLibrary("junit-bom"))) + "testImplementation"(stringyLibs.getLibrary("junit-jupiter-api")) + "testImplementation"(stringyLibs.getLibrary("junit-jupiter-params")) + "testImplementation"(platform(stringyLibs.getLibrary("mockito-bom"))) + "testImplementation"(stringyLibs.getLibrary("mockito-core")) + "testImplementation"(stringyLibs.getLibrary("mockito-junit-jupiter")) + "testRuntimeOnly"(stringyLibs.getLibrary("junit-jupiter-engine")) +} + +// Java 8 turns on doclint which we fail +tasks.withType().configureEach { + options.encoding = "UTF-8" + (options as StandardJavadocDocletOptions).apply { + //addBooleanOption("Werror", true) + addBooleanOption("Xdoclint:all", true) + addBooleanOption("Xdoclint:-missing", true) + tags( + "apiNote:a:API Note:", + "implSpec:a:Implementation Requirements:", + "implNote:a:Implementation Note:" + ) + } +} + +configure { + withJavadocJar() + withSourcesJar() +} + +configurations["compileClasspath"].apply { + resolutionStrategy.componentSelection { + withModule("org.slf4j:slf4j-api") { + if (commonJava.banSlf4j.get()) { + reject("No SLF4J allowed on compile classpath") + } + } + } +} + +tasks.named("check").configure { + dependsOn("checkstyleMain", "checkstyleTest") +} diff --git a/build-logic/src/main/kotlin/buildlogic.common.gradle.kts b/build-logic/src/main/kotlin/buildlogic.common.gradle.kts new file mode 100644 index 000000000..1a84a9538 --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.common.gradle.kts @@ -0,0 +1,69 @@ +import buildlogic.getLibrary +import buildlogic.stringyLibs +import org.gradle.plugins.ide.idea.model.IdeaModel + +plugins { + id("org.cadixdev.licenser") +} + +group = rootProject.group +version = rootProject.version + +repositories { + mavenCentral() + maven { + name = "EngineHub" + url = uri("https://maven.enginehub.org/repo/") + } +} + +configurations.all { + resolutionStrategy { + cacheChangingModulesFor(1, TimeUnit.DAYS) + } +} + +plugins.withId("java") { + the().toolchain { + languageVersion.set(JavaLanguageVersion.of(21)) + } +} + +dependencies { + for (conf in listOf("implementation", "api")) { + if (!configurations.names.contains(conf)) { + continue + } + add(conf, platform(stringyLibs.getLibrary("log4j-bom")).map { + val dep = create(it) + dep.because("Mojang provides Log4j") + dep + }) + constraints { + add(conf, stringyLibs.getLibrary("guava")) { + because("Mojang provides Guava") + } + add(conf, stringyLibs.getLibrary("gson")) { + because("Mojang provides Gson") + } + add(conf, stringyLibs.getLibrary("fastutil")) { + because("Mojang provides FastUtil") + } + } + } +} + +license { + header(rootProject.file("HEADER.txt")) + include("**/*.java") + include("**/*.kt") +} + +plugins.withId("idea") { + configure { + module { + isDownloadSources = true + isDownloadJavadoc = true + } + } +} diff --git a/build-logic/src/main/kotlin/buildlogic.core-and-platform.gradle.kts b/build-logic/src/main/kotlin/buildlogic.core-and-platform.gradle.kts new file mode 100644 index 000000000..ce369ccec --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.core-and-platform.gradle.kts @@ -0,0 +1,23 @@ +plugins { + id("java") + id("maven-publish") + id("buildlogic.common-java") + id("buildlogic.artifactory-sub") +} + +ext["internalVersion"] = "$version+${rootProject.ext["gitCommitHash"]}" + +publishing { + publications { + register("maven") { + versionMapping { + usage("java-api") { + fromResolutionOf("runtimeClasspath") + } + usage("java-runtime") { + fromResolutionResult() + } + } + } + } +} diff --git a/build-logic/src/main/kotlin/buildlogic.libs.gradle.kts b/build-logic/src/main/kotlin/buildlogic.libs.gradle.kts new file mode 100644 index 000000000..f10cd29aa --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.libs.gradle.kts @@ -0,0 +1,182 @@ +plugins { + id("java-base") + id("maven-publish") + id("com.github.johnrengelman.shadow") + id("com.jfrog.artifactory") + id("buildlogic.common") + id("buildlogic.artifactory-sub") +} + +// A horrible hack because `softwareComponentFactory` has to be gotten via plugin +// gradle why +internal open class LibsConfigPluginHack @Inject constructor( + private val softwareComponentFactory: SoftwareComponentFactory +) : Plugin { + override fun apply(project: Project) { + val libsComponents = softwareComponentFactory.adhoc("libs") + project.components.add(libsComponents) + } +} + +configurations { + create("shade") +} + +group = "${rootProject.group}.worldguard-libs" + +val relocations = mapOf( + "org.enginehub.squirrelid" to "com.sk89q.worldguard.util.profile", +) + +tasks.register("jar") { + configurations = listOf(project.configurations["shade"]) + archiveClassifier.set("") + + // Yeet module-info's + exclude("module-info.class") + + dependencies { + exclude(dependency("com.google.guava:guava")) + exclude(dependency("com.google.code.gson:gson")) + exclude(dependency("com.google.errorprone:error_prone_annotations")) + exclude(dependency("com.google.guava:failureaccess")) + exclude(dependency("org.checkerframework:checker-qual")) + exclude(dependency("org.jetbrains:annotations")) + exclude(dependency("org.apache.logging.log4j:log4j-api")) + exclude(dependency("com.google.code.findbugs:jsr305")) + exclude { + it.moduleGroup == "org.jetbrains.kotlin" + } + + include(dependency("org.enginehub:squirrelid")) + include(dependency("org.khelekore:prtree")) + } + + relocations.forEach { (from, to) -> + relocate(from, to) + } +} +val altConfigFiles = { artifactType: String -> + val deps = configurations["shade"].incoming.dependencies + .filterIsInstance() + .map { it.copy() } + .map { dependency -> + val category = dependency.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)?.name + if (category == Category.REGULAR_PLATFORM || category == Category.ENFORCED_PLATFORM) { + return@map dependency + } + try { + dependency.artifact { + name = dependency.name + type = artifactType + extension = "jar" + classifier = artifactType + } + } catch (e: Exception) { + throw RuntimeException("Failed to add artifact to dependency: $dependency", e) + } + dependency + } + + files(configurations.detachedConfiguration(*deps.toTypedArray()) + .resolvedConfiguration.lenientConfiguration.artifacts + .filter { it.classifier == artifactType } + .map { zipTree(it.file) }) +} +tasks.register("sourcesJar") { + from({ + altConfigFiles("sources") + }) + + // Yeet module-info's + exclude("module-info.java") + + relocations.forEach { (from, to) -> + val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)") + val textPattern = Regex.fromLiteral(from) + eachFile { + filter { + it.replaceFirst(textPattern, to) + } + path = path.replaceFirst(filePattern, "$1${to.replace('.', '/')}$2") + } + } + archiveClassifier.set("sources") +} + +tasks.named("assemble").configure { + dependsOn("jar", "sourcesJar") +} + +project.apply() + +val libsComponent = project.components["libs"] as AdhocComponentWithVariants + +val apiElements = project.configurations.register("apiElements") { + isVisible = false + description = "API elements for libs" + isCanBeResolved = false + isCanBeConsumed = true + attributes { + attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_API)) + attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) + attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) + attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16) + } + outgoing.artifact(tasks.named("jar")) +} + +val runtimeElements = project.configurations.register("runtimeElements") { + isVisible = false + description = "Runtime elements for libs" + isCanBeResolved = false + isCanBeConsumed = true + attributes { + attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) + attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) + attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16) + } + outgoing.artifact(tasks.named("jar")) +} + +val sourcesElements = project.configurations.register("sourcesElements") { + isVisible = false + description = "Source elements for libs" + isCanBeResolved = false + isCanBeConsumed = true + attributes { + attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.DOCUMENTATION)) + attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, project.objects.named(DocsType.SOURCES)) + } + outgoing.artifact(tasks.named("sourcesJar")) +} + +libsComponent.addVariantsFromConfiguration(apiElements.get()) { + mapToMavenScope("compile") +} + +libsComponent.addVariantsFromConfiguration(runtimeElements.get()) { + mapToMavenScope("runtime") +} + +libsComponent.addVariantsFromConfiguration(sourcesElements.get()) { + mapToMavenScope("runtime") +} + +configure { + publications { + register("maven") { + from(libsComponent) + } + } +} + +if (project != project(":worldguard-libs:core")) { + evaluationDependsOn(":worldguard-libs:core") + configurations["shade"].shouldResolveConsistentlyWith(project(":worldguard-libs:core").configurations["shade"]) +} diff --git a/build-logic/src/main/kotlin/buildlogic.platform.gradle.kts b/build-logic/src/main/kotlin/buildlogic.platform.gradle.kts new file mode 100644 index 000000000..a8eb61dca --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic.platform.gradle.kts @@ -0,0 +1,39 @@ +plugins { + id("com.github.johnrengelman.shadow") + id("buildlogic.core-and-platform") +} + +tasks.named("shadowJar") { + archiveClassifier.set("dist") + dependencies { + include(project(":worldguard-libs:core")) + include(project(":worldguard-core")) + + relocate("org.flywaydb", "com.sk89q.worldguard.internal.flywaydb") { + include(dependency("org.flywaydb:flyway-core:3.0")) + } + exclude("com.google.code.findbugs:jsr305") + } + exclude("GradleStart**") + exclude(".cache") + exclude("LICENSE*") + exclude("META-INF/maven/**") + minimize() +} +val javaComponent = components["java"] as AdhocComponentWithVariants +// I don't think we want this published (it's the shadow jar) +javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { + skip() +} + +afterEvaluate { + tasks.named("jar") { + val version = project(":worldguard-core").version + inputs.property("version", version) + val attributes = mutableMapOf( + "Implementation-Version" to version, + "WorldGuard-Version" to version, + ) + manifest.attributes(attributes) + } +} diff --git a/build-logic/src/main/kotlin/buildlogic/CommonJavaExtension.kt b/build-logic/src/main/kotlin/buildlogic/CommonJavaExtension.kt new file mode 100644 index 000000000..8631f5379 --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic/CommonJavaExtension.kt @@ -0,0 +1,7 @@ +package buildlogic + +import org.gradle.api.provider.Property + +interface CommonJavaExtension { + val banSlf4j: Property +} diff --git a/build-logic/src/main/kotlin/buildlogic/GradleExtras.kt b/build-logic/src/main/kotlin/buildlogic/GradleExtras.kt new file mode 100644 index 000000000..dcc537fa3 --- /dev/null +++ b/build-logic/src/main/kotlin/buildlogic/GradleExtras.kt @@ -0,0 +1,24 @@ +package buildlogic + +import org.gradle.api.Project +import org.gradle.api.artifacts.MinimalExternalModuleDependency +import org.gradle.api.artifacts.VersionCatalog +import org.gradle.api.artifacts.VersionCatalogsExtension +import org.gradle.api.artifacts.VersionConstraint +import org.gradle.api.plugins.ExtraPropertiesExtension +import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.getByType + +val Project.ext: ExtraPropertiesExtension + get() = extensions.getByType() + +val Project.stringyLibs: VersionCatalog + get() = extensions.getByType().named("libs") + +fun VersionCatalog.getLibrary(name: String): Provider = findLibrary(name).orElseThrow { + error("Library $name not found in version catalog") +} + +fun VersionCatalog.getVersion(name: String): VersionConstraint = findVersion(name).orElseThrow { + error("Version $name not found in version catalog") +} diff --git a/build.gradle.kts b/build.gradle.kts index caa15ac54..a6b538a43 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,26 +1,18 @@ import org.ajoberstar.grgit.Grgit -logger.lifecycle(""" -******************************************* - You are building WorldGuard! - If you encounter trouble: - 1) Try running 'build' in a separate Gradle run - 2) Use gradlew and not gradle - 3) If you still need help, ask on Discord! https://discord.gg/enginehub - - Output files will be in [subproject]/build/libs -******************************************* -""") - -applyRootArtifactoryConfig() +plugins { + alias(libs.plugins.codecov) + id("buildlogic.common") + id("buildlogic.artifactory-root") +} if (!project.hasProperty("gitCommitHash")) { apply(plugin = "org.ajoberstar.grgit") ext["gitCommitHash"] = try { - Grgit.open(mapOf("currentDir" to project.rootDir))?.head()?.abbreviatedId + extensions.getByName("grgit").head()?.abbreviatedId } catch (e: Exception) { logger.warn("Error getting commit hash", e) "no.git.id" } -} \ No newline at end of file +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index 1b858d015..000000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - `kotlin-dsl` - kotlin("jvm") version embeddedKotlinVersion -} - -repositories { - mavenCentral() - gradlePluginPortal() -} - -dependencies { - implementation(gradleApi()) - implementation("gradle.plugin.org.cadixdev.gradle:licenser:0.6.1") - implementation("org.ajoberstar.grgit:grgit-gradle:5.2.2") - implementation("com.github.johnrengelman:shadow:8.1.1") - implementation("org.jfrog.buildinfo:build-info-extractor-gradle:5.2.0") - constraints { - val asmVersion = "[9.7,)" - implementation("org.ow2.asm:asm:$asmVersion") { - because("Need Java 21 support in shadow") - } - implementation("org.ow2.asm:asm-commons:$asmVersion") { - because("Need Java 21 support in shadow") - } - implementation("org.vafer:jdependency:[2.10,)") { - because("Need Java 21 support in shadow") - } - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/ArtifactoryConfig.kt b/buildSrc/src/main/kotlin/ArtifactoryConfig.kt deleted file mode 100644 index 929bab7af..000000000 --- a/buildSrc/src/main/kotlin/ArtifactoryConfig.kt +++ /dev/null @@ -1,40 +0,0 @@ -import org.gradle.api.Project -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.named -import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention -import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask - -private const val ARTIFACTORY_CONTEXT_URL = "artifactory_contextUrl" -private const val ARTIFACTORY_USER = "artifactory_user" -private const val ARTIFACTORY_PASSWORD = "artifactory_password" - -fun Project.applyRootArtifactoryConfig() { - if (!project.hasProperty(ARTIFACTORY_CONTEXT_URL)) ext[ARTIFACTORY_CONTEXT_URL] = "http://localhost" - if (!project.hasProperty(ARTIFACTORY_USER)) ext[ARTIFACTORY_USER] = "guest" - if (!project.hasProperty(ARTIFACTORY_PASSWORD)) ext[ARTIFACTORY_PASSWORD] = "" - - apply(plugin = "com.jfrog.artifactory") - configure { - setContextUrl("${project.property(ARTIFACTORY_CONTEXT_URL)}") - clientConfig.publisher.run { - repoKey = when { - "${project.version}".contains("SNAPSHOT") -> "libs-snapshot-local" - else -> "libs-release-local" - } - username = "${project.property(ARTIFACTORY_USER)}" - password = "${project.property(ARTIFACTORY_PASSWORD)}" - isMaven = true - isIvy = false - } - } - tasks.named("artifactoryPublish") { - isSkip = true - } -} - -fun Project.applyCommonArtifactoryConfig() { - tasks.named("artifactoryPublish") { - publications("maven") - } -} diff --git a/buildSrc/src/main/kotlin/CommonConfig.kt b/buildSrc/src/main/kotlin/CommonConfig.kt deleted file mode 100644 index 543514320..000000000 --- a/buildSrc/src/main/kotlin/CommonConfig.kt +++ /dev/null @@ -1,38 +0,0 @@ -import org.cadixdev.gradle.licenser.LicenseExtension -import org.gradle.api.Project -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.jvm.toolchain.JavaLanguageVersion -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.repositories -import org.gradle.kotlin.dsl.the - -fun Project.applyCommonConfiguration() { - group = rootProject.group - version = rootProject.version - - repositories { - mavenCentral() - maven { url = uri("https://maven.enginehub.org/repo/") } - maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") } - } - - configurations.all { - resolutionStrategy { - cacheChangingModulesFor(5, "MINUTES") - } - } - - plugins.withId("java") { - the().toolchain { - languageVersion.set(JavaLanguageVersion.of(21)) - } - } - - apply(plugin = "org.cadixdev.licenser") - configure { - header(rootProject.file("HEADER.txt")) - include("**/*.java") - include("**/*.kt") - } -} diff --git a/buildSrc/src/main/kotlin/GradleExtras.kt b/buildSrc/src/main/kotlin/GradleExtras.kt deleted file mode 100644 index e7d1e0ede..000000000 --- a/buildSrc/src/main/kotlin/GradleExtras.kt +++ /dev/null @@ -1,12 +0,0 @@ -import org.gradle.api.Project -import org.gradle.api.plugins.ExtraPropertiesExtension -import org.gradle.api.plugins.JavaPluginConvention -import org.gradle.api.tasks.SourceSetContainer -import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.the - -val Project.ext: ExtraPropertiesExtension - get() = extensions.getByType() - -val Project.sourceSets: SourceSetContainer - get() = the().sourceSets diff --git a/buildSrc/src/main/kotlin/LibsConfig.kt b/buildSrc/src/main/kotlin/LibsConfig.kt deleted file mode 100644 index 3a78ce604..000000000 --- a/buildSrc/src/main/kotlin/LibsConfig.kt +++ /dev/null @@ -1,171 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.artifacts.ModuleDependency -import org.gradle.api.attributes.Bundling -import org.gradle.api.attributes.Category -import org.gradle.api.attributes.DocsType -import org.gradle.api.attributes.LibraryElements -import org.gradle.api.attributes.Usage -import org.gradle.api.attributes.java.TargetJvmVersion -import org.gradle.api.component.AdhocComponentWithVariants -import org.gradle.api.component.SoftwareComponentFactory -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.tasks.bundling.Jar -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.invoke -import org.gradle.kotlin.dsl.named -import org.gradle.kotlin.dsl.register -import javax.inject.Inject - -fun Project.applyLibrariesConfiguration() { - applyCommonConfiguration() - apply(plugin = "java-base") - apply(plugin = "maven-publish") - apply(plugin = "com.github.johnrengelman.shadow") - apply(plugin = "com.jfrog.artifactory") - - configurations { - create("shade") - } - - group = "${rootProject.group}.worldguard-libs" - - val relocations = mapOf( - "org.enginehub.squirrelid" to "com.sk89q.worldguard.util.profile" - ) - - tasks.register("jar") { - configurations = listOf(project.configurations["shade"]) - archiveClassifier.set("") - - dependencies { - exclude(dependency("com.google.code.findbugs:jsr305")) - } - - relocations.forEach { (from, to) -> - relocate(from, to) - } - } - val altConfigFiles = { artifactType: String -> - val deps = configurations["shade"].incoming.dependencies - .filterIsInstance() - .map { it.copy() } - .map { dependency -> - dependency.artifact { - name = dependency.name - type = artifactType - extension = "jar" - classifier = artifactType - } - dependency - } - - files(configurations.detachedConfiguration(*deps.toTypedArray()) - .resolvedConfiguration.lenientConfiguration.artifacts - .filter { it.classifier == artifactType } - .map { zipTree(it.file) }) - } - tasks.register("sourcesJar") { - from({ - altConfigFiles("sources") - }) - relocations.forEach { (from, to) -> - val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)") - val textPattern = Regex.fromLiteral(from) - eachFile { - filter { - it.replaceFirst(textPattern, to) - } - path = path.replaceFirst(filePattern, "$1${to.replace('.', '/')}$2") - } - } - archiveClassifier.set("sources") - } - - tasks.named("assemble").configure { - dependsOn("jar", "sourcesJar") - } - - project.apply() - - val libsComponent = project.components["libs"] as AdhocComponentWithVariants - - val apiElements = project.configurations.register("apiElements") { - isVisible = false - description = "API elements for libs" - isCanBeResolved = false - isCanBeConsumed = true - attributes { - attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_API)) - attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) - attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) - attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8) - } - outgoing.artifact(tasks.named("jar")) - } - - val runtimeElements = project.configurations.register("runtimeElements") { - isVisible = false - description = "Runtime elements for libs" - isCanBeResolved = false - isCanBeConsumed = true - attributes { - attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) - attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) - attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) - attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8) - } - outgoing.artifact(tasks.named("jar")) - } - - val sourcesElements = project.configurations.register("sourcesElements") { - isVisible = false - description = "Source elements for libs" - isCanBeResolved = false - isCanBeConsumed = true - attributes { - attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) - attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.DOCUMENTATION)) - attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) - attribute(DocsType.DOCS_TYPE_ATTRIBUTE, project.objects.named(DocsType.SOURCES)) - } - outgoing.artifact(tasks.named("sourcesJar")) - } - - libsComponent.addVariantsFromConfiguration(apiElements.get()) { - mapToMavenScope("compile") - } - - libsComponent.addVariantsFromConfiguration(runtimeElements.get()) { - mapToMavenScope("runtime") - } - - libsComponent.addVariantsFromConfiguration(sourcesElements.get()) { - mapToMavenScope("runtime") - } - - configure { - publications { - register("maven") { - from(libsComponent) - } - } - } - - applyCommonArtifactoryConfig() -} - -internal open class LibsConfigPluginHack @Inject constructor( - private val softwareComponentFactory: SoftwareComponentFactory -) : Plugin { - override fun apply(project: Project) { - val libsComponents = softwareComponentFactory.adhoc("libs") - project.components.add(libsComponents) - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/PlatformConfig.kt b/buildSrc/src/main/kotlin/PlatformConfig.kt deleted file mode 100644 index 3cd5375eb..000000000 --- a/buildSrc/src/main/kotlin/PlatformConfig.kt +++ /dev/null @@ -1,113 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import org.gradle.api.Project -import org.gradle.api.component.AdhocComponentWithVariants -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.plugins.quality.CheckstyleExtension -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.tasks.javadoc.Javadoc -import org.gradle.api.tasks.testing.Test -import org.gradle.external.javadoc.StandardJavadocDocletOptions -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.named -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.withType -import org.gradle.kotlin.dsl.the - -fun Project.applyPlatformAndCoreConfiguration() { - applyCommonConfiguration() - apply(plugin = "java") - apply(plugin = "eclipse") - apply(plugin = "idea") - apply(plugin = "maven-publish") - apply(plugin = "checkstyle") - apply(plugin = "com.jfrog.artifactory") - - ext["internalVersion"] = "$version+${rootProject.ext["gitCommitHash"]}" - - configure { - configFile = rootProject.file("config/checkstyle/checkstyle.xml") - toolVersion = "10.3" - } - - tasks.withType().configureEach { - useJUnitPlatform() - } - - dependencies { - "compileOnly"("com.google.code.findbugs:jsr305:3.0.2") - "testCompileOnly"("com.google.code.findbugs:jsr305:3.0.2") - "testImplementation"("org.junit.jupiter:junit-jupiter-api:${Versions.JUNIT}") - "testImplementation"("org.junit.jupiter:junit-jupiter-params:${Versions.JUNIT}") - "testImplementation"("org.mockito:mockito-core:${Versions.MOCKITO}") - "testImplementation"("org.mockito:mockito-junit-jupiter:${Versions.MOCKITO}") - "testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT}") - } - - // Java 8 turns on doclint which we fail - tasks.withType().configureEach { - (options as StandardJavadocDocletOptions).apply { - addStringOption("Xdoclint:none", "-quiet") - tags( - "apiNote:a:API Note:", - "implSpec:a:Implementation Requirements:", - "implNote:a:Implementation Note:" - ) - } - } - - the().withJavadocJar() - - if (name == "worldguard-core" || name == "worldguard-bukkit") { - the().withSourcesJar() - } - - tasks.named("check").configure { - dependsOn("checkstyleMain", "checkstyleTest") - } - - configure { - publications { - register("maven") { - from(components["java"]) - versionMapping { - usage("java-api") { - fromResolutionOf("runtimeClasspath") - } - usage("java-runtime") { - fromResolutionResult() - } - } - } - } - } - - applyCommonArtifactoryConfig() -} - -fun Project.applyShadowConfiguration() { - apply(plugin = "com.github.johnrengelman.shadow") - tasks.named("shadowJar") { - archiveClassifier.set("dist") - dependencies { - include(project(":worldguard-libs:core")) - //include(project(":worldguard-libs:${project.name.replace("worldguard-", "")}")) - include(project(":worldguard-core")) - - relocate("org.flywaydb", "com.sk89q.worldguard.internal.flywaydb") { - include(dependency("org.flywaydb:flyway-core:3.0")) - } - exclude("com.google.code.findbugs:jsr305") - } - exclude("GradleStart**") - exclude(".cache") - exclude("LICENSE*") - } - val javaComponent = components["java"] as AdhocComponentWithVariants - javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { - skip() - } -} diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt deleted file mode 100644 index 105af054f..000000000 --- a/buildSrc/src/main/kotlin/Versions.kt +++ /dev/null @@ -1,10 +0,0 @@ -object Versions { - // const val PISTON = "0.4.3" - // const val AUTO_VALUE = "1.6.5" - const val WORLDEDIT = "7.3.0" - const val JUNIT = "5.9.1" - const val MOCKITO = "4.9.0" - const val SQUIRRELID = "0.3.2" - const val GUAVA = "31.1-jre" - const val FINDBUGS = "3.0.2" -} diff --git a/gradle.properties b/gradle.properties index b3cb7fcd5..11b233380 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,4 @@ group=com.sk89q.worldguard version=7.0.11-SNAPSHOT + +org.gradle.parallel=true diff --git a/gradle/gradle-daemon-jvm.properties b/gradle/gradle-daemon-jvm.properties new file mode 100644 index 000000000..63e5bbdf4 --- /dev/null +++ b/gradle/gradle-daemon-jvm.properties @@ -0,0 +1,2 @@ +#This file is generated by updateDaemonJvm +toolchainVersion=21 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..b85664edb --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,76 @@ +[plugins] +codecov = "org.enginehub.codecov:0.2.0" + +[versions] +worldedit = "7.3.0" + +# Minimum versions we apply to make dependencies support newer Java +minimumAsm = "9.7" +minimumJdependency = "2.10" +minimumTinyRemapper = "0.8.11" + +lang-version = "1450" + +[libraries] + +licenser = "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1" +grgit = "org.ajoberstar.grgit:grgit-gradle:5.2.2" +shadow = "com.github.johnrengelman:shadow:8.1.1" +jfrog-buildinfo = "org.jfrog.buildinfo:build-info-extractor-gradle:5.2.0" + +paperweight = "io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.7.1" + +squirrelid = "org.enginehub:squirrelid:0.3.2" + +autoService = "com.google.auto.service:auto-service:1.1.1" + +jsr305 = "com.google.code.findbugs:jsr305:3.0.2" +jetbrains-annotations = "org.jetbrains:annotations:24.1.0" + +junit-bom = "org.junit:junit-bom:5.10.2" +junit-jupiter-api.module = "org.junit.jupiter:junit-jupiter-api" +junit-jupiter-params.module = "org.junit.jupiter:junit-jupiter-params" +junit-jupiter-engine.module = "org.junit.jupiter:junit-jupiter-engine" + +mockito-bom = "org.mockito:mockito-bom:5.11.0" +mockito-core.module = "org.mockito:mockito-core" +mockito-junit-jupiter.module = "org.mockito:mockito-junit-jupiter" + +spigot = "org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT" +paperApi = "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT" +paperLib = "io.papermc:paperlib:1.0.8" + +dummypermscompat = "com.sk89q:dummypermscompat:1.10" +bstats-bukkit = "org.bstats:bstats-bukkit:2.2.1" + +prtree = "org.khelekore:prtree:1.5.0" + +# Also update in build-logic/src/main/kotlin/buildlogic.platform.gradle.kts +flyway-core = "org.flywaydb:flyway-core:3.0" + +commandbook = "com.sk89q:commandbook:2.3" + +hamcrest-library = "org.hamcrest:hamcrest-library:2.2" + +# Mojang-provided libraries, CHECK AGAINST MINECRAFT for versions +guava = "com.google.guava:guava:32.1.3-jre!!" +log4j-bom = "org.apache.logging.log4j:log4j-bom:2.22.1!!" +gson = "com.google.code.gson:gson:2.10.1!!" +fastutil = "it.unimi.dsi:fastutil:8.5.12!!" + +# Bukkit-provided libraries, CHECK AGAINST SPIGOT for versions +# Note that we need to balance support for older MC versus working at all on newer ones, so the exact versions here +# may not be the same as the ones in the latest Bukkit API. +snakeyaml = "org.yaml:snakeyaml:2.0" + +[libraries.worldedit-core] +module = "com.sk89q.worldedit:worldedit-core" +version.ref = "worldedit" + +[libraries.worldedit-bukkit] +module = "com.sk89q.worldedit:worldedit-bukkit" +version.ref = "worldedit" + +[libraries.worldedit-libs-ap] +module = "com.sk89q.worldedit.worldedit-libs:ap" +version.ref = "worldedit" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23a4..a4413138c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle.kts b/settings.gradle.kts index ead83aeae..8c2135822 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,37 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven { + name = "EngineHub" + url = uri("https://maven.enginehub.org/repo/") + } + } +} +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + +logger.lifecycle(""" +******************************************* + You are building WorldGuard! + + If you encounter trouble: + 1) Read COMPILING.md if you haven't yet + 2) Try running 'build' in a separate Gradle run + 3) Use gradlew and not gradle + 4) If you still need help, ask on Discord! https://discord.gg/enginehub + + Output files will be in [subproject]/build/libs +******************************************* +""") + rootProject.name = "worldguard" +includeBuild("build-logic") + include("worldguard-libs") include("worldguard-libs:core") -include("worldguard-core") -//include("worldguard-libs:bukkit") -include("worldguard-bukkit") + +listOf("bukkit", "core").forEach { + include("worldguard-$it") +} diff --git a/worldguard-bukkit/build.gradle.kts b/worldguard-bukkit/build.gradle.kts index 6b0e5d5ec..f23469043 100644 --- a/worldguard-bukkit/build.gradle.kts +++ b/worldguard-bukkit/build.gradle.kts @@ -2,33 +2,47 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { `java-library` + id("buildlogic.platform") } -applyPlatformAndCoreConfiguration() -applyShadowConfiguration() - repositories { maven { - name = "paper" - url = uri("https://repo.papermc.io/repository/maven-public/") + name = "Spigot" + url = uri("https://hub.spigotmc.org/nexus/content/groups/public") } } -configurations { - compileClasspath.get().extendsFrom(create("shadeOnly")) +val localImplementation = configurations.create("localImplementation") { + description = "Dependencies used locally, but provided by the runtime Bukkit implementation" + isCanBeConsumed = false + isCanBeResolved = false } +configurations["compileOnly"].extendsFrom(localImplementation) +configurations["testImplementation"].extendsFrom(localImplementation) dependencies { "api"(project(":worldguard-core")) - "compileOnly"("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") - "runtimeOnly"("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") { + "api"(libs.worldedit.bukkit) { isTransitive = false } + "compileOnly"(libs.commandbook) { isTransitive = false } + // Technically this is api, but everyone should already have some form of the bukkit API + // Avoid pulling in another one, especially one so outdated. + "localImplementation"(libs.spigot) { + exclude("junit", "junit") + } + + "compileOnly"(libs.jetbrains.annotations) { + because("Resolving Spigot annotations") + } + "testCompileOnly"(libs.jetbrains.annotations) { + because("Resolving Spigot annotations") + } + "compileOnly"(libs.paperApi) { + exclude("org.slf4j", "slf4j-api") exclude("junit", "junit") } - "api"("com.sk89q.worldedit:worldedit-bukkit:${Versions.WORLDEDIT}") { isTransitive = false } - "implementation"("com.google.guava:guava:${Versions.GUAVA}") - "compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false } - "shadeOnly"("io.papermc:paperlib:1.0.8") - "shadeOnly"("org.bstats:bstats-bukkit:3.0.1") + + "implementation"(libs.paperLib) + "implementation"(libs.bstats.bukkit) } tasks.named("processResources") { @@ -39,31 +53,25 @@ tasks.named("processResources") { } } -tasks.named("jar") { - val projectVersion = project.version - inputs.property("projectVersion", projectVersion) - manifest { - attributes("Implementation-Version" to projectVersion) - } -} - tasks.named("shadowJar") { - configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"]) - dependencies { include(dependency(":worldguard-core")) - relocate("org.bstats", "com.sk89q.worldguard.bukkit.bstats") { - include(dependency("org.bstats:")) - } - relocate ("io.papermc.lib", "com.sk89q.worldguard.bukkit.paperlib") { - include(dependency("io.papermc:paperlib")) - } - relocate ("co.aikar.timings.lib", "com.sk89q.worldguard.bukkit.timingslib") { - include(dependency("co.aikar:minecraft-timings")) - } + include(dependency("org.bstats:")) + include(dependency("io.papermc:paperlib")) + include(dependency("co.aikar:minecraft-timings")) + + relocate("org.bstats", "com.sk89q.worldguard.bukkit.bstats") + relocate("io.papermc.lib", "com.sk89q.worldguard.bukkit.paperlib") + relocate("co.aikar.timings.lib", "com.sk89q.worldguard.bukkit.timingslib") } } tasks.named("assemble").configure { dependsOn("shadowJar") } + +configure { + publications.named("maven") { + from(components["java"]) + } +} diff --git a/worldguard-core/build.gradle.kts b/worldguard-core/build.gradle.kts index 9e5666162..d6f7eac53 100644 --- a/worldguard-core/build.gradle.kts +++ b/worldguard-core/build.gradle.kts @@ -1,20 +1,51 @@ +import org.cadixdev.gradle.licenser.LicenseExtension + plugins { `java-library` + id("buildlogic.core-and-platform") } -applyPlatformAndCoreConfiguration() - dependencies { + constraints { + "implementation"(libs.snakeyaml) { + because("Bukkit provides SnakeYaml") + } + } + "api"(project(":worldguard-libs:core")) - "api"("com.sk89q.worldedit:worldedit-core:${Versions.WORLDEDIT}") - "implementation"("org.flywaydb:flyway-core:3.0") - "implementation"("org.yaml:snakeyaml:2.0") - "implementation"("com.google.guava:guava:${Versions.GUAVA}") + "api"(libs.worldedit.core) + "implementation"(libs.flyway.core) + "implementation"(libs.snakeyaml) + "implementation"(libs.guava) + "compileOnlyApi"(libs.jsr305) + "implementation"(libs.gson) + + "compileOnly"(libs.worldedit.libs.ap) + "annotationProcessor"(libs.worldedit.libs.ap) + // ensure this is on the classpath for the AP + "annotationProcessor"(libs.guava) + + "compileOnly"(libs.autoService) { + because("Needed to resolve annotations in Piston") + } - "compileOnly"("com.google.code.findbugs:jsr305:${Versions.FINDBUGS}") - "testImplementation"("org.hamcrest:hamcrest-library:2.2") + "testImplementation"(libs.hamcrest.library) } -tasks.withType().configureEach { +tasks.compileJava { dependsOn(":worldguard-libs:build") -} \ No newline at end of file + options.compilerArgs.add("-Aarg.name.key.prefix=") +} + +configure { + exclude { + it.file.startsWith(project.layout.buildDirectory.get().asFile) + } +} + +configure { + publications.named("maven") { + artifactId = the().archivesName.get() + from(components["java"]) + } +} diff --git a/worldguard-libs/build.gradle.kts b/worldguard-libs/build.gradle.kts index 33c839af1..152530cb0 100644 --- a/worldguard-libs/build.gradle.kts +++ b/worldguard-libs/build.gradle.kts @@ -1,3 +1,3 @@ tasks.register("build") { dependsOn(subprojects.map { it.tasks.named("build") }) -} \ No newline at end of file +} diff --git a/worldguard-libs/bukkit/build.gradle.kts b/worldguard-libs/bukkit/build.gradle.kts deleted file mode 100644 index 388618cea..000000000 --- a/worldguard-libs/bukkit/build.gradle.kts +++ /dev/null @@ -1 +0,0 @@ -applyLibrariesConfiguration() diff --git a/worldguard-libs/core/build.gradle.kts b/worldguard-libs/core/build.gradle.kts index 035191ede..94f4841f7 100644 --- a/worldguard-libs/core/build.gradle.kts +++ b/worldguard-libs/core/build.gradle.kts @@ -1,18 +1,8 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - -applyLibrariesConfiguration() - -dependencies { - "shade"("org.enginehub:squirrelid:${Versions.SQUIRRELID}") - "shade"("org.khelekore:prtree:1.5.0") +plugins { + id("buildlogic.libs") } -tasks.named("jar") { - dependencies { - relocate("org.enginehub.squirrelid", "com.sk89q.worldguard.util.profile") { - include(dependency("org.enginehub:squirrelid")) - } - - include(dependency("org.khelekore:prtree")) - } +dependencies { + "shade"(libs.squirrelid) + "shade"(libs.prtree) } From ca49458a4478b4208e2528e112816baa719929d9 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 21 Jul 2024 23:06:56 -0400 Subject: [PATCH 25/50] A bit of cleanup. Definitely did not accidentally make a 40MB jar halfway through. --- build-logic/build.gradle.kts | 5 ----- .../kotlin/buildlogic.common-java.gradle.kts | 16 ---------------- .../src/main/kotlin/buildlogic.libs.gradle.kts | 7 ++----- .../main/kotlin/buildlogic.platform.gradle.kts | 2 +- .../kotlin/buildlogic/CommonJavaExtension.kt | 7 ------- build.gradle.kts | 1 - config/checkstyle/import-control.xml | 1 - gradle/libs.versions.toml | 12 +----------- settings.gradle.kts | 4 ---- worldguard-bukkit/build.gradle.kts | 9 --------- worldguard-libs/core/build.gradle.kts | 4 +++- 11 files changed, 7 insertions(+), 61 deletions(-) delete mode 100644 build-logic/src/main/kotlin/buildlogic/CommonJavaExtension.kt diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 178689749..8c51ba4c2 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -4,10 +4,6 @@ plugins { repositories { gradlePluginPortal() - maven { - name = "EngineHub Repository" - url = uri("https://maven.enginehub.org/repo/") - } } dependencies { @@ -16,7 +12,6 @@ dependencies { implementation(libs.grgit) implementation(libs.shadow) implementation(libs.jfrog.buildinfo) - implementation(libs.paperweight) implementation(libs.gson) constraints { diff --git a/build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts b/build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts index 2271301f2..89526875c 100644 --- a/build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts +++ b/build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts @@ -8,9 +8,6 @@ plugins { id("buildlogic.common") } -val commonJava = extensions.create("commonJava") -commonJava.banSlf4j.convention(true) - tasks .withType() .matching { it.name == "compileJava" || it.name == "compileTestJava" } @@ -40,9 +37,6 @@ dependencies { "testImplementation"(platform(stringyLibs.getLibrary("junit-bom"))) "testImplementation"(stringyLibs.getLibrary("junit-jupiter-api")) "testImplementation"(stringyLibs.getLibrary("junit-jupiter-params")) - "testImplementation"(platform(stringyLibs.getLibrary("mockito-bom"))) - "testImplementation"(stringyLibs.getLibrary("mockito-core")) - "testImplementation"(stringyLibs.getLibrary("mockito-junit-jupiter")) "testRuntimeOnly"(stringyLibs.getLibrary("junit-jupiter-engine")) } @@ -66,16 +60,6 @@ configure { withSourcesJar() } -configurations["compileClasspath"].apply { - resolutionStrategy.componentSelection { - withModule("org.slf4j:slf4j-api") { - if (commonJava.banSlf4j.get()) { - reject("No SLF4J allowed on compile classpath") - } - } - } -} - tasks.named("check").configure { dependsOn("checkstyleMain", "checkstyleTest") } diff --git a/build-logic/src/main/kotlin/buildlogic.libs.gradle.kts b/build-logic/src/main/kotlin/buildlogic.libs.gradle.kts index f10cd29aa..ca37db667 100644 --- a/build-logic/src/main/kotlin/buildlogic.libs.gradle.kts +++ b/build-logic/src/main/kotlin/buildlogic.libs.gradle.kts @@ -47,9 +47,6 @@ tasks.register("jar" exclude { it.moduleGroup == "org.jetbrains.kotlin" } - - include(dependency("org.enginehub:squirrelid")) - include(dependency("org.khelekore:prtree")) } relocations.forEach { (from, to) -> @@ -122,7 +119,7 @@ val apiElements = project.configurations.register("apiElements") { attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16) + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) } outgoing.artifact(tasks.named("jar")) } @@ -137,7 +134,7 @@ val runtimeElements = project.configurations.register("runtimeElements") { attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.SHADOWED)) attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16) + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) } outgoing.artifact(tasks.named("jar")) } diff --git a/build-logic/src/main/kotlin/buildlogic.platform.gradle.kts b/build-logic/src/main/kotlin/buildlogic.platform.gradle.kts index a8eb61dca..b1221c82d 100644 --- a/build-logic/src/main/kotlin/buildlogic.platform.gradle.kts +++ b/build-logic/src/main/kotlin/buildlogic.platform.gradle.kts @@ -10,7 +10,7 @@ tasks.named("shadowJ include(project(":worldguard-core")) relocate("org.flywaydb", "com.sk89q.worldguard.internal.flywaydb") { - include(dependency("org.flywaydb:flyway-core:3.0")) + include(dependency("org.flywaydb:flyway-core")) } exclude("com.google.code.findbugs:jsr305") } diff --git a/build-logic/src/main/kotlin/buildlogic/CommonJavaExtension.kt b/build-logic/src/main/kotlin/buildlogic/CommonJavaExtension.kt deleted file mode 100644 index 8631f5379..000000000 --- a/build-logic/src/main/kotlin/buildlogic/CommonJavaExtension.kt +++ /dev/null @@ -1,7 +0,0 @@ -package buildlogic - -import org.gradle.api.provider.Property - -interface CommonJavaExtension { - val banSlf4j: Property -} diff --git a/build.gradle.kts b/build.gradle.kts index a6b538a43..aa62db092 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,6 @@ import org.ajoberstar.grgit.Grgit plugins { - alias(libs.plugins.codecov) id("buildlogic.common") id("buildlogic.artifactory-root") } diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index b00f80c27..abb251d1c 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -7,7 +7,6 @@ - diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b85664edb..ccd972853 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,3 @@ -[plugins] -codecov = "org.enginehub.codecov:0.2.0" - [versions] worldedit = "7.3.0" @@ -9,7 +6,7 @@ minimumAsm = "9.7" minimumJdependency = "2.10" minimumTinyRemapper = "0.8.11" -lang-version = "1450" +# lang-version = "" [libraries] @@ -18,8 +15,6 @@ grgit = "org.ajoberstar.grgit:grgit-gradle:5.2.2" shadow = "com.github.johnrengelman:shadow:8.1.1" jfrog-buildinfo = "org.jfrog.buildinfo:build-info-extractor-gradle:5.2.0" -paperweight = "io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.7.1" - squirrelid = "org.enginehub:squirrelid:0.3.2" autoService = "com.google.auto.service:auto-service:1.1.1" @@ -32,10 +27,6 @@ junit-jupiter-api.module = "org.junit.jupiter:junit-jupiter-api" junit-jupiter-params.module = "org.junit.jupiter:junit-jupiter-params" junit-jupiter-engine.module = "org.junit.jupiter:junit-jupiter-engine" -mockito-bom = "org.mockito:mockito-bom:5.11.0" -mockito-core.module = "org.mockito:mockito-core" -mockito-junit-jupiter.module = "org.mockito:mockito-junit-jupiter" - spigot = "org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT" paperApi = "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT" paperLib = "io.papermc:paperlib:1.0.8" @@ -45,7 +36,6 @@ bstats-bukkit = "org.bstats:bstats-bukkit:2.2.1" prtree = "org.khelekore:prtree:1.5.0" -# Also update in build-logic/src/main/kotlin/buildlogic.platform.gradle.kts flyway-core = "org.flywaydb:flyway-core:3.0" commandbook = "com.sk89q:commandbook:2.3" diff --git a/settings.gradle.kts b/settings.gradle.kts index 8c2135822..d0ca0d3e0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,10 +1,6 @@ pluginManagement { repositories { gradlePluginPortal() - maven { - name = "EngineHub" - url = uri("https://maven.enginehub.org/repo/") - } } } plugins { diff --git a/worldguard-bukkit/build.gradle.kts b/worldguard-bukkit/build.gradle.kts index f23469043..34d128a04 100644 --- a/worldguard-bukkit/build.gradle.kts +++ b/worldguard-bukkit/build.gradle.kts @@ -5,13 +5,6 @@ plugins { id("buildlogic.platform") } -repositories { - maven { - name = "Spigot" - url = uri("https://hub.spigotmc.org/nexus/content/groups/public") - } -} - val localImplementation = configurations.create("localImplementation") { description = "Dependencies used locally, but provided by the runtime Bukkit implementation" isCanBeConsumed = false @@ -58,11 +51,9 @@ tasks.named("shadowJar") { include(dependency(":worldguard-core")) include(dependency("org.bstats:")) include(dependency("io.papermc:paperlib")) - include(dependency("co.aikar:minecraft-timings")) relocate("org.bstats", "com.sk89q.worldguard.bukkit.bstats") relocate("io.papermc.lib", "com.sk89q.worldguard.bukkit.paperlib") - relocate("co.aikar.timings.lib", "com.sk89q.worldguard.bukkit.timingslib") } } diff --git a/worldguard-libs/core/build.gradle.kts b/worldguard-libs/core/build.gradle.kts index 94f4841f7..ebfc595b0 100644 --- a/worldguard-libs/core/build.gradle.kts +++ b/worldguard-libs/core/build.gradle.kts @@ -3,6 +3,8 @@ plugins { } dependencies { - "shade"(libs.squirrelid) + "shade"(libs.squirrelid) { + isTransitive = false + } "shade"(libs.prtree) } From 8ffc81ad749b584acb8c1ea1992a4381e27a8f2d Mon Sep 17 00:00:00 2001 From: Joo200 Date: Mon, 22 Jul 2024 21:42:44 +0200 Subject: [PATCH 26/50] Fix NPE for teleport events without target location Fixes #2111 --- .../worldguard/bukkit/listener/WorldGuardPlayerListener.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java index d9daa9e8e..1656ab323 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java @@ -350,6 +350,11 @@ public void onItemHeldChange(PlayerItemHeldEvent event) { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerTeleport(PlayerTeleportEvent event) { + if (event.getTo() == null) { + // The target location for PlayerTeleportEvents can be null. + // Those events will be ignored by the server, so we can ignore them too. + return; + } Player player = event.getPlayer(); if (com.sk89q.worldguard.bukkit.util.Entities.isNPC(player)) return; LocalPlayer localPlayer = getPlugin().wrapPlayer(player); From 7a0458dddc141ecf065c95349a145a4b968df8a4 Mon Sep 17 00:00:00 2001 From: KaspianDev Date: Thu, 8 Aug 2024 19:24:36 +0200 Subject: [PATCH 27/50] Fix compilation --- build-logic/src/main/kotlin/buildlogic.common.gradle.kts | 4 ++++ .../sk89q/worldguard/bukkit/listener/PlayerMoveListener.java | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build-logic/src/main/kotlin/buildlogic.common.gradle.kts b/build-logic/src/main/kotlin/buildlogic.common.gradle.kts index 1a84a9538..be15302b1 100644 --- a/build-logic/src/main/kotlin/buildlogic.common.gradle.kts +++ b/build-logic/src/main/kotlin/buildlogic.common.gradle.kts @@ -15,6 +15,10 @@ repositories { name = "EngineHub" url = uri("https://maven.enginehub.org/repo/") } + maven { + name = "devmart-other" + url = uri("https://nexuslite.gcnt.net/repos/other/") + } } configurations.all { diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java index dc8c0bea0..ede19224b 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java @@ -25,7 +25,6 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.session.MoveType; import com.sk89q.worldguard.session.Session; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.AbstractHorse; import org.bukkit.entity.Entity; @@ -40,7 +39,6 @@ import org.bukkit.event.vehicle.VehicleEnterEvent; import org.bukkit.plugin.PluginManager; import org.bukkit.util.Vector; -import org.spigotmc.event.entity.EntityMountEvent; import java.util.concurrent.TimeUnit; public class PlayerMoveListener extends AbstractListener { From aa46529ecb1c323404f2a21b3fdc07ba3c2fcd7a Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 8 Sep 2024 12:05:09 -0400 Subject: [PATCH 28/50] Extend use flag to all (trap)doors. There's no tag which has wood+copper, but iron are not interactable anyway. Relates to #2130. --- .../main/java/com/sk89q/worldguard/bukkit/util/Materials.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 231a0bbe1..97ddce443 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -1315,8 +1315,8 @@ public static boolean isVine(Material newType) { */ public static boolean isUseFlagApplicable(Material material) { if (Tag.BUTTONS.isTagged(material) - || Tag.WOODEN_DOORS.isTagged(material) - || Tag.WOODEN_TRAPDOORS.isTagged(material) + || Tag.DOORS.isTagged(material) + || Tag.TRAPDOORS.isTagged(material) || Tag.FENCE_GATES.isTagged(material) || Tag.PRESSURE_PLATES.isTagged(material)) { return true; From 70d225ef2f5aa86aa9d8c7f6598114711d8af652 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 8 Sep 2024 12:37:51 -0400 Subject: [PATCH 29/50] Split chest boat ride/open. --- .../bukkit/listener/RegionProtectionListener.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index f5942d753..e42b68c95 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -61,6 +61,7 @@ import org.bukkit.event.Event; import org.bukkit.event.Event.Result; import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerTakeLecternBookEvent; import org.bukkit.event.vehicle.VehicleExitEvent; @@ -410,13 +411,15 @@ public void onUseEntity(UseEntityEvent event) { canUse = event.getRelevantFlags().isEmpty() || query.queryState(BukkitAdapter.adapt(target), associable, combine(event)) != State.DENY; what = "use that"; /* Paintings, item frames, etc. */ - } else if (Entities.isConsideredBuildingIfUsed(entity)) { + } else if (Entities.isConsideredBuildingIfUsed(entity) + // weird case since sneak+interact is chest access and not ride + || type == EntityType.CHEST_BOAT && event.getOriginalEvent() instanceof InventoryOpenEvent) { if ((type == EntityType.ITEM_FRAME || type == EntityType.GLOW_ITEM_FRAME) && event.getCause().getFirstPlayer() != null && ((ItemFrame) entity).getItem().getType() != Material.AIR) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.ITEM_FRAME_ROTATE)); what = "change that"; - } else if (Entities.isMinecart(type)) { + } else if (Entities.isMinecart(type) || type == EntityType.CHEST_BOAT) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS)); what = "open that"; } else { From 2ea50689b9e6e407f241c1ef074c4d2570fe078a Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 8 Sep 2024 12:42:41 -0400 Subject: [PATCH 30/50] Workaround books no longer sending change block for lecterns. Fixes #2124. --- .../main/java/com/sk89q/worldguard/bukkit/util/Materials.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 97ddce443..ea0e2f047 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -1495,6 +1495,9 @@ public static boolean isToolApplicable(Material toolMaterial, Material targetMat case SUSPICIOUS_GRAVEL, SUSPICIOUS_SAND -> true; default -> false; }; + case WRITTEN_BOOK: + case WRITABLE_BOOK: + return targetMaterial == Material.LECTERN; default: return false; } From b73a0a7179428e72ed757f91b1d94afb845353c4 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 8 Sep 2024 13:40:13 -0400 Subject: [PATCH 31/50] Check mob-damage for potion splashes from e.g. witches. Note that bypass bypasses this if the player with bypass is the target of the potion, but only for the player with bypass. Fixes #2134. --- .../bukkit/listener/EventAbstractionListener.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 14c49c2ad..9aafddb98 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -1015,7 +1015,6 @@ public void onPotionSplash(PotionSplashEvent event) { // Fire item interaction event Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem())); - // Fire entity interaction event if (!event.isCancelled()) { int blocked = 0; @@ -1027,8 +1026,11 @@ public void onPotionSplash(PotionSplashEvent event) { ? new DamageEntityEvent(event, cause, affected) : new UseEntityEvent(event, cause, affected); - // Consider the potion splash flag + // Consider extra relevant flags delegate.getRelevantFlags().add(Flags.POTION_SPLASH); + if (potion.getShooter() instanceof LivingEntity shooter && !(shooter instanceof Player) && affected instanceof Player) { + delegate.getRelevantFlags().add(Flags.MOB_DAMAGE); + } if (Events.fireAndTestCancel(delegate)) { event.setIntensity(affected, 0); From afb619d2ace96513069f5c6b14fca83d1163ca4b Mon Sep 17 00:00:00 2001 From: Joo200 Date: Mon, 22 Jul 2024 21:40:57 +0200 Subject: [PATCH 32/50] Fix breeze damage flags --- .../bukkit/BukkitWorldConfiguration.java | 1 + .../event/block/AbstractBlockEvent.java | 2 +- .../listener/EventAbstractionListener.java | 29 +++++++---- .../listener/WorldGuardEntityListener.java | 52 +++++++------------ .../worldguard/bukkit/util/Entities.java | 22 ++++++++ .../worldguard/bukkit/util/Materials.java | 1 + .../worldguard/config/WorldConfiguration.java | 1 + 7 files changed, 64 insertions(+), 44 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java index ba58b48ed..fe02c2ebb 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java @@ -215,6 +215,7 @@ public void loadConfiguration() { blockEnderDragonPortalCreation = getBoolean("mobs.block-enderdragon-portal-creation", false); blockFireballExplosions = getBoolean("mobs.block-fireball-explosions", false); blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false); + blockWindChargeExplosions = getBoolean("mobs.block-windcharge-explosions", false); antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false); allowTamedSpawns = getBoolean("mobs.allow-tamed-spawns", true); disableEndermanGriefing = getBoolean("mobs.disable-enderman-griefing", false); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java index 8e1192523..02fac016e 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java @@ -45,7 +45,7 @@ * This event is an internal event. We do not recommend handling or throwing * this event or its subclasses as the interface is highly subject to change. */ -abstract class AbstractBlockEvent extends DelegateEvent implements BulkEvent { +public abstract class AbstractBlockEvent extends DelegateEvent implements BulkEvent { private final World world; private List blocks; diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 9aafddb98..1a523158b 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -25,6 +25,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.cause.Cause; import com.sk89q.worldguard.bukkit.event.DelegateEvent; +import com.sk89q.worldguard.bukkit.event.block.AbstractBlockEvent; import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent; import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent; import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent; @@ -46,10 +47,12 @@ import com.sk89q.worldguard.bukkit.util.Materials; import com.sk89q.worldguard.config.WorldConfiguration; import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.flags.StateFlag; import io.papermc.lib.PaperLib; import io.papermc.paper.event.player.PlayerOpenSignEvent; import org.bukkit.Bukkit; import org.bukkit.Effect; +import org.bukkit.ExplosionResult; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -65,7 +68,6 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.type.Dispenser; -import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; @@ -358,14 +360,21 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { @EventHandler(ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); - if (entity instanceof AbstractWindCharge) { - UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR); - useEvent.getRelevantFlags().add(Flags.WIND_CHARGE_BURST); - useEvent.setSilent(true); - Events.fireBulkEventToCancel(event, useEvent); + AbstractBlockEvent wgEvent; + + if (event.getExplosionResult() == ExplosionResult.TRIGGER_BLOCK) { + wgEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR); + } else if (event.getExplosionResult() == ExplosionResult.DESTROY || event.getExplosionResult() == ExplosionResult.DESTROY_WITH_DECAY) { + wgEvent = new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR); + } else { return; } - Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); + + wgEvent.getRelevantFlags().add(Entities.getExplosionFlag(event.getEntity())); + + wgEvent.setSilent(true); + Events.fireBulkEventToCancel(event, wgEvent); + if (entity instanceof Creeper) { Cause.untrackParentCause(entity); } @@ -584,7 +593,7 @@ public void onEntityInteract(EntityInteractEvent event) { @EventHandler(ignoreCancelled = true) public void onBlockFertilize(BlockFertilizeEvent event) { - if (event.getBlocks().isEmpty()) return; + if (event.getBlocks().isEmpty()) return; Cause cause = create(event.getPlayer(), event.getBlock()); Events.fireToCancel(event, new PlaceBlockEvent(event, cause, event.getBlock().getWorld(), event.getBlocks())); } @@ -750,7 +759,7 @@ public void onHangingBreak(HangingBreakEvent event) { if (event.isCancelled() && remover instanceof Player) { playDenyEffect((Player) remover, event.getEntity().getLocation()); } - } else if (event.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION){ + } else if (event.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION) { DestroyEntityEvent destroyEntityEvent = new DestroyEntityEvent(event, Cause.unknown(), event.getEntity()); destroyEntityEvent.getRelevantFlags().add(Flags.OTHER_EXPLOSION); if (event.getEntity() instanceof ItemFrame) { @@ -1112,7 +1121,7 @@ public void onLingeringApply(AreaEffectCloudApplyEvent event) { } @EventHandler(ignoreCancelled = true) - public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event){ + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { onPlayerInteractEntity(event); } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 7ea3bf477..111cffdd5 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -44,6 +44,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Creeper; import org.bukkit.entity.EnderCrystal; @@ -311,13 +312,17 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) { return; } } - if (event.getDamager() instanceof Fireball) { - Fireball fireball = (Fireball) event.getDamager(); + if (event.getDamager() instanceof Fireball fireball) { if (fireball instanceof WitherSkull) { if (wcfg.blockWitherSkullExplosions) { event.setCancelled(true); return; } + } else if (fireball instanceof AbstractWindCharge) { + if (wcfg.blockWindChargeExplosions) { + event.setCancelled(true); + return; + } } else { if (wcfg.blockFireballExplosions) { event.setCancelled(true); @@ -325,8 +330,9 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) { } } if (wcfg.useRegions) { + WorldGuardPlugin.inst().getLogger().info("Getting damager type " + event.getDamager().getType()); RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); - if (!query.testState(localPlayer.getLocation(), localPlayer, Flags.GHAST_FIREBALL) && wcfg.explosionFlagCancellation) { + if (!query.testState(localPlayer.getLocation(), localPlayer, Entities.getExplosionFlag(event.getDamager())) && wcfg.explosionFlagCancellation) { event.setCancelled(true); return; } @@ -483,6 +489,11 @@ public void onEntityExplode(EntityExplodeEvent event) { event.blockList().clear(); return; } + } else if (ent instanceof AbstractWindCharge) { + if (wcfg.blockWindChargeExplosions) { + event.setCancelled(true); + return; + } } else { if (wcfg.blockFireballExplosions) { event.setCancelled(true); @@ -493,16 +504,6 @@ public void onEntityExplode(EntityExplodeEvent event) { return; } } - // allow wither skull blocking since there is no dedicated flag atm - if (wcfg.useRegions) { - for (Block block : event.blockList()) { - if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.GHAST_FIREBALL)) { - event.blockList().clear(); - if (wcfg.explosionFlagCancellation) event.setCancelled(true); - return; - } - } - } } else if (ent instanceof Wither) { if (wcfg.blockWitherExplosions) { event.setCancelled(true); @@ -512,34 +513,14 @@ public void onEntityExplode(EntityExplodeEvent event) { event.blockList().clear(); return; } - if (wcfg.useRegions) { - for (Block block : event.blockList()) { - if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(block.getLocation()), - (RegionAssociable) null, Flags.WITHER_DAMAGE))) { - event.blockList().clear(); - event.setCancelled(true); - return; - } - } - } } else { // unhandled entity if (wcfg.blockOtherExplosions) { event.setCancelled(true); return; } - if (wcfg.useRegions) { - for (Block block : event.blockList()) { - if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.OTHER_EXPLOSION)) { - event.blockList().clear(); - if (wcfg.explosionFlagCancellation) event.setCancelled(true); - return; - } - } - } } - if (wcfg.signChestProtection) { for (Block block : event.blockList()) { if (wcfg.isChestProtected(BukkitAdapter.adapt(block.getLocation()))) { @@ -592,6 +573,11 @@ public void onExplosionPrime(ExplosionPrimeEvent event) { event.setCancelled(true); return; } + } else if (event instanceof AbstractWindCharge) { + if (wcfg.blockWindChargeExplosions) { + event.setCancelled(true); + return; + } } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java index 8a89e7a77..205d0b649 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java @@ -19,6 +19,9 @@ package com.sk89q.worldguard.bukkit.util; +import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.flags.StateFlag; +import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.Allay; import org.bukkit.entity.Ambient; import org.bukkit.entity.ArmorStand; @@ -28,6 +31,8 @@ import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Fireball; +import org.bukkit.entity.Firework; import org.bukkit.entity.Flying; import org.bukkit.entity.Hanging; import org.bukkit.entity.LivingEntity; @@ -43,11 +48,13 @@ import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; import org.bukkit.entity.Vehicle; +import org.bukkit.entity.Wither; import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.inventory.InventoryHolder; import org.bukkit.projectiles.ProjectileSource; +import javax.annotation.Nonnull; import javax.annotation.Nullable; public final class Entities { @@ -245,4 +252,19 @@ public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReaso default -> false; }; } + + /** + * Get the explosion flag relevant for an entity type. + * @param entity the entity + * @return the relevant StateFlag or OTHER_EXPLOSION if none is matching + */ + public static @Nonnull StateFlag getExplosionFlag(Entity entity) { + return switch (entity) { + case AbstractWindCharge abstractWindCharge -> Flags.WIND_CHARGE_BURST; + case Firework firework -> Flags.FIREWORK_DAMAGE; + case Fireball fireball -> Flags.GHAST_FIREBALL; + case Wither wither -> Flags.WITHER_DAMAGE; + case null, default -> Flags.OTHER_EXPLOSION; + }; + } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index ea0e2f047..28032158b 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -22,6 +22,7 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.sk89q.worldguard.protection.flags.Flags; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.entity.EntityType; diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java b/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java index df3d5fc18..0f0c24604 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java @@ -101,6 +101,7 @@ public abstract class WorldConfiguration { public boolean blockEnderDragonPortalCreation; public boolean blockFireballExplosions; public boolean blockFireballBlockDamage; + public boolean blockWindChargeExplosions; public boolean blockOtherExplosions; public boolean blockEntityPaintingDestroy; public boolean blockEntityItemFrameDestroy; From 9dd7d7c03ef7a66128f22639e37a83f7569a5f49 Mon Sep 17 00:00:00 2001 From: Joo200 Date: Sat, 27 Jul 2024 16:58:19 +0200 Subject: [PATCH 33/50] Fix wind-charge-burst flag for player knockback --- .../bukkit/listener/EventAbstractionListener.java | 13 +++++++++++++ .../bukkit/listener/WorldGuardEntityListener.java | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 1a523158b..58e971da4 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -68,6 +68,7 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.type.Dispenser; +import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; @@ -117,6 +118,7 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.entity.EntityKnockbackByEntityEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntityTameEvent; import org.bukkit.event.entity.EntityUnleashEvent; @@ -357,6 +359,17 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { } + @EventHandler(ignoreCancelled = true) + public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) { + Entity damager = event.getSourceEntity(); + + final DamageEntityEvent eventToFire = new DamageEntityEvent(event, create(damager), event.getEntity()); + if (damager instanceof AbstractWindCharge) { + eventToFire.getRelevantFlags().add(Flags.WIND_CHARGE_BURST); + } + Events.fireToCancel(event, eventToFire); + } + @EventHandler(ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 111cffdd5..8ae09c3c5 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -330,7 +330,6 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) { } } if (wcfg.useRegions) { - WorldGuardPlugin.inst().getLogger().info("Getting damager type " + event.getDamager().getType()); RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); if (!query.testState(localPlayer.getLocation(), localPlayer, Entities.getExplosionFlag(event.getDamager())) && wcfg.explosionFlagCancellation) { event.setCancelled(true); From 679b56948f41869bd545564a8c57562f157a6b66 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 8 Sep 2024 16:46:50 -0400 Subject: [PATCH 34/50] Split wind charge into breeze/player flags. Player flag is build-checked (default false) and breeze flag is not (default true). Having multiple flags is ugly but if we need every bit of behavior to be manipulable this is the only way. --- .../bukkit/listener/EventAbstractionListener.java | 14 ++++++++------ .../com/sk89q/worldguard/bukkit/util/Entities.java | 6 ++++-- .../sk89q/worldguard/bukkit/util/Materials.java | 1 - .../sk89q/worldguard/protection/flags/Flags.java | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 58e971da4..987e84238 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -47,7 +47,6 @@ import com.sk89q.worldguard.bukkit.util.Materials; import com.sk89q.worldguard.config.WorldConfiguration; import com.sk89q.worldguard.protection.flags.Flags; -import com.sk89q.worldguard.protection.flags.StateFlag; import io.papermc.lib.PaperLib; import io.papermc.paper.event.player.PlayerOpenSignEvent; import org.bukkit.Bukkit; @@ -68,8 +67,8 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.type.Dispenser; -import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.AreaEffectCloud; +import org.bukkit.entity.BreezeWindCharge; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -83,6 +82,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import org.bukkit.entity.ThrownPotion; +import org.bukkit.entity.WindCharge; import org.bukkit.entity.minecart.HopperMinecart; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -328,10 +328,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { // Fire two events: one as BREAK and one as PLACE if (toType != Material.AIR && fromType != Material.AIR) { - BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, block); - setDelegateEventMaterialOptions(breakDelagate, fromType, toType); + BreakBlockEvent breakDelegate = new BreakBlockEvent(event, cause, block); + setDelegateEventMaterialOptions(breakDelegate, fromType, toType); boolean denied; - if (!(denied = Events.fireToCancel(event, breakDelagate))) { + if (!(denied = Events.fireToCancel(event, breakDelegate))) { PlaceBlockEvent placeDelegate = new PlaceBlockEvent(event, cause, block.getLocation(), toType); setDelegateEventMaterialOptions(placeDelegate, fromType, toType); denied = Events.fireToCancel(event, placeDelegate); @@ -364,7 +364,9 @@ public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) { Entity damager = event.getSourceEntity(); final DamageEntityEvent eventToFire = new DamageEntityEvent(event, create(damager), event.getEntity()); - if (damager instanceof AbstractWindCharge) { + if (damager instanceof BreezeWindCharge) { + eventToFire.getRelevantFlags().add(Flags.BREEZE_WIND_CHARGE); + } else if (damager instanceof WindCharge) { eventToFire.getRelevantFlags().add(Flags.WIND_CHARGE_BURST); } Events.fireToCancel(event, eventToFire); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java index 205d0b649..c66cefe5d 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java @@ -21,11 +21,11 @@ import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.flags.StateFlag; -import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.Allay; import org.bukkit.entity.Ambient; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Arrow; +import org.bukkit.entity.BreezeWindCharge; import org.bukkit.entity.Creature; import org.bukkit.entity.EnderCrystal; import org.bukkit.entity.EnderDragon; @@ -48,6 +48,7 @@ import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; import org.bukkit.entity.Vehicle; +import org.bukkit.entity.WindCharge; import org.bukkit.entity.Wither; import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -260,7 +261,8 @@ public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReaso */ public static @Nonnull StateFlag getExplosionFlag(Entity entity) { return switch (entity) { - case AbstractWindCharge abstractWindCharge -> Flags.WIND_CHARGE_BURST; + case BreezeWindCharge breezeWindCharge -> Flags.BREEZE_WIND_CHARGE; + case WindCharge windCharge -> Flags.WIND_CHARGE_BURST; case Firework firework -> Flags.FIREWORK_DAMAGE; case Fireball fireball -> Flags.GHAST_FIREBALL; case Wither wither -> Flags.WITHER_DAMAGE; diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 28032158b..ea0e2f047 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -22,7 +22,6 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.sk89q.worldguard.protection.flags.Flags; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.entity.EntityType; diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java index 5702cfe15..6b7c20630 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java @@ -74,6 +74,7 @@ public final class Flags { public static final StateFlag FIREWORK_DAMAGE = register(new StateFlag("firework-damage", false)); public static final StateFlag USE_ANVIL = register(new StateFlag("use-anvil", false)); public static final StateFlag USE_DRIPLEAF = register(new StateFlag("use-dripleaf", false)); + public static final StateFlag WIND_CHARGE_BURST = register(new StateFlag("wind-charge-burst", false)); // These flags are similar to the ones above (used in tandem with BUILD), // but their defaults are set to TRUE because it is more user friendly. @@ -93,7 +94,7 @@ public final class Flags { public static final StateFlag ENDERDRAGON_BLOCK_DAMAGE = register(new StateFlag("enderdragon-block-damage", true)); public static final StateFlag GHAST_FIREBALL = register(new StateFlag("ghast-fireball", true)); public static final StateFlag OTHER_EXPLOSION = register(new StateFlag("other-explosion", true)); - public static final StateFlag WIND_CHARGE_BURST = register(new StateFlag("wind-charge-burst", true)); + public static final StateFlag BREEZE_WIND_CHARGE = register(new StateFlag("breeze-charge-explosion", true)); public static final StateFlag WITHER_DAMAGE = register(new StateFlag("wither-damage", true)); public static final StateFlag ENDER_BUILD = register(new StateFlag("enderman-grief", true)); public static final StateFlag SNOWMAN_TRAILS = register(new StateFlag("snowman-trails", true)); From cb011a88cfbb8e836621fec5661e73be7f1120fc Mon Sep 17 00:00:00 2001 From: ploppyperson Date: Mon, 9 Sep 2024 20:43:58 +0100 Subject: [PATCH 35/50] Add moisture-change flag (#1879) (#2096) * Create and implement moisture-change flag * Fix imports * Add comment * Actually read the value from config. Closes #1879 --------- Co-authored-by: wizjany --- .../bukkit/BukkitWorldConfiguration.java | 1 + .../listener/WorldGuardBlockListener.java | 21 +++++++++++++++++++ .../worldguard/config/WorldConfiguration.java | 1 + .../worldguard/protection/flags/Flags.java | 1 + 4 files changed, 24 insertions(+) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java index fe02c2ebb..08ffd0b61 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java @@ -283,6 +283,7 @@ public void loadConfiguration() { disableSculkGrowth = getBoolean("dynamics.disable-sculk-growth", false); disableCropGrowth = getBoolean("dynamics.disable-crop-growth", false); disableSoilDehydration = getBoolean("dynamics.disable-soil-dehydration", false); + disableSoilMoistureChange = getBoolean("dynamics.disable-soil-moisture-change", false); disableCoralBlockFade = getBoolean("dynamics.disable-coral-block-fade", false); disableCopperBlockFade = getBoolean("dynamics.disable-copper-block-fade", false); allowedSnowFallOver = new HashSet<>(convertLegacyBlocks(getStringList("dynamics.snow-fall-blocks", null))); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardBlockListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardBlockListener.java index ad8e11c6e..a9dd5866f 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardBlockListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardBlockListener.java @@ -56,6 +56,7 @@ import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.block.MoistureChangeEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; @@ -726,4 +727,24 @@ public void onBlockExplode(BlockExplodeEvent event) { } } + /** + * Called when the moisture level of a block changes + */ + @EventHandler(ignoreCancelled = true) + public void onMoistureChange(MoistureChangeEvent event) { + WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld()); + + if (wcfg.disableSoilMoistureChange) { + event.setCancelled(true); + return; + } + + if (wcfg.useRegions) { + if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery() + .queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.MOISTURE_CHANGE))) { + event.setCancelled(true); + } + } + } + } diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java b/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java index 0f0c24604..c98f23c6e 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java @@ -167,6 +167,7 @@ public abstract class WorldConfiguration { public boolean disableEndermanGriefing; public boolean disableSnowmanTrails; public boolean disableSoilDehydration; + public boolean disableSoilMoistureChange; public boolean disableCoralBlockFade; public boolean disableCopperBlockFade; public Set allowedSnowFallOver; diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java index 6b7c20630..3aacacd97 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java @@ -130,6 +130,7 @@ public final class Flags { public static final StateFlag COPPER_FADE = register(new StateFlag("copper-fade", true)); public static final StateFlag WATER_FLOW = register(new StateFlag("water-flow", true)); public static final StateFlag LAVA_FLOW = register(new StateFlag("lava-flow", true)); + public static final StateFlag MOISTURE_CHANGE = register(new StateFlag("moisture-change", true)); public static final RegistryFlag WEATHER_LOCK = register(new RegistryFlag<>("weather-lock", WeatherType.REGISTRY)); public static final StringFlag TIME_LOCK = register(new StringFlag("time-lock")); From 068ad680fc0d7058ec4d65c86345bbecf2af244a Mon Sep 17 00:00:00 2001 From: wizjany Date: Mon, 9 Sep 2024 16:24:43 -0400 Subject: [PATCH 36/50] Release 7.0.11. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 11b233380..ff846277d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ group=com.sk89q.worldguard -version=7.0.11-SNAPSHOT +version=7.0.11 org.gradle.parallel=true From fb88d56646fa631e264c191876c45d0c2d4b70f7 Mon Sep 17 00:00:00 2001 From: wizjany Date: Mon, 9 Sep 2024 16:56:05 -0400 Subject: [PATCH 37/50] Bump to SNAPSHOT for dev. Also update the changelog. --- CHANGELOG.md | 12 ++++++++++++ gradle.properties | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daf51917b..b6a89fa42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 7.0.11 + +* Add support for MC 1.21. +* Add wind-charge-burst flag which is checked along with `use` (for the interaction) or `pvp` (for the knockback). +* Add breeze-charge-explosion flag for breeze charges (i.e. from the mob, not player wind charges). +* Add moisture-change flag and config options. +* Fix an error if a player logged in to an unloaded world. +* Fix chest boat usage always being counted as ride. +* Consider potions thrown by mobs as mob-damage. +* Workaround spigot no longer sending block change events when a book is placed on a lectern. +* Improve accuracy of target blocks in blacklist/build-perms events. + ## 7.0.10 * Add support for MC 1.20.5 and 1.20.6, drop support for other 1.20 versions diff --git a/gradle.properties b/gradle.properties index ff846277d..fc4dff5b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ group=com.sk89q.worldguard -version=7.0.11 +version=7.0.12-SNAPSHOT org.gradle.parallel=true From 03aac83f4c2bc58b775f29af3e8a618d5434ded2 Mon Sep 17 00:00:00 2001 From: wizjany Date: Thu, 12 Sep 2024 20:55:03 -0400 Subject: [PATCH 38/50] Match explosion flag coverage with EntityListener. --- .../main/java/com/sk89q/worldguard/bukkit/util/Entities.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java index c66cefe5d..47ca48241 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java @@ -27,6 +27,7 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.BreezeWindCharge; import org.bukkit.entity.Creature; +import org.bukkit.entity.Creeper; import org.bukkit.entity.EnderCrystal; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; @@ -266,6 +267,10 @@ public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReaso case Firework firework -> Flags.FIREWORK_DAMAGE; case Fireball fireball -> Flags.GHAST_FIREBALL; case Wither wither -> Flags.WITHER_DAMAGE; + case Creeper creeper -> Flags.CREEPER_EXPLOSION; + case TNTPrimed tnt -> Flags.TNT; + case ExplosiveMinecart minecart -> Flags.TNT; + case EnderDragon dragon -> Flags.ENDERDRAGON_BLOCK_DAMAGE; case null, default -> Flags.OTHER_EXPLOSION; }; } From 830472d36e87c201124bd4b81b75842b066ce455 Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 13 Sep 2024 11:46:06 -0400 Subject: [PATCH 39/50] Revert previous changes to explosion event handling. Event abstraction sucks and everything needs rewriting. --- .../event/block/AbstractBlockEvent.java | 2 +- .../listener/EventAbstractionListener.java | 43 +++++++++++-------- .../listener/WorldGuardEntityListener.java | 31 +++++++++++++ .../worldguard/bukkit/util/Entities.java | 2 +- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java index 02fac016e..8e1192523 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java @@ -45,7 +45,7 @@ * This event is an internal event. We do not recommend handling or throwing * this event or its subclasses as the interface is highly subject to change. */ -public abstract class AbstractBlockEvent extends DelegateEvent implements BulkEvent { +abstract class AbstractBlockEvent extends DelegateEvent implements BulkEvent { private final World world; private List blocks; diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 987e84238..80a99955c 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -25,7 +25,6 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.cause.Cause; import com.sk89q.worldguard.bukkit.event.DelegateEvent; -import com.sk89q.worldguard.bukkit.event.block.AbstractBlockEvent; import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent; import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent; import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent; @@ -116,6 +115,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityKnockbackByEntityEvent; @@ -181,9 +181,11 @@ public EventAbstractionListener(WorldGuardPlugin plugin) { public void registerEvents() { super.registerEvents(); + PluginManager pm = getPlugin().getServer().getPluginManager(); if (PaperLib.isPaper()) { - PluginManager pm = getPlugin().getServer().getPluginManager(); pm.registerEvents(new EventAbstractionListener.PaperListener(), getPlugin()); + } else { + pm.registerEvents(new EventAbstractionListener.SpigotListener(), getPlugin()); } } @@ -359,10 +361,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { } - @EventHandler(ignoreCancelled = true) - public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) { - Entity damager = event.getSourceEntity(); - + private static void handleKnockback(T event, Entity damager) { final DamageEntityEvent eventToFire = new DamageEntityEvent(event, create(damager), event.getEntity()); if (damager instanceof BreezeWindCharge) { eventToFire.getRelevantFlags().add(Flags.BREEZE_WIND_CHARGE); @@ -372,24 +371,19 @@ public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) { Events.fireToCancel(event, eventToFire); } + @SuppressWarnings("UnstableApiUsage") @EventHandler(ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); - AbstractBlockEvent wgEvent; - if (event.getExplosionResult() == ExplosionResult.TRIGGER_BLOCK) { - wgEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR); + UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR); + useEvent.getRelevantFlags().add(Entities.getExplosionFlag(entity)); + useEvent.setSilent(true); + Events.fireBulkEventToCancel(event, useEvent); } else if (event.getExplosionResult() == ExplosionResult.DESTROY || event.getExplosionResult() == ExplosionResult.DESTROY_WITH_DECAY) { - wgEvent = new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR); - } else { - return; + Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); } - wgEvent.getRelevantFlags().add(Entities.getExplosionFlag(event.getEntity())); - - wgEvent.setSilent(true); - Events.fireBulkEventToCancel(event, wgEvent); - if (entity instanceof Creeper) { Cause.untrackParentCause(entity); } @@ -1295,7 +1289,7 @@ private static void playDenyEffect(Location location) { } } - private class PaperListener implements Listener { + private static class PaperListener implements Listener { @EventHandler(ignoreCancelled = true) public void onEntityTransform(EntityZapEvent event) { Events.fireToCancel(event, new DamageEntityEvent(event, create(event.getBolt()), event.getEntity())); @@ -1308,5 +1302,18 @@ public void onSignOpen(PlayerOpenSignEvent event) { Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), event.getSign().getBlock())); } } + + @EventHandler(ignoreCancelled = true) + public void onEntityKnockbackByEntity(com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent event) { + handleKnockback(event, event.getHitBy()); + } + } + + @SuppressWarnings("removal") + private static class SpigotListener implements Listener { + @EventHandler(ignoreCancelled = true) + public void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) { + handleKnockback(event, event.getSourceEntity()); + } } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 8ae09c3c5..559db3f99 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -61,6 +61,7 @@ import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; +import org.bukkit.entity.WindCharge; import org.bukkit.entity.Wither; import org.bukkit.entity.WitherSkull; import org.bukkit.entity.Wolf; @@ -503,6 +504,16 @@ public void onEntityExplode(EntityExplodeEvent event) { return; } } + if (wcfg.useRegions && !(ent instanceof WindCharge)) { + for (Block block : event.blockList()) { + if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery() + .testState(BukkitAdapter.adapt(block.getLocation()), null, Entities.getExplosionFlag(ent))) { + event.blockList().clear(); + if (wcfg.explosionFlagCancellation) event.setCancelled(true); + return; + } + } + } } else if (ent instanceof Wither) { if (wcfg.blockWitherExplosions) { event.setCancelled(true); @@ -512,12 +523,32 @@ public void onEntityExplode(EntityExplodeEvent event) { event.blockList().clear(); return; } + if (wcfg.useRegions) { + for (Block block : event.blockList()) { + if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery() + .testState(BukkitAdapter.adapt(block.getLocation()), null, Flags.WITHER_DAMAGE)) { + event.blockList().clear(); + event.setCancelled(true); + return; + } + } + } } else { // unhandled entity if (wcfg.blockOtherExplosions) { event.setCancelled(true); return; } + if (wcfg.useRegions) { + for (Block block : event.blockList()) { + if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery() + .testState(BukkitAdapter.adapt(block.getLocation()), null, Flags.OTHER_EXPLOSION)) { + event.blockList().clear(); + if (wcfg.explosionFlagCancellation) event.setCancelled(true); + return; + } + } + } } if (wcfg.signChestProtection) { diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java index 47ca48241..2031e424b 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java @@ -246,7 +246,7 @@ public static boolean isAoECloud(EntityType type) { * This is true for custom creations or the summon command. * * @param spawnReason the reason - * @return true if considerd plugin spawning + * @return true if considered plugin spawning */ public static boolean isPluginSpawning(CreatureSpawnEvent.SpawnReason spawnReason) { return switch (spawnReason) { From 829a4a42df95fb7427b374ca177e6aa91822337a Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 13 Sep 2024 11:58:22 -0400 Subject: [PATCH 40/50] Release 7.0.12. --- CHANGELOG.md | 4 ++++ gradle.properties | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6a89fa42..8c37fc8ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.0.12 + +* Fix a change in the default behavior of explosion flag handling. + ## 7.0.11 * Add support for MC 1.21. diff --git a/gradle.properties b/gradle.properties index fc4dff5b3..343a6f4cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ group=com.sk89q.worldguard -version=7.0.12-SNAPSHOT +version=7.0.12 org.gradle.parallel=true From 02dc89b2243afcb06187e03c0c5acef4bf0e7821 Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 13 Sep 2024 11:58:55 -0400 Subject: [PATCH 41/50] Bump to snapshot. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 343a6f4cc..30f75f29d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ group=com.sk89q.worldguard -version=7.0.12 +version=7.0.13-SNAPSHOT org.gradle.parallel=true From a0e397e57f6426913a031ba043266528b801f9a5 Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 13 Sep 2024 14:15:32 -0400 Subject: [PATCH 42/50] Use more snapshot-less holders on Paper. This is already past the debounce so in theory it's not getting hit *often*, but I guess if it's really slow it'll still show up. --- .../bukkit/listener/EventAbstractionListener.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 80a99955c..8f7ec03e7 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -1241,9 +1241,9 @@ private static void handleInventoryHolderUse(T o useBlockEvent.setAllowed(true); } Events.fireToCancel(originalEvent, useBlockEvent); - } else if (holder instanceof DoubleChest) { - InventoryHolder left = ((DoubleChest) holder).getLeftSide(); - InventoryHolder right = ((DoubleChest) holder).getRightSide(); + } else if (holder instanceof DoubleChest doubleChest) { + InventoryHolder left = PaperLib.isPaper() ? doubleChest.getLeftSide(false) : doubleChest.getLeftSide(); + InventoryHolder right = PaperLib.isPaper() ? doubleChest.getRightSide(false) : doubleChest.getRightSide(); if (left instanceof Chest) { Events.fireToCancel(originalEvent, new UseBlockEvent(originalEvent, cause, ((Chest) left).getBlock())); } From d9716a5bd8f5009d928a3dd8b89ef9f3b333fea0 Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 13 Sep 2024 14:29:18 -0400 Subject: [PATCH 43/50] Ignore arrow combustion. Closes #2144. --- .../bukkit/listener/EventAbstractionListener.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 8f7ec03e7..f2e771dbd 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -67,6 +67,7 @@ import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.type.Dispenser; import org.bukkit.entity.AreaEffectCloud; +import org.bukkit.entity.Arrow; import org.bukkit.entity.BreezeWindCharge; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; @@ -913,11 +914,19 @@ public void onEntityDamage(EntityDamageEvent event) { @EventHandler(ignoreCancelled = true) public void onEntityCombust(EntityCombustEvent event) { - if (event instanceof EntityCombustByBlockEvent) { + if (event instanceof EntityCombustByBlockEvent combustByBlockEvent) { // at the time of writing, spigot is throwing null for the event's combuster. this causes lots of issues downstream. // whenever (i mean if ever) it is fixed, use getCombuster again instead of the current block - Events.fireToCancel(event, new DamageEntityEvent(event, create(event.getEntity().getLocation().getBlock()), event.getEntity())); + Block combuster = combustByBlockEvent.getCombuster(); + Events.fireToCancel(event, new DamageEntityEvent(event, + create(combuster == null ? event.getEntity().getLocation().getBlock() : combuster), event.getEntity())); } else if (event instanceof EntityCombustByEntityEvent) { + if (event.getEntity() instanceof Arrow) { + // this only happens from the Flame enchant. igniting arrows in other ways (eg with lava) doesn't even + // throw the combust event, not even the CombustByBlock event... they're also very buggy and don't even + // show as lit on the client consistently + return; + } Events.fireToCancel(event, new DamageEntityEvent(event, create(((EntityCombustByEntityEvent) event).getCombuster()), event.getEntity())); } } From 3b9ab47a97779b8c4b900084f54933f1b8556861 Mon Sep 17 00:00:00 2001 From: Joo200 Date: Thu, 17 Oct 2024 01:43:27 +0200 Subject: [PATCH 44/50] Avoid using metadata storage if possible (#2150) * Avoid using metadata storage if possible * Fix cause detection, use always on paper * Fix fat fingers Co-authored-by: aurora <21148213+aurorasmiles@users.noreply.github.com> --- .../com/sk89q/worldguard/bukkit/cause/Cause.java | 12 ++++++++++-- .../bukkit/listener/EventAbstractionListener.java | 12 +++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java index f3847b33a..84f0c3f60 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java @@ -32,8 +32,10 @@ import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Creature; +import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Firework; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; @@ -326,15 +328,21 @@ private void addAll(@Nullable Object... element) { addAll(player.getPlayer()); // player object if online, else null } } - } else if (o instanceof Creature && ((Creature) o).getTarget() != null) { + } else if (o instanceof Creeper c) { indirect = true; - addAll(((Creature) o).getTarget()); + addAll(c.getTarget(), c.getIgniter()); + } else if (o instanceof Creature c) { + indirect = true; + addAll(c.getTarget()); } else if (o instanceof BlockProjectileSource) { addAll(((BlockProjectileSource) o).getBlock()); } else if (o instanceof LightningStrike && PaperLib.isPaper() && ((LightningStrike) o).getCausingEntity() != null) { indirect = true; addAll(((LightningStrike) o).getCausingEntity()); + } else if (o instanceof FallingBlock f && PaperLib.isPaper() && f.getOrigin() != null) { + indirect = true; + addAll(f.getOrigin().getBlock()); } // Add manually tracked parent causes diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index f2e771dbd..334127cc0 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -347,7 +347,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { } else if (toType == Material.AIR) { // Track the source so later we can create a proper chain of causes if (entity instanceof FallingBlock) { - Cause.trackParentCause(entity, block); + if (!PaperLib.isPaper()) { + // On paper we use FallingBlock#getOrigin to get the origin location, on spigot we store it. + Cause.trackParentCause(entity, block); + } // Switch around the event Events.fireToCancel(event, new SpawnEntityEvent(event, create(block), entity)); @@ -864,12 +867,7 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (matchingItem != null && hasInteractBypass(world, matchingItem)) { useEntityEvent.setAllowed(true); } - if (!Events.fireToCancel(event, useEntityEvent)) { - // so this is a hack but CreeperIgniteEvent doesn't actually tell us who, so we need to do it here - if (item.getType() == Material.FLINT_AND_STEEL && entity.getType() == EntityType.CREEPER) { - Cause.trackParentCause(entity, player); - } - } + Events.fireToCancel(event, useEntityEvent); } @EventHandler(ignoreCancelled = true) From 5579d197aba38e544cebbebf8c04c86f8f256549 Mon Sep 17 00:00:00 2001 From: wizjany Date: Mon, 28 Oct 2024 08:24:28 -0400 Subject: [PATCH 45/50] Remove stack size bypassing perm. Entire command should eventually be removed. --- .../sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java index 37e7f07ac..53d11f13a 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java @@ -172,8 +172,9 @@ public Path getConfigDir() { } @Override + @Deprecated(forRemoval = true) public void stackPlayerInventory(LocalPlayer localPlayer) { - boolean ignoreMax = localPlayer.hasPermission("worldguard.stack.illegitimate"); + boolean ignoreMax = false; // localPlayer.hasPermission("worldguard.stack.illegitimate"); Player player = ((BukkitPlayer) localPlayer).getPlayer(); @@ -191,7 +192,7 @@ public void stackPlayerInventory(LocalPlayer localPlayer) { continue; } - int max = ignoreMax ? 64 : item.getMaxStackSize(); + int max = /*ignoreMax ? 64 :*/ item.getMaxStackSize(); if (item.getAmount() < max) { int needed = max - item.getAmount(); // Number of needed items until max From 764d258ed02516fee655bbc7f4b00a2d986bd24b Mon Sep 17 00:00:00 2001 From: wizjany Date: Mon, 28 Oct 2024 08:49:59 -0400 Subject: [PATCH 46/50] Fix deprecations on stack methods. Also this was supposed to be on a branch but I just realized I forgot. --- .../com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java | 2 +- .../java/com/sk89q/worldguard/commands/GeneralCommands.java | 1 + .../sk89q/worldguard/internal/platform/WorldGuardPlatform.java | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java index 53d11f13a..f1e70e051 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java @@ -171,8 +171,8 @@ public Path getConfigDir() { return WorldGuardPlugin.inst().getDataFolder().toPath(); } + @SuppressWarnings("removal") @Override - @Deprecated(forRemoval = true) public void stackPlayerInventory(LocalPlayer localPlayer) { boolean ignoreMax = false; // localPlayer.hasPermission("worldguard.stack.illegitimate"); diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java b/worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java index 1111355a9..61aa037c0 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java @@ -229,6 +229,7 @@ public void locate(CommandContext args, Actor sender) throws CommandException { } } + @SuppressWarnings("removal") @Command(aliases = {"stack", ";"}, usage = "", desc = "Stack items", max = 0) @CommandPermissions({"worldguard.stack"}) public void stack(CommandContext args, Actor sender) throws CommandException { diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/internal/platform/WorldGuardPlatform.java b/worldguard-core/src/main/java/com/sk89q/worldguard/internal/platform/WorldGuardPlatform.java index 71e26a4d6..0bbaaa94d 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/internal/platform/WorldGuardPlatform.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/internal/platform/WorldGuardPlatform.java @@ -145,6 +145,7 @@ public interface WorldGuardPlatform { * * @param localPlayer The player */ + @Deprecated(forRemoval = true) void stackPlayerInventory(LocalPlayer localPlayer); /** From 1a59d1eb297d10de2f446a5eea041a869c393c6d Mon Sep 17 00:00:00 2001 From: wizjany Date: Sat, 9 Nov 2024 13:29:04 -0500 Subject: [PATCH 47/50] Update to 1.21.3. (#2153) * Initial update to 1.21.3. Compiles, launches, nothing tested yet. * Boat tag includes chest boat tag. * Avoid Material.values call. * Split ride checks to separate event handler. Bypass the interact entirely and let EntityMount handle it, since we can't discriminate usage in interact. --- gradle/libs.versions.toml | 4 +-- .../listener/EventAbstractionListener.java | 2 +- .../listener/RegionProtectionListener.java | 31 ++++++++++++++++--- .../worldguard/bukkit/util/Entities.java | 7 +++-- .../worldguard/bukkit/util/Materials.java | 17 +++++++--- 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ccd972853..a874fa203 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,8 +27,8 @@ junit-jupiter-api.module = "org.junit.jupiter:junit-jupiter-api" junit-jupiter-params.module = "org.junit.jupiter:junit-jupiter-params" junit-jupiter-engine.module = "org.junit.jupiter:junit-jupiter-engine" -spigot = "org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT" -paperApi = "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT" +spigot = "org.spigotmc:spigot-api:1.21.3-R0.1-SNAPSHOT" +paperApi = "io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT" paperLib = "io.papermc:paperlib:1.0.8" dummypermscompat = "com.sk89q:dummypermscompat:1.10" diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 334127cc0..120ac1a32 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -1196,7 +1196,7 @@ private static void handleBlockRightClick(T even // Handle created boats if (item != null && Materials.isBoat(item.getType())) { - Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT)); + Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), Materials.getRelatedEntity(item.getType()))); return; } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index e42b68c95..698bea903 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -61,6 +61,7 @@ import org.bukkit.event.Event; import org.bukkit.event.Event.Result; import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityMountEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerTakeLecternBookEvent; import org.bukkit.event.vehicle.VehicleExitEvent; @@ -413,13 +414,13 @@ public void onUseEntity(UseEntityEvent event) { /* Paintings, item frames, etc. */ } else if (Entities.isConsideredBuildingIfUsed(entity) // weird case since sneak+interact is chest access and not ride - || type == EntityType.CHEST_BOAT && event.getOriginalEvent() instanceof InventoryOpenEvent) { + || event.getOriginalEvent() instanceof InventoryOpenEvent) { if ((type == EntityType.ITEM_FRAME || type == EntityType.GLOW_ITEM_FRAME) && event.getCause().getFirstPlayer() != null && ((ItemFrame) entity).getItem().getType() != Material.AIR) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.ITEM_FRAME_ROTATE)); what = "change that"; - } else if (Entities.isMinecart(type) || type == EntityType.CHEST_BOAT) { + } else if (event.getOriginalEvent() instanceof InventoryOpenEvent) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS)); what = "open that"; } else { @@ -428,9 +429,10 @@ public void onUseEntity(UseEntityEvent event) { } /* Ridden on use */ } else if (Entities.isRiddenOnUse(entity)) { - canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.RIDE, Flags.INTERACT)); + // this is bypassed here as it's handled by the entity mount listener below + // bukkit actually gives three events in this case - in order: PlayerInteractAtEntity, VehicleEnter, EntityMount + canUse = true; what = "ride that"; - /* Everything else */ } else { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT)); @@ -519,6 +521,27 @@ public void onDamageEntity(DamageEntityEvent event) { } } + @EventHandler + public void onEntityMount(EntityMountEvent event) { + Entity vehicle = event.getMount(); + if (!isRegionSupportEnabled(vehicle.getWorld())) return; // Region support disabled + if (!(event.getEntity() instanceof Player player)) { + return; + } + Cause cause = Cause.create(player); + if (isWhitelisted(cause, vehicle.getWorld(), false)) { + return; + } + RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); + Location location = vehicle.getLocation(); + LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); + if (!query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.RIDE, Flags.INTERACT)) { + event.setCancelled(true); + DelegateEvent dummy = new UseEntityEvent(event, cause, vehicle); + tellErrorMessage(dummy, cause, vehicle.getLocation(), "ride that"); + } + } + @EventHandler(ignoreCancelled = true) public void onVehicleExit(VehicleExitEvent event) { Entity vehicle = event.getVehicle(); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java index 2031e424b..d8292c701 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java @@ -122,8 +122,11 @@ public static boolean isVehicle(EntityType type) { * @return true if the type is a Boat type */ public static boolean isBoat(EntityType type) { - return switch(type) { - case BOAT, CHEST_BOAT -> true; + return switch (type) { + case OAK_BOAT, DARK_OAK_BOAT, SPRUCE_BOAT, ACACIA_BOAT, CHERRY_BOAT, JUNGLE_BOAT, MANGROVE_BOAT, + BIRCH_BOAT, PALE_OAK_BOAT, BAMBOO_RAFT, OAK_CHEST_BOAT, DARK_OAK_CHEST_BOAT, SPRUCE_CHEST_BOAT, + ACACIA_CHEST_BOAT, CHERRY_CHEST_BOAT, JUNGLE_CHEST_BOAT, MANGROVE_CHEST_BOAT, BIRCH_CHEST_BOAT, + PALE_OAK_CHEST_BOAT, BAMBOO_CHEST_RAFT -> true; default -> false; }; } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index ea0e2f047..04d48dc98 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -23,6 +23,7 @@ import com.google.common.collect.HashBiMap; import com.sk89q.worldguard.protection.flags.Flags; import org.bukkit.Material; +import org.bukkit.Registry; import org.bukkit.Tag; import org.bukkit.entity.EntityType; import org.bukkit.potion.PotionEffect; @@ -69,7 +70,6 @@ private static void putMaterialTag(Tag tag, Integer value) { ENTITY_ITEMS.put(EntityType.TNT, Material.TNT); ENTITY_ITEMS.put(EntityType.FIREWORK_ROCKET, Material.FIREWORK_ROCKET); ENTITY_ITEMS.put(EntityType.COMMAND_BLOCK_MINECART, Material.COMMAND_BLOCK_MINECART); - ENTITY_ITEMS.put(EntityType.BOAT, Material.OAK_BOAT); ENTITY_ITEMS.put(EntityType.MINECART, Material.MINECART); ENTITY_ITEMS.put(EntityType.CHEST_MINECART, Material.CHEST_MINECART); ENTITY_ITEMS.put(EntityType.FURNACE_MINECART, Material.FURNACE_MINECART); @@ -80,6 +80,15 @@ private static void putMaterialTag(Tag tag, Integer value) { ENTITY_ITEMS.put(EntityType.ARMOR_STAND, Material.ARMOR_STAND); ENTITY_ITEMS.put(EntityType.END_CRYSTAL, Material.END_CRYSTAL); + for (String wood : new String[]{"OAK", "SPRUCE", "BIRCH", "JUNGLE", "ACACIA", "DARK_OAK", "MANGROVE", "CHERRY", "PALE_OAK"}) { + String regular = wood + "_BOAT"; + String chest = wood + "_CHEST_BOAT"; + ENTITY_ITEMS.put(EntityType.valueOf(regular), Material.getMaterial(regular)); + ENTITY_ITEMS.put(EntityType.valueOf(chest), Material.getMaterial(chest)); + } + ENTITY_ITEMS.put(EntityType.BAMBOO_RAFT, Material.BAMBOO_RAFT); + ENTITY_ITEMS.put(EntityType.BAMBOO_CHEST_RAFT, Material.BAMBOO_CHEST_RAFT); + // preset some tags to a default value, override some of them: putMaterialTag(Tag.DOORS, MODIFIED_ON_RIGHT); putMaterialTag(Tag.TRAPDOORS, MODIFIED_ON_RIGHT); @@ -877,6 +886,7 @@ private static void putMaterialTag(Tag tag, Integer value) { putMaterialTag(Tag.SHULKER_BOXES, MODIFIED_ON_RIGHT); putMaterialTag(Tag.ITEMS_BOATS, 0); + putMaterialTag(Tag.ITEMS_CHEST_BOATS, 0); putMaterialTag(Tag.BANNERS, 0); putMaterialTag(Tag.SLABS, 0); putMaterialTag(Tag.PLANKS, 0); @@ -925,8 +935,7 @@ private static void putMaterialTag(Tag tag, Integer value) { }); // Check for missing items/blocks - for (Material material : Material.values()) { - if (material.isLegacy()) continue; + Registry.MATERIAL.stream().forEach(material -> { // Add spawn eggs if (isSpawnEgg(material)) { MATERIAL_FLAGS.put(material, 0); @@ -937,7 +946,7 @@ private static void putMaterialTag(Tag tag, Integer value) { if (!MATERIAL_FLAGS.containsKey(material)) { logger.fine("Missing material definition for " + (material.isBlock() ? "block " : "item ") + material.name()); } - } + }); // DAMAGE_EFFECTS.add(PotionEffectType.SPEED); DAMAGE_EFFECTS.add(PotionEffectType.SLOWNESS); From 2f13ae0444409376feb6c7674591142fe854e12e Mon Sep 17 00:00:00 2001 From: wizjany Date: Sat, 9 Nov 2024 13:48:02 -0500 Subject: [PATCH 48/50] Release 7.0.13-beta-1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 30f75f29d..305dc0e11 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ group=com.sk89q.worldguard -version=7.0.13-SNAPSHOT +version=7.0.13-beta-1 org.gradle.parallel=true From 7ae07a9497c0061c839936562310a4ebc660b726 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sat, 9 Nov 2024 13:52:24 -0500 Subject: [PATCH 49/50] Back to snapshot. Also update changelog cuz I forgot. --- CHANGELOG.md | 8 ++++++++ gradle.properties | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c37fc8ec..327baa8e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 7.0.13 (beta) + +* Update to 1.21.3 +* Remove max-stack-size bypass in stack command +* Fix a falling block metadata leak. (May still be problematic on Spigot, use Paper.) +* Fix flame enchant being blocked as entity damage on the arrow itself. +* More Paper-specific performance enhancements for hoppers. + ## 7.0.12 * Fix a change in the default behavior of explosion flag handling. diff --git a/gradle.properties b/gradle.properties index 305dc0e11..30f75f29d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ group=com.sk89q.worldguard -version=7.0.13-beta-1 +version=7.0.13-SNAPSHOT org.gradle.parallel=true From 89b6bdc16ad40ecf9ed8d8ff476dc9e3e39bc94e Mon Sep 17 00:00:00 2001 From: wizjany Date: Tue, 10 Dec 2024 16:27:24 -0500 Subject: [PATCH 50/50] Fix typo. Only affected the config option, not the flag, so not too surprised it wasn't noticed earlier. https://github.com/EngineHub/WorldGuard/pull/2115/files/679b56948f41869bd545564a8c57562f157a6b66#r1878791900 --- .../worldguard/bukkit/listener/WorldGuardEntityListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 559db3f99..080a68db5 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -603,7 +603,7 @@ public void onExplosionPrime(ExplosionPrimeEvent event) { event.setCancelled(true); return; } - } else if (event instanceof AbstractWindCharge) { + } else if (event.getEntity() instanceof AbstractWindCharge) { if (wcfg.blockWindChargeExplosions) { event.setCancelled(true); return;