From 98d49cb80bf6a8fee6b87b6a5c74e21cefdc53e3 Mon Sep 17 00:00:00 2001 From: ShakeforProtein Date: Tue, 11 Aug 2020 14:20:03 +1000 Subject: [PATCH] Perm node update for update checker. Adds some basic world guard protection, but also dependency. --- pom.xml | 18 +- .../treebotrunks/Commands/Anvil.java | 105 +++++---- .../treebotrunks/Commands/BlastFurnace.java | 107 +++++---- .../treebotrunks/Commands/BrewingStand.java | 120 +++++----- .../treebotrunks/Commands/Cartographer.java | 101 +++++---- .../treebotrunks/Commands/Enchant.java | 101 +++++---- .../treebotrunks/Commands/Furnace.java | 109 ++++----- .../treebotrunks/Commands/Grindstone.java | 101 +++++---- .../treebotrunks/Commands/Loom.java | 101 +++++---- .../treebotrunks/Commands/Smoker.java | 107 +++++---- .../treebotrunks/Commands/Stonecutter.java | 101 +++++---- .../Listeners/InventoryListener.java | 214 ++++++++++-------- .../treebotrunks/TreeboTrunk.java | 61 +++-- src/main/resources/plugin.yml | 19 +- 14 files changed, 752 insertions(+), 613 deletions(-) diff --git a/pom.xml b/pom.xml index 32279bd..05578fe 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.ShakeforProtein TreeboTrunks - 0.0.5 + 0.0.9 jar TreeboTrunks @@ -90,6 +90,10 @@ CodeMC https://repo.codemc.org/repository/maven-public + + sk89q-repo + https://maven.enginehub.org/repo/ + @@ -105,5 +109,17 @@ 1.5 compile + + com.sk89q.worldguard + worldguard-bukkit + 7.0.1 + provided + + + com.sk89q.worldedit + worldedit-bukkit + 7.0.1-SNAPSHOT + provided + diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Anvil.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Anvil.java index 84013a6..f4e9215 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Anvil.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Anvil.java @@ -1,5 +1,9 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.protection.regions.RegionQuery; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -33,58 +37,65 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String if (sender instanceof Player) { Player p = (Player) sender; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("Anvils." + time + ".X", l.getBlockX()); - pl.getConfig().set("Anvils." + time + ".Y", l.getBlockY()); - pl.getConfig().set("Anvils." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("Anvils." + time + ".World", l.getWorld().getName()); + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); - p.getLocation().getBlock().setType(Material.ANVIL); - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand - int delay = 600; - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName("" + (delay / 20)); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("Anvils." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { + + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("Anvils." + time + ".X", l.getBlockX()); + pl.getConfig().set("Anvils." + time + ".Y", l.getBlockY()); + pl.getConfig().set("Anvils." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("Anvils." + time + ".World", l.getWorld().getName()); + + p.getLocation().getBlock().setType(Material.ANVIL); + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + int delay = 600; + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName("" + (delay / 20)); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("Anvils." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; + }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("Anvils." + time + ".X"); - y = pl.getConfig().getInt("Anvils." + time + ".Y"); - z = pl.getConfig().getInt("Anvils." + time + ".Z"); - String world = pl.getConfig().getString("Anvils." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("Anvils." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Anvils." + time + ".AST"))).remove(); + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("Anvils." + time + ".X"); + y = pl.getConfig().getInt("Anvils." + time + ".Y"); + z = pl.getConfig().getInt("Anvils." + time + ".Z"); + String world = pl.getConfig().getString("Anvils." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("Anvils." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Anvils." + time + ".AST"))).remove(); + } + pl.getConfig().set("Anvils." + time, null); } - pl.getConfig().set("Anvils." + time, null); - } - }, delay); + }, delay); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/BlastFurnace.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/BlastFurnace.java index 12158a4..c8c5e4b 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/BlastFurnace.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/BlastFurnace.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -34,59 +35,65 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String Player p = (Player) sender; int delay = 3600; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("BlastFurnaces." + time + ".X", l.getBlockX()); - pl.getConfig().set("BlastFurnaces." + time + ".Y", l.getBlockY()); - pl.getConfig().set("BlastFurnaces." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("BlastFurnaces." + time + ".World", l.getWorld().getName()); - - p.getLocation().getBlock().setType(Material.BLAST_FURNACE); - - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand - - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("BlastFurnaces." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); + + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("BlastFurnaces." + time + ".X", l.getBlockX()); + pl.getConfig().set("BlastFurnaces." + time + ".Y", l.getBlockY()); + pl.getConfig().set("BlastFurnaces." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("BlastFurnaces." + time + ".World", l.getWorld().getName()); + + p.getLocation().getBlock().setType(Material.BLAST_FURNACE); + + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("BlastFurnaces." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("BlastFurnaces." + time + ".X"); - y = pl.getConfig().getInt("BlastFurnaces." + time + ".Y"); - z = pl.getConfig().getInt("BlastFurnaces." + time + ".Z"); - String world = pl.getConfig().getString("BlastFurnaces." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("BlastFurnaces." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("BlastFurnaces." + time + ".AST"))).remove(); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("BlastFurnaces." + time + ".X"); + y = pl.getConfig().getInt("BlastFurnaces." + time + ".Y"); + z = pl.getConfig().getInt("BlastFurnaces." + time + ".Z"); + String world = pl.getConfig().getString("BlastFurnaces." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("BlastFurnaces." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("BlastFurnaces." + time + ".AST"))).remove(); + } + pl.getConfig().set("BlastFurnaces." + time, null); } - pl.getConfig().set("BlastFurnaces." + time, null); - } - }, delay); + }, delay); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/BrewingStand.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/BrewingStand.java index 55b5e55..f4cc526 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/BrewingStand.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/BrewingStand.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -37,68 +38,75 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String Player p = (Player) sender; int delay = 3600; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("BrewingStands." + time + ".X", l.getBlockX()); - pl.getConfig().set("BrewingStands." + time + ".Y", l.getBlockY()); - pl.getConfig().set("BrewingStands." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("BrewingStands." + time + ".World", l.getWorld().getName()); - - p.getLocation().getBlock().setType(Material.BREWING_STAND); - - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand - - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("BrewingStands." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); + + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("BrewingStands." + time + ".X", l.getBlockX()); + pl.getConfig().set("BrewingStands." + time + ".Y", l.getBlockY()); + pl.getConfig().set("BrewingStands." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("BrewingStands." + time + ".World", l.getWorld().getName()); + + p.getLocation().getBlock().setType(Material.BREWING_STAND); + + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("BrewingStands." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("BrewingStands." + time + ".X"); - y = pl.getConfig().getInt("BrewingStands." + time + ".Y"); - z = pl.getConfig().getInt("BrewingStands." + time + ".Z"); - String world = pl.getConfig().getString("BrewingStands." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - - if (loc.getBlock().getState() instanceof org.bukkit.block.data.type.BrewingStand) { - Bukkit.broadcastMessage("Brewing Stand"); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("BrewingStands." + time + ".X"); + y = pl.getConfig().getInt("BrewingStands." + time + ".Y"); + z = pl.getConfig().getInt("BrewingStands." + time + ".Z"); + String world = pl.getConfig().getString("BrewingStands." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + + if (loc.getBlock().getState() instanceof org.bukkit.block.data.type.BrewingStand) { + Bukkit.broadcastMessage("Brewing Stand"); + } + + + //loc.getBlock().breakNaturally(); + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("BrewingStands." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("BrewingStands." + time + ".AST"))).remove(); + } + pl.getConfig().set("BrewingStands." + time, null); } - - - //loc.getBlock().breakNaturally(); - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("BrewingStands." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("BrewingStands." + time + ".AST"))).remove(); - } - pl.getConfig().set("BrewingStands." + time, null); - } - }, delay); + }, delay); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } + } else { sender.sendMessage(pl.badge + pl.err + "You must be a player to use this command"); } diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Cartographer.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Cartographer.java index 2bc186b..815d07a 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Cartographer.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Cartographer.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -31,60 +32,66 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String if (sender instanceof Player) { Player p = (Player) sender; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("Cartographers." + time + ".X", l.getBlockX()); - pl.getConfig().set("Cartographers." + time + ".Y", l.getBlockY()); - pl.getConfig().set("Cartographers." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("Cartographers." + time + ".World", l.getWorld().getName()); + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); - p.getLocation().getBlock().setType(Material.CARTOGRAPHY_TABLE); + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("Cartographers." + time + ".X", l.getBlockX()); + pl.getConfig().set("Cartographers." + time + ".Y", l.getBlockY()); + pl.getConfig().set("Cartographers." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("Cartographers." + time + ".World", l.getWorld().getName()); + p.getLocation().getBlock().setType(Material.CARTOGRAPHY_TABLE); - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand - int delay = 600; - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("Cartographers." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + int delay = 600; + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("Cartographers." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("Cartographers." + time + ".X"); - y = pl.getConfig().getInt("Cartographers." + time + ".Y"); - z = pl.getConfig().getInt("Cartographers." + time + ".Z"); - String world = pl.getConfig().getString("Cartographers." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("Cartographers." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Cartographers." + time + ".AST"))).remove(); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("Cartographers." + time + ".X"); + y = pl.getConfig().getInt("Cartographers." + time + ".Y"); + z = pl.getConfig().getInt("Cartographers." + time + ".Z"); + String world = pl.getConfig().getString("Cartographers." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("Cartographers." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Cartographers." + time + ".AST"))).remove(); + } + pl.getConfig().set("Cartographers." + time, null); } - pl.getConfig().set("Cartographers." + time, null); - } - }, delay); + }, delay); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Enchant.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Enchant.java index 7065b7f..0157ff9 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Enchant.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Enchant.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -33,59 +34,65 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String if (sender instanceof Player) { Player p = (Player) sender; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("EnchTables." + time + ".X", l.getBlockX()); - pl.getConfig().set("EnchTables." + time + ".Y", l.getBlockY()); - pl.getConfig().set("EnchTables." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("EnchTables." + time + ".World", l.getWorld().getName()); + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); - p.getLocation().getBlock().setType(Material.ENCHANTING_TABLE); + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("EnchTables." + time + ".X", l.getBlockX()); + pl.getConfig().set("EnchTables." + time + ".Y", l.getBlockY()); + pl.getConfig().set("EnchTables." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("EnchTables." + time + ".World", l.getWorld().getName()); - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + p.getLocation().getBlock().setType(Material.ENCHANTING_TABLE); - int delay = 600; - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("EnchTables." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + int delay = 600; + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("EnchTables." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("EnchTables." + time + ".X"); - y = pl.getConfig().getInt("EnchTables." + time + ".Y"); - z = pl.getConfig().getInt("EnchTables." + time + ".Z"); - String world = pl.getConfig().getString("EnchTables." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("EnchTables." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("EnchTables." + time + ".AST"))).remove(); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("EnchTables." + time + ".X"); + y = pl.getConfig().getInt("EnchTables." + time + ".Y"); + z = pl.getConfig().getInt("EnchTables." + time + ".Z"); + String world = pl.getConfig().getString("EnchTables." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("EnchTables." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("EnchTables." + time + ".AST"))).remove(); + } + pl.getConfig().set("EnchTables." + time, null); } - pl.getConfig().set("EnchTables." + time, null); - } - }, 600L); + }, 600L); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Furnace.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Furnace.java index 40aa572..ab3e15a 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Furnace.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Furnace.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -38,60 +39,66 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String Player p = (Player) sender; int delay = 3600; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { - - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("Furnaces." + time + ".X", l.getBlockX()); - pl.getConfig().set("Furnaces." + time + ".Y", l.getBlockY()); - pl.getConfig().set("Furnaces." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("Furnaces." + time + ".World", l.getWorld().getName()); - - p.getLocation().getBlock().setType(Material.FURNACE); - - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand - - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("Furnaces." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); + + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { + + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("Furnaces." + time + ".X", l.getBlockX()); + pl.getConfig().set("Furnaces." + time + ".Y", l.getBlockY()); + pl.getConfig().set("Furnaces." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("Furnaces." + time + ".World", l.getWorld().getName()); + + p.getLocation().getBlock().setType(Material.FURNACE); + + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("Furnaces." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("Furnaces." + time + ".X"); - y = pl.getConfig().getInt("Furnaces." + time + ".Y"); - z = pl.getConfig().getInt("Furnaces." + time + ".Z"); - String world = pl.getConfig().getString("Furnaces." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("Furnaces." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Furnaces." + time + ".AST"))).remove(); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("Furnaces." + time + ".X"); + y = pl.getConfig().getInt("Furnaces." + time + ".Y"); + z = pl.getConfig().getInt("Furnaces." + time + ".Z"); + String world = pl.getConfig().getString("Furnaces." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("Furnaces." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Furnaces." + time + ".AST"))).remove(); + } + pl.getConfig().set("Furnaces." + time, null); } - pl.getConfig().set("Furnaces." + time, null); - } - }, delay); + }, delay); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Grindstone.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Grindstone.java index aa4e4fc..b71fee7 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Grindstone.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Grindstone.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -33,59 +34,65 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String if (sender instanceof Player) { Player p = (Player) sender; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("Grindstones." + time + ".X", l.getBlockX()); - pl.getConfig().set("Grindstones." + time + ".Y", l.getBlockY()); - pl.getConfig().set("Grindstones." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("Grindstones." + time + ".World", l.getWorld().getName()); + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { - p.getLocation().getBlock().setType(Material.GRINDSTONE); - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("Grindstones." + time + ".X", l.getBlockX()); + pl.getConfig().set("Grindstones." + time + ".Y", l.getBlockY()); + pl.getConfig().set("Grindstones." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("Grindstones." + time + ".World", l.getWorld().getName()); - int delay = 600; - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("Grindstones." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + p.getLocation().getBlock().setType(Material.GRINDSTONE); + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + int delay = 600; + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("Grindstones." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("Grindstones." + time + ".X"); - y = pl.getConfig().getInt("Grindstones." + time + ".Y"); - z = pl.getConfig().getInt("Grindstones." + time + ".Z"); - String world = pl.getConfig().getString("Grindstones." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("Grindstones." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Grindstones." + time + ".AST"))).remove(); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("Grindstones." + time + ".X"); + y = pl.getConfig().getInt("Grindstones." + time + ".Y"); + z = pl.getConfig().getInt("Grindstones." + time + ".Z"); + String world = pl.getConfig().getString("Grindstones." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("Grindstones." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Grindstones." + time + ".AST"))).remove(); + } + pl.getConfig().set("Grindstones." + time, null); } - pl.getConfig().set("Grindstones." + time, null); - } - }, 600L); + }, 600L); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Loom.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Loom.java index 7ed48dc..0b37218 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Loom.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Loom.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -31,59 +32,65 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String if (sender instanceof Player) { Player p = (Player) sender; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("Looms." + time + ".X", l.getBlockX()); - pl.getConfig().set("Looms." + time + ".Y", l.getBlockY()); - pl.getConfig().set("Looms." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("Looms." + time + ".World", l.getWorld().getName()); + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); - p.getLocation().getBlock().setType(Material.LOOM); + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("Looms." + time + ".X", l.getBlockX()); + pl.getConfig().set("Looms." + time + ".Y", l.getBlockY()); + pl.getConfig().set("Looms." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("Looms." + time + ".World", l.getWorld().getName()); - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + p.getLocation().getBlock().setType(Material.LOOM); - int delay = 600; - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("Looms." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + int delay = 600; + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("Looms." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("Looms." + time + ".X"); - y = pl.getConfig().getInt("Looms." + time + ".Y"); - z = pl.getConfig().getInt("Looms." + time + ".Z"); - String world = pl.getConfig().getString("Looms." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("Looms." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Looms." + time + ".AST"))).remove(); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("Looms." + time + ".X"); + y = pl.getConfig().getInt("Looms." + time + ".Y"); + z = pl.getConfig().getInt("Looms." + time + ".Z"); + String world = pl.getConfig().getString("Looms." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("Looms." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Looms." + time + ".AST"))).remove(); + } + pl.getConfig().set("Looms." + time, null); } - pl.getConfig().set("Looms." + time, null); - } - }, 600L); + }, 600L); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Smoker.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Smoker.java index 699164a..891e104 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Smoker.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Smoker.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -37,60 +38,66 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String Player p = (Player) sender; int delay = 3600; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("Smokers." + time + ".X", l.getBlockX()); - pl.getConfig().set("Smokers." + time + ".Y", l.getBlockY()); - pl.getConfig().set("Smokers." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("Smokers." + time + ".World", l.getWorld().getName()); - - p.getLocation().getBlock().setType(Material.SMOKER); - - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, 0, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand - - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("Smokers." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { + + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("Smokers." + time + ".X", l.getBlockX()); + pl.getConfig().set("Smokers." + time + ".Y", l.getBlockY()); + pl.getConfig().set("Smokers." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("Smokers." + time + ".World", l.getWorld().getName()); + + p.getLocation().getBlock().setType(Material.SMOKER); + + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, 0, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("Smokers." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("Smokers." + time + ".X"); - y = pl.getConfig().getInt("Smokers." + time + ".Y"); - z = pl.getConfig().getInt("Smokers." + time + ".Z"); - String world = pl.getConfig().getString("Smokers." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("Smokers." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Smokers." + time + ".AST"))).remove(); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("Smokers." + time + ".X"); + y = pl.getConfig().getInt("Smokers." + time + ".Y"); + z = pl.getConfig().getInt("Smokers." + time + ".Z"); + String world = pl.getConfig().getString("Smokers." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("Smokers." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Smokers." + time + ".AST"))).remove(); + } + pl.getConfig().set("Smokers." + time, null); } - pl.getConfig().set("Smokers." + time, null); - } - }, delay); + }, delay); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Stonecutter.java b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Stonecutter.java index b40b644..75802e5 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Commands/Stonecutter.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Commands/Stonecutter.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treebotrunks.Commands; +import com.sk89q.worldguard.LocalPlayer; import me.shakeforprotein.treebotrunks.TreeboTrunk; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -30,61 +31,67 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String if (sender instanceof Player) { Player p = (Player) sender; if (pl.whitelistHash.containsKey(p.getLocation().getBlock().getType())) { + LocalPlayer wgPlayer = pl.worldGuardPlugin.wrapPlayer(p); - if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { - if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { - long time = System.currentTimeMillis(); - Location l = p.getLocation().getBlock().getLocation(); - pl.getConfig().set("Stonecutters." + time + ".X", l.getBlockX()); - pl.getConfig().set("Stonecutters." + time + ".Y", l.getBlockY()); - pl.getConfig().set("Stonecutters." + time + ".Z", l.getBlockZ()); - pl.getConfig().set("Stonecutters." + time + ".World", l.getWorld().getName()); + if (pl.hasBypass(wgPlayer, p.getLocation()) || pl.canBuild(wgPlayer, p.getLocation())) { - p.getLocation().getBlock().setType(Material.STONECUTTER); + if (!p.getLocation().subtract(0, 1, 0).getBlock().isEmpty()) { + if (!p.getLocation().subtract(0, 1, 0).getBlock().isLiquid()) { + long time = System.currentTimeMillis(); + Location l = p.getLocation().getBlock().getLocation(); + pl.getConfig().set("Stonecutters." + time + ".X", l.getBlockX()); + pl.getConfig().set("Stonecutters." + time + ".Y", l.getBlockY()); + pl.getConfig().set("Stonecutters." + time + ".Z", l.getBlockZ()); + pl.getConfig().set("Stonecutters." + time + ".World", l.getWorld().getName()); + p.getLocation().getBlock().setType(Material.STONECUTTER); - ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand - int delay = 600; - as.setGravity(false); //Make sure it doesn't fall - as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it - as.setCustomName((delay / 20) + ""); //Set this to the text you want - as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not - as.setVisible(false); - pl.getConfig().set("Stonecutters." + time + ".AST", as.getUniqueId()); - pl.astHash.putIfAbsent(as, delay / 20); - BukkitRunnable runnable = new BukkitRunnable() { - @Override - public void run() { - int currentVal = pl.astHash.get(as); - if (currentVal > 0) { - currentVal--; - String newName = currentVal + ""; - as.setCustomName(ChatColor.GOLD + newName); - pl.astHash.replace(as, currentVal); - } else { - this.cancel(); + ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l.add(0.5, -0.5, 0.5), EntityType.ARMOR_STAND); //Spawn the ArmorStand + + int delay = 600; + as.setGravity(false); //Make sure it doesn't fall + as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it + as.setCustomName((delay / 20) + ""); //Set this to the text you want + as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not + as.setVisible(false); + pl.getConfig().set("Stonecutters." + time + ".AST", as.getUniqueId()); + pl.astHash.putIfAbsent(as, delay / 20); + BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + int currentVal = pl.astHash.get(as); + if (currentVal > 0) { + currentVal--; + String newName = currentVal + ""; + as.setCustomName(ChatColor.GOLD + newName); + pl.astHash.replace(as, currentVal); + } else { + this.cancel(); + } } - } - }; - runnable.runTaskTimer(pl, 20L, 20L); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - int x, y, z = 0; - x = pl.getConfig().getInt("Stonecutters." + time + ".X"); - y = pl.getConfig().getInt("Stonecutters." + time + ".Y"); - z = pl.getConfig().getInt("Stonecutters." + time + ".Z"); - String world = pl.getConfig().getString("Stonecutters." + time + ".World"); - Location loc = new Location(Bukkit.getWorld(world), x, y, z); - loc.getBlock().setType(Material.AIR); - if (pl.getConfig().getString("Stonecutters." + time + ".AST") != null) { - Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Stonecutters." + time + ".AST"))).remove(); + }; + runnable.runTaskTimer(pl, 20L, 20L); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + int x, y, z = 0; + x = pl.getConfig().getInt("Stonecutters." + time + ".X"); + y = pl.getConfig().getInt("Stonecutters." + time + ".Y"); + z = pl.getConfig().getInt("Stonecutters." + time + ".Z"); + String world = pl.getConfig().getString("Stonecutters." + time + ".World"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z); + loc.getBlock().setType(Material.AIR); + if (pl.getConfig().getString("Stonecutters." + time + ".AST") != null) { + Bukkit.getEntity(UUID.fromString(pl.getConfig().getString("Stonecutters." + time + ".AST"))).remove(); + } + pl.getConfig().set("Stonecutters." + time, null); } - pl.getConfig().set("Stonecutters." + time, null); - } - }, 600L); + }, 600L); + } } + } else { + p.sendMessage(pl.badge + pl.err + "You are not entitled to build here"); } } } else { diff --git a/src/main/java/me/shakeforprotein/treebotrunks/Listeners/InventoryListener.java b/src/main/java/me/shakeforprotein/treebotrunks/Listeners/InventoryListener.java index 42eeaba..e2aff59 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/Listeners/InventoryListener.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/Listeners/InventoryListener.java @@ -19,7 +19,11 @@ import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import java.io.File; import java.io.IOException; @@ -245,30 +249,32 @@ public void inventoryClickListener(InventoryClickEvent e) { e.getWhoClicked().closeInventory(); } else { e.setCancelled(true); - int max = pl.getVarPerm("treebotrunk.chest", (Player) e.getWhoClicked()); - if (e.getSlot() < max + 1) { - ClickType cT = e.getClick(); - if (cT == ClickType.LEFT) { - Bukkit.dispatchCommand(e.getWhoClicked(), "chest " + e.getSlot()); - } else if (cT == ClickType.RIGHT) { - Inventory newInv = Bukkit.createInventory(null, 9, pl.badge + " Configure_Chest_" + e.getSlot() + "_" + world); - ItemStack nameTag = new ItemStack(Material.NAME_TAG, 1); - ItemStack icon = new ItemStack(Material.FILLED_MAP, 1); - ItemStack back = new ItemStack(Material.BARRIER, 1); - ItemMeta tagMeta = nameTag.getItemMeta(); - ItemMeta iconMeta = icon.getItemMeta(); - ItemMeta backMeta = back.getItemMeta(); - tagMeta.setDisplayName("Rename Chest " + e.getSlot() + "_" + world); - iconMeta.setDisplayName("Set icon for Chest " + e.getSlot() + "_" + world); - backMeta.setDisplayName("Return to previous menu"); - nameTag.setItemMeta(tagMeta); - icon.setItemMeta(iconMeta); - back.setItemMeta(backMeta); - newInv.setItem(0, nameTag); - newInv.setItem(1, icon); - newInv.setItem(8, back); + if (!(e.getClickedInventory() instanceof PlayerInventory)) { + int max = pl.getVarPerm("treebotrunk.chest", (Player) e.getWhoClicked()); + if (e.getSlot() < max + 1) { + ClickType cT = e.getClick(); + if (cT == ClickType.LEFT) { + Bukkit.dispatchCommand(e.getWhoClicked(), "chest " + e.getSlot()); + } else if (cT == ClickType.RIGHT) { + Inventory newInv = Bukkit.createInventory(null, 9, pl.badge + " Configure_Chest_" + e.getSlot() + "_" + world); + ItemStack nameTag = new ItemStack(Material.NAME_TAG, 1); + ItemStack icon = new ItemStack(Material.FILLED_MAP, 1); + ItemStack back = new ItemStack(Material.BARRIER, 1); + ItemMeta tagMeta = nameTag.getItemMeta(); + ItemMeta iconMeta = icon.getItemMeta(); + ItemMeta backMeta = back.getItemMeta(); + tagMeta.setDisplayName("Rename Chest " + e.getSlot() + "_" + world); + iconMeta.setDisplayName("Set icon for Chest " + e.getSlot() + "_" + world); + backMeta.setDisplayName("Return to previous menu"); + nameTag.setItemMeta(tagMeta); + icon.setItemMeta(iconMeta); + back.setItemMeta(backMeta); + newInv.setItem(0, nameTag); + newInv.setItem(1, icon); + newInv.setItem(8, back); - e.getWhoClicked().openInventory(newInv); + e.getWhoClicked().openInventory(newInv); + } } } } @@ -277,30 +283,32 @@ public void inventoryClickListener(InventoryClickEvent e) { e.getWhoClicked().closeInventory(); } else { e.setCancelled(true); - int max = pl.getVarPerm("treebotrunk.belt", (Player) e.getWhoClicked()); - if (e.getSlot() < max + 1) { - ClickType cT = e.getClick(); - if (cT == ClickType.LEFT) { - Bukkit.dispatchCommand(e.getWhoClicked(), "belt " + e.getSlot()); - } else if (cT == ClickType.RIGHT) { - Inventory newInv = Bukkit.createInventory(null, 9, pl.badge + " Configure_Belt_" + e.getSlot() + "_" + world); - ItemStack nameTag = new ItemStack(Material.NAME_TAG, 1); - ItemStack icon = new ItemStack(Material.FILLED_MAP, 1); - ItemStack back = new ItemStack(Material.BARRIER, 1); - ItemMeta tagMeta = nameTag.getItemMeta(); - ItemMeta iconMeta = icon.getItemMeta(); - ItemMeta backMeta = back.getItemMeta(); - tagMeta.setDisplayName("Rename Belt " + e.getSlot() + "_" + world); - iconMeta.setDisplayName("Set icon for Belt " + e.getSlot() + "_" + world); - backMeta.setDisplayName("Return to previous menu"); - nameTag.setItemMeta(tagMeta); - icon.setItemMeta(iconMeta); - back.setItemMeta(backMeta); - newInv.setItem(0, nameTag); - newInv.setItem(1, icon); - newInv.setItem(8, back); + if (!(e.getClickedInventory() instanceof PlayerInventory)) { + int max = pl.getVarPerm("treebotrunk.belt", (Player) e.getWhoClicked()); + if (e.getSlot() < max + 1) { + ClickType cT = e.getClick(); + if (cT == ClickType.LEFT) { + Bukkit.dispatchCommand(e.getWhoClicked(), "belt " + e.getSlot()); + } else if (cT == ClickType.RIGHT) { + Inventory newInv = Bukkit.createInventory(null, 9, pl.badge + " Configure_Belt_" + e.getSlot() + "_" + world); + ItemStack nameTag = new ItemStack(Material.NAME_TAG, 1); + ItemStack icon = new ItemStack(Material.FILLED_MAP, 1); + ItemStack back = new ItemStack(Material.BARRIER, 1); + ItemMeta tagMeta = nameTag.getItemMeta(); + ItemMeta iconMeta = icon.getItemMeta(); + ItemMeta backMeta = back.getItemMeta(); + tagMeta.setDisplayName("Rename Belt " + e.getSlot() + "_" + world); + iconMeta.setDisplayName("Set icon for Belt " + e.getSlot() + "_" + world); + backMeta.setDisplayName("Return to previous menu"); + nameTag.setItemMeta(tagMeta); + icon.setItemMeta(iconMeta); + back.setItemMeta(backMeta); + newInv.setItem(0, nameTag); + newInv.setItem(1, icon); + newInv.setItem(8, back); - e.getWhoClicked().openInventory(newInv); + e.getWhoClicked().openInventory(newInv); + } } } } @@ -309,29 +317,31 @@ public void inventoryClickListener(InventoryClickEvent e) { e.getWhoClicked().closeInventory(); } else { e.setCancelled(true); - int max = pl.getVarPerm("treebotrunk.barrel", (Player) e.getWhoClicked()); - if (e.getSlot() < max + 1) { - ClickType cT = e.getClick(); - if (cT == ClickType.LEFT) { - Bukkit.dispatchCommand(e.getWhoClicked(), "barrel " + e.getSlot()); - } else if (cT == ClickType.RIGHT) { - Inventory newInv = Bukkit.createInventory(null, 9, pl.badge + " Configure_Barrel_" + e.getSlot() + "_" + world); - ItemStack nameTag = new ItemStack(Material.NAME_TAG, 1); - ItemStack icon = new ItemStack(Material.FILLED_MAP, 1); - ItemStack back = new ItemStack(Material.BARRIER, 1); - ItemMeta tagMeta = nameTag.getItemMeta(); - ItemMeta iconMeta = icon.getItemMeta(); - ItemMeta backMeta = back.getItemMeta(); - tagMeta.setDisplayName("Rename Barrel " + e.getSlot() + "_" + world); - iconMeta.setDisplayName("Set icon for Barrel " + e.getSlot() + "_" + world); - backMeta.setDisplayName("Return to previous menu"); - nameTag.setItemMeta(tagMeta); - icon.setItemMeta(iconMeta); - back.setItemMeta(backMeta); - newInv.setItem(0, nameTag); - newInv.setItem(1, icon); - newInv.setItem(8, back); - e.getWhoClicked().openInventory(newInv); + if (!(e.getClickedInventory() instanceof PlayerInventory)) { + int max = pl.getVarPerm("treebotrunk.barrel", (Player) e.getWhoClicked()); + if (e.getSlot() < max + 1) { + ClickType cT = e.getClick(); + if (cT == ClickType.LEFT) { + Bukkit.dispatchCommand(e.getWhoClicked(), "barrel " + e.getSlot()); + } else if (cT == ClickType.RIGHT) { + Inventory newInv = Bukkit.createInventory(null, 9, pl.badge + " Configure_Barrel_" + e.getSlot() + "_" + world); + ItemStack nameTag = new ItemStack(Material.NAME_TAG, 1); + ItemStack icon = new ItemStack(Material.FILLED_MAP, 1); + ItemStack back = new ItemStack(Material.BARRIER, 1); + ItemMeta tagMeta = nameTag.getItemMeta(); + ItemMeta iconMeta = icon.getItemMeta(); + ItemMeta backMeta = back.getItemMeta(); + tagMeta.setDisplayName("Rename Barrel " + e.getSlot() + "_" + world); + iconMeta.setDisplayName("Set icon for Barrel " + e.getSlot() + "_" + world); + backMeta.setDisplayName("Return to previous menu"); + nameTag.setItemMeta(tagMeta); + icon.setItemMeta(iconMeta); + back.setItemMeta(backMeta); + newInv.setItem(0, nameTag); + newInv.setItem(1, icon); + newInv.setItem(8, back); + e.getWhoClicked().openInventory(newInv); + } } } } @@ -340,35 +350,46 @@ public void inventoryClickListener(InventoryClickEvent e) { e.getWhoClicked().closeInventory(); } else { e.setCancelled(true); - String type = e.getView().getTitle().split("_")[1].toLowerCase(); - String uuid = e.getWhoClicked().getUniqueId().toString(); - String slot = e.getView().getTitle().split("_")[2]; - Inventory inv = e.getInventory(); - if (e.getInventory().getItem(e.getSlot()) != null && e.getInventory().getItem(e.getSlot()).getType() != Material.AIR) { - if (e.getInventory().getItem(e.getSlot()).getType() == Material.NAME_TAG) { - e.getWhoClicked().closeInventory(); - e.getWhoClicked().sendMessage(pl.badge + ChatColor.GOLD + " Enter the new name for " + type + " " + slot + "_" + world); - pl.getConfig().set("ListeningTo." + e.getWhoClicked().getUniqueId().toString(), true); - pl.getConfig().set("ValuesFor." + e.getWhoClicked().getUniqueId().toString() + ".type", type.toLowerCase()); - pl.getConfig().set("ValuesFor." + e.getWhoClicked().getUniqueId().toString() + ".number", slot); - } else if (e.getInventory().getItem(e.getSlot()).getType() == Material.FILLED_MAP) { - ItemStack item = e.getWhoClicked().getInventory().getItemInMainHand(); - if (item.getType() != Material.AIR) { - File invFile = new File(pl.getDataFolder() + File.separator + type + File.separator, e.getWhoClicked().getUniqueId().toString() + "_" + type + "_" + slot + "_" + world + ".yml"); - FileConfiguration invYaml = YamlConfiguration.loadConfiguration(invFile); - invYaml.set("icon", item.getType().name().toUpperCase()); - try { - invYaml.save(invFile); - } catch (IOException err) { - err.printStackTrace(); + if (!(e.getClickedInventory() instanceof PlayerInventory)) { + String type = e.getView().getTitle().split("_")[1].toLowerCase(); + String uuid = e.getWhoClicked().getUniqueId().toString(); + String slot = e.getView().getTitle().split("_")[2]; + Inventory inv = e.getInventory(); + if (e.getInventory().getItem(e.getSlot()) != null && e.getInventory().getItem(e.getSlot()).getType() != Material.AIR) { + if (e.getInventory().getItem(e.getSlot()).getType() == Material.NAME_TAG) { + e.getWhoClicked().closeInventory(); + e.getWhoClicked().sendMessage(pl.badge + ChatColor.GOLD + " Enter the new name for " + type + " " + slot + "_" + world); + Bukkit.getScheduler().runTaskLaterAsynchronously(pl, new Runnable() { + @Override + public void run() { + if(pl.getConfig().getBoolean("ListeningTo." + e.getWhoClicked().getUniqueId().toString())){ + pl.getConfig().set("ListeningTo." + e.getWhoClicked().getUniqueId().toString(), false); + e.getWhoClicked().sendMessage(pl.badge + ChatColor.RED + " Timeout: " + ChatColor.GOLD +"No longer monitoring user input for rename."); + } + } + }, 300); + pl.getConfig().set("ListeningTo." + e.getWhoClicked().getUniqueId().toString(), true); + pl.getConfig().set("ValuesFor." + e.getWhoClicked().getUniqueId().toString() + ".type", type.toLowerCase()); + pl.getConfig().set("ValuesFor." + e.getWhoClicked().getUniqueId().toString() + ".number", slot); + } else if (e.getInventory().getItem(e.getSlot()).getType() == Material.FILLED_MAP) { + ItemStack item = e.getWhoClicked().getInventory().getItemInMainHand(); + if (item.getType() != Material.AIR) { + File invFile = new File(pl.getDataFolder() + File.separator + type + File.separator, e.getWhoClicked().getUniqueId().toString() + "_" + type + "_" + slot + "_" + world + ".yml"); + FileConfiguration invYaml = YamlConfiguration.loadConfiguration(invFile); + invYaml.set("icon", item.getType().name().toUpperCase()); + try { + invYaml.save(invFile); + } catch (IOException err) { + err.printStackTrace(); + } + e.getWhoClicked().sendMessage(pl.badge + " Icon set for " + type + " " + slot); + Bukkit.dispatchCommand(e.getWhoClicked(), "" + type + "s"); + } else { + e.getWhoClicked().sendMessage(pl.badge + " You must hold an item to use as an icon in your main hand"); } - e.getWhoClicked().sendMessage(pl.badge + " Icon set for " + type + " " + slot); - Bukkit.dispatchCommand(e.getWhoClicked(), "/" + type + "s"); - } else { - e.getWhoClicked().sendMessage(pl.badge + " You must hold an item to use as an icon in your main hand"); + } else if (e.getInventory().getItem(e.getSlot()).getType() == Material.BARRIER) { + Bukkit.dispatchCommand(e.getWhoClicked(), "" + type + "s"); } - } else if (e.getInventory().getItem(e.getSlot()).getType() == Material.BARRIER) { - Bukkit.dispatchCommand(e.getWhoClicked(), "/" + type + "s"); } } } @@ -388,6 +409,7 @@ public void chatEvent(AsyncPlayerChatEvent e) { invYaml.set("title", e.getMessage().replace(" ", "_").replace("'", "").replace("/", "").replace("\"", "")); pl.getConfig().set("ListeningTo." + p.getUniqueId().toString(), null); pl.getConfig().set("ValuesFor." + p.getUniqueId().toString(), null); + p.sendMessage(pl.badge + " Name set for " + type + " " + slot); try { invYaml.save(invFile); diff --git a/src/main/java/me/shakeforprotein/treebotrunks/TreeboTrunk.java b/src/main/java/me/shakeforprotein/treebotrunks/TreeboTrunk.java index ec1f496..ae46228 100644 --- a/src/main/java/me/shakeforprotein/treebotrunks/TreeboTrunk.java +++ b/src/main/java/me/shakeforprotein/treebotrunks/TreeboTrunk.java @@ -1,5 +1,14 @@ package me.shakeforprotein.treebotrunks; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.BukkitUtil; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.regions.RegionQuery; import me.shakeforprotein.treebotrunks.Commands.*; import me.shakeforprotein.treebotrunks.Listeners.InventoryListener; import me.shakeforprotein.treebotrunks.Listeners.JoinListener; @@ -7,6 +16,7 @@ import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -31,6 +41,10 @@ public final class TreeboTrunk extends JavaPlugin { public Boolean requiresUpdate = false; public static String spigotVersion = "0"; public HashMap notifyHash = new HashMap<>(); + public WorldGuard worldGuard = WorldGuard.getInstance(); + public WorldGuardPlugin worldGuardPlugin = WorldGuardPlugin.inst(); + public WorldEdit worldEdit = WorldEdit.getInstance(); + public WorldEditPlugin worldEditPlugin = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); @Override public void onEnable() { @@ -60,13 +74,13 @@ public void onEnable() { Bukkit.getPluginManager().registerEvents(new InventoryListener(this), this); Bukkit.getPluginManager().registerEvents(new JoinListener(this), this); - if(getConfig().get("bstatsIntegration") != null) { + if (getConfig().get("bstatsIntegration") != null) { if (getConfig().getBoolean("bstatsIntegration")) { Metrics metrics = new Metrics(this); } } - if(getConfig().get("updateChecker") != null){ - if(getConfig().getBoolean("checkUpdates")) { + if (getConfig().get("updateChecker") != null) { + if (getConfig().getBoolean("checkUpdates")) { if (getConfig().getString("updateChecker").equalsIgnoreCase("spigot")) { new SpigotUpdateChecker(this, 73787).getVersion(version -> { if (!this.getDescription().getVersion().equalsIgnoreCase(version)) { @@ -81,14 +95,14 @@ public void onEnable() { } } } - if(getConfig().get("whitelistBlocks") != null){ + if (getConfig().get("whitelistBlocks") != null) { List whiteList = new ArrayList<>(); whiteList = getConfig().getStringList("whitelistBlocks"); - for(String item : whiteList){ + for (String item : whiteList) { whitelistHash.putIfAbsent(Material.valueOf(item), Material.valueOf(item)); } } - } + } @Override public void onDisable() { @@ -109,35 +123,31 @@ public static int getVarPerm(String perm, Player p) { return max; } - public static boolean isNumeric (String str) - { + public static boolean isNumeric(String str) { return str.matches("\\d+"); } - public void openInventory(String type, Player p, int container){ + public void openInventory(String type, Player p, int container) { String world = p.getWorld().getName().split("_")[0]; int size = 9; String icon = "CHEST"; - if(type.equalsIgnoreCase("belt")){ + if (type.equalsIgnoreCase("belt")) { icon = "LEAD"; size = 9; - } - else if(type.equalsIgnoreCase("barrel")){ + } else if (type.equalsIgnoreCase("barrel")) { size = 27; icon = "BARREL"; - } - else if(type.equalsIgnoreCase("chest")){ + } else if (type.equalsIgnoreCase("chest")) { size = 54; - } - else{ + } else { p.sendMessage(badge + err + "Invalid inventory specification"); } File invFile = new File(this.getDataFolder() + File.separator + type + File.separator, p.getUniqueId().toString() + "_" + type + "_" + container + "_" + world + ".yml"); FileConfiguration invYaml = YamlConfiguration.loadConfiguration(invFile); Inventory thisInv = Bukkit.createInventory(null, size, badge + p.getUniqueId().toString() + "_" + type + "_" + container); - if(invFile.exists()){ - if(invYaml.getConfigurationSection("Inventory") != null) { + if (invFile.exists()) { + if (invYaml.getConfigurationSection("Inventory") != null) { for (String key : invYaml.getConfigurationSection("Inventory").getKeys(false)) { thisInv.setItem(invYaml.getInt("Inventory." + key + ".slot"), invYaml.getItemStack("Inventory." + key + ".item")); } @@ -150,4 +160,19 @@ else if(type.equalsIgnoreCase("chest")){ invFile = null; invYaml = null; } + + public boolean canBuild(LocalPlayer p, Location l) { + RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); + com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(l); + if (!hasBypass(p, l)) { + return query.testState(loc, p, Flags.BUILD); + } else { + return true; + } + } + + + public boolean hasBypass(LocalPlayer p, Location l) { + return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(p, p.getWorld()); + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fb666be..2ba74b9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,6 +5,7 @@ api-version: 1.13 authors: [ShakeforProtein] description: Mass virtual chest storage website: http://treebomc.com +depend: [WorldGuard, WorldEdit] commands: belt: @@ -51,20 +52,20 @@ commands: usage: "/loom" description: "Temporarily Places a loom at your feet if the block is clear" furnace: - permission: treebotrunk.loom - usage: "/loom" + permission: treebotrunk.furnace + usage: "/furnace" description: "Temporarily Places a Furnace at your feet if the block is clear" blastfurnace: - permission: treebotrunk.loom - usage: "/loom" + permission: treebotrunk.blastfurnace + usage: "/blastfurnace" description: "Temporarily Places a Blast Furnace at your feet if the block is clear" smoker: - permission: treebotrunk.loom - usage: "/loom" - description: "Temporarily Places a Smoke at your feet if the block is clear" + permission: treebotrunk.smoker + usage: "/smoker" + description: "Temporarily Places a Smoker at your feet if the block is clear" brew: permission: treebotrunk.brew - usage: "/loom" + usage: "/brew" description: "Temporarily Places a Brewing Stand at your feet if the block is clear" chests: permission: treebotrunk.chest.open @@ -73,7 +74,7 @@ commands: barrels: permission: treebotrunk.barrel.open permissions: - treebotrunk.admin: + treebotrunks.admin: default: op description: Allows player to see update notifications treebotrunk.belt.open: