From e516cf2ec614fa58a78f6c4b3de76e6a162ddb8c Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Thu, 21 Mar 2024 21:52:44 +0100 Subject: [PATCH] Add YardWatch plugin with WorldGuard integration Introduced a new plugin, YardWatch, implemented with WorldGuard for protection. The plugin checks if WorldGuard is enabled and regulates breaking blocks, placing blocks, and interactions based on WorldGuard's build and interact flags. Also included are updated .gitignore and pom.xml files to manage the project setup. --- .gitignore | 113 ++++++++++++++++++ pom.xml | 94 +++++++++++++++ .../youhavetrouble/yardwatch/YardWatch.java | 20 ++++ .../yardwatch/hooks/WorldGuardProtection.java | 92 ++++++++++++++ src/main/resources/plugin.yml | 12 ++ 5 files changed, 331 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/me/youhavetrouble/yardwatch/YardWatch.java create mode 100644 src/main/java/me/youhavetrouble/yardwatch/hooks/WorldGuardProtection.java create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4788b4b --- /dev/null +++ b/.gitignore @@ -0,0 +1,113 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +target/ + +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next + +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +# Common working directory +run/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2ca3795 --- /dev/null +++ b/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + + me.youhavetrouble + YardWatch + 1.0 + jar + + YardWatch + + Implementation of YardWatchAPI for common protection plugins + + 1.8 + UTF-8 + + https://youhavetrouble.me + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + + + src/main/resources + true + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + jitpack.io + https://jitpack.io + + + sk89q-repo + https://maven.enginehub.org/repo/ + + + + + + com.destroystokyo.paper + paper-api + 1.13-R0.1-SNAPSHOT + provided + + + com.sk89q.worldguard + worldguard-bukkit + 7.0.4-SNAPSHOT + provided + + + com.github.YouHaveTrouble + YardWatchAPI + 2.0.0 + compile + + + + diff --git a/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java b/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java new file mode 100644 index 0000000..f2d0991 --- /dev/null +++ b/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java @@ -0,0 +1,20 @@ +package me.youhavetrouble.yardwatch; + +import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection; +import org.bukkit.plugin.ServicePriority; +import org.bukkit.plugin.java.JavaPlugin; + +public final class YardWatch extends JavaPlugin { + + @Override + public void onEnable() { + + if (getServer().getPluginManager().isPluginEnabled("WorldGuard")) { + getServer().getServicesManager().register( + Protection.class, new WorldGuardProtection(this), this, ServicePriority.Normal + ); + } + + + } +} diff --git a/src/main/java/me/youhavetrouble/yardwatch/hooks/WorldGuardProtection.java b/src/main/java/me/youhavetrouble/yardwatch/hooks/WorldGuardProtection.java new file mode 100644 index 0000000..31ed401 --- /dev/null +++ b/src/main/java/me/youhavetrouble/yardwatch/hooks/WorldGuardProtection.java @@ -0,0 +1,92 @@ +package me.youhavetrouble.yardwatch.hooks; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.protection.regions.RegionQuery; +import me.youhavetrouble.yardwatch.Protection; +import me.youhavetrouble.yardwatch.YardWatch; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public class WorldGuardProtection implements Protection { + + private final YardWatch plugin; + + public WorldGuardProtection(YardWatch plugin) { + this.plugin = plugin; + } + + @Override + public boolean isEnabled() { + return plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard"); + } + + @Override + public boolean isProtected(Location location) { + if (!isEnabled()) return false; + if (location.getWorld() == null) return false; + com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(location); + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = container.createQuery(); + return query.testBuild(wgLocation, null); + } + + @Override + public boolean canBreakBlock(Player player, BlockState blockState) { + if (!isEnabled()) return true; + Location location = blockState.getLocation(); + com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(location); + LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player, true); + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = container.createQuery(); + return query.testState(wgLocation, localPlayer, Flags.BUILD); + } + + @Override + public boolean canPlaceBlock(Player player, Location location) { + if (!isEnabled()) return true; + com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(location); + LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player, true); + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = container.createQuery(); + return query.testState(wgLocation, localPlayer, Flags.BUILD); + } + + @Override + public boolean canInteract(Player player, BlockState blockState) { + if (!isEnabled()) return true; + com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(blockState.getLocation()); + LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player, true); + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = container.createQuery(); + return query.testState(wgLocation, localPlayer, Flags.INTERACT); + } + + @Override + public boolean canInteract(Player player, Entity entity) { + if (!isEnabled()) return true; + com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(entity.getLocation()); + LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player, true); + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = container.createQuery(); + return query.testState(wgLocation, localPlayer, Flags.INTERACT); + } + + @Override + public boolean canDamage(Entity attacker, Entity target) { + if (!isEnabled()) return true; + if (!(attacker instanceof Player)) return true; + Player player = (Player) attacker; + com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(target.getLocation()); + LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player, true); + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = container.createQuery(); + return query.testState(wgLocation, localPlayer, Flags.INTERACT); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..5948376 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,12 @@ +name: YardWatch +version: '${project.version}' +main: me.youhavetrouble.yardwatch.YardWatch +api-version: '1.13' +softdepend: + - "WorldGuard" + - "GriefPrevention" + - "Towny" +authors: + - "YouHaveTrouble" +description: "Implementation of YardWatchAPI for common protection plugins" +website: "https://youhavetrouble.me"