3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-27 12:00:07 +01:00

Various fixes and improvements

- Added support for PlotSquared
- Added generic checks for other plugins (e.g. PlotMe)
- Added checks for stand movement (so you can't move your stand outside
your region)
- Added checks for '*' nodes and operator in permission checking
- other minor tweaks
Dieser Commit ist enthalten in:
boy0001 2015-03-13 15:57:51 +11:00
Ursprung cb097b0a63
Commit 37ebbd9e37
7 geänderte Dateien mit 150 neuen und 29 gelöschten Zeilen

6
.gitignore vendored
Datei anzeigen

@ -1,4 +1,8 @@
.idea/ .idea/
libs/ libs/
out/ out/
ArmorStand.iml ArmorStand.iml
/bin/
*.project
.classpath

Datei anzeigen

@ -23,6 +23,9 @@ class Commands implements CommandExecutor {
return false; return false;
} }
Player p = (Player) sender; Player p = (Player) sender;
if (!Utils.hasPermissionNode(p, "astools.command")) {
p.sendMessage(ChatColor.RED + "You don't have permission to use this command");
}
if(args.length == 0) { if(args.length == 0) {
UUID uuid = p.getUniqueId(); UUID uuid = p.getUniqueId();
if(plugin.savedInventories.containsKey(uuid)) { if(plugin.savedInventories.containsKey(uuid)) {
@ -39,7 +42,7 @@ class Commands implements CommandExecutor {
} }
} }
if(args[0].equalsIgnoreCase("reload")) { if(args[0].equalsIgnoreCase("reload")) {
if(p.hasPermission("astools.reload")) { if(Utils.hasPermissionNode(p, "astools.reload")) {
Config.reload(); Config.reload();
p.sendMessage(ChatColor.GREEN + Config.conReload); p.sendMessage(ChatColor.GREEN + Config.conReload);
return true; return true;

Datei anzeigen

@ -100,6 +100,12 @@ class Config {
invulnerable = config.getBoolean("invulnerable"); invulnerable = config.getBoolean("invulnerable");
equipmentLock = config.getBoolean("equipmentLock"); equipmentLock = config.getBoolean("equipmentLock");
plugin.carryingArmorStand.clear(); plugin.carryingArmorStand.clear();
Plugin plotSquared = plugin.getServer().getPluginManager().getPlugin("PlotSquared");
if (plotSquared != null && plotSquared.isEnabled()) {
new PlotSquaredHook(plugin);
}
Plugin worldGuard = plugin.getServer().getPluginManager().getPlugin("WorldGuard"); Plugin worldGuard = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
worldGuardPlugin = worldGuard == null || !(worldGuard instanceof WorldGuardPlugin) ? null : (WorldGuardPlugin) worldGuard; worldGuardPlugin = worldGuard == null || !(worldGuard instanceof WorldGuardPlugin) ? null : (WorldGuardPlugin) worldGuard;
if(config.getBoolean("integrateWithWorldGuard")) { if(config.getBoolean("integrateWithWorldGuard")) {

Datei anzeigen

@ -1,5 +1,6 @@
package com.gmail.St3venAU.plugins.ArmorStandTools; package com.gmail.St3venAU.plugins.ArmorStandTools;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -14,6 +15,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -53,16 +55,24 @@ public class MainListener implements Listener {
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
if (event.getRightClicked() instanceof ArmorStand) { if (event.getRightClicked() instanceof ArmorStand) {
Player p = event.getPlayer(); Player p = event.getPlayer();
if(plugin.carryingArmorStand.containsKey(p.getUniqueId()) && playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) { if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) {
plugin.carryingArmorStand.remove(p.getUniqueId()); if (playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) {
Utils.actionBarMsg(p, Config.asDropped); plugin.carryingArmorStand.remove(p.getUniqueId());
event.setCancelled(true); Utils.actionBarMsg(p, Config.asDropped);
return; event.setCancelled(true);
return;
}
else {
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
}
} }
ArmorStandTool tool = ArmorStandTool.get(p.getItemInHand()); ArmorStandTool tool = ArmorStandTool.get(p.getItemInHand());
if(tool == null) return; if(tool == null) return;
ArmorStand as = (ArmorStand) event.getRightClicked(); ArmorStand as = (ArmorStand) event.getRightClicked();
if (!playerHasPermission(p, event.getRightClicked().getLocation().getBlock(), tool)) return; if (!playerHasPermission(p, event.getRightClicked().getLocation().getBlock(), tool)) {
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
return;
}
double num = event.getClickedPosition().getY() - 0.05; double num = event.getClickedPosition().getY() - 0.05;
if (num < 0) { if (num < 0) {
num = 0; num = 0;
@ -264,8 +274,12 @@ public class MainListener implements Listener {
Utils.actionBarMsg(p, Config.asDropped); Utils.actionBarMsg(p, Config.asDropped);
return; return;
} }
as.teleport(Utils.getLocationFacingPlayer(p)); Location loc = Utils.getLocationFacingPlayer(p);
Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying); Block block = loc.getBlock();
if (playerHasPermission(p, block, null)) {
as.teleport(loc);
Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying);
}
} }
} }
@ -337,10 +351,16 @@ public class MainListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Player p = event.getPlayer(); Player p = event.getPlayer();
if(plugin.carryingArmorStand.containsKey(p.getUniqueId()) && playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) { if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) {
plugin.carryingArmorStand.remove(p.getUniqueId()); boolean perm = playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null);
Utils.actionBarMsg(p, Config.asDropped); if (perm) {
event.setCancelled(true); plugin.carryingArmorStand.remove(p.getUniqueId());
Utils.actionBarMsg(p, Config.asDropped);
event.setCancelled(true);
}
else {
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
}
return; return;
} }
Action action = event.getAction(); Action action = event.getAction();
@ -351,8 +371,11 @@ public class MainListener implements Listener {
Utils.cycleInventory(p); Utils.cycleInventory(p);
return; return;
} }
if(action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { else if(action == Action.RIGHT_CLICK_BLOCK) {
if(!playerHasPermission(p, p.getLocation().getBlock(), tool)) return; if (!playerHasPermission(p, event.getClickedBlock(), tool)) {
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
return;
}
switch (tool) { switch (tool) {
case SUMMON: case SUMMON:
event.setCancelled(true); event.setCancelled(true);
@ -565,20 +588,49 @@ public class MainListener implements Listener {
} }
return null; return null;
} }
public boolean checkPermission(Player player, Block block) {
// Check PlotSquared
Location loc = block.getLocation();
if (PlotSquaredHook.api != null) {
if (PlotSquaredHook.isPlotWorld(loc)) {
boolean result = PlotSquaredHook.checkPermission(player, loc);
return result;
}
}
// check WorldGuard
if(Config.worldGuardPlugin != null) {
boolean canBuild = Config.worldGuardPlugin.canBuild(player, block);
return canBuild;
}
// Use standard permission checking (will support basically any plugin)
BlockBreakEvent mybreak = new BlockBreakEvent(block, player);
Bukkit.getServer().getPluginManager().callEvent(mybreak);
boolean hasperm;
if (mybreak.isCancelled()) {
hasperm = false;
} else {
hasperm = true;
}
BlockPlaceEvent place = new BlockPlaceEvent(block, block.getState(), block, null, player, true);
Bukkit.getServer().getPluginManager().callEvent(place);
if (place.isCancelled()) {
hasperm = false;
}
return hasperm;
}
boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) { boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) {
if(!p.isOp() && (!p.hasPermission("astools.use") if(tool != null && !p.isOp() && (!Utils.hasPermissionNode(p, "astools.use")
|| (ArmorStandTool.SAVE == tool && !p.hasPermission("astools.cmdblock")) || (ArmorStandTool.SAVE == tool && !Utils.hasPermissionNode(p, "astools.cmdblock"))
|| (ArmorStandTool.CLONE == tool && !p.hasPermission("astools.clone")))) { || (ArmorStandTool.CLONE == tool && !Utils.hasPermissionNode(p, "astools.clone")))) {
p.sendMessage(ChatColor.RED + Config.noPerm); p.sendMessage(ChatColor.RED + Config.noPerm);
return false; return false;
} }
if(Config.worldGuardPlugin == null) return true; return checkPermission(p, b);
boolean canBuild = Config.worldGuardPlugin.canBuild(p, b);
if(!canBuild) {
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
}
return canBuild;
} }
void pickUpArmorStand(ArmorStand as, Player p, boolean newlySummoned) { void pickUpArmorStand(ArmorStand as, Player p, boolean newlySummoned) {

Datei anzeigen

@ -0,0 +1,40 @@
package com.gmail.St3venAU.plugins.ArmorStandTools;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class PlotSquaredHook {
public static PlotAPI api = null;
public PlotSquaredHook(Main plugin) {
PlotSquaredHook.api = new PlotAPI(plugin);
}
public static boolean isPlotWorld(Location loc) {
World world = loc.getWorld();
return api.isPlotWorld(world);
}
public static boolean checkPermission(Player player, Location loc) {
Plot plot = api.getPlot(loc);
if (plot == null) {
return Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.admin.build.road");
}
PlotPlayer pp = BukkitUtil.getPlayer(player);
UUID uuid = pp.getUUID();
if (plot.isAdded(uuid)) {
return true;
}
return Permissions.hasPermission(pp, "plots.admin.build.other");
}
}

Datei anzeigen

@ -24,6 +24,24 @@ class Utils {
} }
return false; return false;
} }
public static boolean hasPermissionNode(Player player, String perm) {
if ((player == null) || player.isOp()) {
return true;
}
if (player.hasPermission(perm)) {
return true;
}
final String[] nodes = perm.split("\\.");
final StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i] + ("."));
if (player.hasPermission(n + "*")) {
return true;
}
}
return false;
}
static boolean hasItems(Player p) { static boolean hasItems(Player p) {
for(ItemStack i : p.getInventory()) { for(ItemStack i : p.getInventory()) {

Datei anzeigen

@ -8,6 +8,4 @@ commands:
astools: astools:
description: Give yourself all of the armor stand tools (Warning; clears your inventory). description: Give yourself all of the armor stand tools (Warning; clears your inventory).
aliases: ast aliases: ast
usage: Usage /astools or /astools reload usage: Usage /astools or /astools reload
permission: astools.command
permission-message: You don't have permission to use this command