From 555e8ceff8394a5671c8b1fefc1904a10568efa6 Mon Sep 17 00:00:00 2001 From: totemo Date: Sun, 14 Jul 2019 19:24:59 +0930 Subject: [PATCH 1/2] Build with Maven, inserting version into plugin.yml. Git ignore build artifacts. --- .gitignore | 32 ++++++++++++++++++++++++ plugin.yml | 4 +-- pom.xml | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c1f7f40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# 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* + +# Eclipse stuff: +.project +.settings +.classpath + +# Build: +/classes/ +target/ diff --git a/plugin.yml b/plugin.yml index 77839e2..5609cfa 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ main: com.rifledluffy.chairs.RFChairs name: RFChairs -version: 6.0 +version: ${project.version} authors: [Rifle D. Luffy, VicenteRD, carlpoole, i0xHeX] api-version: 1.13 description: Chairs but Rifle's way. @@ -43,4 +43,4 @@ permissions: rfchairs.reset: true rfchairs.update: true rfchairs.manage: true - rfchairs.use: true \ No newline at end of file + rfchairs.use: true diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..203c561 --- /dev/null +++ b/pom.xml @@ -0,0 +1,72 @@ + + 4.0.0 + + com.rifledluffy + RiflesChairs + 6.0-SNAPSHOT + + Chairs, but Rifle's way.. + https://github.com/RifleDLuffy/RFChairs + + + UTF-8 + 1.8 + 1.8 + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + sk89q-repo + http://maven.sk89q.com/repo/ + + + jitpack.io + https://jitpack.io + + + + + + org.spigotmc + spigot-api + 1.13.2-R0.1-SNAPSHOT + + + com.sk89q.worldguard + worldguard-bukkit + 7.0.0 + jar + + + com.github.IntellectualSites + PlotSquared + 23b88a375da7587175c6662bdd3d9d96e7fe7060 + + + com.github.TechFortress + GriefPrevention + 16.12.alpha + + + + + clean package + ${basedir}/src + + + . + true + ${basedir} + + plugin.yml + config.yml + + + + + From 9b2397f4ff6103defda4faffe9241429b3baa436 Mon Sep 17 00:00:00 2001 From: totemo Date: Wed, 16 Jun 2021 01:00:21 +0930 Subject: [PATCH 2/2] Version 6.0.1 * Fix region checking code. It was picking up all regions in all worlds at specified coordinates. Now only regions applicable to the current world at the specified location are checked. * Treat all air material types equivalently. --- pom.xml | 2 +- .../chairs/managers/WorldGuardManager.java | 113 ++++++++---------- src/com/rifledluffy/chairs/utility/Util.java | 14 ++- 3 files changed, 62 insertions(+), 67 deletions(-) diff --git a/pom.xml b/pom.xml index 203c561..7bbda5d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.rifledluffy RiflesChairs - 6.0-SNAPSHOT + 6.0.1 Chairs, but Rifle's way.. https://github.com/RifleDLuffy/RFChairs diff --git a/src/com/rifledluffy/chairs/managers/WorldGuardManager.java b/src/com/rifledluffy/chairs/managers/WorldGuardManager.java index b773819..ba7cece 100644 --- a/src/com/rifledluffy/chairs/managers/WorldGuardManager.java +++ b/src/com/rifledluffy/chairs/managers/WorldGuardManager.java @@ -1,86 +1,77 @@ package com.rifledluffy.chairs.managers; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + import com.rifledluffy.chairs.RFChairs; import com.rifledluffy.chairs.chairs.Chair; -import com.rifledluffy.chairs.utility.Util; -import com.sk89q.worldedit.math.BlockVector3; +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.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.RegionContainer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; public class WorldGuardManager { - private RFChairs plugin = RFChairs.getInstance(); - public WorldGuard worldGuard; - public WorldGuardPlugin worldGuardPlugin; - public RegionContainer container; - @SuppressWarnings("rawtypes") - public static Flag flag; + private RFChairs plugin = RFChairs.getInstance(); + public WorldGuard worldGuard; + public WorldGuardPlugin worldGuardPlugin; + public RegionContainer container; + public static StateFlag flag; - public WorldGuardManager() {} - - public void setup() { - worldGuard = WorldGuard.getInstance(); - } - - public void register() { - flag = new StateFlag("allow-seating", true); - FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); - try { - registry.register(flag); - plugin.log("Custom Flag Registered!"); - } catch (FlagConflictException e) { - plugin.log("Unable to register custom worldguard flag!"); - } - } - - public WorldGuardPlugin getWorldGuard() { - Plugin plugin = this.plugin.getServer().getPluginManager().getPlugin("WorldGuard"); - - if (!(plugin instanceof WorldGuardPlugin)) return null; - return (WorldGuardPlugin) plugin; - } - - public boolean validateSeating(Chair chair, Player player) { - double xPos = chair.getLocation().getX(); - double yPos = chair.getLocation().getY(); - double zPos = chair.getLocation().getZ(); + public WorldGuardManager() { + } - WorldGuardManager worldManager = plugin.getWorldGuardManager(); + public void setup() { + worldGuard = WorldGuard.getInstance(); + } - LocalPlayer localPlayer = worldManager.getWorldGuard().wrapPlayer(player); + public void register() { + flag = new StateFlag("allow-seating", true); + FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); + try { + registry.register(flag); + plugin.log("Custom Flag Registered!"); + } catch (FlagConflictException e) { + plugin.log("Unable to register custom worldguard flag!"); + } + } - BlockVector3 vector3 = BlockVector3.at(xPos, yPos, zPos); + public WorldGuardPlugin getWorldGuard() { + Plugin plugin = this.plugin.getServer().getPluginManager().getPlugin("WorldGuard"); - List regionSetList = getContainer().getLoaded().stream() - .map(manager -> manager.getApplicableRegions(vector3)) - .collect(Collectors.toList()); + if (!(plugin instanceof WorldGuardPlugin)) { + return null; + } + return (WorldGuardPlugin) plugin; + } - if (regionSetList.size() == 0) return true; + public boolean validateSeating(Chair chair, Player player) { + RegionContainer container = getContainer(); + Location loc = chair.getLocation(); + RegionManager regionManager = container.get(BukkitAdapter.adapt(loc.getWorld())); + if (regionManager != null) { + com.sk89q.worldedit.util.Location weLoc = BukkitAdapter.adapt(loc); + LocalPlayer wgPlayer = getWorldGuard().wrapPlayer(player); + ApplicableRegionSet applicableRegions = regionManager.getApplicableRegions(weLoc.toVector().toBlockPoint()); + return applicableRegions.testState(wgPlayer, getFlag()); + } else { + return true; + } + } - return regionSetList.stream() - .allMatch(set -> set.testState(localPlayer, (StateFlag) worldManager.getFlag())); - } + public RegionContainer getContainer() { + return worldGuard.getPlatform().getRegionContainer(); + } - public RegionContainer getContainer() { - return worldGuard.getPlatform().getRegionContainer(); - } - - public Flag getFlag() { - return flag; - } + public StateFlag getFlag() { + return flag; + } } diff --git a/src/com/rifledluffy/chairs/utility/Util.java b/src/com/rifledluffy/chairs/utility/Util.java index d0c03e3..e8bc260 100644 --- a/src/com/rifledluffy/chairs/utility/Util.java +++ b/src/com/rifledluffy/chairs/utility/Util.java @@ -119,10 +119,14 @@ public static boolean surroundedBlock(Block block) { && !validExit(block.getRelative(BlockFace.SOUTH)) && !validExit(block.getRelative(BlockFace.WEST)); } - + + private static boolean isAir(Material type) { + return type == Material.AIR || type == Material.CAVE_AIR || type == Material.VOID_AIR; + } + private static boolean validExit(Block block) { Material type = block.getType(); - return type == Material.AIR || type.name().equals("WALL_SIGN") || type.name().endsWith("_WALL_SIGN"); + return isAir(type) || type.name().equals("WALL_SIGN") || type.name().endsWith("_WALL_SIGN"); } public static boolean isLiqiudOrMagma(Block block) { @@ -144,7 +148,7 @@ public static boolean validCouch(Block block) { BlockFace side = faces.get(0); BlockFace otherSide = faces.get(1); - if (block.getRelative(BlockFace.UP).getType() != Material.AIR) return false; + if (!isAir(block.getRelative(BlockFace.UP).getType())) return false; if (validatedChair(block.getRelative(side))) if (validSeat(block.getRelative(side), side, block)) validSides++; if (validatedChair(block.getRelative(otherSide))) if (validSeat(block.getRelative(otherSide), otherSide, block)) validSides++; @@ -288,11 +292,11 @@ public static Block getBlockFromDirection(Block block, String direction) { } public static boolean canFitPlayer(Block block) { - return block.getType() == Material.AIR && block.getRelative(BlockFace.UP).getType() == Material.AIR; + return isAir(block.getType()) && isAir(block.getRelative(BlockFace.UP).getType()); } public static boolean safePlace(Block block) { - return block.getRelative(BlockFace.DOWN).getType() != Material.AIR; + return isAir(block.getRelative(BlockFace.DOWN).getType()); } public static Vector getVectorDir(Location caster, Location target) {