3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-28 04:20:08 +01:00

Simplified permission checks

Dieser Commit ist enthalten in:
St3venAU 2015-03-11 21:48:57 +08:00
Ursprung caccc66e71
Commit cb097b0a63

Datei anzeigen

@ -53,17 +53,16 @@ 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()) && !permissionCheck(plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), p)) { if(plugin.carryingArmorStand.containsKey(p.getUniqueId()) && playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) {
plugin.carryingArmorStand.remove(p.getUniqueId()); plugin.carryingArmorStand.remove(p.getUniqueId());
Utils.actionBarMsg(p, Config.asDropped); Utils.actionBarMsg(p, Config.asDropped);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!p.hasPermission("astools.use") && !p.isOp()) return;
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();
Block b = as.getLocation().getBlock(); if (!playerHasPermission(p, event.getRightClicked().getLocation().getBlock(), tool)) 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;
@ -76,157 +75,115 @@ public class MainListener implements Listener {
switch(tool) { switch(tool) {
case HEADX: case HEADX:
if(permissionCheck(b, p)) return;
as.setHeadPose(as.getHeadPose().setX(angle)); as.setHeadPose(as.getHeadPose().setX(angle));
break; break;
case HEADY: case HEADY:
if(permissionCheck(b, p)) return;
as.setHeadPose(as.getHeadPose().setY(angle)); as.setHeadPose(as.getHeadPose().setY(angle));
break; break;
case HEADZ: case HEADZ:
if(permissionCheck(b, p)) return;
as.setHeadPose(as.getHeadPose().setZ(angle)); as.setHeadPose(as.getHeadPose().setZ(angle));
break; break;
case LARMX: case LARMX:
if(permissionCheck(b, p)) return;
as.setLeftArmPose(as.getLeftArmPose().setX(angle)); as.setLeftArmPose(as.getLeftArmPose().setX(angle));
break; break;
case LARMY: case LARMY:
if(permissionCheck(b, p)) return;
as.setLeftArmPose(as.getLeftArmPose().setY(angle)); as.setLeftArmPose(as.getLeftArmPose().setY(angle));
break; break;
case LARMZ: case LARMZ:
if(permissionCheck(b, p)) return;
as.setLeftArmPose(as.getLeftArmPose().setZ(angle)); as.setLeftArmPose(as.getLeftArmPose().setZ(angle));
break; break;
case RARMX: case RARMX:
if(permissionCheck(b, p)) return;
as.setRightArmPose(as.getRightArmPose().setX(angle)); as.setRightArmPose(as.getRightArmPose().setX(angle));
break; break;
case RARMY: case RARMY:
if(permissionCheck(b, p)) return;
as.setRightArmPose(as.getRightArmPose().setY(angle)); as.setRightArmPose(as.getRightArmPose().setY(angle));
break; break;
case RARMZ: case RARMZ:
if(permissionCheck(b, p)) return;
as.setRightArmPose(as.getRightArmPose().setZ(angle)); as.setRightArmPose(as.getRightArmPose().setZ(angle));
break; break;
case LLEGX: case LLEGX:
if(permissionCheck(b, p)) return;
as.setLeftLegPose(as.getLeftLegPose().setX(angle)); as.setLeftLegPose(as.getLeftLegPose().setX(angle));
break; break;
case LLEGY: case LLEGY:
if(permissionCheck(b, p)) return;
as.setLeftLegPose(as.getLeftLegPose().setY(angle)); as.setLeftLegPose(as.getLeftLegPose().setY(angle));
break; break;
case LLEGZ: case LLEGZ:
if(permissionCheck(b, p)) return;
as.setLeftLegPose(as.getLeftLegPose().setZ(angle)); as.setLeftLegPose(as.getLeftLegPose().setZ(angle));
break; break;
case RLEGX: case RLEGX:
if(permissionCheck(b, p)) return;
as.setRightLegPose(as.getRightLegPose().setX(angle)); as.setRightLegPose(as.getRightLegPose().setX(angle));
break; break;
case RLEGY: case RLEGY:
if(permissionCheck(b, p)) return;
as.setRightLegPose(as.getRightLegPose().setY(angle)); as.setRightLegPose(as.getRightLegPose().setY(angle));
break; break;
case RLEGZ: case RLEGZ:
if(permissionCheck(b, p)) return;
as.setRightLegPose(as.getRightLegPose().setZ(angle)); as.setRightLegPose(as.getRightLegPose().setZ(angle));
break; break;
case BODYX: case BODYX:
if(permissionCheck(b, p)) return;
as.setBodyPose(as.getBodyPose().setX(angle)); as.setBodyPose(as.getBodyPose().setX(angle));
break; break;
case BODYY: case BODYY:
if(permissionCheck(b, p)) return;
as.setBodyPose(as.getBodyPose().setY(angle)); as.setBodyPose(as.getBodyPose().setY(angle));
break; break;
case BODYZ: case BODYZ:
if(permissionCheck(b, p)) return;
as.setBodyPose(as.getBodyPose().setZ(angle)); as.setBodyPose(as.getBodyPose().setZ(angle));
break; break;
case MOVEX: case MOVEX:
if(permissionCheck(b, p)) return;
as.teleport(as.getLocation().add(0.05 * (p.isSneaking() ? -1 : 1), 0.0, 0.0)); as.teleport(as.getLocation().add(0.05 * (p.isSneaking() ? -1 : 1), 0.0, 0.0));
break; break;
case MOVEY: case MOVEY:
if(permissionCheck(b, p)) return;
as.teleport(as.getLocation().add(0.0, 0.05 * (p.isSneaking() ? -1 : 1), 0.0)); as.teleport(as.getLocation().add(0.0, 0.05 * (p.isSneaking() ? -1 : 1), 0.0));
break; break;
case MOVEZ: case MOVEZ:
if(permissionCheck(b, p)) return;
as.teleport(as.getLocation().add(0.0, 0.0, 0.05 * (p.isSneaking() ? -1 : 1))); as.teleport(as.getLocation().add(0.0, 0.0, 0.05 * (p.isSneaking() ? -1 : 1)));
break; break;
case ROTAT: case ROTAT:
if(permissionCheck(b, p)) return;
Location l = as.getLocation(); Location l = as.getLocation();
l.setYaw(((float) num) * 180F); l.setYaw(((float) num) * 180F);
as.teleport(l); as.teleport(l);
break; break;
case INVIS: case INVIS:
if(permissionCheck(b, p)) return;
as.setVisible(!as.isVisible()); as.setVisible(!as.isVisible());
p.sendMessage(ChatColor.GREEN + Config.asVisible + ": " + (as.isVisible() ? Config.isTrue : Config.isFalse)); p.sendMessage(ChatColor.GREEN + Config.asVisible + ": " + (as.isVisible() ? Config.isTrue : Config.isFalse));
break; break;
case CLONE: case CLONE:
if (p.hasPermission("astools.clone") || p.isOp()) { pickUpArmorStand(clone(as), p, true);
if(permissionCheck(b, p)) return; p.sendMessage(ChatColor.GREEN + Config.asCloned);
pickUpArmorStand(clone(as), p, true); Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying);
p.sendMessage(ChatColor.GREEN + Config.asCloned);
Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying);
} else {
p.sendMessage(ChatColor.RED + Config.noPerm);
}
break; break;
case SAVE: case SAVE:
if (p.hasPermission("astools.cmdblock") || p.isOp()) { generateCmdBlock(p.getLocation(), as);
if(permissionCheck(b, p)) return; p.sendMessage(ChatColor.GREEN + Config.cbCreated);
generateCmdBlock(p.getLocation(), as);
p.sendMessage(ChatColor.GREEN + Config.cbCreated);
} else {
p.sendMessage(ChatColor.RED + Config.noPerm);
}
break; break;
case SIZE: case SIZE:
if(permissionCheck(b, p)) return;
as.setSmall(!as.isSmall()); as.setSmall(!as.isSmall());
p.sendMessage(ChatColor.GREEN + Config.size + ": " + (as.isSmall() ? Config.small : Config.normal)); p.sendMessage(ChatColor.GREEN + Config.size + ": " + (as.isSmall() ? Config.small : Config.normal));
break; break;
case BASE: case BASE:
if(permissionCheck(b, p)) return;
as.setBasePlate(!as.hasBasePlate()); as.setBasePlate(!as.hasBasePlate());
p.sendMessage(ChatColor.GREEN + Config.basePlate + ": " + (as.hasBasePlate() ? Config.isOn : Config.isOff)); p.sendMessage(ChatColor.GREEN + Config.basePlate + ": " + (as.hasBasePlate() ? Config.isOn : Config.isOff));
break; break;
case GRAV: case GRAV:
if(permissionCheck(b, p)) return;
as.setGravity(!as.hasGravity()); as.setGravity(!as.hasGravity());
p.sendMessage(ChatColor.GREEN + Config.gravity + ": " + (as.hasGravity() ? Config.isOn : Config.isOff)); p.sendMessage(ChatColor.GREEN + Config.gravity + ": " + (as.hasGravity() ? Config.isOn : Config.isOff));
break; break;
case ARMS: case ARMS:
if(permissionCheck(b, p)) return;
as.setArms(!as.hasArms()); as.setArms(!as.hasArms());
p.sendMessage(ChatColor.GREEN + Config.arms + ": " + (as.hasArms() ? Config.isOn : Config.isOff)); p.sendMessage(ChatColor.GREEN + Config.arms + ": " + (as.hasArms() ? Config.isOn : Config.isOff));
break; break;
case NAME: case NAME:
if(permissionCheck(b, p)) return;
setName(p, as); setName(p, as);
break; break;
case PHEAD: case PHEAD:
if(permissionCheck(b, p)) return;
setPlayerSkull(p, as); setPlayerSkull(p, as);
break; break;
case INVUL: case INVUL:
if(permissionCheck(b, p)) return;
p.sendMessage(ChatColor.GREEN + Config.invul + ": " + (NBT.toggleInvulnerability(as) ? Config.isOn : Config.isOff)); p.sendMessage(ChatColor.GREEN + Config.invul + ": " + (NBT.toggleInvulnerability(as) ? Config.isOn : Config.isOff));
break; break;
case SLOTS: case SLOTS:
if(permissionCheck(b, p)) return;
p.sendMessage(ChatColor.GREEN + Config.equip + ": " + (NBT.toggleSlotsDisabled(as) ? Config.locked : Config.unLocked)); p.sendMessage(ChatColor.GREEN + Config.equip + ": " + (NBT.toggleSlotsDisabled(as) ? Config.locked : Config.unLocked));
break; break;
case MOVE: case MOVE:
if(permissionCheck(b, p)) return;
UUID uuid = p.getUniqueId(); UUID uuid = p.getUniqueId();
if(plugin.carryingArmorStand.containsKey(uuid)) { if(plugin.carryingArmorStand.containsKey(uuid)) {
plugin.carryingArmorStand.remove(uuid); plugin.carryingArmorStand.remove(uuid);
@ -258,6 +215,8 @@ public class MainListener implements Listener {
if (event.getRightClicked() instanceof ItemFrame && ArmorStandTool.isTool(event.getPlayer().getItemInHand())) { if (event.getRightClicked() instanceof ItemFrame && ArmorStandTool.isTool(event.getPlayer().getItemInHand())) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().updateInventory(); event.getPlayer().updateInventory();
} else if(!(event.getRightClicked() instanceof ArmorStand) && ArmorStandTool.NAME.is(event.getPlayer().getItemInHand())) {
event.setCancelled(true);
} }
} }
@ -378,28 +337,33 @@ 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();
ItemStack inHand = event.getItem(); if(plugin.carryingArmorStand.containsKey(p.getUniqueId()) && playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) {
if(plugin.carryingArmorStand.containsKey(p.getUniqueId()) && !permissionCheck(plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), p)) {
plugin.carryingArmorStand.remove(p.getUniqueId()); plugin.carryingArmorStand.remove(p.getUniqueId());
Utils.actionBarMsg(p, Config.asDropped); Utils.actionBarMsg(p, Config.asDropped);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) { Action action = event.getAction();
if (ArmorStandTool.isTool(inHand)) { ArmorStandTool tool = ArmorStandTool.get(event.getItem());
event.setCancelled(true); if(tool == null) return;
Utils.cycleInventory(p); if(action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
} event.setCancelled(true);
} else if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) { Utils.cycleInventory(p);
if(ArmorStandTool.SUMMON.is(inHand)) { return;
event.setCancelled(true); }
Location l = Utils.getLocationFacingPlayer(p); if(action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
if(permissionCheck(l.getBlock(), p)) return; if(!playerHasPermission(p, p.getLocation().getBlock(), tool)) return;
pickUpArmorStand(spawnArmorStand(l), p, true); switch (tool) {
Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying); case SUMMON:
p.updateInventory(); event.setCancelled(true);
} else if(ArmorStandTool.NAME.is(inHand)) { Location l = Utils.getLocationFacingPlayer(p);
event.setCancelled(true); pickUpArmorStand(spawnArmorStand(l), p, true);
Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying);
p.updateInventory();
break;
case NAME:
event.setCancelled(true);
break;
} }
} }
} }
@ -602,13 +566,19 @@ public class MainListener implements Listener {
return null; return null;
} }
boolean permissionCheck(Block b, Player p) { boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) {
if(Config.worldGuardPlugin == null) return false; if(!p.isOp() && (!p.hasPermission("astools.use")
|| (ArmorStandTool.SAVE == tool && !p.hasPermission("astools.cmdblock"))
|| (ArmorStandTool.CLONE == tool && !p.hasPermission("astools.clone")))) {
p.sendMessage(ChatColor.RED + Config.noPerm);
return false;
}
if(Config.worldGuardPlugin == null) return true;
boolean canBuild = Config.worldGuardPlugin.canBuild(p, b); boolean canBuild = Config.worldGuardPlugin.canBuild(p, b);
if(!canBuild) { if(!canBuild) {
p.sendMessage(ChatColor.RED + Config.wgNoPerm); p.sendMessage(ChatColor.RED + Config.wgNoPerm);
} }
return !canBuild; return canBuild;
} }
void pickUpArmorStand(ArmorStand as, Player p, boolean newlySummoned) { void pickUpArmorStand(ArmorStand as, Player p, boolean newlySummoned) {