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

Merge pull request #1 from boy0001/master

Various fixes and improvements
Dieser Commit ist enthalten in:
St3venAU 2015-03-30 00:15:12 +08:00
Commit b0c0ee6718
8 geänderte Dateien mit 221 neuen und 38 gelöschten Zeilen

4
.gitignore vendored
Datei anzeigen

@ -2,3 +2,7 @@
libs/ libs/
out/ out/
ArmorStand.iml ArmorStand.iml
/bin/
*.project
.classpath

Datei anzeigen

@ -1,11 +1,18 @@
package com.gmail.St3venAU.plugins.ArmorStandTools; package com.gmail.St3venAU.plugins.ArmorStandTools;
import net.minecraft.server.v1_8_R1.Material;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.List;
import java.util.UUID; import java.util.UUID;
class Commands implements CommandExecutor { class Commands implements CommandExecutor {
@ -23,6 +30,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)) {
@ -38,8 +48,54 @@ class Commands implements CommandExecutor {
return true; return true;
} }
} }
if(args[0].equalsIgnoreCase("head")) {
// get the entity you are looking at
if(!Utils.hasPermissionNode(p, "astools.head")) {
p.sendMessage(ChatColor.RED + Config.noHeadPerm);
return true;
}
List<Entity> nearby = p.getNearbyEntities(16, 16, 16);
if (nearby.size() == 0) {
p.sendMessage(ChatColor.RED + Config.notTarget);
return true;
}
double min = 0.5;
Entity closest = null;
Vector loc = p.getLocation().toVector();
for (Entity entity : nearby) {
Vector eLoc = entity.getLocation().toVector().subtract(loc).normalize();
Vector target = p.getLocation().getDirection().normalize();
double diff = eLoc.subtract(target).length();
if (diff < min) {
min = diff;
closest = entity;
}
}
if (closest == null || !(closest instanceof ArmorStand)) {
p.sendMessage(ChatColor.RED + Config.notTarget);
return true;
}
ArmorStand as = (ArmorStand) closest;
if (!MainListener.checkPermission(p, closest.getLocation().getBlock())) {
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
return true;
}
ItemStack item = p.getItemInHand();
if (item == null || item.getTypeId() == 0) {
as.setHelmet(new ItemStack(0));
p.sendMessage(ChatColor.GREEN + Config.setHead);
return true;
}
if (!item.getType().isBlock()) {
p.sendMessage(ChatColor.RED + Config.notBlock);
return true;
}
as.setHelmet(item);
p.sendMessage(ChatColor.GREEN + Config.setHead);
return true;
}
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

@ -34,9 +34,9 @@ class Config {
asCloned, carrying, noPerm, cbCreated, size, small, asCloned, carrying, noPerm, cbCreated, size, small,
normal, basePlate, isOn, isOff, gravity, arms, invul, normal, basePlate, isOn, isOff, gravity, arms, invul,
equip, locked, unLocked, notConsole, giveMsg1, equip, locked, unLocked, notConsole, giveMsg1,
giveMsg2, conReload, noRelPerm, noAirError, giveMsg2, conReload, noRelPerm, noHeadPerm, notTarget, notBlock, noAirError,
pleaseWait, appliedHead, noHead, invalidName, pleaseWait, appliedHead, noHead, invalidName,
wgNoPerm; wgNoPerm, setHead;
public static void reload(Main main) { public static void reload(Main main) {
plugin = main; plugin = main;
@ -74,12 +74,16 @@ class Config {
giveMsg2 = languageConfig.getString("giveMsg2"); giveMsg2 = languageConfig.getString("giveMsg2");
conReload = languageConfig.getString("conReload"); conReload = languageConfig.getString("conReload");
noRelPerm = languageConfig.getString("noRelPerm"); noRelPerm = languageConfig.getString("noRelPerm");
noHeadPerm = languageConfig.getString("noHeadPerm");
notTarget = languageConfig.getString("notTarget");
notBlock = languageConfig.getString("notBlock");
noAirError = languageConfig.getString("noAirError"); noAirError = languageConfig.getString("noAirError");
pleaseWait = languageConfig.getString("pleaseWait"); pleaseWait = languageConfig.getString("pleaseWait");
appliedHead = languageConfig.getString("appliedHead"); appliedHead = languageConfig.getString("appliedHead");
noHead = languageConfig.getString("noHead"); noHead = languageConfig.getString("noHead");
invalidName = languageConfig.getString("invalidName"); invalidName = languageConfig.getString("invalidName");
wgNoPerm = languageConfig.getString("wgNoPerm"); wgNoPerm = languageConfig.getString("wgNoPerm");
setHead = languageConfig.getString("setHead");
} }
private static void reloadMainConfig() { private static void reloadMainConfig() {
@ -100,6 +104,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())) {
if (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;
} }
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;
@ -202,9 +212,10 @@ public class MainListener implements Listener {
p.sendMessage(ChatColor.GREEN + "Deletion Protection: Enabled"); p.sendMessage(ChatColor.GREEN + "Deletion Protection: Enabled");
} }
break; break;
default: default: {
cancel = tool == ArmorStandTool.SUMMON || tool == ArmorStandTool.SAVE || event.isCancelled(); cancel = tool == ArmorStandTool.SUMMON || tool == ArmorStandTool.SAVE || event.isCancelled();
} }
}
event.setCancelled(cancel); event.setCancelled(cancel);
} }
} }
@ -241,8 +252,8 @@ public class MainListener implements Listener {
clone.setCustomNameVisible(as.isCustomNameVisible()); clone.setCustomNameVisible(as.isCustomNameVisible());
clone.setSmall(as.isSmall()); clone.setSmall(as.isSmall());
clone.setMaxHealth(as.getMaxHealth()); clone.setMaxHealth(as.getMaxHealth());
NBT.setSlotsDisabled(clone, NBT.getDisabledSlots(as) == 2039583); NBT.setSlotsDisabled(as, Config.equipmentLock);
NBT.setInvulnerable(clone, NBT.isInvulnerable(as)); NBT.setInvulnerable(as, Config.invulnerable);
return clone; return clone;
} }
@ -264,10 +275,14 @@ 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);
Block block = loc.getBlock();
if (playerHasPermission(p, block, null)) {
as.teleport(loc);
Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying); Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying);
} }
} }
}
@EventHandler @EventHandler
public void onPlayerDeath(PlayerDeathEvent event) { public void onPlayerDeath(PlayerDeathEvent event) {
@ -337,10 +352,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())) {
boolean perm = playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null);
if (perm) {
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);
}
else {
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
}
return; return;
} }
Action action = event.getAction(); Action action = event.getAction();
@ -351,8 +372,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);
@ -523,7 +547,7 @@ public class MainListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void setName(Player p, ArmorStand as) { private void setName(Player p, ArmorStand as) {
Block b = Utils.findAnAirBlock(p.getLocation()); Block b = Utils.findAnAirBlock(p.getLocation());
if(b == null) { if(b == null || !checkPermission(p, b)) {
p.sendMessage(ChatColor.RED + Config.noAirError); p.sendMessage(ChatColor.RED + Config.noAirError);
return; return;
} }
@ -537,7 +561,7 @@ public class MainListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void setPlayerSkull(Player p, ArmorStand as) { private void setPlayerSkull(Player p, ArmorStand as) {
Block b = Utils.findAnAirBlock(p.getLocation()); Block b = Utils.findAnAirBlock(p.getLocation());
if(b == null) { if(b == null || !checkPermission(p, b)) {
p.sendMessage(ChatColor.RED + Config.noAirError); p.sendMessage(ChatColor.RED + Config.noAirError);
return; return;
} }
@ -566,19 +590,48 @@ public class MainListener implements Listener {
return null; return null;
} }
boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) { public static boolean checkPermission(Player player, Block block) {
if(!p.isOp() && (!p.hasPermission("astools.use")
|| (ArmorStandTool.SAVE == tool && !p.hasPermission("astools.cmdblock")) // Check PlotSquared
|| (ArmorStandTool.CLONE == tool && !p.hasPermission("astools.clone")))) { 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;
}
public static boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) {
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); 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

@ -25,6 +25,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()) {
if(ArmorStandTool.isTool(i)) { if(ArmorStandTool.isTool(i)) {

Datei anzeigen

@ -42,12 +42,16 @@ giveMsg1: 'Given armor stand tools. L-click any tool to cycle through tools.'
giveMsg2: 'Run this command again to return your inventory.' giveMsg2: 'Run this command again to return your inventory.'
conReload: 'Armor Stand Tools config reloaded' conReload: 'Armor Stand Tools config reloaded'
noRelPerm: 'You do not have permission to reload the plugin' noRelPerm: 'You do not have permission to reload the plugin'
noHeadPerm: 'You do not have permission to set a head'
notTarget: 'You are not looking at an ArmorStand'
noAirError: 'Error: Failed to find a near-by air block. Move and try again.' noAirError: 'Error: Failed to find a near-by air block. Move and try again.'
pleaseWait: 'Please wait, this may take a few seconds...' pleaseWait: 'Please wait, this may take a few seconds...'
appliedHead: 'Applied the head of player' appliedHead: 'Applied the head of player'
noHead: 'No player head found for player' noHead: 'No player head found for player'
invalidName: 'is not a valid minecraft username' invalidName: 'is not a valid minecraft username'
wgNoPerm: 'You do not have permission to alter an armor stand in this region' wgNoPerm: 'You do not have permission to alter an armor stand in this region'
notBlock: 'You are not holding a block'
setHead: 'Set the head block'
# #
############################# #############################
# Tool names & descriptions # # Tool names & descriptions #

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 or /astools head
permission: astools.command
permission-message: You don't have permission to use this command