- 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 * Temporary class until this is fixed in Bukkit RB
*
* @author Acrobot * @author Acrobot
*/ */
public class bInventoryFix { 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.DB.Transaction;
import com.Acrobot.ChestShop.Listeners.*; import com.Acrobot.ChestShop.Listeners.*;
import com.Acrobot.ChestShop.Logging.FileWriterQueue; 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.avaje.ebean.EbeanServer;
import com.lennardf1989.bukkitex.Database; import com.lennardf1989.bukkitex.Database;
import org.bukkit.Bukkit;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
@ -54,6 +57,7 @@ public class ChestShop extends JavaPlugin {
pluginEnable.initializePlugins(); pluginEnable.initializePlugins();
warnAboutSpawnProtection(); warnAboutSpawnProtection();
warnAboutOldBukkit();
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) setupDB(); 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); if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) scheduleTask(new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L);
@ -95,13 +99,21 @@ public class ChestShop extends JavaPlugin {
} }
} }
///////////////////// WARN ABOUT SPAWN PROTECTION /////////////////////////// ///////////////////// WARN ///////////////////////////
private static void warnAboutSpawnProtection() { private static void warnAboutSpawnProtection() {
if (getBukkitConfig().getInt("settings.spawn-radius") > 0) if (getBukkitConfig().getInt("settings.spawn-radius") > 0)
System.err.println(ChestShop.chatPrefix + "WARNING! Your spawn-radius in bukkit.yml isn't set to 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!"); "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 //////////////////////////////// ///////////////////// DATABASE STUFF ////////////////////////////////
private static YamlConfiguration getBukkitConfig() { private static YamlConfiguration getBukkitConfig() {
return YamlConfiguration.loadConfiguration(new File("bukkit.yml")); return YamlConfiguration.loadConfiguration(new File("bukkit.yml"));

View File

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

View File

@ -1,42 +1,43 @@
package com.Acrobot.ChestShop.Chests; package com.Acrobot.ChestShop.Chests;
import com.Acrobot.ChestShop.Utils.uBlock; import com.Acrobot.ChestShop.BukkitFixes.bInventoryFix;
import com.Acrobot.ChestShop.Utils.uInventory; import com.Acrobot.ChestShop.Utils.uInventory;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* @author Acrobot * @author Acrobot
*/ */
public class MinecraftChest_forNewBukkit implements ChestObject { public class OldMCchest implements ChestObject {
private final Chest chest; private final Inventory inventory;
public MinecraftChest_forNewBukkit(Chest chest) { public OldMCchest(Chest chest) {
this.chest = chest; this.inventory = bInventoryFix.getInventory(chest);
} }
public ItemStack[] getContents() { public ItemStack[] getContents() {
return chest.getInventory().getContents(); return inventory.getContents();
} }
public void setSlot(int slot, ItemStack item) { public void setSlot(int slot, ItemStack item) {
chest.getInventory().setItem(slot, item); inventory.setItem(slot, item);
} }
public void clearSlot(int slot) { public void clearSlot(int slot) {
chest.getInventory().setItem(slot, null); inventory.clear(slot);
} }
public void addItem(ItemStack item, int amount) { 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) { 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) { 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) { 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) { 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() { public int getSize() {
return chest.getInventory().getSize(); return inventory.getSize();
}
public Chest getNeighbor() {
return uBlock.findNeighbor(chest);
} }
} }

View File

@ -58,7 +58,6 @@ public class ItemInfo implements CommandExecutor {
} }
private static String joinArray(String[] array) { private static String joinArray(String[] array) {
StringBuilder b = new StringBuilder(array.length); StringBuilder b = new StringBuilder(array.length);
for (String s : array) b.append(s).append(' '); for (String s : array) b.append(s).append(' ');

View File

@ -39,9 +39,9 @@ public enum Language {
NO_PERMISSION("You don't have permissions to do that!"), NO_PERMISSION("You don't have permissions to do that!"),
INCORRECT_ITEM_ID("You have specified invalid item id!"), 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; private final String text;

View File

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

View File

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

View File

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

View File

@ -38,7 +38,9 @@ public class DataValue {
materialData = new Coal(CoalType.valueOf(type)); materialData = new Coal(CoalType.valueOf(type));
break; break;
} }
} catch (Exception e) { return 0; } } catch (Exception e) {
return 0;
}
return (materialData == null ? 0 : materialData.getData()); return (materialData == null ? 0 : materialData.getData());
} }
@ -71,7 +73,9 @@ public class DataValue {
name = CoalType.getByData((byte) dur).name(); name = CoalType.getByData((byte) dur).name();
break; break;
} }
} catch (Exception e) { return null; } } catch (Exception e) {
return null;
}
return name; return name;
} }

View File

@ -47,6 +47,12 @@ public class Items {
return uSign.capitalizeFirst((name != null && showData ? name + '_' : "") + is.getType()); 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) { public static ItemStack getItemStack(String itemName) {
ItemStack toReturn = getFromOddItem(itemName); ItemStack toReturn = getFromOddItem(itemName);
if (toReturn != null) return toReturn; if (toReturn != null) return toReturn;

View File

@ -41,7 +41,6 @@ public class playerInteract implements Listener {
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
Player player = event.getPlayer(); 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) { if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) {
Default protection = new Default(); Default protection = new Default();
if (!hasAdminPermissions(player) && (protection.isProtected(block) && !protection.canAccess(player, block))) { if (!hasAdminPermissions(player) && (protection.isProtected(block) && !protection.canAccess(player, block))) {
@ -54,6 +53,7 @@ public class playerInteract implements Listener {
if (!uSign.isSign(block)) return; if (!uSign.isSign(block)) return;
Sign sign = (Sign) block.getState(); 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 (!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) {

View File

@ -10,7 +10,6 @@ import com.Acrobot.ChestShop.Protection.Security;
import com.Acrobot.ChestShop.Utils.WorldGuard.uWorldGuard; import com.Acrobot.ChestShop.Utils.WorldGuard.uWorldGuard;
import com.Acrobot.ChestShop.Utils.uHeroes; import com.Acrobot.ChestShop.Utils.uHeroes;
import com.Acrobot.ChestShop.Utils.uSign; import com.Acrobot.ChestShop.Utils.uSign;
import com.daemitus.deadbolt.Deadbolt;
import com.griefcraft.lwc.LWCPlugin; import com.griefcraft.lwc.LWCPlugin;
import com.herocraftonline.heroes.Heroes; import com.herocraftonline.heroes.Heroes;
import com.nijikokun.register.payment.forChestShop.Method; import com.nijikokun.register.payment.forChestShop.Method;
@ -59,7 +58,6 @@ public class pluginEnable {
LockettePlugin.lockette = (Lockette) plugin; LockettePlugin.lockette = (Lockette) plugin;
Security.protections.add(new LockettePlugin()); Security.protections.add(new LockettePlugin());
} else if (name.equals("Deadbolt")) { } else if (name.equals("Deadbolt")) {
DeadboltPlugin.deadbolt = (Deadbolt) plugin;
Security.protections.add(new DeadboltPlugin()); Security.protections.add(new DeadboltPlugin());
} else if (name.equals("OddItem")) { } else if (name.equals("OddItem")) {
Odd.isInitialized = true; Odd.isInitialized = true;

View File

@ -80,8 +80,8 @@ public class signChange implements Listener {
dropSign(event); dropSign(event);
return; return;
} else if (!playerIsAdmin) { } else if (!playerIsAdmin) {
if (!Config.getBoolean(Property.ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK) && !Security.canPlaceSign(player, (Sign) signBlock.getState())) { if (!Security.canPlaceSign(player, (Sign) signBlock.getState())) {
player.sendMessage(Config.getLocal(Language.ANOTHER_SHOP_DETECTED)); player.sendMessage(Config.getLocal(Language.CANNOT_CREATE_SHOP_HERE));
dropSign(event); dropSign(event);
return; return;
} }
@ -92,7 +92,7 @@ public class signChange implements Listener {
boolean bothActive = uSign.towny != null && uWorldGuard.wg != null; boolean bothActive = uSign.towny != null && uWorldGuard.wg != null;
if (((!canBuildTowny || !canBuildWorldGuard) && !bothActive) || (bothActive && !canBuildTowny && !canBuildWorldGuard)) { 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); dropSign(event);
return; return;
} }
@ -128,7 +128,7 @@ public class signChange implements Listener {
} }
if (Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)) { 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())) { if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && chest != null && Security.protect(player.getName(), chest.getBlock())) {
player.sendMessage(Config.getLocal(Language.PROTECTED_SHOP)); 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.Config.Property;
import com.Acrobot.ChestShop.DB.Queue; import com.Acrobot.ChestShop.DB.Queue;
import com.Acrobot.ChestShop.DB.Transaction; import com.Acrobot.ChestShop.DB.Transaction;
import com.Acrobot.ChestShop.Items.Items;
import com.Acrobot.ChestShop.Shop.Shop; import com.Acrobot.ChestShop.Shop.Shop;
import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -32,10 +34,20 @@ public class Logging {
} }
public static void logTransaction(boolean isBuying, Shop shop, Player player) { 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); 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) { private static void logToDatabase(boolean isBuying, Shop shop, Player player) {
Transaction transaction = new Transaction(); 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.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import java.io.BufferedReader; import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.Proxy; import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Collections; import java.util.*;
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;
public class Metrics { public class Metrics {
@ -299,11 +287,8 @@ public class Metrics {
// Is this the first update this hour? // Is this the first update this hour?
if (response.contains("OK This is your first update this hour")) { if (response.contains("OK This is your first update this hour")) {
synchronized (graphs) { synchronized (graphs) {
Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
Graph graph = iter.next();
for (Graph graph : graphs) {
for (Plotter plotter : graph.getPlotters()) { for (Plotter plotter : graph.getPlotters()) {
plotter.reset(); plotter.reset();
} }
@ -474,6 +459,7 @@ public class Metrics {
/** /**
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph * Gets an <b>unmodifiable</b> set of the plotter objects in the graph
*
* @return * @return
*/ */
public Set<Plotter> getPlotters() { public Set<Plotter> getPlotters() {

View File

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

View File

@ -1,8 +1,11 @@
package com.Acrobot.ChestShop.Protection; 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.Listeners.blockBreak;
import com.Acrobot.ChestShop.Utils.uLongName; import com.Acrobot.ChestShop.Utils.uLongName;
import com.Acrobot.ChestShop.Utils.uSign; import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -14,7 +17,8 @@ import java.util.ArrayList;
* @author Acrobot * @author Acrobot
*/ */
public class Security { 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 ArrayList<Protection> protections = new ArrayList<Protection>();
public static boolean protect(String name, Block block) { public static boolean protect(String name, Block block) {
@ -36,13 +40,31 @@ public class Security {
} }
public static boolean canPlaceSign(Player p, Sign sign) { 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) { for (BlockFace bf : faces) {
Block block = baseBlock.getRelative(bf); 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 true;
} }
return false; return false;

View File

@ -27,7 +27,7 @@ public class Shop {
public float buyPrice; public float buyPrice;
public float sellPrice; public float sellPrice;
public final String owner; public final String owner;
private final Sign sign; public final Sign sign;
public Shop(ChestObject chest, boolean buy, Sign sign, ItemStack... itemStacks) { public Shop(ChestObject chest, boolean buy, Sign sign, ItemStack... itemStacks) {
this.stock = itemStacks[0]; this.stock = itemStacks[0];

View File

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

View File

@ -19,7 +19,10 @@ public class uEnchantment {
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(); 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) {
@ -27,15 +30,19 @@ public class uEnchantment {
Map<Enchantment, Integer> map = new HashMap<Enchantment, Integer>(); Map<Enchantment, Integer> map = new HashMap<Enchantment, Integer>();
String integer = String.valueOf(Integer.parseInt(base32, 32)); 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); String item = integer.substring(i * 3, i * 3 + 3);
Enchantment ench = Enchantment.getById(Integer.parseInt(item.substring(0, 2))); Enchantment ench = Enchantment.getById(Integer.parseInt(item.substring(0, 2)));
if (ench == null) continue; if (ench == null) continue;
int level = Integer.parseInt(item.substring(2)); int level = Integer.parseInt(item.substring(2));
if (ench.getMaxLevel() < level || level < ench.getStartLevel()) continue; if (ench.getMaxLevel() < level || level < ench.getStartLevel()) continue;
map.put(ench, level); map.put(ench, level);
} }
return map; return map;
} }
} }

View File

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

View File

@ -4,6 +4,7 @@ import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Config.Property;
import com.palmergames.bukkit.towny.NotRegisteredException; import com.palmergames.bukkit.towny.NotRegisteredException;
import com.palmergames.bukkit.towny.object.TownBlockType; import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -35,12 +36,18 @@ public class uTowny {
} }
private static boolean isBlockOwner(Player player, Location location) { private static boolean isBlockOwner(Player player, Location location) {
try { return uSign.towny.getTownyUniverse().getTownBlock(location).isOwner(uSign.towny.getTownyUniverse().getResident(player.getName())); try {
} catch (NotRegisteredException ex) { return false; } 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) { private static boolean isResident(Player p, Location l) {
try { return uSign.towny.getTownyUniverse().getTownBlock(l).getTown().hasResident(p.getName()); try {
} catch (NotRegisteredException ex) { return false; } 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; package com.nijikokun.register.payment.forChestShop.methods;
import com.nijikokun.register.payment.forChestShop.Method;
import com.iConomy.iConomy; import com.iConomy.iConomy;
import com.iConomy.system.Account; import com.iConomy.system.Account;
import com.iConomy.system.BankAccount; import com.iConomy.system.BankAccount;
import com.iConomy.system.Holdings; import com.iConomy.system.Holdings;
import com.iConomy.util.Constants; import com.iConomy.util.Constants;
import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
/** /**
@ -18,10 +16,10 @@ import org.bukkit.plugin.Plugin;
* @license AOL license <http://aol.nexua.org> * @license AOL license <http://aol.nexua.org>
*/ */
public class iCo5 implements Method { public class iCo5 implements Method {
private iConomy iConomy; private iConomy iconomy;
public iConomy getPlugin() { public iConomy getPlugin() {
return this.iConomy; return this.iconomy;
} }
public String getName() { public String getName() {
@ -88,7 +86,7 @@ public class iCo5 implements Method {
} }
public void setPlugin(Plugin plugin) { public void setPlugin(Plugin plugin) {
iConomy = (iConomy)plugin; iconomy = (iConomy) plugin;
} }
public static class iCoAccount implements MethodAccount { public static class iCoAccount implements MethodAccount {

View File

@ -2,7 +2,10 @@ name: ChestShop
main: com.Acrobot.ChestShop.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 author: Acrobot
@ -11,7 +14,7 @@ description: >
softdepend: [LWC, Lockette, Deadbolt, OddItem, Towny, WorldGuard, Vault, Heroes, softdepend: [LWC, Lockette, Deadbolt, OddItem, Towny, WorldGuard, Vault, Heroes,
iConomy, BOSEconomy, Essentials, 3co, MultiCurrency, Currency, SimpleChestLock] iConomy, BOSEconomy, Essentials, SimpleChestLock]
commands: commands:
iteminfo: iteminfo:
aliases: [iinfo] aliases: [iinfo]