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:
Ursprung
cb097b0a63
Commit
37ebbd9e37
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,3 +2,7 @@
|
||||
libs/
|
||||
out/
|
||||
ArmorStand.iml
|
||||
/bin/
|
||||
|
||||
*.project
|
||||
.classpath
|
@ -23,6 +23,9 @@ class Commands implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
if(plugin.savedInventories.containsKey(uuid)) {
|
||||
@ -39,7 +42,7 @@ class Commands implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
if(args[0].equalsIgnoreCase("reload")) {
|
||||
if(p.hasPermission("astools.reload")) {
|
||||
if(Utils.hasPermissionNode(p, "astools.reload")) {
|
||||
Config.reload();
|
||||
p.sendMessage(ChatColor.GREEN + Config.conReload);
|
||||
return true;
|
||||
|
@ -100,6 +100,12 @@ class Config {
|
||||
invulnerable = config.getBoolean("invulnerable");
|
||||
equipmentLock = config.getBoolean("equipmentLock");
|
||||
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");
|
||||
worldGuardPlugin = worldGuard == null || !(worldGuard instanceof WorldGuardPlugin) ? null : (WorldGuardPlugin) worldGuard;
|
||||
if(config.getBoolean("integrateWithWorldGuard")) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.St3venAU.plugins.ArmorStandTools;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -14,6 +15,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
@ -53,16 +55,24 @@ public class MainListener implements Listener {
|
||||
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
|
||||
if (event.getRightClicked() instanceof ArmorStand) {
|
||||
Player p = event.getPlayer();
|
||||
if(plugin.carryingArmorStand.containsKey(p.getUniqueId()) && playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) {
|
||||
plugin.carryingArmorStand.remove(p.getUniqueId());
|
||||
Utils.actionBarMsg(p, Config.asDropped);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) {
|
||||
if (playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) {
|
||||
plugin.carryingArmorStand.remove(p.getUniqueId());
|
||||
Utils.actionBarMsg(p, Config.asDropped);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
|
||||
}
|
||||
}
|
||||
ArmorStandTool tool = ArmorStandTool.get(p.getItemInHand());
|
||||
if(tool == null) return;
|
||||
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;
|
||||
if (num < 0) {
|
||||
num = 0;
|
||||
@ -264,8 +274,12 @@ public class MainListener implements Listener {
|
||||
Utils.actionBarMsg(p, Config.asDropped);
|
||||
return;
|
||||
}
|
||||
as.teleport(Utils.getLocationFacingPlayer(p));
|
||||
Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying);
|
||||
Location loc = Utils.getLocationFacingPlayer(p);
|
||||
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
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if(plugin.carryingArmorStand.containsKey(p.getUniqueId()) && playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) {
|
||||
plugin.carryingArmorStand.remove(p.getUniqueId());
|
||||
Utils.actionBarMsg(p, Config.asDropped);
|
||||
event.setCancelled(true);
|
||||
if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) {
|
||||
boolean perm = playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null);
|
||||
if (perm) {
|
||||
plugin.carryingArmorStand.remove(p.getUniqueId());
|
||||
Utils.actionBarMsg(p, Config.asDropped);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else {
|
||||
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Action action = event.getAction();
|
||||
@ -351,8 +371,11 @@ public class MainListener implements Listener {
|
||||
Utils.cycleInventory(p);
|
||||
return;
|
||||
}
|
||||
if(action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
|
||||
if(!playerHasPermission(p, p.getLocation().getBlock(), tool)) return;
|
||||
else if(action == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (!playerHasPermission(p, event.getClickedBlock(), tool)) {
|
||||
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
|
||||
return;
|
||||
}
|
||||
switch (tool) {
|
||||
case SUMMON:
|
||||
event.setCancelled(true);
|
||||
@ -566,19 +589,48 @@ public class MainListener implements Listener {
|
||||
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) {
|
||||
if(!p.isOp() && (!p.hasPermission("astools.use")
|
||||
|| (ArmorStandTool.SAVE == tool && !p.hasPermission("astools.cmdblock"))
|
||||
|| (ArmorStandTool.CLONE == tool && !p.hasPermission("astools.clone")))) {
|
||||
if(tool != null && !p.isOp() && (!Utils.hasPermissionNode(p, "astools.use")
|
||||
|| (ArmorStandTool.SAVE == tool && !Utils.hasPermissionNode(p, "astools.cmdblock"))
|
||||
|| (ArmorStandTool.CLONE == tool && !Utils.hasPermissionNode(p, "astools.clone")))) {
|
||||
p.sendMessage(ChatColor.RED + Config.noPerm);
|
||||
return false;
|
||||
}
|
||||
if(Config.worldGuardPlugin == null) return true;
|
||||
boolean canBuild = Config.worldGuardPlugin.canBuild(p, b);
|
||||
if(!canBuild) {
|
||||
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
|
||||
}
|
||||
return canBuild;
|
||||
return checkPermission(p, b);
|
||||
}
|
||||
|
||||
void pickUpArmorStand(ArmorStand as, Player p, boolean newlySummoned) {
|
||||
|
40
src/com/gmail/St3venAU/plugins/ArmorStandTools/PlotSquaredHook.java
Normale Datei
40
src/com/gmail/St3venAU/plugins/ArmorStandTools/PlotSquaredHook.java
Normale Datei
@ -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");
|
||||
}
|
||||
}
|
@ -25,6 +25,24 @@ class Utils {
|
||||
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) {
|
||||
for(ItemStack i : p.getInventory()) {
|
||||
if(ArmorStandTool.isTool(i)) {
|
||||
|
@ -9,5 +9,3 @@ commands:
|
||||
description: Give yourself all of the armor stand tools (Warning; clears your inventory).
|
||||
aliases: ast
|
||||
usage: Usage /astools or /astools reload
|
||||
permission: astools.command
|
||||
permission-message: You don't have permission to use this command
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren