From 7fdb2ad7d32a3f22d6049cbf35cf8f3b3b9839f9 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 12 Jan 2013 14:12:12 +0000 Subject: [PATCH 01/22] Pull item meta from itemdb class --- .../src/com/earth2me/essentials/ItemDb.java | 92 +------------ .../src/com/earth2me/essentials/Kit.java | 9 +- .../earth2me/essentials/MetaItemStack.java | 121 ++++++++++++++++++ .../essentials/commands/Commandenchant.java | 10 +- .../essentials/commands/Commandgive.java | 10 +- .../essentials/commands/Commanditem.java | 10 +- 6 files changed, 142 insertions(+), 110 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/MetaItemStack.java diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index 85753e816..a277c5892 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -5,9 +5,7 @@ import com.earth2me.essentials.api.IItemDb; import java.util.*; import java.util.regex.Pattern; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; public class ItemDb implements IConf, IItemDb @@ -139,95 +137,7 @@ public class ItemDb implements IConf, IItemDb retval.setDurability(metaData); return retval; } - - public void addStringEnchantment(final User user, final boolean allowUnsafe, final ItemStack stack, final String string) throws Exception - { - final String[] split = splitPattern.split(string, 2); - if (split.length < 1) - { - return; - } - - Enchantment enchantment = getEnchantment(user, split[0]); - - int level = -1; - if (split.length > 1) - { - try - { - level = Integer.parseInt(split[1]); - } - catch (NumberFormatException ex) - { - level = -1; - } - } - - if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) - { - level = enchantment.getMaxLevel(); - } - addEnchantment(user, allowUnsafe, stack, enchantment, level); - } - - public void addEnchantment(final User user, final boolean allowUnsafe, final ItemStack stack, final Enchantment enchantment, final int level) throws Exception - { - try - { - if (stack.getType().equals(Material.ENCHANTED_BOOK)) - { - EnchantmentStorageMeta meta = (EnchantmentStorageMeta)stack.getItemMeta(); - if (level == 0) - { - meta.removeStoredEnchant(enchantment); - } - else - { - meta.addStoredEnchant(enchantment, level, allowUnsafe); - } - stack.setItemMeta(meta); - } - else // all other material types besides ENCHANTED_BOOK - { - if (level == 0) - { - stack.removeEnchantment(enchantment); - } - else - { - if (allowUnsafe) - { - stack.addUnsafeEnchantment(enchantment, level); - } - else - { - stack.addEnchantment(enchantment, level); - } - } - } - } - catch (Exception ex) - { - throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); - } - } - - //TODO: Properly TL this - public Enchantment getEnchantment(final User user, final String name) throws Exception - { - final Enchantment enchantment = Enchantments.getByName(name); - if (enchantment == null) - { - throw new Exception(_("enchantmentNotFound") + ": " + name); - } - final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); - if (user != null && !user.isAuthorized("essentials.enchant." + enchantmentName)) - { - throw new Exception(_("enchantmentPerm", enchantmentName)); - } - return enchantment; - } - + public String names(ItemStack item) { ItemData itemData = new ItemData(item.getTypeId(), item.getDurability()); diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index 4f0957f38..b2b100553 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -115,24 +115,25 @@ public class Kit } final String[] parts = d.split(" "); - final ItemStack stack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1); + final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1); + final MetaItemStack stack = new MetaItemStack(parseStack); if (parts.length > 2) { for (int i = 2; i < parts.length; i++) { - ess.getItemDb().addStringEnchantment(null, allowUnsafe, stack, parts[i]); + stack.addStringEnchantment(null, allowUnsafe, parts[i]); } } final Map overfilled; if (user.isAuthorized("essentials.oversizedstacks")) { - overfilled = InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack); + overfilled = InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase()); } else { - overfilled = InventoryWorkaround.addItems(user.getInventory(), stack); + overfilled = InventoryWorkaround.addItems(user.getInventory(), stack.getBase()); } for (ItemStack itemStack : overfilled.values()) { diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java new file mode 100644 index 000000000..9aa064590 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -0,0 +1,121 @@ +package com.earth2me.essentials; + +import static com.earth2me.essentials.I18n._; +import java.util.Locale; +import java.util.regex.Pattern; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; + + +public class MetaItemStack extends ItemStack +{ + private final transient Pattern splitPattern = Pattern.compile("[:+',;.]"); + private final ItemStack stack; + + public MetaItemStack(final ItemStack stack) + { + this.stack = stack; + } + + public ItemStack getBase() + { + return stack; + } + + public void addStringMeta(final User user, final boolean allowUnsafe, final String string) throws Exception + { + + } + + public void addStringEnchantment(final User user, final boolean allowUnsafe, final String string) throws Exception + { + final String[] split = splitPattern.split(string, 2); + if (split.length < 1) + { + return; + } + + Enchantment enchantment = getEnchantment(user, split[0]); + + int level = -1; + if (split.length > 1) + { + try + { + level = Integer.parseInt(split[1]); + } + catch (NumberFormatException ex) + { + level = -1; + } + } + + if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) + { + level = enchantment.getMaxLevel(); + } + addEnchantment(user, allowUnsafe, enchantment, level); + } + + public void addEnchantment(final User user, final boolean allowUnsafe, final Enchantment enchantment, final int level) throws Exception + { + try + { + if (stack.getType().equals(Material.ENCHANTED_BOOK)) + { + EnchantmentStorageMeta meta = (EnchantmentStorageMeta)stack.getItemMeta(); + if (level == 0) + { + meta.removeStoredEnchant(enchantment); + } + else + { + meta.addStoredEnchant(enchantment, level, allowUnsafe); + } + stack.setItemMeta(meta); + } + else // all other material types besides ENCHANTED_BOOK + { + if (level == 0) + { + stack.removeEnchantment(enchantment); + } + else + { + if (allowUnsafe) + { + stack.addUnsafeEnchantment(enchantment, level); + } + else + { + stack.addEnchantment(enchantment, level); + } + } + } + } + catch (Exception ex) + { + throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); + } + } + + //TODO: Properly TL this + public Enchantment getEnchantment(final User user, final String name) throws Exception + { + final Enchantment enchantment = Enchantments.getByName(name); + if (enchantment == null) + { + throw new Exception(_("enchantmentNotFound") + ": " + name); + } + final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); + if (user != null && !user.isAuthorized("essentials.enchant." + enchantmentName)) + { + throw new Exception(_("enchantmentPerm", enchantmentName)); + } + return enchantment; + } + + +} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java index 97abbc6db..461631282 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Enchantments; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import java.util.Locale; @@ -10,7 +11,6 @@ import java.util.Set; import java.util.TreeSet; import org.bukkit.Server; import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; public class Commandenchant extends EssentialsCommand @@ -24,7 +24,7 @@ public class Commandenchant extends EssentialsCommand @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - final ItemStack stack = user.getItemInHand(); + final MetaItemStack stack = new MetaItemStack(user.getItemInHand()); if (stack == null) { throw new Exception(_("nothingInHand")); @@ -58,11 +58,11 @@ public class Commandenchant extends EssentialsCommand } final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe"); - final Enchantment enchantment = ess.getItemDb().getEnchantment(user, args[0]); - ess.getItemDb().addEnchantment(user, allowUnsafe, stack, enchantment, level); + final Enchantment enchantment = stack.getEnchantment(user, args[0]); + stack.addEnchantment(user, allowUnsafe, enchantment, level); - user.getInventory().setItemInHand(stack); + user.getInventory().setItemInHand(stack.getBase()); user.updateInventory(); final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); if (level == 0) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 94b4b6d6b..0fabf3afc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; @@ -9,7 +10,6 @@ import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; public class Commandgive extends EssentialsCommand @@ -27,7 +27,7 @@ public class Commandgive extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final ItemStack stack = ess.getItemDb().get(args[1]); + final MetaItemStack stack = new MetaItemStack(ess.getItemDb().get(args[1])); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (sender instanceof Player @@ -78,7 +78,7 @@ public class Commandgive extends EssentialsCommand for (int i = Util.isInt(args[3]) ? 4 : 3; i < args.length; i++) { - ess.getItemDb().addStringEnchantment(null, allowUnsafe, stack, args[i]); + stack.addStringEnchantment(null, allowUnsafe, args[i]); } } @@ -91,11 +91,11 @@ public class Commandgive extends EssentialsCommand sender.sendMessage(_("giveSpawn", stack.getAmount(), itemName, giveTo.getDisplayName())); if (giveTo.isAuthorized("essentials.oversizedstacks")) { - InventoryWorkaround.addOversizedItems(giveTo.getInventory(), ess.getSettings().getOversizedStackSize(), stack); + InventoryWorkaround.addOversizedItems(giveTo.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase()); } else { - InventoryWorkaround.addItems(giveTo.getInventory(), stack); + InventoryWorkaround.addItems(giveTo.getInventory(), stack.getBase()); } giveTo.updateInventory(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index a071d8068..096da99d5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.User; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import java.util.Locale; import org.bukkit.Material; import org.bukkit.Server; -import org.bukkit.inventory.ItemStack; public class Commanditem extends EssentialsCommand @@ -23,7 +23,7 @@ public class Commanditem extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - final ItemStack stack = ess.getItemDb().get(args[0]); + final MetaItemStack stack = new MetaItemStack(ess.getItemDb().get(args[0])); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (ess.getSettings().permissionBasedItemSpawn() @@ -60,7 +60,7 @@ public class Commanditem extends EssentialsCommand for (int i = 2; i < args.length; i++) { - ess.getItemDb().addStringEnchantment(null, allowUnsafe, stack, args[i]); + stack.addStringEnchantment(null, allowUnsafe, args[i]); } } @@ -74,11 +74,11 @@ public class Commanditem extends EssentialsCommand user.sendMessage(_("itemSpawn", stack.getAmount(), displayName)); if (user.isAuthorized("essentials.oversizedstacks")) { - InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack); + InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase()); } else { - InventoryWorkaround.addItems(user.getInventory(), stack); + InventoryWorkaround.addItems(user.getInventory(), stack.getBase()); } user.updateInventory(); } From 298ab846c126cb5a3a76ac883c614498cc4aaace Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 12 Jan 2013 17:05:05 +0000 Subject: [PATCH 02/22] Don't extend ItemStack --- Essentials/src/com/earth2me/essentials/Kit.java | 8 ++++---- .../src/com/earth2me/essentials/MetaItemStack.java | 6 +++--- .../essentials/commands/Commandenchant.java | 11 +++++++---- .../earth2me/essentials/commands/Commandgive.java | 13 ++++++++----- .../earth2me/essentials/commands/Commanditem.java | 11 +++++++---- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index b2b100553..35b105612 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -116,24 +116,24 @@ public class Kit final String[] parts = d.split(" "); final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1); - final MetaItemStack stack = new MetaItemStack(parseStack); + final MetaItemStack metaStack = new MetaItemStack(parseStack); if (parts.length > 2) { for (int i = 2; i < parts.length; i++) { - stack.addStringEnchantment(null, allowUnsafe, parts[i]); + metaStack.addStringEnchantment(null, allowUnsafe, parts[i]); } } final Map overfilled; if (user.isAuthorized("essentials.oversizedstacks")) { - overfilled = InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase()); + overfilled = InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), metaStack.getItemStack()); } else { - overfilled = InventoryWorkaround.addItems(user.getInventory(), stack.getBase()); + overfilled = InventoryWorkaround.addItems(user.getInventory(), metaStack.getItemStack()); } for (ItemStack itemStack : overfilled.values()) { diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index 9aa064590..cf4aa70ec 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -9,17 +9,17 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; -public class MetaItemStack extends ItemStack +public class MetaItemStack { private final transient Pattern splitPattern = Pattern.compile("[:+',;.]"); private final ItemStack stack; public MetaItemStack(final ItemStack stack) { - this.stack = stack; + this.stack = stack.clone(); } - public ItemStack getBase() + public ItemStack getItemStack() { return stack; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java index 461631282..663652436 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java @@ -11,6 +11,7 @@ import java.util.Set; import java.util.TreeSet; import org.bukkit.Server; import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; public class Commandenchant extends EssentialsCommand @@ -24,7 +25,7 @@ public class Commandenchant extends EssentialsCommand @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - final MetaItemStack stack = new MetaItemStack(user.getItemInHand()); + final ItemStack stack = user.getItemInHand(); if (stack == null) { throw new Exception(_("nothingInHand")); @@ -58,11 +59,13 @@ public class Commandenchant extends EssentialsCommand } final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe"); - final Enchantment enchantment = stack.getEnchantment(user, args[0]); - stack.addEnchantment(user, allowUnsafe, enchantment, level); + + final MetaItemStack metaStack = new MetaItemStack(stack); + final Enchantment enchantment = metaStack.getEnchantment(user, args[0]); + metaStack.addEnchantment(user, allowUnsafe, enchantment, level); - user.getInventory().setItemInHand(stack.getBase()); + user.getInventory().setItemInHand(metaStack.getItemStack()); user.updateInventory(); final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); if (level == 0) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 0fabf3afc..c80ff0d1b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -10,6 +10,7 @@ import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; public class Commandgive extends EssentialsCommand @@ -27,7 +28,7 @@ public class Commandgive extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final MetaItemStack stack = new MetaItemStack(ess.getItemDb().get(args[1])); + ItemStack stack = ess.getItemDb().get(args[1]); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (sender instanceof Player @@ -70,7 +71,8 @@ public class Commandgive extends EssentialsCommand if (args.length > 3) { - boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments(); + MetaItemStack metaStack = new MetaItemStack(stack); + boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments(); if (allowUnsafe && sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.enchant.allowunsafe")) { allowUnsafe = false; @@ -78,8 +80,9 @@ public class Commandgive extends EssentialsCommand for (int i = Util.isInt(args[3]) ? 4 : 3; i < args.length; i++) { - stack.addStringEnchantment(null, allowUnsafe, args[i]); + metaStack.addStringEnchantment(null, allowUnsafe, args[i]); } + stack = metaStack.getItemStack(); } if (stack.getType() == Material.AIR) @@ -91,11 +94,11 @@ public class Commandgive extends EssentialsCommand sender.sendMessage(_("giveSpawn", stack.getAmount(), itemName, giveTo.getDisplayName())); if (giveTo.isAuthorized("essentials.oversizedstacks")) { - InventoryWorkaround.addOversizedItems(giveTo.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase()); + InventoryWorkaround.addOversizedItems(giveTo.getInventory(), ess.getSettings().getOversizedStackSize(), stack); } else { - InventoryWorkaround.addItems(giveTo.getInventory(), stack.getBase()); + InventoryWorkaround.addItems(giveTo.getInventory(), stack); } giveTo.updateInventory(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 096da99d5..0acd1f60f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import java.util.Locale; import org.bukkit.Material; import org.bukkit.Server; +import org.bukkit.inventory.ItemStack; public class Commanditem extends EssentialsCommand @@ -23,7 +24,7 @@ public class Commanditem extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - final MetaItemStack stack = new MetaItemStack(ess.getItemDb().get(args[0])); + ItemStack stack = ess.getItemDb().get(args[0]); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (ess.getSettings().permissionBasedItemSpawn() @@ -56,12 +57,14 @@ public class Commanditem extends EssentialsCommand } if (args.length > 2) { + MetaItemStack metaStack = new MetaItemStack(stack); final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchant.allowunsafe"); for (int i = 2; i < args.length; i++) { - stack.addStringEnchantment(null, allowUnsafe, args[i]); + metaStack.addStringEnchantment(null, allowUnsafe, args[i]); } + stack = metaStack.getItemStack(); } @@ -74,11 +77,11 @@ public class Commanditem extends EssentialsCommand user.sendMessage(_("itemSpawn", stack.getAmount(), displayName)); if (user.isAuthorized("essentials.oversizedstacks")) { - InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack.getBase()); + InventoryWorkaround.addOversizedItems(user.getInventory(), ess.getSettings().getOversizedStackSize(), stack); } else { - InventoryWorkaround.addItems(user.getInventory(), stack.getBase()); + InventoryWorkaround.addItems(user.getInventory(), stack); } user.updateInventory(); } From ef1492a2a286876eeff767e72a88854646c36532 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 12 Jan 2013 19:30:06 +0000 Subject: [PATCH 03/22] Clean up userdata saving, to prevent CMI Also update config section code to use newer bukkit methods --- .../earth2me/essentials/EssentialsConf.java | 163 +++++++++--------- .../src/com/earth2me/essentials/UserData.java | 27 ++- 2 files changed, 92 insertions(+), 98 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 70e683da4..175afb110 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -221,6 +221,69 @@ public class EssentialsConf extends YamlConfiguration this.resourceClass = resClass; } + public void save() + { + try + { + save(configFile); + } + catch (IOException ex) + { + LOGGER.log(Level.SEVERE, ex.getMessage(), ex); + } + } + + public void saveWithError() throws IOException + { + save(configFile); + } + + @Override + public synchronized void save(final File file) throws IOException + { + if (file == null) + { + throw new IllegalArgumentException("File cannot be null"); + } + + Files.createParentDirs(file); + + final String data = saveToString(); + + if (data.length() == 0) + { + return; + } + + if (!configFile.exists()) + { + try + { + LOGGER.log(Level.INFO, _("creatingEmptyConfig", configFile.toString())); + if (!configFile.createNewFile()) + { + LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString())); + } + } + catch (IOException ex) + { + LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()), ex); + } + } + + + final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), UTF8); + + try + { + writer.write(data); + } + finally + { + writer.close(); + } + } + public boolean hasProperty(final String path) { return isSet(path); @@ -305,94 +368,14 @@ public class EssentialsConf extends YamlConfiguration set(path, map); } - public long getLong(final String path, final long def) + public void setProperty(String path, List object) { - try - { - final Number num = (Number)get(path); - return num == null ? def : num.longValue(); - } - catch (ClassCastException ex) - { - return def; - } + set(path, new ArrayList(object)); } - @Override - public double getDouble(final String path, final double def) + public void setProperty(String path, Map object) { - try - { - Number num = (Number)get(path); - return num == null ? def : num.doubleValue(); - } - catch (ClassCastException ex) - { - return def; - } - } - - public void save() - { - try - { - save(configFile); - } - catch (IOException ex) - { - LOGGER.log(Level.SEVERE, ex.getMessage(), ex); - } - } - - public void saveWithError() throws IOException - { - save(configFile); - } - - @Override - public synchronized void save(final File file) throws IOException - { - if (file == null) - { - throw new IllegalArgumentException("File cannot be null"); - } - - Files.createParentDirs(file); - - final String data = saveToString(); - - if (data.length() == 0) - { - return; - } - - if (!configFile.exists()) - { - try - { - LOGGER.log(Level.INFO, _("creatingEmptyConfig", configFile.toString())); - if (!configFile.createNewFile()) - { - LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString())); - } - } - catch (IOException ex) - { - LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()), ex); - } - } - - - final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), UTF8); - - try - { - writer.write(data); - } - finally - { - writer.close(); - } + set(path, new LinkedHashMap(object)); } public Object getProperty(String path) @@ -464,6 +447,12 @@ public class EssentialsConf extends YamlConfiguration return super.getDouble(path); } + @Override + public synchronized double getDouble(final String path, final double def) + { + return super.getDouble(path, def); + } + @Override public synchronized List getDoubleList(String path) { @@ -524,6 +513,12 @@ public class EssentialsConf extends YamlConfiguration return super.getLong(path); } + @Override + public synchronized long getLong(final String path, final long def) + { + return super.getLong(path, def); + } + @Override public synchronized List getLongList(String path) { diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 94b1631f5..930a9c913 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -5,7 +5,6 @@ import java.io.File; import java.util.*; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.MemoryConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -794,44 +793,44 @@ public abstract class UserData extends PlayerExtension implements IConf { return config.getBoolean("powertoolsenabled", true); } - private ConfigurationSection kitTimestamps; - - private ConfigurationSection _getKitTimestamps() + private Map kitTimestamps; + + private Map _getKitTimestamps() { - + if (config.isConfigurationSection("timestamps.kits")) { final ConfigurationSection section = config.getConfigurationSection("timestamps.kits"); - final ConfigurationSection newSection = new MemoryConfiguration(); + final Map timestamps = new HashMap(); for (String command : section.getKeys(false)) { if (section.isLong(command)) { - newSection.set(command.toLowerCase(Locale.ENGLISH), section.getLong(command)); + timestamps.put(command.toLowerCase(Locale.ENGLISH), section.getLong(command)); } else if (section.isInt(command)) { - newSection.set(command.toLowerCase(Locale.ENGLISH), (long)section.getInt(command)); + timestamps.put(command.toLowerCase(Locale.ENGLISH), (long)section.getInt(command)); } } - return newSection; + return timestamps; } - return new MemoryConfiguration(); + return new HashMap(); } - + public long getKitTimestamp(String name) { name = name.replace('.', '_').replace('/', '_'); - if (kitTimestamps != null) + if (kitTimestamps != null && kitTimestamps.containsKey(name)) { - return kitTimestamps.getLong(name, 0l); + return kitTimestamps.get(name); } return 0l; } public void setKitTimestamp(final String name, final long time) { - kitTimestamps.set(name.toLowerCase(Locale.ENGLISH), time); + kitTimestamps.put(name.toLowerCase(Locale.ENGLISH), time); config.setProperty("timestamps.kits", kitTimestamps); config.save(); } From 18a15ca63c2c68b45b8004c6f2d1f2693407e16b Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 13 Jan 2013 04:44:28 +0000 Subject: [PATCH 04/22] Add provisional support for basic item Meta Adds /book command to allow reediting of signed books. --- .../src/com/earth2me/essentials/Kit.java | 2 +- .../earth2me/essentials/MetaItemStack.java | 79 ++++++++++++++++++- .../essentials/commands/Commandbook.java | 45 +++++++++++ .../essentials/commands/Commandgive.java | 2 +- .../essentials/commands/Commanditem.java | 2 +- Essentials/src/config.yml | 9 ++- Essentials/src/plugin.yml | 4 + 7 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandbook.java diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index 35b105612..4ff59a948 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -122,7 +122,7 @@ public class Kit { for (int i = 2; i < parts.length; i++) { - metaStack.addStringEnchantment(null, allowUnsafe, parts[i]); + metaStack.addStringMeta(null, allowUnsafe, parts[i]); } } diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index cf4aa70ec..0dea8c63d 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -1,12 +1,19 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; +import java.util.logging.Logger; import java.util.regex.Pattern; +import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.SkullMeta; public class MetaItemStack @@ -18,15 +25,78 @@ public class MetaItemStack { this.stack = stack.clone(); } - + public ItemStack getItemStack() { return stack; } + //TODO: TL this public void addStringMeta(final User user, final boolean allowUnsafe, final String string) throws Exception { + final String[] split = splitPattern.split(string, 2); + if (split.length < 1) + { + return; + } + if (split.length > 1 && split[0].equalsIgnoreCase("name")) + { + final String displayName = split[1].replace('_', ' '); + final ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(displayName); + stack.setItemMeta(meta); + } + else if (split.length > 1 && (split[0].equalsIgnoreCase("lore") || split[0].equalsIgnoreCase("desc"))) + { + final List lore = new ArrayList(); + for (String line : split[1].split("\\|")) + { + lore.add(line.replace('_', ' ')); + } + final ItemMeta meta = stack.getItemMeta(); + meta.setLore(lore); + stack.setItemMeta(meta); + } + else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && stack.getType() == Material.SKULL_ITEM) + { + if (stack.getDurability() == 3) + { + final String owner = split[1]; + final SkullMeta meta = (SkullMeta)stack.getItemMeta(); + boolean result = meta.setOwner(owner); + stack.setItemMeta(meta); + } + else + { + throw new Exception("You can only set the owner of player skulls (397:3)"); + } + } + else if (split.length > 1 && (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour")) + && (stack.getType() == Material.LEATHER_BOOTS + || stack.getType() == Material.LEATHER_CHESTPLATE + || stack.getType() == Material.LEATHER_HELMET + || stack.getType() == Material.LEATHER_LEGGINGS)) + { + final String[] color = split[1].split("\\|"); + if (color.length == 3) + { + final int red = Util.isInt(color[0]) ? Integer.parseInt(color[0]) : 0; + final int green = Util.isInt(color[1]) ? Integer.parseInt(color[1]) : 0; + final int blue = Util.isInt(color[2]) ? Integer.parseInt(color[2]) : 0; + final LeatherArmorMeta meta = (LeatherArmorMeta)stack.getItemMeta(); + meta.setColor(Color.fromRGB(red, green, blue)); + stack.setItemMeta(meta); + } + else + { + throw new Exception("Leather Color Syntax: color:|| eg: color:255|0|0"); + } + } + else + { + parseEnchantmentStrings(user, allowUnsafe, split); + } } public void addStringEnchantment(final User user, final boolean allowUnsafe, final String string) throws Exception @@ -37,6 +107,11 @@ public class MetaItemStack return; } + parseEnchantmentStrings(user, allowUnsafe, split); + } + + private void parseEnchantmentStrings(final User user, final boolean allowUnsafe, final String[] split) throws Exception + { Enchantment enchantment = getEnchantment(user, split[0]); int level = -1; @@ -116,6 +191,4 @@ public class MetaItemStack } return enchantment; } - - } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java new file mode 100644 index 000000000..da46dbe7a --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java @@ -0,0 +1,45 @@ +package com.earth2me.essentials.commands; + +import com.earth2me.essentials.User; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + + +public class Commandbook extends EssentialsCommand +{ + public Commandbook() + { + super("book"); + } + + + //TODO: Translate this + @Override + public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + { + + ItemStack item = user.getItemInHand(); + if (item.getType() == Material.WRITTEN_BOOK) + { + ItemMeta meta = item.getItemMeta(); + ItemStack newItem = new ItemStack(Material.BOOK_AND_QUILL, item.getAmount()); + newItem.setItemMeta(meta); + user.setItemInHand(newItem); + user.sendMessage("You can now edit the contents of this book."); + } + else if (item.getType() == Material.BOOK_AND_QUILL) + { + ItemMeta meta = item.getItemMeta(); + ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount()); + newItem.setItemMeta(meta); + user.setItemInHand(newItem); + user.sendMessage("This book is now locked and signed."); + } + else + { + throw new Exception("You are not holding a book."); + } + } +} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index c80ff0d1b..49b60a8e7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -80,7 +80,7 @@ public class Commandgive extends EssentialsCommand for (int i = Util.isInt(args[3]) ? 4 : 3; i < args.length; i++) { - metaStack.addStringEnchantment(null, allowUnsafe, args[i]); + metaStack.addStringMeta(null, allowUnsafe, args[i]); } stack = metaStack.getItemStack(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 0acd1f60f..b69c73f2c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -62,7 +62,7 @@ public class Commanditem extends EssentialsCommand for (int i = 2; i < args.length; i++) { - metaStack.addStringEnchantment(null, allowUnsafe, args[i]); + metaStack.addStringMeta(null, allowUnsafe, args[i]); } stack = metaStack.getItemStack(); } diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 4453f355c..724a1b82f 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -212,8 +212,9 @@ kits: dtools: delay: 10 items: - - 277 1 efficiency:1 durability:1 - - 278 1 + - 277 1 digspeed:3 name:Dwarf lore:Diggy|Diggy|Hole + - 278 1 efficiency:1 durability:1 fortune:1 name:Gigadrill lore:The_drill_that_pierces|the_heavens + - 298 1 color:255|0|0 - 279:780 1 tools: delay: 10 @@ -222,6 +223,10 @@ kits: - 273 1 - 274 1 - 275 1 + notch: + delay: 1000 + items: + - 397:3 1 player:Notch # Essentials Sign Control # See http://wiki.ess3.net/wiki/Sign_Tutorial for instructions on how to use these. diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 8c66921d0..10ed7da21 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -39,6 +39,10 @@ commands: description: Bans an IP address. usage: /
aliases: [ebanip] + book: + description: Allows reopening written books. + usage: / + aliases: [ebook] break: description: Breaks the block you are looking at. usage: / From dd9b7e0d3cbd28164bb7c400cba8485c4a6b2f02 Mon Sep 17 00:00:00 2001 From: Necrodoom Date: Sun, 13 Jan 2013 15:01:10 +0200 Subject: [PATCH 05/22] update ID 397:3 --- Essentials/src/items.csv | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Essentials/src/items.csv b/Essentials/src/items.csv index bcc3fffb8..f60743467 100644 --- a/Essentials/src/items.csv +++ b/Essentials/src/items.csv @@ -5763,8 +5763,10 @@ headwitherskeleton,397,1 headwskeletion,397,1 zombiehead,397,2 headzombie,397,2 +playerhead,397,3 humanhead,397,3 stevehead,397,3 +headplayer,397,3 headhuman,397,3 headsteve,397,3 creeperhead,397,4 From b860e943f63f2006a15441e75492dc9b44f041cc Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sun, 13 Jan 2013 16:20:09 +0000 Subject: [PATCH 06/22] Synchronize pushing to Bukkit perms to prevent any ConcurrentModificationException. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../permissions/BukkitPermissions.java | 37 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 175d59959..0fb2d9d17 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -205,4 +205,5 @@ v 2.0: - Add support for Rcon. - Prevent GM commands from being used on CommandBlocks. - Clear our attachment map upon a manload so we correctly reconfigure a players new permissions. - - Synchronize the raising of GroupManager events to Bukkit.getServer() (should prevent deadlocks). \ No newline at end of file + - Synchronize the raising of GroupManager events to Bukkit.getServer() (should prevent deadlocks). + - Synchronize pushing to Bukkit perms to prevent any ConcurrentModificationException. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 6b02a2286..a200a7b9a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -137,8 +137,7 @@ public class BukkitPermissions { /** * Push all permissions which are registered with GM for this player, on - * this world to Bukkit - * and make it update for the child nodes. + * this world to Bukkit and make it update for the child nodes. * * @param player * @param world @@ -148,9 +147,9 @@ public class BukkitPermissions { if (player == null || !GroupManager.isLoaded()) { return; } - + String name = player.getName(); - + // Reset the User objects player reference. User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(name); if (user != null) @@ -175,7 +174,8 @@ public class BukkitPermissions { List playerPermArray = new ArrayList(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(name, false)); LinkedHashMap newPerms = new LinkedHashMap(); - // Sort the perm list by parent/child, so it will push to superperms correctly. + // Sort the perm list by parent/child, so it will push to superperms + // correctly. playerPermArray = sort(playerPermArray); Boolean value = false; @@ -186,25 +186,28 @@ public class BukkitPermissions { /** * This is put in place until such a time as Bukkit pull 466 is - * implemented - * https://github.com/Bukkit/Bukkit/pull/466 + * implemented https://github.com/Bukkit/Bukkit/pull/466 */ try { // Codename_B source - @SuppressWarnings("unchecked") - Map orig = (Map) permissions.get(attachment); - // Clear the map (faster than removing the attachment and recalculating) - orig.clear(); - // Then whack our map into there - orig.putAll(newPerms); - // That's all folks! - attachment.getPermissible().recalculatePermissions(); - //player.recalculatePermissions(); + synchronized (attachment.getPermissible()) { + + @SuppressWarnings("unchecked") + Map orig = (Map) permissions.get(attachment); + // Clear the map (faster than removing the attachment and + // recalculating) + orig.clear(); + // Then whack our map into there + orig.putAll(newPerms); + // That's all folks! + attachment.getPermissible().recalculatePermissions(); + + } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } - + GroupManager.logger.finest("Attachment updated for: " + name); } From 24f56892ad7230f61bcd1aac583d12e72e53907d Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sun, 13 Jan 2013 16:20:38 +0000 Subject: [PATCH 07/22] Fix the logger so errors are reported again. --- .../src/org/anjocaido/groupmanager/GMConfiguration.java | 2 +- .../src/org/anjocaido/groupmanager/GroupManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java index 95fd35eb0..4fcd0a554 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GMConfiguration.java @@ -112,7 +112,7 @@ public class GMConfiguration { Object level = ((Map) getElement("settings", GMconfig).get("logging")).get("level"); if (level instanceof String) - level = (String) level; + loggerLevel = (String) level; /* * Store our mirrors map for parsing later. diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 8298988e6..3236b9b84 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -152,7 +152,7 @@ public class GroupManager extends JavaPlugin { ch = new GMLoggerHandler(); GroupManager.logger.addHandler(ch); } - logger.setLevel(Level.ALL); + GroupManager.logger.setLevel(Level.ALL); // Create the backup folder, if it doesn't exist. prepareFileFields(); From 9fe7712bd670395fd61c698e81316441438044bc Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 13 Jan 2013 16:30:22 +0000 Subject: [PATCH 08/22] Clean up TextPager --- .../commands/Commandbalancetop.java | 2 +- .../essentials/textreader/TextPager.java | 69 +++++-------------- 2 files changed, 20 insertions(+), 51 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 0179db0c0..4711ffe40 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -82,7 +82,7 @@ public class Commandbalancetop extends EssentialsCommand cal.setTimeInMillis(cacheage); final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); sender.sendMessage(_("balanceTop", format.format(cal.getTime()))); - new TextPager(cache).showPage(Integer.toString(page), "", "balancetop", sender); + new TextPager(cache).showPage(Integer.toString(page), null, "balancetop", sender); } diff --git a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java index 3242d7509..503606527 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java +++ b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java @@ -30,57 +30,10 @@ public class TextPager List chapters = text.getChapters(); Map bookmarks = text.getBookmarks(); - if (bookmarks.isEmpty()) - { - int page = 1; - try - { - page = Integer.parseInt(pageStr); - } - catch (Exception ex) - { - page = 1; - } - if (page < 1) - { - page = 1; - } - - final int start = onePage ? 0 : (page - 1) * 9; - final int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0); - if (!onePage && commandName != null) - { - StringBuilder content = new StringBuilder(); - final String[] title = commandName.split(" ", 2); - if (title.length > 1) - { - content.append(I18n.capitalCase(title[0])).append(": "); - content.append(title[1]); - } - else if (chapterPageStr != null) - { - content.append(I18n.capitalCase(commandName)).append(": "); - content.append(chapterPageStr); - } - else - { - content.append(I18n.capitalCase(commandName)); - } - sender.sendMessage(_("infoPages", page, pages, content)); - } - for (int i = start; i < lines.size() && i < start + (onePage ? 20 : 9); i++) - { - sender.sendMessage("§r" + lines.get(i)); - } - if (!onePage && page < pages && commandName != null) - { - sender.sendMessage(_("readNextPage", commandName, page + 1)); - } - return; - } - if (pageStr == null || pageStr.isEmpty() || pageStr.matches("[0-9]+")) { + //If an info file starts with a chapter title, list the chapters + //If not display the text up until the first chapter. if (lines.get(0).startsWith("#")) { if (onePage) @@ -133,7 +86,23 @@ public class TextPager if (!onePage && commandName != null) { - sender.sendMessage(_("infoPages", page, pages, I18n.capitalCase(commandName))); + StringBuilder content = new StringBuilder(); + final String[] title = commandName.split(" ", 2); + if (title.length > 1) + { + content.append(I18n.capitalCase(title[0])).append(": "); + content.append(title[1]); + } + else if (chapterPageStr != null) + { + content.append(I18n.capitalCase(commandName)).append(": "); + content.append(chapterPageStr); + } + else + { + content.append(I18n.capitalCase(commandName)); + } + sender.sendMessage(_("infoPages", page, pages, content)); } for (int i = start; i < end && i < start + (onePage ? 20 : 9); i++) { From ad7009c77ebbb47a9694ed4e7f57e8eb5044beaf Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sun, 13 Jan 2013 16:39:53 +0000 Subject: [PATCH 09/22] Do not grant any permissions (nort update Bukkit) if the server is in offline mode and the player has the permission node 'groupmanager.noofflineperms'. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../permissions/AnjoPermissionsHandler.java | 10 ++++++++++ .../groupmanager/permissions/BukkitPermissions.java | 13 ++++++++++++- EssentialsGroupManager/src/users.yml | 9 ++++++--- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 0fb2d9d17..74e1581a6 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -206,4 +206,5 @@ v 2.0: - Prevent GM commands from being used on CommandBlocks. - Clear our attachment map upon a manload so we correctly reconfigure a players new permissions. - Synchronize the raising of GroupManager events to Bukkit.getServer() (should prevent deadlocks). - - Synchronize pushing to Bukkit perms to prevent any ConcurrentModificationException. \ No newline at end of file + - Synchronize pushing to Bukkit perms to prevent any ConcurrentModificationException. + - Do not grant any permissions (nort update Bukkit) if the server is in offline mode and the player has the permission node 'groupmanager.noofflineperms'. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java index e954a88fd..59efb33dc 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java @@ -16,6 +16,7 @@ import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.data.User; import org.anjocaido.groupmanager.utils.PermissionCheckResult; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** @@ -784,6 +785,15 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface { if (user == null || targetPermission == null || targetPermission.isEmpty()) { return result; } + + /* + * Do not push any perms to bukkit if... + * We are in offline mode + * and the player has the 'groupmanager.noofflineperms' permission. + */ + if (!Bukkit.getServer().getOnlineMode() + && (checkFullGMPermission(user, "groupmanager.noofflineperms", true).resultType == PermissionCheckResult.Type.FOUND)) + return result; if (checkBukkit) { // Check Bukkit perms to support plugins which add perms via code diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index a200a7b9a..03742b023 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -31,7 +31,6 @@ import java.util.WeakHashMap; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.User; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -183,6 +182,18 @@ public class BukkitPermissions { value = (!permission.startsWith("-")); newPerms.put((value ? permission : permission.substring(1)), value); } + + /* + * Do not push any perms to bukkit if... + * We are in offline mode + * and the player has the 'groupmanager.noofflineperms' permission. + */ + if (!Bukkit.getServer().getOnlineMode() + && (newPerms.containsKey("groupmanager.noofflineperms") && (newPerms.get("groupmanager.noofflineperms") == true))) { + removeAttachment(name); + return; + } + /** * This is put in place until such a time as Bukkit pull 466 is diff --git a/EssentialsGroupManager/src/users.yml b/EssentialsGroupManager/src/users.yml index 19496ad84..eaea6232d 100644 --- a/EssentialsGroupManager/src/users.yml +++ b/EssentialsGroupManager/src/users.yml @@ -3,13 +3,16 @@ users: snowleo: group: Builder subgroups: [] - permissions: [] + permissions: + - groupmanager.noofflineperms KHobbits: group: Moderator subgroups: [] - permissions: [] + permissions: + - groupmanager.noofflineperms ElgarL: group: Moderator subgroups: [] - permissions: [] + permissions: + - groupmanager.noofflineperms From 675c4b7897d906f1d8ca0ef0176b88dc09049419 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sun, 13 Jan 2013 16:40:53 +0000 Subject: [PATCH 10/22] typo in changelog. --- EssentialsGroupManager/src/Changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 74e1581a6..bbdab6a4f 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -207,4 +207,4 @@ v 2.0: - Clear our attachment map upon a manload so we correctly reconfigure a players new permissions. - Synchronize the raising of GroupManager events to Bukkit.getServer() (should prevent deadlocks). - Synchronize pushing to Bukkit perms to prevent any ConcurrentModificationException. - - Do not grant any permissions (nort update Bukkit) if the server is in offline mode and the player has the permission node 'groupmanager.noofflineperms'. \ No newline at end of file + - Do not grant any permissions (nor update Bukkit) if the server is in offline mode and the player has the permission node 'groupmanager.noofflineperms'. \ No newline at end of file From bd22aec38a64580b48b3a016954e55fb17482efd Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 13 Jan 2013 21:08:24 +0000 Subject: [PATCH 11/22] Adding support for books made from /einfo --- .../src/com/earth2me/essentials/Kit.java | 2 +- .../earth2me/essentials/MetaItemStack.java | 52 +++++--- .../src/com/earth2me/essentials/Util.java | 2 +- .../commands/Commandbalancetop.java | 2 +- .../essentials/commands/Commandbook.java | 2 +- .../essentials/commands/Commandgive.java | 2 +- .../essentials/commands/Commanditem.java | 2 +- .../essentials/textreader/BookInput.java | 124 ++++++++++++++++++ .../essentials/textreader/BookPager.java | 122 +++++++++++++++++ .../essentials/textreader/TextPager.java | 9 +- Essentials/src/config.yml | 4 + Essentials/src/info.txt | 8 +- 12 files changed, 305 insertions(+), 26 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/textreader/BookInput.java create mode 100644 Essentials/src/com/earth2me/essentials/textreader/BookPager.java diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index 4ff59a948..13652701a 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -122,7 +122,7 @@ public class Kit { for (int i = 2; i < parts.length; i++) { - metaStack.addStringMeta(null, allowUnsafe, parts[i]); + metaStack.addStringMeta(null, allowUnsafe, parts[i], ess); } } diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index 0dea8c63d..f7b78b5c8 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -1,45 +1,42 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.textreader.*; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.logging.Logger; import java.util.regex.Pattern; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.inventory.meta.*; public class MetaItemStack { private final transient Pattern splitPattern = Pattern.compile("[:+',;.]"); private final ItemStack stack; - + public MetaItemStack(final ItemStack stack) { this.stack = stack.clone(); } - + public ItemStack getItemStack() { return stack; } //TODO: TL this - public void addStringMeta(final User user, final boolean allowUnsafe, final String string) throws Exception + public void addStringMeta(final User user, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception { final String[] split = splitPattern.split(string, 2); if (split.length < 1) { return; } - + if (split.length > 1 && split[0].equalsIgnoreCase("name")) { final String displayName = split[1].replace('_', ' '); @@ -72,6 +69,31 @@ public class MetaItemStack throw new Exception("You can only set the owner of player skulls (397:3)"); } } + else if (split.length > 1 && split[0].equalsIgnoreCase("info") && stack.getType() == Material.WRITTEN_BOOK) + { + final BookMeta meta = (BookMeta)stack.getItemMeta(); + final IText input = new BookInput("info", true, ess); + final BookPager pager = new BookPager(input); + + List pages = pager.getPages(split[1]); + meta.setPages(pages); + + stack.setItemMeta(meta); + } + else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == Material.WRITTEN_BOOK) + { + final String author = split[1]; + final BookMeta meta = (BookMeta)stack.getItemMeta(); + meta.setAuthor(author); + stack.setItemMeta(meta); + } + else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK) + { + final String title = split[1]; + final BookMeta meta = (BookMeta)stack.getItemMeta(); + meta.setTitle(title); + stack.setItemMeta(meta); + } else if (split.length > 1 && (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour")) && (stack.getType() == Material.LEATHER_BOOTS || stack.getType() == Material.LEATHER_CHESTPLATE @@ -98,7 +120,7 @@ public class MetaItemStack parseEnchantmentStrings(user, allowUnsafe, split); } } - + public void addStringEnchantment(final User user, final boolean allowUnsafe, final String string) throws Exception { final String[] split = splitPattern.split(string, 2); @@ -106,14 +128,14 @@ public class MetaItemStack { return; } - + parseEnchantmentStrings(user, allowUnsafe, split); } - + private void parseEnchantmentStrings(final User user, final boolean allowUnsafe, final String[] split) throws Exception { Enchantment enchantment = getEnchantment(user, split[0]); - + int level = -1; if (split.length > 1) { @@ -126,14 +148,14 @@ public class MetaItemStack level = -1; } } - + if (level < 0 || (!allowUnsafe && level > enchantment.getMaxLevel())) { level = enchantment.getMaxLevel(); } addEnchantment(user, allowUnsafe, enchantment, level); } - + public void addEnchantment(final User user, final boolean allowUnsafe, final Enchantment enchantment, final int level) throws Exception { try diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index a31d18f0e..ad24a80d8 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -604,7 +604,7 @@ public class Util return input.substring(pos, pos + 2); } private static transient final Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-z]{2,3}(?:/\\S+)?)"); - private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]"); + private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]?"); private static transient final Pattern LOGCOLOR_PATTERN = Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]"); private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])"); private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-Fa-f]"); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 4711ffe40..d9007587f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -12,7 +12,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.bukkit.Server; import org.bukkit.command.CommandSender; - +//TODO: Remove op and replace with perm public class Commandbalancetop extends EssentialsCommand { public Commandbalancetop() diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java index da46dbe7a..19d316032 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java @@ -39,7 +39,7 @@ public class Commandbook extends EssentialsCommand } else { - throw new Exception("You are not holding a book."); + throw new Exception("You are not holding a writable book."); } } } \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 49b60a8e7..dfaf1b189 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -80,7 +80,7 @@ public class Commandgive extends EssentialsCommand for (int i = Util.isInt(args[3]) ? 4 : 3; i < args.length; i++) { - metaStack.addStringMeta(null, allowUnsafe, args[i]); + metaStack.addStringMeta(null, allowUnsafe, args[i], ess); } stack = metaStack.getItemStack(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index b69c73f2c..223162e2d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -62,7 +62,7 @@ public class Commanditem extends EssentialsCommand for (int i = 2; i < args.length; i++) { - metaStack.addStringMeta(null, allowUnsafe, args[i]); + metaStack.addStringMeta(null, allowUnsafe, args[i], ess); } stack = metaStack.getItemStack(); } diff --git a/Essentials/src/com/earth2me/essentials/textreader/BookInput.java b/Essentials/src/com/earth2me/essentials/textreader/BookInput.java new file mode 100644 index 000000000..26ee1dad5 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/textreader/BookInput.java @@ -0,0 +1,124 @@ +package com.earth2me.essentials.textreader; + +import com.earth2me.essentials.IEssentials; +import java.io.*; +import java.lang.ref.SoftReference; +import java.util.*; + + +public class BookInput implements IText +{ + private final transient List lines; + private final transient List chapters; + private final transient Map bookmarks; + private final transient long lastChange; + private final static HashMap> cache = new HashMap>(); + + public BookInput(final String filename, final boolean createFile, final IEssentials ess) throws IOException + { + + File file = null; + if (file == null || !file.exists()) + { + file = new File(ess.getDataFolder(), filename + ".txt"); + } + if (file.exists()) + { + lastChange = file.lastModified(); + boolean readFromfile; + synchronized (cache) + { + final SoftReference inputRef = cache.get(file.getName()); + BookInput input; + if (inputRef == null || (input = inputRef.get()) == null || input.lastChange < lastChange) + { + lines = new ArrayList(); + chapters = new ArrayList(); + bookmarks = new HashMap(); + cache.put(file.getName(), new SoftReference(this)); + readFromfile = true; + } + else + { + lines = Collections.unmodifiableList(input.getLines()); + chapters = Collections.unmodifiableList(input.getChapters()); + bookmarks = Collections.unmodifiableMap(input.getBookmarks()); + readFromfile = false; + } + } + if (readFromfile) + { + final BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); + try + { + int lineNumber = 0; + while (bufferedReader.ready()) + { + final String line = bufferedReader.readLine(); + if (line == null) + { + break; + } + if (line.length() > 0 && line.charAt(0) == '#') + { + bookmarks.put(line.substring(1).toLowerCase(Locale.ENGLISH).replaceAll("&[0-9a-fk]", ""), lineNumber); + chapters.add(line.substring(1).replace('&', '§').replace("§§", "&")); + } + lines.add(line.replace('&', '§').replace("§§", "&")); + lineNumber++; + } + } + finally + { + bufferedReader.close(); + } + } + } + else + { + lastChange = 0; + lines = Collections.emptyList(); + chapters = Collections.emptyList(); + bookmarks = Collections.emptyMap(); + if (createFile) + { + final InputStream input = ess.getResource(filename + ".txt"); + final OutputStream output = new FileOutputStream(file); + try + { + final byte[] buffer = new byte[1024]; + int length = input.read(buffer); + while (length > 0) + { + output.write(buffer, 0, length); + length = input.read(buffer); + } + } + finally + { + output.close(); + input.close(); + } + throw new FileNotFoundException("File " + filename + ".txt does not exist. Creating one for you."); + } + } + } + + @Override + public List getLines() + { + return lines; + } + + @Override + public List getChapters() + { + return chapters; + } + + @Override + public Map getBookmarks() + { + return bookmarks; + } +} diff --git a/Essentials/src/com/earth2me/essentials/textreader/BookPager.java b/Essentials/src/com/earth2me/essentials/textreader/BookPager.java new file mode 100644 index 000000000..0cd2c630e --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/textreader/BookPager.java @@ -0,0 +1,122 @@ +package com.earth2me.essentials.textreader; + +import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.Util; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.logging.Logger; + + +public class BookPager +{ + private final transient IText text; + + public BookPager(final IText text) + { + this.text = text; + } + + public List getPages(final String pageStr) throws Exception + { + List lines = text.getLines(); + List chapters = text.getChapters(); + Map bookmarks = text.getBookmarks(); + + int chapterpage = 0; + + //This checks to see if we have the chapter in the index + if (!bookmarks.containsKey(pageStr.toLowerCase(Locale.ENGLISH))) + { + throw new Exception("No such /einfo chapter!"); + } + + //Since we have a valid chapter, count the number of lines in the chapter + final int chapterstart = bookmarks.get(pageStr.toLowerCase(Locale.ENGLISH)) + 1; + int chapterend; + for (chapterend = chapterstart; chapterend < lines.size(); chapterend++) + { + final String line = lines.get(chapterend); + if (line.length() > 0 && line.charAt(0) == '#') + { + break; + } + } + + List pageLines = new ArrayList(); + + for (int lineNo = chapterstart; lineNo < chapterend; lineNo += 1) + { + String pageLine = "\u00a70" + lines.get(lineNo); + String tempLine; + final double max = 18; + final int lineLength = pageLine.length(); + double length = 0; + int pointer = 0; + int start = 0; + double weight = 1; + + while (pointer < lineLength) + { + if (length >= max) + { + tempLine = pageLine.substring(start, pointer); + pageLines.add(tempLine); + start = pointer; + length = 0; + } + + Character letter = pageLine.charAt(pointer); + + if (letter == '\u00a7') + { + Character nextLetter = pageLine.charAt(pointer + 1); + if (nextLetter == 'l') + { + weight = 1.25; + } + else + { + weight = 1; + } + pointer++; + } + else if (letter == ' ') + { + length += (0.7 * weight); + } + else + { + length += weight; + } + pointer++; + } + if (length > 0) + { + tempLine = pageLine.substring(start, lineLength); + pageLines.add(tempLine); + } + } + + List pages = new ArrayList(); + + for (int count = 0; count < pageLines.size(); count += 12) + { + + StringBuilder newPage = new StringBuilder(); + + for (int i = count; i < count + 12 && i < pageLines.size(); i++) + { + newPage.append("\n").append(pageLines.get(i)); + //Logger.getLogger("Minecraft").info("adding line " + pageLines.get(i) + " to book"); + } + + //Logger.getLogger("Minecraft").info("adding page to book"); + pages.add(newPage.toString()); + } + + return pages; + + } +} diff --git a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java index 503606527..c9353f89e 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java +++ b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java @@ -30,6 +30,8 @@ public class TextPager List chapters = text.getChapters(); Map bookmarks = text.getBookmarks(); + //This code deals with the initial chapter. We use this to display the initial output or contents. + //We also use this code to display some extra information if we don't intend to use chapters if (pageStr == null || pageStr.isEmpty() || pageStr.matches("[0-9]+")) { //If an info file starts with a chapter title, list the chapters @@ -116,6 +118,7 @@ public class TextPager } } + //If we have a chapter, check to see if we have a page number int chapterpage = 0; if (chapterPageStr != null) { @@ -133,11 +136,14 @@ public class TextPager } } + //This checks to see if we have the chapter in the index if (!bookmarks.containsKey(pageStr.toLowerCase(Locale.ENGLISH))) { sender.sendMessage(_("infoUnknownChapter")); return; } + + //Since we have a valid chapter, count the number of lines in the chapter final int chapterstart = bookmarks.get(pageStr.toLowerCase(Locale.ENGLISH)) + 1; int chapterend; for (chapterend = chapterstart; chapterend < lines.size(); chapterend++) @@ -148,8 +154,9 @@ public class TextPager break; } } + + //Display the chapter from the starting position final int start = chapterstart + (onePage ? 0 : chapterpage * 9); - final int page = chapterpage + 1; final int pages = (chapterend - chapterstart) / 9 + ((chapterend - chapterstart) % 9 > 0 ? 1 : 0); if (!onePage && commandName != null) diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 724a1b82f..b1ebf6ca0 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -227,6 +227,10 @@ kits: delay: 1000 items: - 397:3 1 player:Notch + color: + delay: 1000 + items: + - 387 1 title:Colors author:KHobbits lore:Ingame_color_codes info:Colors # Essentials Sign Control # See http://wiki.ess3.net/wiki/Sign_Tutorial for instructions on how to use these. diff --git a/Essentials/src/info.txt b/Essentials/src/info.txt index 965780a15..fbd433843 100644 --- a/Essentials/src/info.txt +++ b/Essentials/src/info.txt @@ -29,10 +29,10 @@ Minecraft colors: &4 &&4 &5 &&5 &6 &&6 &7 &&7 &8 &&8 &9 &&9 &a &&a &b &&b &c &&c &d &&d &e &&e &f &&f - -&&k &k Magic!&r &&l &l Bold! -&&m &m Strike!&r &&n &n Underline! -&&o &o Italic!&r &&r &r reset format codes! +&0 +&&k &kMagic&r &&l &lBold +&&m &mStrike&r &&n &nUline +&&o &oItalic&r &&r &rReset #Tags &6Player name:&r {PLAYER} From 7e3fd489562f7de9874eba346cc55f516c0b9d1a Mon Sep 17 00:00:00 2001 From: GunfighterJ Date: Sun, 13 Jan 2013 15:54:11 -0600 Subject: [PATCH 12/22] Added more book commands for editing author and title --- .../essentials/commands/Commandbook.java | 78 +++++++++++++++++-- Essentials/src/messages.properties | 8 ++ Essentials/src/messages_cs.properties | 8 ++ Essentials/src/messages_da.properties | 8 ++ Essentials/src/messages_de.properties | 8 ++ Essentials/src/messages_en.properties | 8 ++ Essentials/src/messages_es.properties | 8 ++ Essentials/src/messages_fi.properties | 8 ++ Essentials/src/messages_fr.properties | 8 ++ Essentials/src/messages_it.properties | 8 ++ Essentials/src/messages_nl.properties | 8 ++ Essentials/src/messages_pl.properties | 8 ++ Essentials/src/messages_pt.properties | 8 ++ Essentials/src/messages_se.properties | 44 ++++++----- 14 files changed, 192 insertions(+), 26 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java index 19d316032..e2af2d522 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java @@ -1,9 +1,11 @@ package com.earth2me.essentials.commands; +import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.ItemMeta; @@ -14,32 +16,92 @@ public class Commandbook extends EssentialsCommand super("book"); } - //TODO: Translate this @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { ItemStack item = user.getItemInHand(); + String player = user.getName(); if (item.getType() == Material.WRITTEN_BOOK) { ItemMeta meta = item.getItemMeta(); - ItemStack newItem = new ItemStack(Material.BOOK_AND_QUILL, item.getAmount()); - newItem.setItemMeta(meta); - user.setItemInHand(newItem); - user.sendMessage("You can now edit the contents of this book."); + BookMeta bmeta = (BookMeta)meta; + if (args[0].equalsIgnoreCase("author")) + { + if (user.isAuthorized("essentals.book.author")) + { + ItemStack newbook = new ItemStack(Material.WRITTEN_BOOK, 1); + bmeta.setAuthor(args[1]); + newbook.setItemMeta(bmeta); + user.setItemInHand(newbook); + user.sendMessage(_("bookAuthorSet", args[1])); + } + else + { + user.sendMessage(_("denyChangeAuthor")); + } + } + else if (args[0].equalsIgnoreCase("title")) + { + if (user.isAuthorized("essentials.book.title")) + { + + if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.title.others")) + { + ItemStack newbook = new ItemStack(Material.WRITTEN_BOOK, 1); + bmeta.setTitle(args[1]); + newbook.setItemMeta(bmeta); + user.setItemInHand(newbook); + user.sendMessage(_("bookTitleSet", args[1])); + } + else + { + user.sendMessage(_("denyChangeTitle")); + } + } + else + { + user.sendMessage(_("denyChangeTitle")); + } + } + else + { + if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others")) + { + ItemStack newItem = new ItemStack(Material.BOOK_AND_QUILL, item.getAmount()); + newItem.setItemMeta(meta); + user.setItemInHand(newItem); + user.sendMessage(_("editBookContents")); + } + else + { + user.sendMessage(_("denyBookEdit")); + } + } } else if (item.getType() == Material.BOOK_AND_QUILL) { ItemMeta meta = item.getItemMeta(); + BookMeta bmeta = (BookMeta)meta; + bmeta.setAuthor(player); ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount()); - newItem.setItemMeta(meta); + newItem.setItemMeta(bmeta); user.setItemInHand(newItem); - user.sendMessage("This book is now locked and signed."); + user.sendMessage(_("bookLocked")); } else { - throw new Exception("You are not holding a writable book."); + throw new Exception(_("holdBook")); } } + + private boolean isAuthor(BookMeta bmeta, String player) + { + if (bmeta.getAuthor().equalsIgnoreCase(player)) + { + return true; + } + return false; + } } \ No newline at end of file diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 9f27e5eea..b5bdfc340 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties index 486c085cb..56772abc7 100644 --- a/Essentials/src/messages_cs.properties +++ b/Essentials/src/messages_cs.properties @@ -481,3 +481,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index f69dc4ebb..3e13c65f5 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 2d2284542..568b7f760 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 9f27e5eea..b5bdfc340 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index 7915968fb..983bbb70b 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties index 05da0a0d6..f64ad8cf2 100644 --- a/Essentials/src/messages_fi.properties +++ b/Essentials/src/messages_fi.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 82566c31e..8d4116697 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties index c8bcdd711..02ce6c483 100644 --- a/Essentials/src/messages_it.properties +++ b/Essentials/src/messages_it.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index 11fe951d6..81ae25e03 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties index 4c666c1cc..923e125f5 100644 --- a/Essentials/src/messages_pl.properties +++ b/Essentials/src/messages_pl.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties index 8db1a6bc4..f7ea1a220 100644 --- a/Essentials/src/messages_pt.properties +++ b/Essentials/src/messages_pt.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_se.properties b/Essentials/src/messages_se.properties index 03b5f35ae..a110218a3 100644 --- a/Essentials/src/messages_se.properties +++ b/Essentials/src/messages_se.properties @@ -5,15 +5,15 @@ action=* {0} {1} addedToAccount=\u00a7a{0} har blivit tillagt p\u00e5 ditt konto. addedToOthersAccount=\u00a7a{0} har blivit tillagt p\u00e5 {1}\u00a7a konto. Ny balans: {2} -adventure = \u00E4ventyr +adventure = \u00e4ventyr alertBroke=gjorde s\u00f6nder: alertFormat=\u00a73[{0}] \u00a7f {1} \u00a76 {2} at: {3} alertPlaced=placerade: alertUsed=anv\u00e4nde: -antiBuildBreak=\u00a74Du har inte till\u00E5telse att ta s\u00F6nder {0} blocks h\u00E4r. -antiBuildInteract=\u00a74Du har inte till\u00E5telse att p\u00E5verka {0}. -antiBuildPlace=\u00a74Du har inte till\u00E5telse att placera {0} h\u00E4r. -antiBuildUse=\u00a74Du har inte till\u00E5telse att anv\u00E4nda {0}. +antiBuildBreak=\u00a74Du har inte till\u00e5telse att ta s\u00f6nder {0} blocks h\u00e4r. +antiBuildInteract=\u00a74Du har inte till\u00e5telse att p\u00e5verka {0}. +antiBuildPlace=\u00a74Du har inte till\u00e5telse att placera {0} h\u00e4r. +antiBuildUse=\u00a74Du har inte till\u00e5telse att anv\u00e4nda {0}. autoAfkKickReason=Du har blivit utsparkad f\u00f6r att ha varit inaktiv i mer \u00e4n {0} minuter. backAfterDeath=\u00a77Anv\u00e4nd /back kommandot f\u00f6r att komma tillbaka till din d\u00f6dsplats. backUsageMsg=\u00a77Tar dig tillbaka till din f\u00f6reg\u00e5ende position. @@ -115,7 +115,7 @@ godDisabledFor=inaktiverat f\u00f6r {0} godEnabledFor=aktiverat f\u00f6r {0} godMode=\u00a77Od\u00f6dlighet {0}. hatArmor=\u00a7cFel, du kan inte anv\u00e4nda den h\u00e4r saken som en hatt! -hatEmpty=\u00a7cDu har inte p\u00E5 dig en hatt. +hatEmpty=\u00a7cDu har inte p\u00e5 dig en hatt. hatFail=\u00a7cDu m\u00e5ste ha n\u00e5gonting att b\u00e4ra i din hand. hatPlaced=\u00a7eNjut av din nya hatt! hatRemoved=\u00a7eDin hatt har tagits bort. @@ -157,7 +157,7 @@ inventoryClearedOthers=\u00a77F\u00f6rr\u00e5det av \u00a7c{0}\u00a77 \u00e4r re is=\u00e4r itemCannotBeSold=Det objektet kan inte s\u00e4ljas till servern. itemMustBeStacked=Objektet m\u00e5ste k\u00f6pas i staplar. En m\u00e4ngd av 2s kommer bli 2 staplar, etc. -itemNames=F\u00F6rkortning p\u00E5 objekt: {0} +itemNames=F\u00f6rkortning p\u00e5 objekt: {0} itemNotEnough1=\u00a7cDu har inte tillr\u00e4ckligt av den saken f\u00f6r att s\u00e4lja. itemNotEnough2=\u00a77Om du ville s\u00e4lja alla block av den typen, anv\u00e4nd /sell blocknamn itemNotEnough3=\u00a77/sell blocknamn -1 kommer att s\u00e4lja allt av den blocktypen f\u00f6rutom 1 o.s.v. @@ -218,7 +218,7 @@ moneyTaken={0} \u00e4r taget fr\u00e5n ditt bankkonto. month=m\u00e5nad months=m\u00e5nader moreThanZero=M\u00e5ngden m\u00e5ste vara st\u00f6rre \u00e4n 0. -moveSpeed=\u00a77Satte {0}fart till {1} f\u00F6r {2}. +moveSpeed=\u00a77Satte {0}fart till {1} f\u00f6r {2}. msgFormat=\u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2} muteExempt=\u00a7cDu kan inte tysta den spelaren. mutedPlayer=Spelaren {0} \u00e4r tystad. @@ -373,8 +373,8 @@ timeSet=Tid inst\u00e4lld i alla v\u00e4rldar. timeSetPermission=\u00a7cDu har inte tillst\u00e5nd att st\u00e4lla in tiden. timeWorldCurrent=Den nuvarande tiden i {0} \u00e4r \u00a73{1} timeWorldSet=Tiden \u00e4r nu {0} i: \u00a7c{1} -totalWorthAll=\u00a7aS\u00E5lde alla objekt f\u00F6r ett totalt v\u00E4rde av {1}. -totalWorthBlocks=\u00a7aS\u00E5lde alla blocks f\u00F6r ett totalt v\u00E4rde av {1}. +totalWorthAll=\u00a7aS\u00e5lde alla objekt f\u00f6r ett totalt v\u00e4rde av {1}. +totalWorthBlocks=\u00a7aS\u00e5lde alla blocks f\u00f6r ett totalt v\u00e4rde av {1}. tps=Nuvarande TPS = {0} tradeCompleted=\u00a77K\u00f6p avslutat. tradeSignEmpty=K\u00f6pskylten har inget tillg\u00e4ngligt f\u00f6r dig. @@ -447,24 +447,24 @@ year=\u00e5r years=\u00e5r youAreHealed=\u00a77Du har blivit l\u00e4kt. youHaveNewMail=\u00a7cDu har {0} meddelanden!\u00a7f Skriv \u00a77/mail read\u00a7f f\u00f6r att l\u00e4sa dina meddelanden. -posX=\u00a76X: {0} (+\u00D6ster <-> -V\u00e4st) +posX=\u00a76X: {0} (+\u00d6ster <-> -V\u00e4st) posY=\u00a76Y: {0} (+Upp <-> -Ner) posZ=\u00a76Z: {0} (+Syd <-> -Nort) posYaw=\u00a76Girning: {0} (Rotation) posPitch=\u00a76Pitch: {0} (Huvudvinkel) -distance=\u00a76Avst\u00E5nd: {0} +distance=\u00a76Avst\u00e5nd: {0} giveSpawn=\u00a76Ger\u00a7c {0} \u00a76av\u00a7c {1} till\u00a7c {2}\u00a76. warpList={0} uptime=\u00a76Upptid:\u00a7c {0} -antiBuildCraft=\u00a74Du har inte till\u00E5telse att skapa\u00a7c {0}\u00a74. -antiBuildDrop=\u00a74Du har inte till\u00E5telse att kasta ut\u00a7c {0}\u00a74. +antiBuildCraft=\u00a74Du har inte till\u00e5telse att skapa\u00a7c {0}\u00a74. +antiBuildDrop=\u00a74Du har inte till\u00e5telse att kasta ut\u00a7c {0}\u00a74. gcWorld=\u00a76{0} "\u00a7c{1}\u00a76": \u00a7c{2}\u00a76 bitar, \u00a7c{3}\u00a76 enheter invalidHomeName=\u00a74Ogiltigt hemnamn invalidWarpName=\u00a74Ogiltigt warpnamn -userUnknown=\u00a74Varning: Anv\u00E4ndaren '\u00a7c{0}\u00a74' har aldrig varit inne p\u00E5 denna server tidigare. -teleportationEnabledFor=\u00a76TTeleportering aktiverat f\u00F6r {0} -teleportationDisabledFor=\u00a76Teleportering inaktiverat f\u00F6r {0} -kitOnce=\u00a74Du kan inte av\u00E4nda det kitet igen. +userUnknown=\u00a74Varning: Anv\u00e4ndaren '\u00a7c{0}\u00a74' har aldrig varit inne p\u00e5 denna server tidigare. +teleportationEnabledFor=\u00a76TTeleportering aktiverat f\u00f6r {0} +teleportationDisabledFor=\u00a76Teleportering inaktiverat f\u00f6r {0} +kitOnce=\u00a74Du kan inte av\u00e4nda det kitet igen. fullStack=\u00a74Du har redan en full stapel oversizedTempban=\u00a74Du kan inte banna en spelare just vid denna tidpunkt. recipeNone=No recipes exist for {0} @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file From ffe2a283d2461139ab43d067fae1f249759ff6d5 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 13 Jan 2013 22:18:08 +0000 Subject: [PATCH 13/22] Cleanup of book meta. --- .../essentials/textreader/BookInput.java | 2 +- .../essentials/textreader/BookPager.java | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/textreader/BookInput.java b/Essentials/src/com/earth2me/essentials/textreader/BookInput.java index 26ee1dad5..d8df79ec2 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/BookInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/BookInput.java @@ -17,7 +17,7 @@ public class BookInput implements IText public BookInput(final String filename, final boolean createFile, final IEssentials ess) throws IOException { - File file = null; + File file = null; if (file == null || !file.exists()) { file = new File(ess.getDataFolder(), filename + ".txt"); diff --git a/Essentials/src/com/earth2me/essentials/textreader/BookPager.java b/Essentials/src/com/earth2me/essentials/textreader/BookPager.java index 0cd2c630e..1a2d80e9e 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/BookPager.java +++ b/Essentials/src/com/earth2me/essentials/textreader/BookPager.java @@ -1,12 +1,9 @@ package com.earth2me.essentials.textreader; -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.Util; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.logging.Logger; public class BookPager @@ -22,10 +19,9 @@ public class BookPager { List lines = text.getLines(); List chapters = text.getChapters(); + List pageLines = new ArrayList(); Map bookmarks = text.getBookmarks(); - int chapterpage = 0; - //This checks to see if we have the chapter in the index if (!bookmarks.containsKey(pageStr.toLowerCase(Locale.ENGLISH))) { @@ -44,8 +40,6 @@ public class BookPager } } - List pageLines = new ArrayList(); - for (int lineNo = chapterstart; lineNo < chapterend; lineNo += 1) { String pageLine = "\u00a70" + lines.get(lineNo); @@ -72,7 +66,7 @@ public class BookPager if (letter == '\u00a7') { Character nextLetter = pageLine.charAt(pointer + 1); - if (nextLetter == 'l') + if (nextLetter == 'l' || nextLetter == 'L') { weight = 1.25; } @@ -100,23 +94,17 @@ public class BookPager } List pages = new ArrayList(); - for (int count = 0; count < pageLines.size(); count += 12) { - StringBuilder newPage = new StringBuilder(); - for (int i = count; i < count + 12 && i < pageLines.size(); i++) { newPage.append("\n").append(pageLines.get(i)); - //Logger.getLogger("Minecraft").info("adding line " + pageLines.get(i) + " to book"); } - //Logger.getLogger("Minecraft").info("adding page to book"); pages.add(newPage.toString()); } return pages; - } } From 84c06fb74633a3723532b9b1b900d3dc36650a8e Mon Sep 17 00:00:00 2001 From: GunfighterJ Date: Sun, 13 Jan 2013 16:08:46 -0600 Subject: [PATCH 14/22] Added more book arguments for editing author and title amend --- .../essentials/commands/Commandbook.java | 74 +++++++++++++++++-- Essentials/src/messages.properties | 8 ++ Essentials/src/messages_cs.properties | 8 ++ Essentials/src/messages_da.properties | 8 ++ Essentials/src/messages_de.properties | 8 ++ Essentials/src/messages_en.properties | 8 ++ Essentials/src/messages_es.properties | 8 ++ Essentials/src/messages_fi.properties | 8 ++ Essentials/src/messages_fr.properties | 8 ++ Essentials/src/messages_it.properties | 8 ++ Essentials/src/messages_nl.properties | 8 ++ Essentials/src/messages_pl.properties | 8 ++ Essentials/src/messages_pt.properties | 8 ++ Essentials/src/messages_se.properties | 44 ++++++----- 14 files changed, 188 insertions(+), 26 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java index 19d316032..872e17b16 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java @@ -1,9 +1,11 @@ package com.earth2me.essentials.commands; +import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.ItemMeta; @@ -14,32 +16,88 @@ public class Commandbook extends EssentialsCommand super("book"); } - //TODO: Translate this @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { ItemStack item = user.getItemInHand(); + String player = user.getName(); if (item.getType() == Material.WRITTEN_BOOK) { ItemMeta meta = item.getItemMeta(); - ItemStack newItem = new ItemStack(Material.BOOK_AND_QUILL, item.getAmount()); - newItem.setItemMeta(meta); - user.setItemInHand(newItem); - user.sendMessage("You can now edit the contents of this book."); + BookMeta bmeta = (BookMeta)meta; + if (args[0].equalsIgnoreCase("author")) + { + if (user.isAuthorized("essentals.book.author")) + { + ItemStack newbook = new ItemStack(Material.WRITTEN_BOOK, 1); + bmeta.setAuthor(args[1]); + newbook.setItemMeta(bmeta); + user.setItemInHand(newbook); + user.sendMessage(_("bookAuthorSet", args[1])); + } + else + { + user.sendMessage(_("denyChangeAuthor")); + } + } + else if (args[0].equalsIgnoreCase("title")) + { + if (user.isAuthorized("essentials.book.title")) + { + + if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.title.others")) + { + ItemStack newbook = new ItemStack(Material.WRITTEN_BOOK, 1); + bmeta.setTitle(args[1]); + newbook.setItemMeta(bmeta); + user.setItemInHand(newbook); + user.sendMessage(_("bookTitleSet", args[1])); + } + else + { + user.sendMessage(_("denyChangeTitle")); + } + } + else + { + user.sendMessage(_("denyChangeTitle")); + } + } + else + { + if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others")) + { + ItemStack newItem = new ItemStack(Material.BOOK_AND_QUILL, item.getAmount()); + newItem.setItemMeta(meta); + user.setItemInHand(newItem); + user.sendMessage(_("editBookContents")); + } + else + { + user.sendMessage(_("denyBookEdit")); + } + } } else if (item.getType() == Material.BOOK_AND_QUILL) { ItemMeta meta = item.getItemMeta(); + BookMeta bmeta = (BookMeta)meta; + bmeta.setAuthor(player); ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount()); - newItem.setItemMeta(meta); + newItem.setItemMeta(bmeta); user.setItemInHand(newItem); - user.sendMessage("This book is now locked and signed."); + user.sendMessage(_("bookLocked")); } else { - throw new Exception("You are not holding a writable book."); + throw new Exception(_("holdBook")); } } + + private boolean isAuthor(BookMeta bmeta, String player) + { + return bmeta.getAuthor().equalsIgnoreCase(player); + } } \ No newline at end of file diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 9f27e5eea..b5bdfc340 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties index 486c085cb..56772abc7 100644 --- a/Essentials/src/messages_cs.properties +++ b/Essentials/src/messages_cs.properties @@ -481,3 +481,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index f69dc4ebb..3e13c65f5 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 2d2284542..568b7f760 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 9f27e5eea..b5bdfc340 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index 7915968fb..983bbb70b 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties index 05da0a0d6..f64ad8cf2 100644 --- a/Essentials/src/messages_fi.properties +++ b/Essentials/src/messages_fi.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 82566c31e..8d4116697 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties index c8bcdd711..02ce6c483 100644 --- a/Essentials/src/messages_it.properties +++ b/Essentials/src/messages_it.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index 11fe951d6..81ae25e03 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties index 4c666c1cc..923e125f5 100644 --- a/Essentials/src/messages_pl.properties +++ b/Essentials/src/messages_pl.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties index 8db1a6bc4..f7ea1a220 100644 --- a/Essentials/src/messages_pt.properties +++ b/Essentials/src/messages_pt.properties @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file diff --git a/Essentials/src/messages_se.properties b/Essentials/src/messages_se.properties index 03b5f35ae..a110218a3 100644 --- a/Essentials/src/messages_se.properties +++ b/Essentials/src/messages_se.properties @@ -5,15 +5,15 @@ action=* {0} {1} addedToAccount=\u00a7a{0} har blivit tillagt p\u00e5 ditt konto. addedToOthersAccount=\u00a7a{0} har blivit tillagt p\u00e5 {1}\u00a7a konto. Ny balans: {2} -adventure = \u00E4ventyr +adventure = \u00e4ventyr alertBroke=gjorde s\u00f6nder: alertFormat=\u00a73[{0}] \u00a7f {1} \u00a76 {2} at: {3} alertPlaced=placerade: alertUsed=anv\u00e4nde: -antiBuildBreak=\u00a74Du har inte till\u00E5telse att ta s\u00F6nder {0} blocks h\u00E4r. -antiBuildInteract=\u00a74Du har inte till\u00E5telse att p\u00E5verka {0}. -antiBuildPlace=\u00a74Du har inte till\u00E5telse att placera {0} h\u00E4r. -antiBuildUse=\u00a74Du har inte till\u00E5telse att anv\u00E4nda {0}. +antiBuildBreak=\u00a74Du har inte till\u00e5telse att ta s\u00f6nder {0} blocks h\u00e4r. +antiBuildInteract=\u00a74Du har inte till\u00e5telse att p\u00e5verka {0}. +antiBuildPlace=\u00a74Du har inte till\u00e5telse att placera {0} h\u00e4r. +antiBuildUse=\u00a74Du har inte till\u00e5telse att anv\u00e4nda {0}. autoAfkKickReason=Du har blivit utsparkad f\u00f6r att ha varit inaktiv i mer \u00e4n {0} minuter. backAfterDeath=\u00a77Anv\u00e4nd /back kommandot f\u00f6r att komma tillbaka till din d\u00f6dsplats. backUsageMsg=\u00a77Tar dig tillbaka till din f\u00f6reg\u00e5ende position. @@ -115,7 +115,7 @@ godDisabledFor=inaktiverat f\u00f6r {0} godEnabledFor=aktiverat f\u00f6r {0} godMode=\u00a77Od\u00f6dlighet {0}. hatArmor=\u00a7cFel, du kan inte anv\u00e4nda den h\u00e4r saken som en hatt! -hatEmpty=\u00a7cDu har inte p\u00E5 dig en hatt. +hatEmpty=\u00a7cDu har inte p\u00e5 dig en hatt. hatFail=\u00a7cDu m\u00e5ste ha n\u00e5gonting att b\u00e4ra i din hand. hatPlaced=\u00a7eNjut av din nya hatt! hatRemoved=\u00a7eDin hatt har tagits bort. @@ -157,7 +157,7 @@ inventoryClearedOthers=\u00a77F\u00f6rr\u00e5det av \u00a7c{0}\u00a77 \u00e4r re is=\u00e4r itemCannotBeSold=Det objektet kan inte s\u00e4ljas till servern. itemMustBeStacked=Objektet m\u00e5ste k\u00f6pas i staplar. En m\u00e4ngd av 2s kommer bli 2 staplar, etc. -itemNames=F\u00F6rkortning p\u00E5 objekt: {0} +itemNames=F\u00f6rkortning p\u00e5 objekt: {0} itemNotEnough1=\u00a7cDu har inte tillr\u00e4ckligt av den saken f\u00f6r att s\u00e4lja. itemNotEnough2=\u00a77Om du ville s\u00e4lja alla block av den typen, anv\u00e4nd /sell blocknamn itemNotEnough3=\u00a77/sell blocknamn -1 kommer att s\u00e4lja allt av den blocktypen f\u00f6rutom 1 o.s.v. @@ -218,7 +218,7 @@ moneyTaken={0} \u00e4r taget fr\u00e5n ditt bankkonto. month=m\u00e5nad months=m\u00e5nader moreThanZero=M\u00e5ngden m\u00e5ste vara st\u00f6rre \u00e4n 0. -moveSpeed=\u00a77Satte {0}fart till {1} f\u00F6r {2}. +moveSpeed=\u00a77Satte {0}fart till {1} f\u00f6r {2}. msgFormat=\u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2} muteExempt=\u00a7cDu kan inte tysta den spelaren. mutedPlayer=Spelaren {0} \u00e4r tystad. @@ -373,8 +373,8 @@ timeSet=Tid inst\u00e4lld i alla v\u00e4rldar. timeSetPermission=\u00a7cDu har inte tillst\u00e5nd att st\u00e4lla in tiden. timeWorldCurrent=Den nuvarande tiden i {0} \u00e4r \u00a73{1} timeWorldSet=Tiden \u00e4r nu {0} i: \u00a7c{1} -totalWorthAll=\u00a7aS\u00E5lde alla objekt f\u00F6r ett totalt v\u00E4rde av {1}. -totalWorthBlocks=\u00a7aS\u00E5lde alla blocks f\u00F6r ett totalt v\u00E4rde av {1}. +totalWorthAll=\u00a7aS\u00e5lde alla objekt f\u00f6r ett totalt v\u00e4rde av {1}. +totalWorthBlocks=\u00a7aS\u00e5lde alla blocks f\u00f6r ett totalt v\u00e4rde av {1}. tps=Nuvarande TPS = {0} tradeCompleted=\u00a77K\u00f6p avslutat. tradeSignEmpty=K\u00f6pskylten har inget tillg\u00e4ngligt f\u00f6r dig. @@ -447,24 +447,24 @@ year=\u00e5r years=\u00e5r youAreHealed=\u00a77Du har blivit l\u00e4kt. youHaveNewMail=\u00a7cDu har {0} meddelanden!\u00a7f Skriv \u00a77/mail read\u00a7f f\u00f6r att l\u00e4sa dina meddelanden. -posX=\u00a76X: {0} (+\u00D6ster <-> -V\u00e4st) +posX=\u00a76X: {0} (+\u00d6ster <-> -V\u00e4st) posY=\u00a76Y: {0} (+Upp <-> -Ner) posZ=\u00a76Z: {0} (+Syd <-> -Nort) posYaw=\u00a76Girning: {0} (Rotation) posPitch=\u00a76Pitch: {0} (Huvudvinkel) -distance=\u00a76Avst\u00E5nd: {0} +distance=\u00a76Avst\u00e5nd: {0} giveSpawn=\u00a76Ger\u00a7c {0} \u00a76av\u00a7c {1} till\u00a7c {2}\u00a76. warpList={0} uptime=\u00a76Upptid:\u00a7c {0} -antiBuildCraft=\u00a74Du har inte till\u00E5telse att skapa\u00a7c {0}\u00a74. -antiBuildDrop=\u00a74Du har inte till\u00E5telse att kasta ut\u00a7c {0}\u00a74. +antiBuildCraft=\u00a74Du har inte till\u00e5telse att skapa\u00a7c {0}\u00a74. +antiBuildDrop=\u00a74Du har inte till\u00e5telse att kasta ut\u00a7c {0}\u00a74. gcWorld=\u00a76{0} "\u00a7c{1}\u00a76": \u00a7c{2}\u00a76 bitar, \u00a7c{3}\u00a76 enheter invalidHomeName=\u00a74Ogiltigt hemnamn invalidWarpName=\u00a74Ogiltigt warpnamn -userUnknown=\u00a74Varning: Anv\u00E4ndaren '\u00a7c{0}\u00a74' har aldrig varit inne p\u00E5 denna server tidigare. -teleportationEnabledFor=\u00a76TTeleportering aktiverat f\u00F6r {0} -teleportationDisabledFor=\u00a76Teleportering inaktiverat f\u00F6r {0} -kitOnce=\u00a74Du kan inte av\u00E4nda det kitet igen. +userUnknown=\u00a74Varning: Anv\u00e4ndaren '\u00a7c{0}\u00a74' har aldrig varit inne p\u00e5 denna server tidigare. +teleportationEnabledFor=\u00a76TTeleportering aktiverat f\u00f6r {0} +teleportationDisabledFor=\u00a76Teleportering inaktiverat f\u00f6r {0} +kitOnce=\u00a74Du kan inte av\u00e4nda det kitet igen. fullStack=\u00a74Du har redan en full stapel oversizedTempban=\u00a74Du kan inte banna en spelare just vid denna tidpunkt. recipeNone=No recipes exist for {0} @@ -478,3 +478,11 @@ recipeGridItem=\ \u00a7{0}X \u00a76is \u00a7c{1} recipeMore=\u00a76Type /{0} \u00a7c{1}\u00a76 to see other recipes for \u00a7c{2} recipeWhere=\u00a76Where: {0} recipeShapeless=\u00a76Combine \u00a7c{0} +editBookContents=\u00a7eYou may now edit the contents of this book +bookAuthorSet=\u00a76Author of the book set to {0} +bookTitleSet=\u00a76Title of the book set to {0} +denyChangeAuthor=\u00a74You cannot change the author of this book +denyChangeTitle=\u00a74You cannot change the title of this book +denyBookEdit=\u00a74You cannot unlock this book +bookLocked=\u00a7cThis book is now locked +holdBook=\u00a74You are not holding a writable book \ No newline at end of file From 659d602b5789fd999311e21a04455c120b9f31c8 Mon Sep 17 00:00:00 2001 From: GunfighterJ Date: Sun, 13 Jan 2013 17:02:46 -0600 Subject: [PATCH 15/22] Fixes /top command not carrying pitch and yaw --- .../src/com/earth2me/essentials/commands/Commandtop.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index fe7690646..89c5c6f8f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -20,7 +20,9 @@ public class Commandtop extends EssentialsCommand { final int topX = user.getLocation().getBlockX(); final int topZ = user.getLocation().getBlockZ(); - final Location location = new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ); + final float pitch = user.getLocation().getPitch(); + final float yaw = user.getLocation().getYaw(); + final Location location = new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ, yaw, pitch); user.getTeleport().teleport(location, new Trade(this.getName(), ess), TeleportCause.COMMAND); user.sendMessage(_("teleportTop")); } From 7337b86a16a49610955223e849d12110a4ee9cf0 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 13 Jan 2013 23:10:14 +0000 Subject: [PATCH 16/22] Cleanup /book command. --- .../essentials/commands/Commandbook.java | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java index 872e17b16..90c5c4f35 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java @@ -6,7 +6,6 @@ import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.inventory.meta.ItemMeta; public class Commandbook extends EssentialsCommand @@ -20,49 +19,36 @@ public class Commandbook extends EssentialsCommand @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - - ItemStack item = user.getItemInHand(); - String player = user.getName(); + final ItemStack item = user.getItemInHand(); + final String player = user.getName(); if (item.getType() == Material.WRITTEN_BOOK) { - ItemMeta meta = item.getItemMeta(); - BookMeta bmeta = (BookMeta)meta; + BookMeta bmeta = (BookMeta)item.getItemMeta(); + if (args[0].equalsIgnoreCase("author")) { if (user.isAuthorized("essentals.book.author")) { - ItemStack newbook = new ItemStack(Material.WRITTEN_BOOK, 1); bmeta.setAuthor(args[1]); - newbook.setItemMeta(bmeta); - user.setItemInHand(newbook); + item.setItemMeta(bmeta); user.sendMessage(_("bookAuthorSet", args[1])); } else { - user.sendMessage(_("denyChangeAuthor")); + throw new Exception(_("denyChangeAuthor")); } } else if (args[0].equalsIgnoreCase("title")) { - if (user.isAuthorized("essentials.book.title")) + if (user.isAuthorized("essentials.book.title") && (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others"))) { - - if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.title.others")) - { - ItemStack newbook = new ItemStack(Material.WRITTEN_BOOK, 1); - bmeta.setTitle(args[1]); - newbook.setItemMeta(bmeta); - user.setItemInHand(newbook); - user.sendMessage(_("bookTitleSet", args[1])); - } - else - { - user.sendMessage(_("denyChangeTitle")); - } + bmeta.setTitle(args[1]); + item.setItemMeta(bmeta); + user.sendMessage(_("bookTitleSet", args[1])); } else { - user.sendMessage(_("denyChangeTitle")); + throw new Exception(_("denyChangeTitle")); } } else @@ -70,20 +56,19 @@ public class Commandbook extends EssentialsCommand if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others")) { ItemStack newItem = new ItemStack(Material.BOOK_AND_QUILL, item.getAmount()); - newItem.setItemMeta(meta); + newItem.setItemMeta(bmeta); user.setItemInHand(newItem); user.sendMessage(_("editBookContents")); } else { - user.sendMessage(_("denyBookEdit")); + throw new Exception(_("denyBookEdit")); } } } else if (item.getType() == Material.BOOK_AND_QUILL) { - ItemMeta meta = item.getItemMeta(); - BookMeta bmeta = (BookMeta)meta; + BookMeta bmeta = (BookMeta)item.getItemMeta(); bmeta.setAuthor(player); ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount()); newItem.setItemMeta(bmeta); From 0c19b2feed9f44e08086a573fc2dc232d8d1d729 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 14 Jan 2013 07:36:45 +0000 Subject: [PATCH 17/22] All the better to kick you with (Pipe format for linebreak) --- .../essentials/commands/Commandban.java | 2 +- .../essentials/commands/Commandkick.java | 2 +- .../essentials/commands/Commandkickall.java | 2 +- Essentials/src/config.yml | 23 ++++++++++--------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index 05e2b51c6..6bea234f4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -58,7 +58,7 @@ public class Commandban extends EssentialsCommand String banReason; if (args.length > 1) { - banReason = _("banFormat", Util.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n")), senderName); + banReason = _("banFormat", Util.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n")), senderName); } else { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index d977055e2..206127b58 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -40,7 +40,7 @@ public class Commandkick extends EssentialsCommand } String kickReason = args.length > 1 ? getFinalArg(args, 1) : _("kickDefault"); - kickReason = Util.replaceFormat(kickReason.replace("\\n", "\n")); + kickReason = Util.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); target.kickPlayer(kickReason); final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java index 4fc0b20be..6944823f3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java @@ -18,7 +18,7 @@ public class Commandkickall extends EssentialsCommand public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { String kickReason = args.length > 0 ? getFinalArg(args, 0) : _("kickDefault"); - kickReason = Util.replaceFormat(kickReason.replace("\\n", "\n")); + kickReason = Util.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); for (Player onlinePlayer : server.getOnlinePlayers()) { diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index b1ebf6ca0..b12ed72c3 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -205,17 +205,11 @@ player-commands: # Note: All items MUST be followed by a quantity! # All kit names should be lower case, and will be treated as lower in permissions/costs. -# Syntax: - itemID[:DataValue] Amount [Enchantment:Level].. +# Syntax: - itemID[:DataValue/Durability] Amount [Enchantment:Level].. [meta:value]... +# Supported meta includes: name, lore, color, player, title, author, info # 'delay' refers to the cooldown between how often you can use each kit, measured in seconds. # For more information, visit http://wiki.ess3.net/wiki/Command_Reference/ICheat#kits kits: - dtools: - delay: 10 - items: - - 277 1 digspeed:3 name:Dwarf lore:Diggy|Diggy|Hole - - 278 1 efficiency:1 durability:1 fortune:1 name:Gigadrill lore:The_drill_that_pierces|the_heavens - - 298 1 color:255|0|0 - - 279:780 1 tools: delay: 10 items: @@ -223,14 +217,21 @@ kits: - 273 1 - 274 1 - 275 1 + dtools: + delay: 600 + items: + - 278 1 efficiency:1 durability:1 fortune:1 name:Gigadrill lore:The_drill_that_pierces|the_heavens + - 277 1 digspeed:3 name:Dwarf lore:Diggy|Diggy|Hole + - 298 1 color:255|255|255 name:Top_hat lore:Good_day,_Good_day + - 279:780 1 notch: - delay: 1000 + delay: 6000 items: - 397:3 1 player:Notch color: - delay: 1000 + delay: 6000 items: - - 387 1 title:Colors author:KHobbits lore:Ingame_color_codes info:Colors + - 387 1 title:Book_o_Colors author:KHobbits lore:Ingame_color_codes info:Colors # Essentials Sign Control # See http://wiki.ess3.net/wiki/Sign_Tutorial for instructions on how to use these. From ada266a0f9a674508311b38cf9ec890484276d89 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 14 Jan 2013 08:14:20 +0000 Subject: [PATCH 18/22] Switch book meta, to use 'book.txt', and 'book:
'. Should make things clearer and easier to understand. --- Essentials/src/book.txt | 18 ++++++++++++++++++ .../com/earth2me/essentials/MetaItemStack.java | 4 ++-- Essentials/src/config.yml | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 Essentials/src/book.txt diff --git a/Essentials/src/book.txt b/Essentials/src/book.txt new file mode 100644 index 000000000..164910fb7 --- /dev/null +++ b/Essentials/src/book.txt @@ -0,0 +1,18 @@ +This is the book file. + +This file format works similar to the info.txt, motd.txt and rules.txt + +Place content in here that you would like to be used by books ingame. + +You can use this content by using the book:
meta option in kits or item spawning. + +#Colors +Minecraft colors: +&0 &&0 &1 &&1 &2 &&2 &3 &&3 +&4 &&4 &5 &&5 &6 &&6 &7 &&7 +&8 &&8 &9 &&9 &a &&a &b &&b +&c &&c &d &&d &e &&e &f &&f +&0 +&&k &kMagic&r &&l &lBold +&&m &mStrike&r &&n &nUline +&&o &oItalic&r &&r &rReset \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index f7b78b5c8..e514f4df7 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -69,10 +69,10 @@ public class MetaItemStack throw new Exception("You can only set the owner of player skulls (397:3)"); } } - else if (split.length > 1 && split[0].equalsIgnoreCase("info") && stack.getType() == Material.WRITTEN_BOOK) + else if (split.length > 1 && split[0].equalsIgnoreCase("book") && stack.getType() == Material.WRITTEN_BOOK) { final BookMeta meta = (BookMeta)stack.getItemMeta(); - final IText input = new BookInput("info", true, ess); + final IText input = new BookInput("book", true, ess); final BookPager pager = new BookPager(input); List pages = pager.getPages(split[1]); diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index b12ed72c3..28b7e5b92 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -206,7 +206,7 @@ player-commands: # Note: All items MUST be followed by a quantity! # All kit names should be lower case, and will be treated as lower in permissions/costs. # Syntax: - itemID[:DataValue/Durability] Amount [Enchantment:Level].. [meta:value]... -# Supported meta includes: name, lore, color, player, title, author, info +# Supported meta includes: name, lore, color, player, title, author, book # 'delay' refers to the cooldown between how often you can use each kit, measured in seconds. # For more information, visit http://wiki.ess3.net/wiki/Command_Reference/ICheat#kits kits: @@ -231,7 +231,7 @@ kits: color: delay: 6000 items: - - 387 1 title:Book_o_Colors author:KHobbits lore:Ingame_color_codes info:Colors + - 387 1 title:Book_o_Colors author:KHobbits lore:Ingame_color_codes book:Colors # Essentials Sign Control # See http://wiki.ess3.net/wiki/Sign_Tutorial for instructions on how to use these. From f8cf3be87fb663a9adcb39271ee178727722de11 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 14 Jan 2013 08:21:03 +0000 Subject: [PATCH 19/22] Better handle initial book.txt creation. --- .../essentials/textreader/BookInput.java | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/textreader/BookInput.java b/Essentials/src/com/earth2me/essentials/textreader/BookInput.java index d8df79ec2..b0fedbf86 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/BookInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/BookInput.java @@ -22,7 +22,39 @@ public class BookInput implements IText { file = new File(ess.getDataFolder(), filename + ".txt"); } - if (file.exists()) + if (!file.exists()) + { + if (createFile) + { + final InputStream input = ess.getResource(filename + ".txt"); + final OutputStream output = new FileOutputStream(file); + try + { + final byte[] buffer = new byte[1024]; + int length = input.read(buffer); + while (length > 0) + { + output.write(buffer, 0, length); + length = input.read(buffer); + } + } + finally + { + output.close(); + input.close(); + } + ess.getLogger().info("File " + filename + ".txt does not exist. Creating one for you."); + } + } + if (!file.exists()) + { + lastChange = 0; + lines = Collections.emptyList(); + chapters = Collections.emptyList(); + bookmarks = Collections.emptyMap(); + throw new FileNotFoundException("Could not create " + filename + ".txt"); + } + else { lastChange = file.lastModified(); boolean readFromfile; @@ -74,34 +106,6 @@ public class BookInput implements IText } } } - else - { - lastChange = 0; - lines = Collections.emptyList(); - chapters = Collections.emptyList(); - bookmarks = Collections.emptyMap(); - if (createFile) - { - final InputStream input = ess.getResource(filename + ".txt"); - final OutputStream output = new FileOutputStream(file); - try - { - final byte[] buffer = new byte[1024]; - int length = input.read(buffer); - while (length > 0) - { - output.write(buffer, 0, length); - length = input.read(buffer); - } - } - finally - { - output.close(); - input.close(); - } - throw new FileNotFoundException("File " + filename + ".txt does not exist. Creating one for you."); - } - } } @Override From d74952927a03e8461b5f76b1ff2dbdacd53f145c Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 14 Jan 2013 11:59:31 +0000 Subject: [PATCH 20/22] Only show ban reason in the in-game display, not full banFormat. --- .../src/com/earth2me/essentials/commands/Commandban.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index 6bea234f4..b0f15e695 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -58,17 +58,17 @@ public class Commandban extends EssentialsCommand String banReason; if (args.length > 1) { - banReason = _("banFormat", Util.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n")), senderName); + banReason = Util.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n")); } else { - banReason = _("banFormat", _("defaultBanReason"), senderName); + banReason = _("defaultBanReason"); } - user.setBanReason(banReason); + user.setBanReason(_("banFormat", banReason, senderName)); user.setBanned(true); user.setBanTimeout(0); - user.kickPlayer(banReason); + user.kickPlayer(_("banFormat", banReason, senderName)); server.getLogger().log(Level.INFO, _("playerBanned", senderName, user.getName(), banReason)); From 4ffe61a5053b2418f3efc9a882c88c8df71902b5 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 14 Jan 2013 21:34:35 +0000 Subject: [PATCH 21/22] Add colour support to item meta. --- Essentials/src/com/earth2me/essentials/MetaItemStack.java | 6 +++--- Essentials/src/config.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index e514f4df7..6a0257c8b 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -39,7 +39,7 @@ public class MetaItemStack if (split.length > 1 && split[0].equalsIgnoreCase("name")) { - final String displayName = split[1].replace('_', ' '); + final String displayName = Util.replaceFormat(split[1].replace('_', ' ')); final ItemMeta meta = stack.getItemMeta(); meta.setDisplayName(displayName); stack.setItemMeta(meta); @@ -49,7 +49,7 @@ public class MetaItemStack final List lore = new ArrayList(); for (String line : split[1].split("\\|")) { - lore.add(line.replace('_', ' ')); + lore.add(Util.replaceFormat(line.replace('_', ' '))); } final ItemMeta meta = stack.getItemMeta(); meta.setLore(lore); @@ -89,7 +89,7 @@ public class MetaItemStack } else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK) { - final String title = split[1]; + final String title = Util.replaceFormat(split[1].replace('_', ' ')); final BookMeta meta = (BookMeta)stack.getItemMeta(); meta.setTitle(title); stack.setItemMeta(meta); diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 28b7e5b92..fb91f18f0 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -220,9 +220,9 @@ kits: dtools: delay: 600 items: - - 278 1 efficiency:1 durability:1 fortune:1 name:Gigadrill lore:The_drill_that_pierces|the_heavens + - 278 1 efficiency:1 durability:1 fortune:1 name:&4Gigadrill lore:The_drill_that_&npierces|the_heavens - 277 1 digspeed:3 name:Dwarf lore:Diggy|Diggy|Hole - - 298 1 color:255|255|255 name:Top_hat lore:Good_day,_Good_day + - 298 1 color:255|255|255 name:Top_Hat lore:Good_day,_Good_day - 279:780 1 notch: delay: 6000 @@ -231,7 +231,7 @@ kits: color: delay: 6000 items: - - 387 1 title:Book_o_Colors author:KHobbits lore:Ingame_color_codes book:Colors + - 387 1 title:&4Book_&9o_&6Colors author:KHobbits lore:Ingame_color_codes book:Colors # Essentials Sign Control # See http://wiki.ess3.net/wiki/Sign_Tutorial for instructions on how to use these. From 4807fb39e5167f5388f33da25bafd1da1b6e4ba4 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 14 Jan 2013 21:40:25 +0000 Subject: [PATCH 22/22] Couple of extra /helpop aliases. --- Essentials/src/plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 10ed7da21..c7dd232e1 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -152,9 +152,9 @@ commands: usage: / [search term] [page] aliases: [ehelp] helpop: - description: Request help from online operators. + description: Message online admins. usage: / - aliases: [ehelpop] + aliases: [amsg,eamsg,ac,eac,ehelpop] home: description: Teleport to your home. usage: / [player:][name]