- Fixed chests in 1.2.3

- Formatting
- Warning about old Bukkit version
- Renamed "TOWNY_CANNOT_CREATE_SHOP_HERE" to "CANNOT_CREATE_SHOP_HERE" to avoid confusion
- Renamed "NOT_ENOUGH_LWC_PROTECTIONS" to "NOT_ENOUGH_PROTECTIONS" and changed its message

- Fixed armour enchantments
- Logging shop location
- Fixed Heroes for the newest version
- Removed redutant plugin object
- Added dev-url for CraftBukkitUpToDate
- Removed redutant plugins from softdepend
- Fixed a bug when the player interacts with a shop with a sign in hand
This commit is contained in:
Acrobot 2012-03-17 15:00:25 +01:00
parent 73e3616238
commit d6bdb0486a
38 changed files with 254 additions and 228 deletions

View File

@ -10,6 +10,7 @@ import org.bukkit.inventory.Inventory;
/**
* Temporary class until this is fixed in Bukkit RB
*
* @author Acrobot
*/
public class bInventoryFix {

View File

@ -10,8 +10,11 @@ import com.Acrobot.ChestShop.DB.Queue;
import com.Acrobot.ChestShop.DB.Transaction;
import com.Acrobot.ChestShop.Listeners.*;
import com.Acrobot.ChestShop.Logging.FileWriterQueue;
import com.Acrobot.ChestShop.Shop.ShopManagement;
import com.Acrobot.ChestShop.Utils.uNumber;
import com.avaje.ebean.EbeanServer;
import com.lennardf1989.bukkitex.Database;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginDescriptionFile;
@ -54,6 +57,7 @@ public class ChestShop extends JavaPlugin {
pluginEnable.initializePlugins();
warnAboutSpawnProtection();
warnAboutOldBukkit();
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) setupDB();
if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) scheduleTask(new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L);
@ -87,21 +91,29 @@ public class ChestShop extends JavaPlugin {
server.getScheduler().scheduleAsyncRepeatingTask(this, runnable, startTime, repetetionTime);
}
private void startStatistics(){
try{
private void startStatistics() {
try {
new Metrics().beginMeasuringPlugin(this);
} catch (Exception ex){
} catch (Exception ex) {
System.err.println(chatPrefix + "There was an error while submitting statistics.");
}
}
///////////////////// WARN ABOUT SPAWN PROTECTION ///////////////////////////
///////////////////// WARN ///////////////////////////
private static void warnAboutSpawnProtection() {
if (getBukkitConfig().getInt("settings.spawn-radius") > 0)
System.err.println(ChestShop.chatPrefix + "WARNING! Your spawn-radius in bukkit.yml isn't set to 0! " +
"You won't be able to sell to shops built near spawn!");
}
private static void warnAboutOldBukkit() {
String split[] = Bukkit.getBukkitVersion().split("-R");
if (split[0].equals("1.1") && split.length > 1 && uNumber.isInteger(split[1]) && (Integer.parseInt(split[1])) < 7) {
System.err.println(ChestShop.chatPrefix + "Your CraftBukkit version is outdated! Use at least 1.1-R7 or 1.2.3-R0!");
ShopManagement.useOldChest = true;
}
}
///////////////////// DATABASE STUFF ////////////////////////////////
private static YamlConfiguration getBukkitConfig() {
return YamlConfiguration.loadConfiguration(new File("bukkit.yml"));

View File

@ -9,56 +9,34 @@ import org.bukkit.inventory.ItemStack;
* @author Acrobot
*/
public class MinecraftChest implements ChestObject {
private final Chest main;
private final Chest neighbor;
private final Chest chest;
public MinecraftChest(Chest chest) {
this.main = chest;
this.neighbor = getNeighbor();
this.chest = chest;
}
public ItemStack[] getContents() {
ItemStack[] contents = new ItemStack[(neighbor != null ? 54 : 27)];
ItemStack[] chest1 = main.getInventory().getContents();
System.arraycopy(chest1, 0, contents, 0, chest1.length);
if (neighbor != null) {
ItemStack[] chest2 = neighbor.getInventory().getContents();
System.arraycopy(chest2, 0, contents, chest1.length, chest2.length);
}
return contents;
return chest.getInventory().getContents();
}
public void setSlot(int slot, ItemStack item) {
if (slot < main.getInventory().getSize()) {
main.getInventory().setItem(slot, item);
} else {
neighbor.getInventory().setItem(slot - main.getInventory().getSize(), item);
}
chest.getInventory().setItem(slot, item);
}
public void clearSlot(int slot) {
if (slot < main.getInventory().getSize()) {
main.getInventory().setItem(slot, null);
} else {
neighbor.getInventory().setItem(slot - main.getInventory().getSize(), null);
}
chest.getInventory().setItem(slot, null);
}
public void addItem(ItemStack item, int amount) {
int left = addItem(item, amount, main);
if (neighbor != null && left > 0) addItem(item, left, neighbor);
uInventory.add(chest.getInventory(), item, amount);
}
public void removeItem(ItemStack item, short durability, int amount) {
int left = removeItem(item, durability, amount, main);
if (neighbor != null && left > 0) removeItem(item, durability, left, neighbor);
uInventory.remove(chest.getInventory(), item, amount, durability);
}
public int amount(ItemStack item, short durability) {
return amount(item, durability, main) + (neighbor != null ? amount(item, durability, neighbor) : 0);
return uInventory.amount(chest.getInventory(), item, durability);
}
public boolean hasEnough(ItemStack item, int amount, short durability) {
@ -66,31 +44,14 @@ public class MinecraftChest implements ChestObject {
}
public boolean fits(ItemStack item, int amount, short durability) {
int firstChest = fits(item, amount, durability, main);
return (firstChest > 0 && neighbor != null ? fits(item, firstChest, durability, neighbor) <= 0 : firstChest <= 0);
return uInventory.fits(chest.getInventory(), item, amount, durability) <= 0;
}
public int getSize() {
return main.getInventory().getSize() + (neighbor != null ? neighbor.getInventory().getSize() : 0);
return chest.getInventory().getSize();
}
public Chest getNeighbor() {
return uBlock.findNeighbor(main);
}
private static int amount(ItemStack item, short durability, Chest chest) {
return uInventory.amount(chest.getInventory(), item, durability);
}
private static int fits(ItemStack item, int amount, short durability, Chest chest) {
return uInventory.fits(chest.getInventory(), item, amount, durability);
}
private static int addItem(ItemStack item, int amount, Chest chest) {
return uInventory.add(chest.getInventory(), item, amount);
}
private static int removeItem(ItemStack item, short durability, int amount, Chest chest) {
return uInventory.remove(chest.getInventory(), item, amount, durability);
return uBlock.findNeighbor(chest);
}
}

View File

@ -1,42 +1,43 @@
package com.Acrobot.ChestShop.Chests;
import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.BukkitFixes.bInventoryFix;
import com.Acrobot.ChestShop.Utils.uInventory;
import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
*/
public class MinecraftChest_forNewBukkit implements ChestObject {
private final Chest chest;
public class OldMCchest implements ChestObject {
private final Inventory inventory;
public MinecraftChest_forNewBukkit(Chest chest) {
this.chest = chest;
public OldMCchest(Chest chest) {
this.inventory = bInventoryFix.getInventory(chest);
}
public ItemStack[] getContents() {
return chest.getInventory().getContents();
return inventory.getContents();
}
public void setSlot(int slot, ItemStack item) {
chest.getInventory().setItem(slot, item);
inventory.setItem(slot, item);
}
public void clearSlot(int slot) {
chest.getInventory().setItem(slot, null);
inventory.clear(slot);
}
public void addItem(ItemStack item, int amount) {
uInventory.add(chest.getInventory(), item, amount);
uInventory.add(inventory, item, amount);
}
public void removeItem(ItemStack item, short durability, int amount) {
uInventory.remove(chest.getInventory(), item, amount, durability);
uInventory.remove(inventory, item, amount, durability);
}
public int amount(ItemStack item, short durability) {
return uInventory.amount(chest.getInventory(), item, durability);
return uInventory.amount(inventory, item, durability);
}
public boolean hasEnough(ItemStack item, int amount, short durability) {
@ -44,14 +45,10 @@ public class MinecraftChest_forNewBukkit implements ChestObject {
}
public boolean fits(ItemStack item, int amount, short durability) {
return uInventory.fits(chest.getInventory(), item, amount, durability) <= 0;
return uInventory.fits(inventory, item, amount, durability) <= 0;
}
public int getSize() {
return chest.getInventory().getSize();
}
public Chest getNeighbor() {
return uBlock.findNeighbor(chest);
return inventory.getSize();
}
}

View File

@ -48,7 +48,7 @@ public class ItemInfo implements CommandExecutor {
}
private static String intToRoman(int integer){
private static String intToRoman(int integer) {
if (integer == 1) return "I";
if (integer == 2) return "II";
if (integer == 3) return "III";
@ -58,8 +58,7 @@ public class ItemInfo implements CommandExecutor {
}
private static String joinArray(String[] array){
private static String joinArray(String[] array) {
StringBuilder b = new StringBuilder(array.length);
for (String s : array) b.append(s).append(' ');
return b.toString();

View File

@ -13,7 +13,7 @@ import org.bukkit.command.CommandSender;
*/
public class Version implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length > 0 && args[0].equals("reload")){
if (args.length > 0 && args[0].equals("reload")) {
Config.config = new ConfigObject();
sender.sendMessage(ChatColor.DARK_GREEN + "The config was reloaded.");
return true;

View File

@ -39,9 +39,9 @@ public enum Language {
NO_PERMISSION("You don't have permissions to do that!"),
INCORRECT_ITEM_ID("You have specified invalid item id!"),
NOT_ENOUGH_LWC_PROTECTIONS("You have reached the LWC protections limit!"),
NOT_ENOUGH_PROTECTIONS("You have reached the protection limit!"),
TOWNY_CANNOT_CREATE_SHOP_HERE("You can't create shop here!");
CANNOT_CREATE_SHOP_HERE("You can't create shop here!");
private final String text;

View File

@ -23,7 +23,8 @@ public class Transaction {
private float price;
private long sec;
public Transaction() {}
public Transaction() {
}
public float getAveragePricePerItem() {
return price / amount;

View File

@ -5,9 +5,14 @@ package com.Acrobot.ChestShop.Economy;
*/
public interface EcoPlugin {
public boolean hasAccount(String player);
public void add(String player, double amount);
public void subtract(String player, double amount);
public boolean hasEnough(String player, double amount);
public double balance(String player);
public String format(double amount);
}

View File

@ -26,7 +26,7 @@ public class Economy {
economy.add(uLongName.getName(name), amount);
}
public static void addServer(String name, float amount){
public static void addServer(String name, float amount) {
String account = Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
if (!account.isEmpty()) {
float tax = getTax(Property.SERVER_TAX_AMOUNT, amount);
@ -36,7 +36,7 @@ public class Economy {
economy.add(uLongName.getName(name), amount);
}
public static float getTax(Property tax, float price){
public static float getTax(Property tax, float price) {
return (Config.getFloat(tax) / 100F) * price;
}

View File

@ -3,7 +3,7 @@ package com.Acrobot.ChestShop.Economy;
/**
* @author Acrobot
*/
public class NoProvider implements EcoPlugin{
public class NoProvider implements EcoPlugin {
public boolean hasAccount(String player) {
printError();
return false;

View File

@ -5,8 +5,9 @@ import com.nijikokun.register.payment.forChestShop.Method;
/**
* @author Acrobot
*/
public class Register implements EcoPlugin{
public class Register implements EcoPlugin {
public static Method eco;
public boolean hasAccount(String player) {
return eco.hasAccount(player);
}

View File

@ -38,12 +38,14 @@ public class DataValue {
materialData = new Coal(CoalType.valueOf(type));
break;
}
} catch (Exception e) { return 0; }
} catch (Exception e) {
return 0;
}
return (materialData == null ? 0 : materialData.getData());
}
public static String getName(ItemStack is){
public static String getName(ItemStack is) {
short dur = is.getDurability();
if (dur == 0) return null;
@ -71,7 +73,9 @@ public class DataValue {
name = CoalType.getByData((byte) dur).name();
break;
}
} catch (Exception e) { return null; }
} catch (Exception e) {
return null;
}
return name;
}

View File

@ -38,15 +38,21 @@ public class Items {
return finalMaterial;
}
public static String getName(ItemStack is){
public static String getName(ItemStack is) {
return getName(is, true);
}
public static String getName(ItemStack is, boolean showData){
public static String getName(ItemStack is, boolean showData) {
String name = DataValue.getName(is);
return uSign.capitalizeFirst((name != null && showData ? name + '_' : "") + is.getType());
}
public static String getSignName(ItemStack is) {
return is.getType().name()
+ (is.getDurability() > 0 ? ':' + is.getDurability() : "")
+ (!is.getEnchantments().isEmpty() ? '-' + uEnchantment.encodeEnchantment(is.getEnchantments()) : "");
}
public static ItemStack getItemStack(String itemName) {
ItemStack toReturn = getFromOddItem(itemName);
if (toReturn != null) return toReturn;
@ -88,19 +94,19 @@ public class Items {
return toReturn;
}
private static Map<Enchantment, Integer> getEnchantment(String itemName){
private static Map<Enchantment, Integer> getEnchantment(String itemName) {
return uEnchantment.decodeEnchantment(itemName);
}
private static Map<Enchantment, Integer> getEnchant(String original){
private static Map<Enchantment, Integer> getEnchant(String original) {
Matcher m = Enchant.matcher(original);
if (!m.find()) return new HashMap<Enchantment, Integer>();
String group = m.group().substring(1);
return getEnchantment(group);
}
private static ItemStack addEnchantments(ItemStack is, String itemname){
try{ is.addEnchantments(getEnchant(itemname));
private static ItemStack addEnchantments(ItemStack is, String itemname) {
try { is.addEnchantments(getEnchant(itemname));
} catch (Exception ignored) {}
return is;
}

View File

@ -39,7 +39,7 @@ public class blockBreak implements Listener {
if (!isCorrectSign(sign, block)) return false; //It's not a correct shop sign, so don't cancel it
if (playerIsNotOwner(player, sign)) return !isAdmin(player); //If the player isn't the owner or an admin - cancel!
if (weShouldReturnMoney() && !Permission.has(player, Permission.NOFEE)){
if (weShouldReturnMoney() && !Permission.has(player, Permission.NOFEE)) {
float refundPrice = Config.getFloat(Property.SHOP_REFUND_PRICE);
Economy.add(uLongName.getName(sign.getLine(0)), refundPrice); //Add some money
player.sendMessage(Config.getLocal(Language.SHOP_REFUNDED).replace("%amount", Economy.formatBalance(refundPrice)));
@ -109,12 +109,12 @@ public class blockBreak implements Listener {
return pistonDirection != null ? event.getBlock().getRelative((pistonDirection), 2).getLocation().getBlock() : null;
}
private static List<Block> getExtendBlocks(BlockPistonExtendEvent event){
private static List<Block> getExtendBlocks(BlockPistonExtendEvent event) {
BlockFace pistonDirection = getPistonDirection(event.getBlock());
if (pistonDirection == null) return new ArrayList<Block>();
Block piston = event.getBlock();
ArrayList<Block> list = new ArrayList<Block>();
for (int b = 1; b < event.getLength() + 1; b++){
for (int b = 1; b < event.getLength() + 1; b++) {
Block block = piston.getRelative(pistonDirection, b);
Material blockType = block.getType();
if (blockType == Material.AIR) break;

View File

@ -26,12 +26,12 @@ public class blockPlace implements Listener {
}
Block placed = event.getBlockPlaced();
if (placed.getType() == Material.CHEST){
if (placed.getType() == Material.CHEST) {
Chest neighbor = uBlock.findNeighbor(placed);
if (neighbor == null) return;
Block neighborBlock = neighbor.getBlock();
if (Security.isProtected(neighborBlock) && !Security.canAccess(event.getPlayer(), neighborBlock)){
if (Security.isProtected(neighborBlock) && !Security.canAccess(event.getPlayer(), neighborBlock)) {
event.getPlayer().sendMessage(Config.getLocal(Language.ACCESS_DENIED));
event.setCancelled(true);
}

View File

@ -41,7 +41,6 @@ public class playerInteract implements Listener {
Block block = event.getClickedBlock();
Player player = event.getPlayer();
if (player.getItemInHand() != null && player.getItemInHand().getType() == Material.SIGN) return;
if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) {
Default protection = new Default();
if (!hasAdminPermissions(player) && (protection.isProtected(block) && !protection.canAccess(player, block))) {
@ -54,9 +53,10 @@ public class playerInteract implements Listener {
if (!uSign.isSign(block)) return;
Sign sign = (Sign) block.getState();
if (player.getItemInHand() != null && player.getItemInHand().getType() == Material.SIGN) return;
if (!uSign.isValid(sign) || !enoughTimeHasPassed(player) || player.isSneaking()) return;
if (Config.getBoolean(Property.IGNORE_CREATIVE_MODE) && player.getGameMode() == GameMode.CREATIVE){
if (Config.getBoolean(Property.IGNORE_CREATIVE_MODE) && player.getGameMode() == GameMode.CREATIVE) {
event.setCancelled(true);
return;
}

View File

@ -10,7 +10,6 @@ import com.Acrobot.ChestShop.Protection.Security;
import com.Acrobot.ChestShop.Utils.WorldGuard.uWorldGuard;
import com.Acrobot.ChestShop.Utils.uHeroes;
import com.Acrobot.ChestShop.Utils.uSign;
import com.daemitus.deadbolt.Deadbolt;
import com.griefcraft.lwc.LWCPlugin;
import com.herocraftonline.heroes.Heroes;
import com.nijikokun.register.payment.forChestShop.Method;
@ -38,7 +37,7 @@ public class pluginEnable {
loadRegister();
}
private static void loadRegister(){
private static void loadRegister() {
if (com.Acrobot.ChestShop.Economy.Economy.economy == null) {
Method m = Methods.load(ChestShop.pm);
if (m == null) {
@ -59,7 +58,6 @@ public class pluginEnable {
LockettePlugin.lockette = (Lockette) plugin;
Security.protections.add(new LockettePlugin());
} else if (name.equals("Deadbolt")) {
DeadboltPlugin.deadbolt = (Deadbolt) plugin;
Security.protections.add(new DeadboltPlugin());
} else if (name.equals("OddItem")) {
Odd.isInitialized = true;
@ -77,7 +75,7 @@ public class pluginEnable {
com.Acrobot.ChestShop.Economy.Economy.economy = new Vault();
System.out.println(ChestShop.chatPrefix + "Vault loaded using economy plugin " + Vault.economy.getName());
return;
} else if (name.equals("Heroes")){
} else if (name.equals("Heroes")) {
uHeroes.heroes = (Heroes) plugin;
} else if (name.equals("SimpleChestLock")) {
SCLplugin.scl = (SCL) plugin;

View File

@ -80,8 +80,8 @@ public class signChange implements Listener {
dropSign(event);
return;
} else if (!playerIsAdmin) {
if (!Config.getBoolean(Property.ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK) && !Security.canPlaceSign(player, (Sign) signBlock.getState())) {
player.sendMessage(Config.getLocal(Language.ANOTHER_SHOP_DETECTED));
if (!Security.canPlaceSign(player, (Sign) signBlock.getState())) {
player.sendMessage(Config.getLocal(Language.CANNOT_CREATE_SHOP_HERE));
dropSign(event);
return;
}
@ -92,7 +92,7 @@ public class signChange implements Listener {
boolean bothActive = uSign.towny != null && uWorldGuard.wg != null;
if (((!canBuildTowny || !canBuildWorldGuard) && !bothActive) || (bothActive && !canBuildTowny && !canBuildWorldGuard)) {
player.sendMessage(Config.getLocal(Language.TOWNY_CANNOT_CREATE_SHOP_HERE));
player.sendMessage(Config.getLocal(Language.CANNOT_CREATE_SHOP_HERE));
dropSign(event);
return;
}
@ -128,7 +128,7 @@ public class signChange implements Listener {
}
if (Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)) {
if (!Security.protect(player.getName(), signBlock)) player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_LWC_PROTECTIONS));
if (!Security.protect(player.getName(), signBlock)) player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_PROTECTIONS));
}
if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && chest != null && Security.protect(player.getName(), chest.getBlock())) {
player.sendMessage(Config.getLocal(Language.PROTECTED_SHOP));

View File

@ -4,7 +4,9 @@ import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import com.Acrobot.ChestShop.DB.Queue;
import com.Acrobot.ChestShop.DB.Transaction;
import com.Acrobot.ChestShop.Items.Items;
import com.Acrobot.ChestShop.Shop.Shop;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -32,10 +34,20 @@ public class Logging {
}
public static void logTransaction(boolean isBuying, Shop shop, Player player) {
log(player.getName() + (isBuying ? " bought " : " sold ") + shop.stockAmount + ' ' + shop.stock.getType() + " for " + (isBuying ? shop.buyPrice + " from " : shop.sellPrice + " to ") + shop.owner);
log(player.getName()
+ (isBuying ? " bought " : " sold ")
+ shop.stockAmount + ' '
+ Items.getSignName(shop.stock) + " for "
+ (isBuying ? shop.buyPrice + " from " : shop.sellPrice + " to ")
+ shop.owner + " at "
+ locationToString(shop.sign.getLocation()));
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) logToDatabase(isBuying, shop, player);
}
private static String locationToString(Location loc) {
return '[' + loc.getWorld().getName() + "] " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ();
}
private static void logToDatabase(boolean isBuying, Shop shop, Player player) {
Transaction transaction = new Transaction();

View File

@ -33,24 +33,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
public class Metrics {
@ -242,7 +230,7 @@ public class Metrics {
// Acquire a lock on the graphs, which lets us make the assumption we also lock everything
// inside of the graph (e.g plotters)
synchronized(graphs) {
synchronized (graphs) {
for (Graph graph : graphs) {
// Because we have a lock on the graphs set already, it is reasonable to assume
// that our lock transcends down to the individual plotters in the graphs also.
@ -299,11 +287,8 @@ public class Metrics {
// Is this the first update this hour?
if (response.contains("OK This is your first update this hour")) {
synchronized (graphs) {
Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
Graph graph = iter.next();
for (Graph graph : graphs) {
for (Plotter plotter : graph.getPlotters()) {
plotter.reset();
}
@ -474,6 +459,7 @@ public class Metrics {
/**
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
*
* @return
*/
public Set<Plotter> getPlotters() {

View File

@ -37,13 +37,13 @@ public enum Permission {
return player.hasPermission(node) || player.hasPermission(node.toLowerCase());
}
public static boolean otherName(Player p, String name){
public static boolean otherName(Player p, String name) {
if (has(p, Permission.ADMIN)) return false;
String node = OTHER_NAME + name;
return hasPermissionSet(p, node) || hasPermissionSet(p, node.toLowerCase());
}
private static boolean hasPermissionSet(Player p, String perm){
private static boolean hasPermissionSet(Player p, String perm) {
return p.isPermissionSet(perm) && p.hasPermission(perm);
}

View File

@ -9,8 +9,6 @@ import org.bukkit.entity.Player;
* @author Acrobot
*/
public class DeadboltPlugin implements Protection {
public static Deadbolt deadbolt;
public boolean isProtected(Block block) {
return Deadbolt.isProtected(block);
}

View File

@ -1,8 +1,11 @@
package com.Acrobot.ChestShop.Protection;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import com.Acrobot.ChestShop.Listeners.blockBreak;
import com.Acrobot.ChestShop.Utils.uLongName;
import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
@ -14,7 +17,8 @@ import java.util.ArrayList;
* @author Acrobot
*/
public class Security {
private static BlockFace[] faces = {BlockFace.UP, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
private static final BlockFace[] faces = {BlockFace.UP, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
private static final BlockFace[] blockFaces = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
public static ArrayList<Protection> protections = new ArrayList<Protection>();
public static boolean protect(String name, Block block) {
@ -36,13 +40,31 @@ public class Security {
}
public static boolean canPlaceSign(Player p, Sign sign) {
return !thereIsAnotherSignByPlayer(blockBreak.getAttachedFace(sign), sign.getBlock(), uLongName.stripName(p.getName()));
return !anotherShopFound(blockBreak.getAttachedFace(sign), sign.getBlock(), p) && canBePlaced(p, sign.getBlock());
}
private static boolean thereIsAnotherSignByPlayer(Block baseBlock, Block signBlock, String shortName) {
private static boolean canBePlaced(Player p, Block signBlock) {
for (BlockFace bf : blockFaces) {
Block block = signBlock.getRelative(bf);
if (block.getType() != Material.CHEST) continue;
if (isProtected(block) && !canAccess(p, block)) return false;
}
return true;
}
private static boolean anotherShopFound(Block baseBlock, Block signBlock, Player p) {
String shortName = uLongName.stripName(p.getName());
if (Config.getBoolean(Property.ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK)) return false;
for (BlockFace bf : faces) {
Block block = baseBlock.getRelative(bf);
if (uSign.isSign(block) && uSign.isValid((Sign) block.getState()) && !block.equals(signBlock) && blockBreak.getAttachedFace((Sign) block.getState()).equals(baseBlock) && !((Sign) block.getState()).getLine(0).equals(shortName))
if (!uSign.isSign(block)) continue;
Sign s = (Sign) block.getState();
if (uSign.isValid(s) && !block.equals(signBlock) && blockBreak.getAttachedFace(s).equals(baseBlock) && !s.getLine(0).equals(shortName))
return true;
}
return false;

View File

@ -27,7 +27,7 @@ public class Shop {
public float buyPrice;
public float sellPrice;
public final String owner;
private final Sign sign;
public final Sign sign;
public Shop(ChestObject chest, boolean buy, Sign sign, ItemStack... itemStacks) {
this.stock = itemStacks[0];
@ -205,7 +205,7 @@ public class Shop {
return chest.hasEnough(stock, stockAmount, durability);
}
private int stockAmount(ItemStack item, short durability){
private int stockAmount(ItemStack item, short durability) {
return chest.amount(item, durability);
}

View File

@ -1,6 +1,8 @@
package com.Acrobot.ChestShop.Shop;
import com.Acrobot.ChestShop.Chests.ChestObject;
import com.Acrobot.ChestShop.Chests.MinecraftChest;
import com.Acrobot.ChestShop.Chests.OldMCchest;
import com.Acrobot.ChestShop.Items.Items;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.ChatColor;
@ -13,6 +15,8 @@ import org.bukkit.inventory.ItemStack;
* @author Acrobot
*/
public class ShopManagement {
public static boolean useOldChest = false;
public static void buy(Sign sign, Player player) {
Chest chestMc = uBlock.findChest(sign);
ItemStack item = Items.getItemStack(sign.getLine(3));
@ -20,7 +24,7 @@ public class ShopManagement {
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!");
return;
}
Shop shop = new Shop(chestMc != null ? new MinecraftChest(chestMc) : null, true, sign, item);
Shop shop = new Shop(chestMc != null ? getChest(chestMc) : null, true, sign, item);
shop.buy(player);
}
@ -31,7 +35,11 @@ public class ShopManagement {
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!");
return;
}
Shop shop = new Shop(chestMc != null ? new MinecraftChest(chestMc) : null, false, sign, item);
Shop shop = new Shop(chestMc != null ? getChest(chestMc) : null, false, sign, item);
shop.sell(player);
}
public static ChestObject getChest(Chest mc) {
return (useOldChest ? new OldMCchest(mc) : new MinecraftChest(mc));
}
}

View File

@ -30,17 +30,17 @@ public class restrictedSign {
}
public static boolean canDestroy(Player p, Sign sign){
public static boolean canDestroy(Player p, Sign sign) {
Sign shopSign = getAssociatedSign(sign);
return uSign.canAccess(p, shopSign);
}
public static Sign getAssociatedSign(Sign restricted){
public static Sign getAssociatedSign(Sign restricted) {
Block down = restricted.getBlock().getRelative(BlockFace.DOWN);
return uSign.isSign(down) ? (Sign) down.getState() : null;
}
public static boolean hasPermission(Player p, String[] lines){
public static boolean hasPermission(Player p, String[] lines) {
if (Permission.has(p, Permission.ADMIN)) return true;
for (int i = 1; i <= 3; i++) {

View File

@ -29,8 +29,8 @@ public class uBlock {
return null;
}
public static void blockUpdate(Block block){
for (BlockFace bf : shopFaces){
public static void blockUpdate(Block block) {
for (BlockFace bf : shopFaces) {
block.getRelative(bf).getState().update(true);
}
}
@ -54,7 +54,7 @@ public class uBlock {
}
//Well, I need to re-write this plugin... I hate to code like that - sorry!
public static Sign findSign2(Block block){
public static Sign findSign2(Block block) {
for (BlockFace bf : shopFaces) {
Block faceBlock = block.getRelative(bf);
if (uSign.isSign(faceBlock)) {

View File

@ -10,32 +10,39 @@ import java.util.Map;
* @author Acrobot
*/
public class uEnchantment {
public static String getEnchantment(ItemStack item){
public static String getEnchantment(ItemStack item) {
return encodeEnchantment(item.getEnchantments());
}
public static String encodeEnchantment(Map<Enchantment, Integer> map){
public static String encodeEnchantment(Map<Enchantment, Integer> map) {
int integer = 0;
for (Map.Entry<Enchantment, Integer> entry : map.entrySet()){
for (Map.Entry<Enchantment, Integer> entry : map.entrySet()) {
integer = integer * 1000 + (entry.getKey().getId()) * 10 + entry.getValue();
}
return (integer != 0 ? Integer.toString(integer, 32) : null);
if (integer == 0) return null;
return Integer.toString(integer, 32);
}
public static Map<Enchantment, Integer> decodeEnchantment(String base32){
public static Map<Enchantment, Integer> decodeEnchantment(String base32) {
if (base32 == null) return new HashMap<Enchantment, Integer>();
Map<Enchantment, Integer> map = new HashMap<Enchantment, Integer>();
String integer = String.valueOf(Integer.parseInt(base32, 32));
if (integer.length() < 3) integer = '0' + integer;
for (int i = 0; i < (integer.length() / 3); i++){
for (int i = 0; i < integer.length() / 3; i++) {
String item = integer.substring(i * 3, i * 3 + 3);
Enchantment ench = Enchantment.getById(Integer.parseInt(item.substring(0, 2)));
if (ench == null) continue;
int level = Integer.parseInt(item.substring(2));
if (ench.getMaxLevel() < level || level < ench.getStartLevel()) continue;
map.put(ench, level);
}
return map;
}
}

View File

@ -15,7 +15,7 @@ public class uHeroes {
public static void addHeroExp(Player p) {
if (heroes != null) {
Hero hero = heroes.getHeroManager().getHero(p);
Hero hero = heroes.getCharacterManager().getHero(p);
if (hero.hasParty()) {
hero.getParty().gainExp(Config.getDouble(Property.HEROES_EXP), HeroClass.ExperienceType.EXTERNAL, p.getLocation());
} else {

View File

@ -4,6 +4,7 @@ import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import com.palmergames.bukkit.towny.NotRegisteredException;
import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -26,7 +27,7 @@ public class uTowny {
return isInWilderness(chestLocation.getBlock()) || isInWilderness(signLocation.getBlock());
}
private static boolean isInWilderness(Block block){
private static boolean isInWilderness(Block block) {
return uSign.towny.getTownyUniverse().isWilderness(block);
}
@ -35,12 +36,18 @@ public class uTowny {
}
private static boolean isBlockOwner(Player player, Location location) {
try { return uSign.towny.getTownyUniverse().getTownBlock(location).isOwner(uSign.towny.getTownyUniverse().getResident(player.getName()));
} catch (NotRegisteredException ex) { return false; }
try {
return uSign.towny.getTownyUniverse().getTownBlock(location).isOwner(TownyUniverse.getDataSource().getResident(player.getName()));
} catch (NotRegisteredException ex) {
return false;
}
}
private static boolean isResident(Player p, Location l){
try { return uSign.towny.getTownyUniverse().getTownBlock(l).getTown().hasResident(p.getName());
} catch (NotRegisteredException ex) { return false; }
private static boolean isResident(Player p, Location l) {
try {
return uSign.towny.getTownyUniverse().getTownBlock(l).getTown().hasResident(p.getName());
} catch (NotRegisteredException ex) {
return false;
}
}
}

View File

@ -1,13 +1,11 @@
package com.nijikokun.register.payment.forChestShop.methods;
import com.nijikokun.register.payment.forChestShop.Method;
import com.iConomy.iConomy;
import com.iConomy.system.Account;
import com.iConomy.system.BankAccount;
import com.iConomy.system.Holdings;
import com.iConomy.util.Constants;
import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin;
/**
@ -18,10 +16,10 @@ import org.bukkit.plugin.Plugin;
* @license AOL license <http://aol.nexua.org>
*/
public class iCo5 implements Method {
private iConomy iConomy;
private iConomy iconomy;
public iConomy getPlugin() {
return this.iConomy;
return this.iconomy;
}
public String getName() {
@ -62,10 +60,10 @@ public class iCo5 implements Method {
}
public boolean createAccount(String name, double balance) {
if(hasAccount(name))
if (hasAccount(name))
return false;
if(!com.iConomy.iConomy.Accounts.create(name))
if (!com.iConomy.iConomy.Accounts.create(name))
return false;
getAccount(name).set(balance);
@ -88,7 +86,7 @@ public class iCo5 implements Method {
}
public void setPlugin(Plugin plugin) {
iConomy = (iConomy)plugin;
iconomy = (iConomy) plugin;
}
public static class iCoAccount implements MethodAccount {
@ -109,31 +107,31 @@ public class iCo5 implements Method {
}
public boolean set(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.set(amount);
return true;
}
public boolean add(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.add(amount);
return true;
}
public boolean subtract(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.subtract(amount);
return true;
}
public boolean multiply(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.multiply(amount);
return true;
}
public boolean divide(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.divide(amount);
return true;
}
@ -155,7 +153,7 @@ public class iCo5 implements Method {
}
public boolean remove() {
if(this.account == null) return false;
if (this.account == null) return false;
this.account.remove();
return true;
}
@ -187,31 +185,31 @@ public class iCo5 implements Method {
}
public boolean set(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.set(amount);
return true;
}
public boolean add(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.add(amount);
return true;
}
public boolean subtract(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.subtract(amount);
return true;
}
public boolean multiply(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.multiply(amount);
return true;
}
public boolean divide(double amount) {
if(this.holdings == null) return false;
if (this.holdings == null) return false;
this.holdings.divide(amount);
return true;
}
@ -233,7 +231,7 @@ public class iCo5 implements Method {
}
public boolean remove() {
if(this.account == null) return false;
if (this.account == null) return false;
this.account.remove();
return true;
}

View File

@ -2,7 +2,10 @@ name: ChestShop
main: com.Acrobot.ChestShop.ChestShop
version: 3.38
version: 3.39
#for CButD
dev-url: http://dev.bukkit.org/server-mods/chestshop/
author: Acrobot
@ -11,7 +14,7 @@ description: >
softdepend: [LWC, Lockette, Deadbolt, OddItem, Towny, WorldGuard, Vault, Heroes,
iConomy, BOSEconomy, Essentials, 3co, MultiCurrency, Currency, SimpleChestLock]
iConomy, BOSEconomy, Essentials, SimpleChestLock]
commands:
iteminfo:
aliases: [iinfo]