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

Tweaks and bugfixes

Dieser Commit ist enthalten in:
St3venAU 2015-04-14 15:59:10 +08:00
Ursprung d7ef505f49
Commit 03da204f09
7 geänderte Dateien mit 156 neuen und 89 gelöschten Zeilen

Datei anzeigen

@ -33,7 +33,7 @@ class ArmorStandGUI implements Listener {
ArmorStandGUI(Main plugin, ArmorStand as, Player p) { ArmorStandGUI(Main plugin, ArmorStand as, Player p) {
if(inUse.contains(as.getEntityId())) { if(inUse.contains(as.getEntityId())) {
p.sendMessage(ChatColor.RED + "This armor stand's GUI is in use"); p.sendMessage(ChatColor.RED + Config.guiInUse);
return; return;
} }
if(filler == null) { if(filler == null) {
@ -52,7 +52,7 @@ class ArmorStandGUI implements Listener {
this.as = as; this.as = as;
String name = as.getCustomName(); String name = as.getCustomName();
if(name == null) { if(name == null) {
name = "Armor Stand"; name = Config.armorStand;
} else if(name.length() > 32) { } else if(name.length() > 32) {
name = name.substring(0, 32); name = name.substring(0, 32);
} }
@ -74,7 +74,7 @@ class ArmorStandGUI implements Listener {
p.openInventory(i); p.openInventory(i);
} }
ItemStack updateLore(ArmorStandTool tool) { private ItemStack updateLore(ArmorStandTool tool) {
ItemStack item = tool.getItem(); ItemStack item = tool.getItem();
switch (tool) { switch (tool) {
case INVIS: case INVIS:
@ -92,18 +92,18 @@ class ArmorStandGUI implements Listener {
case SLOTS: case SLOTS:
return Utils.setLore(item, ChatColor.AQUA + Config.equip + ": " + (NBT.getDisabledSlots(as) == 2039583 ? (ChatColor.GREEN + Config.locked) : (ChatColor.RED + Config.unLocked))); return Utils.setLore(item, ChatColor.AQUA + Config.equip + ": " + (NBT.getDisabledSlots(as) == 2039583 ? (ChatColor.GREEN + Config.locked) : (ChatColor.RED + Config.unLocked)));
case NODEL: case NODEL:
return Utils.setLore(item, ChatColor.AQUA + "Deletion Protection: " + (as.getMaxHealth() == 50 ? (ChatColor.GREEN + "Enabled") : (ChatColor.RED + "Disabled"))); return Utils.setLore(item, ChatColor.AQUA + "Deletion Protection: " + (as.getMaxHealth() == 50 ? (ChatColor.GREEN + Config.enabled) : (ChatColor.RED + Config.disabled)));
case NAME: case NAME:
return Utils.setLore(item, ChatColor.AQUA + Config.currently + ": " + (as.getCustomName() == null ? (ChatColor.BLUE + "None") : (ChatColor.GREEN + as.getCustomName()))); return Utils.setLore(item, ChatColor.AQUA + Config.currently + ": " + (as.getCustomName() == null ? (ChatColor.BLUE + Config.none) : (ChatColor.GREEN + as.getCustomName())));
case PHEAD: case PHEAD:
String name = plrHeadName(as); String name = plrHeadName(as);
return Utils.setLore(item, ChatColor.AQUA + Config.currently + ": " + (name == null ? (ChatColor.BLUE + "None") : (ChatColor.GREEN + name))); return Utils.setLore(item, ChatColor.AQUA + Config.currently + ": " + (name == null ? (ChatColor.BLUE + Config.none) : (ChatColor.GREEN + name)));
default: default:
return item; return item;
} }
} }
String plrHeadName(ArmorStand as) { private String plrHeadName(ArmorStand as) {
if(as.getHelmet() == null) return null; if(as.getHelmet() == null) return null;
if(!(as.getHelmet().getItemMeta() instanceof SkullMeta)) return null; if(!(as.getHelmet().getItemMeta() instanceof SkullMeta)) return null;
SkullMeta meta = (SkullMeta) as.getHelmet().getItemMeta(); SkullMeta meta = (SkullMeta) as.getHelmet().getItemMeta();
@ -240,7 +240,7 @@ class ArmorStandGUI implements Listener {
} }
} }
void updateInventory() { private void updateInventory() {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {

Datei anzeigen

@ -9,56 +9,58 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
public enum ArmorStandTool { public enum ArmorStandTool {
HEADX ("headX", Material.JACK_O_LANTERN, (short) 0, 12, false, true), HEADX ("headX", Material.JACK_O_LANTERN, (short) 0, 12, false, true, "astools.use"),
HEADY ("headY", Material.JACK_O_LANTERN, (short) 0, 13, false, true), HEADY ("headY", Material.JACK_O_LANTERN, (short) 0, 13, false, true, "astools.use"),
HEADZ ("headZ", Material.JACK_O_LANTERN, (short) 0, 14, false, true), HEADZ ("headZ", Material.JACK_O_LANTERN, (short) 0, 14, false, true, "astools.use"),
LARMX ("lArmX", Material.TORCH, (short) 0, 27, false, true), LARMX ("lArmX", Material.TORCH, (short) 0, 27, false, true, "astools.use"),
LARMY ("lArmY", Material.TORCH, (short) 0, 28, false, true), LARMY ("lArmY", Material.TORCH, (short) 0, 28, false, true, "astools.use"),
LARMZ ("lArmZ", Material.TORCH, (short) 0, 29, false, true), LARMZ ("lArmZ", Material.TORCH, (short) 0, 29, false, true, "astools.use"),
RARMX ("rArmX", Material.REDSTONE_TORCH_ON, (short) 0, 30, false, true), RARMX ("rArmX", Material.REDSTONE_TORCH_ON, (short) 0, 30, false, true, "astools.use"),
RARMY ("rArmY", Material.REDSTONE_TORCH_ON, (short) 0, 31, false, true), RARMY ("rArmY", Material.REDSTONE_TORCH_ON, (short) 0, 31, false, true, "astools.use"),
RARMZ ("rArmZ", Material.REDSTONE_TORCH_ON, (short) 0, 32, false, true), RARMZ ("rArmZ", Material.REDSTONE_TORCH_ON, (short) 0, 32, false, true, "astools.use"),
MOVEX ("moveX", Material.SHEARS, (short) 0, 3, false, true), MOVEX ("moveX", Material.SHEARS, (short) 0, 3, false, true, "astools.use"),
MOVEY ("moveY", Material.SHEARS, (short) 0, 4, false, true), MOVEY ("moveY", Material.SHEARS, (short) 0, 4, false, true, "astools.use"),
MOVEZ ("moveZ", Material.SHEARS, (short) 0, 5, false, true), MOVEZ ("moveZ", Material.SHEARS, (short) 0, 5, false, true, "astools.use"),
LLEGX ("lLegX", Material.BONE, (short) 0, 18, false, true), LLEGX ("lLegX", Material.BONE, (short) 0, 18, false, true, "astools.use"),
LLEGY ("lLegY", Material.BONE, (short) 0, 19, false, true), LLEGY ("lLegY", Material.BONE, (short) 0, 19, false, true, "astools.use"),
LLEGZ ("lLegZ", Material.BONE, (short) 0, 20, false, true), LLEGZ ("lLegZ", Material.BONE, (short) 0, 20, false, true, "astools.use"),
RLEGX ("rLegX", Material.BLAZE_ROD, (short) 0, 21, false, true), RLEGX ("rLegX", Material.BLAZE_ROD, (short) 0, 21, false, true, "astools.use"),
RLEGY ("rLegY", Material.BLAZE_ROD, (short) 0, 22, false, true), RLEGY ("rLegY", Material.BLAZE_ROD, (short) 0, 22, false, true, "astools.use"),
RLEGZ ("rLegZ", Material.BLAZE_ROD, (short) 0, 23, false, true), RLEGZ ("rLegZ", Material.BLAZE_ROD, (short) 0, 23, false, true, "astools.use"),
BODYX ("bodyX", Material.NETHER_BRICK_ITEM, (short) 0, 9, false, true), BODYX ("bodyX", Material.NETHER_BRICK_ITEM, (short) 0, 9, false, true, "astools.use"),
BODYY ("bodyY", Material.NETHER_BRICK_ITEM, (short) 0, 10, false, true), BODYY ("bodyY", Material.NETHER_BRICK_ITEM, (short) 0, 10, false, true, "astools.use"),
BODYZ ("bodyZ", Material.NETHER_BRICK_ITEM, (short) 0, 11, false, true), BODYZ ("bodyZ", Material.NETHER_BRICK_ITEM, (short) 0, 11, false, true, "astools.use"),
SUMMON ("summon", Material.ARMOR_STAND, (short) 0, 0, false, true), SUMMON ("summon", Material.ARMOR_STAND, (short) 0, 0, false, true, "astools.use"),
GUI ("gui", Material.NETHER_STAR, (short) 0, 1, false, true), GUI ("gui", Material.NETHER_STAR, (short) 0, 1, false, true, "astools.use"),
ROTAT ("rotat", Material.MAGMA_CREAM, (short) 0, 2, false, true), ROTAT ("rotat", Material.MAGMA_CREAM, (short) 0, 2, false, true, "astools.use"),
CLONE ("gui_clone", Material.GLOWSTONE_DUST, (short) 0, 16, true, true), CLONE ("gui_clone", Material.GLOWSTONE_DUST, (short) 0, 16, true, true, "astools.clone"),
SAVE ("gui_save", Material.DIAMOND, (short) 0, 17, true, true), SAVE ("gui_save", Material.DIAMOND, (short) 0, 17, true, true, "astools.cmdblock"),
INVIS ("gui_invis", Material.GOLD_NUGGET, (short) 0, 14, true, true), INVIS ("gui_invis", Material.GOLD_NUGGET, (short) 0, 14, true, true, "astools.use"),
SIZE ("gui_size", Material.EMERALD, (short) 0, 23, true, true), SIZE ("gui_size", Material.EMERALD, (short) 0, 23, true, true, "astools.use"),
BASE ("gui_base", Material.BOOK, (short) 0, 22, true, true), BASE ("gui_base", Material.BOOK, (short) 0, 22, true, true, "astools.use"),
GRAV ("gui_grav", Material.GHAST_TEAR, (short) 0, 24, true, true), GRAV ("gui_grav", Material.GHAST_TEAR, (short) 0, 24, true, true, "astools.use"),
ARMS ("gui_arms", Material.ARROW, (short) 0, 21, true, true), ARMS ("gui_arms", Material.ARROW, (short) 0, 21, true, true, "astools.use"),
NAME ("gui_name", Material.NAME_TAG, (short) 0, 12, true, true), NAME ("gui_name", Material.NAME_TAG, (short) 0, 12, true, true, "astools.use"),
SLOTS ("gui_slots", Material.IRON_HOE, (short) 0, 26, true, true), SLOTS ("gui_slots", Material.IRON_HOE, (short) 0, 26, true, true, "astools.use"),
PHEAD ("gui_pHead", Material.SKULL_ITEM, (short) 3, 13, true, true), PHEAD ("gui_pHead", Material.SKULL_ITEM, (short) 3, 13, true, true, "astools.use"),
INVUL ("gui_invul", Material.GOLDEN_CARROT, (short) 0, 25, true, true), INVUL ("gui_invul", Material.GOLDEN_CARROT, (short) 0, 25, true, true, "astools.use"),
MOVE ("gui_move", Material.FEATHER, (short) 0, 15, true, true), MOVE ("gui_move", Material.FEATHER, (short) 0, 15, true, true, "astools.use"),
NODEL ("gui_noDel", Material.WOOD_SPADE, (short) 0, 35, true, false); // Developer tool, disabled by default NODEL ("gui_noDel", Material.WOOD_SPADE, (short) 0, 35, true, false, "astools.use"); // Developer tool, disabled by default
private final ItemStack item; private final ItemStack item;
private final String id; private final String id;
private final int slot; private final int slot;
private final boolean enabled; private boolean enabled;
private final boolean forGui; private final boolean forGui;
private final String permission;
ArmorStandTool(String id, Material m, short data, int slot, boolean forGui, boolean enabled) { ArmorStandTool(String id, Material m, short data, int slot, boolean forGui, boolean enabled, String permission) {
item = new ItemStack(m, 1, data); item = new ItemStack(m, 1, data);
this.id = id; this.id = id;
this.slot = slot; this.slot = slot;
this.forGui = forGui; this.forGui = forGui;
this.enabled = enabled; this.enabled = enabled;
this.permission = permission;
} }
ItemStack getItem() { ItemStack getItem() {
@ -75,10 +77,19 @@ public enum ArmorStandTool {
return forGui; return forGui;
} }
void setEnabled(FileConfiguration config) {
if(this == NODEL) return;
enabled = config.getBoolean("enableTool." + id);
}
boolean isEnabled() { boolean isEnabled() {
return enabled; return enabled;
} }
String getPermission() {
return permission;
}
int getSlot() { int getSlot() {
return slot; return slot;
} }
@ -94,6 +105,9 @@ public enum ArmorStandTool {
static void give(Player p) { static void give(Player p) {
PlayerInventory i = p.getInventory(); PlayerInventory i = p.getInventory();
for(int slot = 0; slot < 36; slot++) {
i.setItem(slot, null);
}
for(ArmorStandTool t : values()) { for(ArmorStandTool t : values()) {
if(t.enabled && !t.forGui) { if(t.enabled && !t.forGui) {
i.setItem(t.slot, t.item); i.setItem(t.slot, t.item);

Datei anzeigen

@ -31,13 +31,13 @@ class Config {
public static String public static String
invReturned, asDropped, asVisible, isTrue, isFalse, invReturned, asDropped, asVisible, isTrue, isFalse,
carrying, cbCreated, size, small, carrying, cbCreated, size, small, normal, basePlate,
normal, basePlate, isOn, isOff, gravity, arms, invul, isOn, isOff, gravity, arms, invul, equip, locked,
equip, locked, unLocked, notConsole, giveMsg1, unLocked, notConsole, giveMsg1, giveMsg2, conReload,
giveMsg2, conReload, noRelPerm, noAirError, noRelPerm, noAirError, pleaseWait, appliedHead,
pleaseWait, appliedHead, noHead, invalidName, noHead, invalidName, wgNoPerm, currently, headFailed,
wgNoPerm, currently, headFailed, noCommandPerm, noCommandPerm, generalNoPerm, armorStand, none,
generalNoPerm; enabled, disabled, guiInUse;
public static void reload(Main main) { public static void reload(Main main) {
plugin = main; plugin = main;
@ -83,6 +83,11 @@ class Config {
currently = languageConfig.getString("currently"); currently = languageConfig.getString("currently");
headFailed = languageConfig.getString("headFailed"); headFailed = languageConfig.getString("headFailed");
generalNoPerm = languageConfig.getString("generalNoPerm"); generalNoPerm = languageConfig.getString("generalNoPerm");
armorStand = languageConfig.getString("armorStand");
none = languageConfig.getString("none");
enabled = languageConfig.getString("enabled");
disabled = languageConfig.getString("disabled");
guiInUse = languageConfig.getString("guiInUse");
} }
private static void reloadMainConfig() { private static void reloadMainConfig() {
@ -104,6 +109,10 @@ class Config {
equipmentLock = config.getBoolean("equipmentLock"); equipmentLock = config.getBoolean("equipmentLock");
plugin.carryingArmorStand.clear(); plugin.carryingArmorStand.clear();
for(ArmorStandTool tool : ArmorStandTool.values()) {
tool.setEnabled(config);
}
Plugin plotSquared = plugin.getServer().getPluginManager().getPlugin("PlotSquared"); Plugin plotSquared = plugin.getServer().getPluginManager().getPlugin("PlotSquared");
if (plotSquared != null && plotSquared.isEnabled()) { if (plotSquared != null && plotSquared.isEnabled()) {
new PlotSquaredHook(plugin); new PlotSquaredHook(plugin);
@ -141,7 +150,7 @@ class Config {
} }
String[] split = s.split(" "); String[] split = s.split(" ");
if(split.length > 2) { if(split.length > 2) {
System.out.println("[ArmorStandTools] Error in Config: Must use the format: MATERIAL_NAME dataValue. Continuing using AIR instead."); System.out.println("[ArmorStandTools] Error in config.yml: Must use the format: MATERIAL_NAME dataValue. Continuing using AIR instead.");
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);
} }
byte dataValue = (byte) 0; byte dataValue = (byte) 0;
@ -149,14 +158,14 @@ class Config {
try { try {
dataValue = Byte.parseByte(split[1]); dataValue = Byte.parseByte(split[1]);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
System.out.println("[ArmorStandTools] Error in Config: Invalid data value specifed. Continuing using data value 0 instead."); System.out.println("[ArmorStandTools] Error in config.yml: Invalid data value specifed. Continuing using data value 0 instead.");
} }
} }
Material m; Material m;
try { try {
m = Material.valueOf(split[0].toUpperCase()); m = Material.valueOf(split[0].toUpperCase());
} catch(IllegalArgumentException iae) { } catch(IllegalArgumentException iae) {
System.out.println("[ArmorStandTools] Error in Config: Invalid material name specifed. Continuing using AIR instead."); System.out.println("[ArmorStandTools] Error in config.yml: Invalid material name specifed. Continuing using AIR instead.");
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);
} }
return new ItemStack(m, 1, dataValue); return new ItemStack(m, 1, dataValue);

Datei anzeigen

@ -182,40 +182,28 @@ public class Main extends JavaPlugin {
b.setMetadata("setSkull", new FixedMetadataValue(this, true)); b.setMetadata("setSkull", new FixedMetadataValue(this, true));
} }
boolean checkPermission(Player player, Block block) { boolean checkPermission(Player p, Block b) {
if(b == null) return true;
if(block == null) return true;
// Check PlotSquared
Location loc = block.getLocation();
if (PlotSquaredHook.api != null) { if (PlotSquaredHook.api != null) {
if (PlotSquaredHook.isPlotWorld(loc)) { Location l = b.getLocation();
return PlotSquaredHook.checkPermission(player, loc); if(PlotSquaredHook.isPlotWorld(l) && !PlotSquaredHook.checkPermission(p, l)) {
return false;
} }
} }
if(Config.worldGuardPlugin != null && !Config.worldGuardPlugin.canBuild(p, b)) {
// check WorldGuard return false;
if(Config.worldGuardPlugin != null) {
return Config.worldGuardPlugin.canBuild(player, block);
} }
BlockBreakEvent breakEvent = new BlockBreakEvent(b, p);
// Use standard permission checking (will support basically any plugin) Bukkit.getServer().getPluginManager().callEvent(breakEvent);
BlockBreakEvent myBreak = new BlockBreakEvent(block, player); if(breakEvent.isCancelled()){
Bukkit.getServer().getPluginManager().callEvent(myBreak); return false;
boolean hasPerm = !myBreak.isCancelled();
BlockPlaceEvent place = new BlockPlaceEvent(block, block.getState(), block, null, player, true);
Bukkit.getServer().getPluginManager().callEvent(place);
if (place.isCancelled()) {
hasPerm = false;
} }
return hasPerm; BlockPlaceEvent placeEvent = new BlockPlaceEvent(b, b.getState(), b, null, p, true);
Bukkit.getServer().getPluginManager().callEvent(placeEvent);
return !placeEvent.isCancelled();
} }
boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) { boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) {
return !(tool != null && !p.isOp() return (tool == null || tool.isEnabled() && Utils.hasPermissionNode(p, tool.getPermission())) && checkPermission(p, b);
&& (!Utils.hasPermissionNode(p, "astools.use")
|| (ArmorStandTool.SAVE == tool && !Utils.hasPermissionNode(p, "astools.cmdblock"))
|| (ArmorStandTool.CLONE == tool && !Utils.hasPermissionNode(p, "astools.clone"))))
&& checkPermission(p, b);
} }
} }

Datei anzeigen

@ -1,6 +1,12 @@
# Armor Stand Tools v2.01 # Armor Stand Tools
# by St3venAU
# St3venAU@gmail.com
# #
# by St3venAU (St3venAU@gmail.com) # Main Config
#
# File generated by: v2.02
# (If this is not the version you are running, consider deleting this
# config to allow it to be re-created. There may be new config options)
# #
# Features: # Features:
# - Summon armor stands # - Summon armor stands
@ -45,3 +51,40 @@ hasGravity: false
name: '' name: ''
invulnerable: false invulnerable: false
equipmentLock: false equipmentLock: false
enableTool:
headX: true
headY: true
headZ: true
lArmX: true
lArmY: true
lArmZ: true
rArmX: true
rArmY: true
rArmZ: true
moveX: true
moveY: true
moveZ: true
lLegX: true
lLegY: true
lLegZ: true
rLegX: true
rLegY: true
rLegZ: true
bodyX: true
bodyY: true
bodyZ: true
summon: true
gui: true
rotat: true
gui_clone: true
gui_save: true
gui_invis: true
gui_size: true
gui_base: true
gui_grav: true
gui_arms: true
gui_name: true
gui_slots: true
gui_pHead: true
gui_invul: true
gui_move: true

Datei anzeigen

@ -1,4 +1,12 @@
# Armor Stand Tools Language Config # Armor Stand Tools
# by St3venAU
# St3venAU@gmail.com
#
# Language Config
#
# File generated by: v2.02
# (If this is not the version you are running, consider deleting this
# config to allow it to be re-created. There may be new config options)
# #
# Edit these strings if you wish to customize the wording # Edit these strings if you wish to customize the wording
# or the language of the text used in this plugin. # or the language of the text used in this plugin.
@ -50,6 +58,11 @@ invalidName: 'is not a valid minecraft username'
wgNoPerm: 'No permission to alter an armor stand in this region' wgNoPerm: 'No permission to alter an armor stand in this region'
headFailed: 'Failed to apply the player head. Try again.' headFailed: 'Failed to apply the player head. Try again.'
noCommandPerm: 'You do not have permission to use this command' noCommandPerm: 'You do not have permission to use this command'
armorStand: 'Armor Stand'
none: 'None'
enabled: 'Enabled'
disabled: 'Disabled'
guiInUse: 'This armor stands GUI is in use'
# #
############################# #############################
# Tool names & descriptions # # Tool names & descriptions #

Datei anzeigen

@ -1,6 +1,6 @@
main: com.gmail.St3venAU.plugins.ArmorStandTools.Main main: com.gmail.St3venAU.plugins.ArmorStandTools.Main
name: ArmorStandTools name: ArmorStandTools
version: 2.01 version: 2.02
author: St3venAU author: St3venAU
description: Armor stand manipulation tools description: Armor stand manipulation tools
softdepend: [WorldGuard, PlotSquared] softdepend: [WorldGuard, PlotSquared]