Final version.

- Speeded it up
- Added Buy/Sell specified ID permission
- Removed EXCLUDE_ITEM permission - just use normal Permission negating
- Doesn't add more LWC's on an already protected block
- Updated Register
- Added option to turn off messages
This commit is contained in:
Acrobot 2011-08-13 12:08:34 +02:00
parent 83a7bbcb6c
commit c64627205e
34 changed files with 785 additions and 346 deletions

View File

@ -30,23 +30,21 @@ import java.util.List;
*/
public class ChestShop extends JavaPlugin {
public static File folder = new File("plugins/ChestShop"); //In case Bukkit fails
public static File folder = new File("plugins/ChestShop");
private static EbeanServer DB;
private static PluginDescriptionFile description;
private static Server server;
public void onEnable() {
blockBreak blockBreak = new blockBreak();
PluginManager pm = getServer().getPluginManager();
//Yep, set up our folder!
folder = getDataFolder();
//Set up our config file!
Config.setUp();
//Register our events
blockBreak blockBreak = new blockBreak();
pm.registerEvent(Event.Type.BLOCK_BREAK, blockBreak, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, new blockPlace(), Event.Priority.Normal, this);
pm.registerEvent(Event.Type.SIGN_CHANGE, new signChange(), Event.Priority.Normal, this);

View File

@ -3,6 +3,7 @@ package com.Acrobot.ChestShop.Commands;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Language;
import com.Acrobot.ChestShop.Items.Items;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -15,27 +16,19 @@ import org.bukkit.inventory.ItemStack;
*/
public class ItemInfo implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
ItemStack item;
if (args.length == 0) {
if (!(sender instanceof Player)) return false;
Player player = (Player) sender;
ItemStack itemInHand = player.getItemInHand();
if (itemInHand.getType() == Material.AIR) return false;
player.sendMessage(Config.getLocal(Language.iteminfo));
player.sendMessage(itemInHand.getTypeId() + ":" + itemInHand.getDurability() + " - " + itemInHand.getType().name());
return true;
item = ((Player) sender).getItemInHand();
} else {
ItemStack item = Items.getItemStack(args[0]);
if (item == null) return false;
sender.sendMessage(Config.getLocal(Language.iteminfo));
sender.sendMessage(item.getTypeId() + ":" + item.getDurability() + " - " + item.getType().name());
return true;
item = Items.getItemStack(args[0]);
}
if(item == null || item.getType() == Material.AIR) return false;
sender.sendMessage(Config.getLocal(Language.iteminfo));
sender.sendMessage(item.getTypeId() + (item.getDurability() != 0 ? " : " + item.getDurability() : "") + " - " + ChatColor.GRAY + item.getType().name());
return true;
}
}

View File

@ -1,6 +1,7 @@
package com.Acrobot.ChestShop.Commands;
import com.Acrobot.ChestShop.ChestShop;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -10,7 +11,7 @@ import org.bukkit.command.CommandSender;
*/
public class Version implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
sender.sendMessage(ChestShop.getPluginName() + "'s version is: " + ChestShop.getVersion());
sender.sendMessage(ChatColor.GRAY + ChestShop.getPluginName() + "'s version is: " + ChatColor.GREEN + ChestShop.getVersion());
return true;
}
}

View File

@ -1,7 +1,6 @@
package com.Acrobot.ChestShop.Config;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Logging.Logging;
import com.Acrobot.ChestShop.Utils.uLongName;
import org.bukkit.util.config.Configuration;
@ -12,21 +11,20 @@ import java.io.FileWriter;
* @author Acrobot
*/
public class Config {
private static File configFile;
private static File langFile;
private static Configuration config = new Configuration(new File(ChestShop.folder, "config.yml"));
private static Configuration language;
private static File configFile = new File(ChestShop.folder, "config.yml");
private static File langFile = new File(ChestShop.folder, "local.yml");
private static Configuration config = new Configuration(configFile);
private static Configuration language = new Configuration(langFile);
public static void setUp() {
setUpConfigurations();
if(!ChestShop.folder.exists()) ChestShop.folder.mkdir();
reloadConfig();
config.load();
reloadLanguage();
language.load();
uLongName.config = new Configuration(new File(ChestShop.folder, "longName.storage"));
uLongName.config.load();
}
@ -48,21 +46,13 @@ public class Config {
}
}
private static void setUpConfigurations(){
configFile = new File(ChestShop.folder, "config.yml");
langFile = new File(ChestShop.folder, "local.yml");
config = new Configuration(configFile);
language = new Configuration(langFile);
}
private static void writeToFile(String string, File file) {
try {
FileWriter fw = new FileWriter(file, true);
fw.write('\n' + string);
fw.write(string + '\n');
fw.close();
} catch (Exception e) {
Logging.log("Couldn't write to file - " + file.getName());
System.out.println("Couldn't write to file - " + file.getName());
}
}
@ -70,6 +60,10 @@ public class Config {
return (Boolean) getValue(value.name());
}
public static float getFloat(Property value){
return new Float(getValue(value.name()).toString());
}
public static String getString(Property value) {
return (String) getValue(value.name());
}
@ -95,7 +89,6 @@ public class Config {
}
public static String getPreferred() {
config = new Configuration(new File("plugins/ChestShop", "config.yml"));
config.load();
return getString(Property.PREFERRED_ECONOMY_PLUGIN);

View File

@ -8,6 +8,7 @@ public enum Property {
REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."),
SERVER_ECONOMY_ACCOUNT("", "Economy account's name you want Admin Shops to be assigned to"),
ADMIN_SHOP_NAME("Admin Shop", "First line of your admin shop should look like this"),
SHOP_CREATION_PRICE(0, "Amount of money player must pay to create a shop"),
LOG_TO_FILE(false, "If true, plugin will log transactions in its own file"),
LOG_TO_CONSOLE(true, "Do you want ChestShop's messages to show up in console?"),
LOG_TO_DATABASE(false, "If true, plugin will log transactions in EBean database"),
@ -18,7 +19,10 @@ public enum Property {
USE_BUILT_IN_PROTECTION(true, "Do you want to use built-in protection against chest destruction?"),
PROTECT_CHEST_WITH_LWC(false, "Do you want to protect shop chests with LWC?"),
PROTECT_SIGN_WITH_LWC(false, "Do you want to protect shop signs with LWC?"),
MASK_CHESTS_AS_OTHER_BLOCKS(false, "Do you want to mask shop chests as other blocks? HIGHLY EXPERIMENTAL, CAN LAG!");
MASK_CHESTS_AS_OTHER_BLOCKS(false, "Do you want to mask shop chests as other blocks? HIGHLY EXPERIMENTAL, CAN LAG!"),
SHOW_MESSAGE_OUT_OF_STOCK(true, "Do you want to show \"Out of stock\" messages?"),
SHOW_TRANSACTION_INFORMATION_CLIENT(true, "Do you want to show \"You bought/sold... \" messages?"),
SHOW_TRANSACTION_INFORMATION_OWNER(true, "Do you want to show \"Somebody bought/sold... \" messages?");
private final Object value;

View File

@ -54,11 +54,10 @@ public class Generator implements Runnable {
private static double generateItemTotal(int itemID, boolean bought, boolean sold) {
double amount = 0;
List<Transaction> list;
if (bought)
list = ChestShop.getDB().find(Transaction.class).where().eq("buy", 1).eq("itemID", itemID).findList();
if (bought) list = ChestShop.getDB().find(Transaction.class).where().eq("buy", 1).eq("itemID", itemID).findList();
else if (sold) list = ChestShop.getDB().find(Transaction.class).where().eq("buy", 0).eq("itemID", itemID).findList();
else list = ChestShop.getDB().find(Transaction.class).where().eq("itemID", itemID).findList();
for (Transaction t : list) amount += t.getAmount();
return amount;
}
@ -118,7 +117,7 @@ public class Generator implements Runnable {
buf = new BufferedWriter(new FileWriter(filePath, true));
long genTime = System.currentTimeMillis();
for (Material m : Material.values()) generateItemStats(m.getId());
buf.close();
generationTime = (System.currentTimeMillis() - genTime) / 1000;

View File

@ -4,22 +4,21 @@ import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
/**
* @author Acrobot
*/
public class Queue implements Runnable {
private static final List<Transaction> queue = new LinkedList<Transaction>();
private static final ArrayList<Transaction> queue = new ArrayList<Transaction>();
public static void addToQueue(Transaction t) {
queue.add(t);
}
public void run() {
List<Transaction> toDelete = ChestShop.getDB().find(Transaction.class).where().lt("sec", System.currentTimeMillis() / 1000 - Config.getInteger(Property.RECORD_TIME_TO_LIVE)).findList();
ChestShop.getDB().delete(toDelete);
ChestShop.getDB().delete(ChestShop.getDB().find(Transaction.class).where().lt("sec", System.currentTimeMillis() / 1000 - Config.getInteger(Property.RECORD_TIME_TO_LIVE)).findList());
ChestShop.getDB().save(queue);
queue.clear();
}

View File

@ -5,7 +5,7 @@ import com.nijikokun.register.payment.forChestShop.Method;
/**
* @author Acrobot
* Economy management
* Economy management
*/
public class Economy {
public static Method economy;

View File

@ -9,36 +9,32 @@ import org.bukkit.material.*;
/**
* @author Acrobot
*/
class DataValue {
public static byte get(String arg, Material material) {
public class DataValue {
public static byte get(String type, Material material) {
if (material == null) return 0;
arg = arg.toUpperCase().replace(" ", "_");
type = type.toUpperCase().replace(" ", "_");
MaterialData materialData = null;
try {
switch (material) {
case SAPLING:
case LOG:
materialData = new Tree(TreeSpecies.valueOf(arg));
materialData = new Tree(TreeSpecies.valueOf(type));
break;
case STEP:
case DOUBLE_STEP:
materialData = new Step(Items.getMaterial(arg));
materialData = new Step(Items.getMaterial(type));
break;
case WOOL:
case INK_SACK:
materialData = new Wool(DyeColor.valueOf(arg));
materialData = new Wool(DyeColor.valueOf(type));
break;
case COAL:
materialData = new Coal(CoalType.valueOf(arg));
materialData = new Coal(CoalType.valueOf(type));
break;
}
} catch (Exception e) {
return 0;
}
} catch (Exception e) { return 0; }
return (materialData == null ? 0 : materialData.getData());
}

View File

@ -12,23 +12,25 @@ public class Items {
public static Material getMaterial(String itemName) {
if (uNumber.isInteger(itemName)) return Material.getMaterial(Integer.parseInt(itemName));
itemName = itemName.replace(" ", "_");
Material finalMaterial = Material.getMaterial(itemName.toUpperCase());
if (finalMaterial != null) return finalMaterial;
int length = 256;
Material finalMat = null;
itemName = itemName.toLowerCase().replace("_", "").replace(" ", "");
for (Material m : Material.values()) {
String matName = m.name().toLowerCase().replace("_", "");
if (matName.startsWith(itemName) && (matName.length() < length)) {
length = matName.length();
finalMat = m;
itemName = itemName.toLowerCase().replace("_", "");
for (Material currentMaterial : Material.values()) {
String materialName = currentMaterial.name().toLowerCase().replace("_", "");
if (materialName.startsWith(itemName) && (materialName.length() < length)) {
length = materialName.length();
finalMaterial = currentMaterial;
}
}
return finalMat;
return finalMaterial;
}
public static ItemStack getItemStack(String itemName) {
ItemStack toReturn;
if ((toReturn = getFromOddItem(itemName)) != null) return toReturn;
ItemStack toReturn = getFromOddItem(itemName);
if (toReturn != null) return toReturn;
Material material = getMaterial(itemName);
if (material != null) return new ItemStack(material, 1);
@ -37,8 +39,7 @@ public class Items {
}
private static ItemStack getFromOddItem(String itemName) {
if (!Odd.isInitialized()) return null;
return Odd.returnItemStack(itemName.replace(":", ";"));
return !Odd.isInitialized() ? null : Odd.returnItemStack(itemName.replace(":", ";"));
}
private static ItemStack getItemStackWithDataValue(String itemName) {
@ -51,24 +52,12 @@ public class Items {
return item == null ? null : new ItemStack(item, 1, Short.parseShort(word[1]));
}
private static ItemStack getItemStackWithDataValueFromWord(String itemName) {
if (!itemName.contains(" ") || getMaterial(itemName) != null) return null;
String[] word = itemName.split(" ");
if (word.length < 2) return null;
String dataValue = word[0];
String material[] = new String[word.length - 1];
System.arraycopy(word, 1, material, 0, word.length - 1);
StringBuilder mat = new StringBuilder();
for (String s : material) mat.append(s);
Material item = getMaterial(mat.toString());
return item == null ? null : new ItemStack(item, 1, DataValue.get(dataValue, item));
private static ItemStack getItemStackWithDataValueFromWord(String itemName){
int indexOfChar = itemName.indexOf(' ');
if(indexOfChar == -1) return null;
Material item = getMaterial(itemName.substring(indexOfChar));
return item == null ? null : new ItemStack(item, 1, DataValue.get(itemName.substring(0, indexOfChar), item));
}
}

View File

@ -30,8 +30,9 @@ import java.util.HashMap;
*/
public class playerInteract extends PlayerListener {
private static final HashMap<Player, Long> lastTransactionTime = new HashMap<Player, Long>();
private static final int interval = 100;
private static final HashMap<Player, Long> lastTransactionTime = new HashMap<Player, Long>(); //Last player's transaction
private static final int interval = 100;//Minimal interval between transactions
public void onPlayerInteract(PlayerInteractEvent event) {
Action action = event.getAction();
@ -42,39 +43,24 @@ public class playerInteract extends PlayerListener {
if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) {
Default protection = new Default();
if (!Permission.has(player, Permission.ADMIN) && !Permission.has(player, Permission.MOD) && (protection.isProtected(block) && !protection.canAccess(player, block))) {
if (!hasAdminPermissions(player) && (protection.isProtected(block) && !protection.canAccess(player, block))) {
player.sendMessage(Config.getLocal(Language.ACCESS_DENIED));
event.setCancelled(true);
return;
}
}
if (!uSign.isSign(block)) return;
if (!uSign.isSign(block)) return; //It's not a sign!
Sign sign = (Sign) block.getState();
if (!uSign.isValid(sign) || lastTransactionTime.containsKey(player) && (System.currentTimeMillis() - lastTransactionTime.get(player)) < interval || player.isSneaking()) return;
if (!uSign.isValid(sign) || !enoughTimeHasPassed(player) || player.isSneaking()) return;
lastTransactionTime.put(player, System.currentTimeMillis());
String playerName = uLongName.stripName(player.getName());
event.setCancelled(true);
if (playerName.equals(sign.getLine(0))) {
Chest chest1 = uBlock.findChest(sign);
if (chest1 == null) {
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
return;
}
IInventory inventory = ((CraftInventory) chest1.getInventory()).getInventory();
Chest chest2 = uBlock.findNeighbor(chest1);
if (chest2 != null) {
IInventory iInv2 = ((CraftInventory) chest2.getInventory()).getInventory();
inventory = new InventoryLargeChest(player.getName() + "'s Shop", inventory, iInv2);
}
((CraftPlayer) player).getHandle().a(inventory);
if (uLongName.stripName(player.getName()).equals(sign.getLine(0))) {
showChestGUI(player, block);
return;
}
@ -91,4 +77,29 @@ public class playerInteract extends PlayerListener {
ShopManagement.sell(sign, player);
}
}
private static boolean enoughTimeHasPassed(Player player) {
return !lastTransactionTime.containsKey(player) || (System.currentTimeMillis() - lastTransactionTime.get(player)) >= interval;
}
private static boolean hasAdminPermissions(Player player) {
return Permission.has(player, Permission.ADMIN) || Permission.has(player, Permission.MOD);
}
private static void showChestGUI(Player player, Block block) {
Chest chest = uBlock.findChest(block);
if (chest == null) { //Sorry, no chest found
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
return;
}
IInventory inventory = ((CraftInventory) chest.getInventory()).getInventory();
chest = uBlock.findNeighbor(chest);
if (chest != null) { //There is also a neighbor chest
inventory = new InventoryLargeChest(player.getName() + "'s Shop", inventory, ((CraftInventory) chest.getInventory()).getInventory());
}
((CraftPlayer) player).getHandle().a(inventory); //Show inventory on the screen
}
}

View File

@ -18,14 +18,27 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.yi.acru.bukkit.Lockette.Lockette;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
/**
* @author Acrobot
*/
public class pluginEnable extends ServerListener {
public static final Methods methods = new Methods(Config.getPreferred());
private static final String lineStart = "[ChestShop] ";
private static List<String> pluginsToLoad = new LinkedList<String>(Arrays.asList(
"Permissions",
"LWC",
"Lockette",
"OddItem"
));
public void onPluginEnable(PluginEnableEvent event) {
LinkedList<String> toRemove = new LinkedList();
//Economy plugins
if (!methods.hasMethod()) {
@ -35,51 +48,33 @@ public class pluginEnable extends ServerListener {
}
}
//Permissions
if (Permission.permissions == null) {
Plugin permissions = ChestShop.getBukkitServer().getPluginManager().getPlugin("Permissions");
if (permissions != null) {
Permission.permissions = ((Permissions) permissions).getHandler();
PluginDescriptionFile pDesc = permissions.getDescription();
System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
for (String pluginName : pluginsToLoad) {
Plugin plugin = ChestShop.getBukkitServer().getPluginManager().getPlugin(pluginName);
if (plugin == null) continue;
initializePlugin(pluginName, plugin);
toRemove.add(pluginName);
}
//LWC
if (LWCplugin.lwc == null) {
Plugin lwcPlugin = ChestShop.getBukkitServer().getPluginManager().getPlugin("LWC");
for (String pluginName : toRemove) pluginsToLoad.remove(pluginName);
}
if (lwcPlugin != null) {
PluginDescriptionFile pDesc = lwcPlugin.getDescription();
LWCplugin.lwc = ((LWCPlugin) lwcPlugin).getLWC();
Security.protection = new LWCplugin();
System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
}
//OddItem
if (Odd.oddItem == null) {
Plugin oddItem = ChestShop.getBukkitServer().getPluginManager().getPlugin("OddItem");
if (oddItem != null) {
PluginDescriptionFile pDesc = oddItem.getDescription();
Odd.oddItem = (OddItem) ChestShop.getBukkitServer().getPluginManager().getPlugin("OddItem");
System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
}
//Lockette
if (LockettePlugin.lockette == null) {
Plugin lockette = ChestShop.getBukkitServer().getPluginManager().getPlugin("Lockette");
if (lockette != null) {
PluginDescriptionFile pDesc = lockette.getDescription();
LockettePlugin.lockette = ((Lockette) lockette);
Security.protection = new LockettePlugin();
System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :)
PluginDescriptionFile description = plugin.getDescription();
if (name.equals("Permissions")) {
if (Permission.permissions != null) return;
Permission.permissions = ((Permissions) plugin).getHandler();
} else if (name.equals("LWC")) {
if (LWCplugin.lwc != null) return;
LWCplugin.lwc = ((LWCPlugin) plugin).getLWC();
Security.protection = new LWCplugin();
} else if (name.equals("Lockette")) {
if (LockettePlugin.lockette != null) return;
LockettePlugin.lockette = (Lockette) plugin;
Security.protection = new LockettePlugin();
} else if (name.equals("OddItem")) {
if (Odd.oddItem != null) return;
Odd.oddItem = (OddItem) plugin;
}
System.out.println(lineStart + description.getName() + " version " + description.getVersion() + " loaded.");
}
}

View File

@ -3,6 +3,7 @@ package com.Acrobot.ChestShop.Listeners;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Language;
import com.Acrobot.ChestShop.Config.Property;
import com.Acrobot.ChestShop.Economy;
import com.Acrobot.ChestShop.Items.Items;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Protection.Default;
@ -31,7 +32,7 @@ public class signChange extends BlockListener {
Block signBlock = event.getBlock();
String[] line = event.getLines();
Boolean isAlmostReady = uSign.isValidPreparedSign(event.getLines());
boolean isAlmostReady = uSign.isValidPreparedSign(line);
Player player = event.getPlayer();
ItemStack stock = Items.getItemStack(line[3]);
@ -46,11 +47,7 @@ public class signChange extends BlockListener {
dropSign(event);
return;
}
if (!(playerIsAdmin ||
Permission.has(player, Permission.SHOP_CREATION) ||
(Permission.has(player, Permission.SHOP_CREATION + "." + mat.getId()) &&
!Permission.has(player, Permission.EXCLUDE_ITEM + "." + mat.getId())))) {
if (!canCreateShop(player, mat.getId())) {
player.sendMessage(Config.getLocal(Language.YOU_CANNOT_CREATE_SHOP));
dropSign(event);
return;
@ -63,50 +60,36 @@ public class signChange extends BlockListener {
return;
}
Block secondSign = signBlock.getRelative(BlockFace.DOWN);
if (!uSign.isSign(secondSign) || !uSign.isValid((Sign) secondSign.getState())) {
dropSign(event);
}
if (!uSign.isSign(secondSign) || !uSign.isValid((Sign) secondSign.getState())) dropSign(event);
}
return;
}
Boolean isReady = uSign.isValid(line);
if (formatFirstLine(line[0], player)) event.setLine(0, uLongName.stripName(player.getName()));
if (line[0].isEmpty() || (!line[0].startsWith(player.getName()) && !Permission.has(player, Permission.ADMIN))) {
event.setLine(0, uLongName.stripName(player.getName()));
}
line = event.getLines();
boolean isAdminShop = uSign.isAdminShop(line[0]);
if (!isReady) {
int prices = line[2].split(":").length;
String oldLine = line[2];
if (prices == 1) {
event.setLine(2, "B " + oldLine);
} else {
event.setLine(2, "B " + oldLine + " S");
}
String thirdLine = formatThirdLine(line[2]);
if (thirdLine == null) {
dropSign(event);
player.sendMessage(Config.getLocal(Language.YOU_CANNOT_CREATE_SHOP));
return;
}
event.setLine(2, thirdLine);
String[] split = line[3].split(":");
if (uNumber.isInteger(split[0])) {
String matName = mat.name();
String materialLine = mat.name();
if (split.length == 2) {
int length = matName.length();
int maxLength = (15 - split[1].length() - 1);
if (length > maxLength) {
matName = matName.substring(0, maxLength);
}
event.setLine(3, matName + ':' + split[1]);
} else {
event.setLine(3, matName);
if (materialLine.length() > maxLength) materialLine = materialLine.substring(0, maxLength);
materialLine = materialLine + ':' + split[1];
}
event.setLine(3, materialLine);
}
Chest chest = uBlock.findChest(signBlock);
line = event.getLines();
boolean isAdminShop = uSign.isAdminShop(line[0]);
if (!isAdminShop) {
if (chest == null) {
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
@ -119,18 +102,13 @@ public class signChange extends BlockListener {
return;
}
boolean canAccess = true;
Block chestBlock = chest.getBlock();
boolean canAccess = !Security.isProtected(chestBlock) || !Security.canAccess(player, chestBlock);
if (Security.isProtected(chestBlock) && !Security.canAccess(player, chestBlock)) {
canAccess = false;
}
if (!(Security.protection instanceof Default)) {
if (!(Security.protection instanceof Default) && canAccess) {
Default protection = new Default();
if (protection.isProtected(chestBlock) && !protection.canAccess(player, chestBlock)) {
if (protection.isProtected(chestBlock) && !protection.canAccess(player, chestBlock))
canAccess = false;
}
}
if (!canAccess) {
@ -141,10 +119,21 @@ public class signChange extends BlockListener {
}
}
if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && chest != null && Security.protect(player.getName(), chest.getBlock())) {
if (Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)) {
Security.protect(player.getName(), signBlock);
float shopCreationPrice = Config.getFloat(Property.SHOP_CREATION_PRICE);
if(shopCreationPrice != 0 && !isAdminShop){
if(!Economy.hasEnough(player.getName(), shopCreationPrice)){
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY));
dropSign(event);
return;
}
Economy.substract(player.getName(), shopCreationPrice);
}
if (Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)) {
Security.protect(player.getName(), signBlock);
}
if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && chest != null && Security.protect(player.getName(), chest.getBlock())) {
player.sendMessage(Config.getLocal(Language.PROTECTED_SHOP));
}
@ -152,6 +141,30 @@ public class signChange extends BlockListener {
player.sendMessage(Config.getLocal(Language.SHOP_CREATED));
}
private static boolean canCreateShop(Player player, boolean isAdmin, int ID) {
return isAdmin ||
Permission.has(player, Permission.SHOP_CREATION) ||
Permission.has(player, Permission.SHOP_CREATION.toString() + '.' + ID);
}
private static boolean canCreateShop(Player player, int ID) {
return canCreateShop(player, Permission.has(player, Permission.ADMIN), ID);
}
private static String formatThirdLine(String thirdLine) {
String[] split = thirdLine.split(":");
if (uNumber.isFloat(split[0])) thirdLine = "B " + thirdLine;
if (split.length == 2 && uNumber.isFloat(split[1])) thirdLine = thirdLine + " S";
if (thirdLine.length() > 15) thirdLine = thirdLine.replace(" ", "");
return (thirdLine.length() > 15 ? null : thirdLine);
}
private static boolean formatFirstLine(String line1, Player player) {
return line1.isEmpty() ||
(!line1.equals(uLongName.stripName(player.getName())) && !Permission.has(player, Permission.ADMIN));
}
private static void dropSign(SignChangeEvent event) {
event.setCancelled(true);

View File

@ -33,7 +33,7 @@ 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);
if (Config.getBoolean(Property.LOG_TO_DATABASE)) logToDatabase(isBuying, shop, player);
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) logToDatabase(isBuying, shop, player);
}
private static void logToDatabase(boolean isBuying, Shop shop, Player player){

View File

@ -8,8 +8,9 @@ import org.bukkit.entity.Player;
*/
public enum Permission {
SHOP_CREATION("ChestShop.shop.create"),
EXCLUDE_ITEM("ChestShop.shop.exclude"),
BUY("ChestShop.shop.buy"),
BUY_ID("ChestShop.shop.buy."),
SELL_ID("ChestShop.shop.sell."),
SELL("ChestShop.shop.sell"),
ADMIN("ChestShop.admin"),
MOD("ChestShop.mod");
@ -27,7 +28,6 @@ public enum Permission {
}
public static boolean has(Player player, String node) {
//return !node.contains("exclude") && !node.contains ("create.") && ((!node.contains("admin") && !node.contains("mod")) || player.isOp());
if (permissions != null) return permissions.has(player, node);
return player.hasPermission(node);
}

View File

@ -2,7 +2,6 @@ package com.Acrobot.ChestShop.Protection;
import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.uLongName;
import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
@ -13,25 +12,23 @@ import org.bukkit.entity.Player;
*/
public class Default implements Protection {
public boolean isProtected(Block block) {
if ((uSign.isSign(block) && uSign.isValid((Sign) block.getState())) || uBlock.findSign(block) != null) return true;
if (!(block.getState() instanceof Chest)) return false;
if (uBlock.findSign(block) != null) return true;
Chest neighbor = uBlock.findNeighbor(block);
return neighbor != null && uBlock.findSign(neighbor.getBlock()) != null;
}
public boolean canAccess(Player player, Block block) {
String playerName = player.getName();
Sign sign = uBlock.findSign(block);
if(sign != null) return uLongName.stripName(playerName).equals(sign.getLine(0));
Chest neighborChest = uBlock.findNeighbor(block);
Sign neighborSign = (neighborChest != null ? uBlock.findSign(neighborChest.getBlock()) : null);
String playerName = player.getName();
String signLine = "";
if (uSign.isSign(block) && uSign.isValid((Sign) block.getState())) signLine = ((Sign) block.getState()).getLine(0);
if (sign != null) signLine = sign.getLine(0);
if (neighborSign != null) signLine = neighborSign.getLine(0);
return uLongName.stripName(playerName).equals(signLine);
return neighborSign != null && uLongName.stripName(playerName).equals(neighborSign.getLine(0));
}
public boolean protect(String name, Block block) {

View File

@ -21,6 +21,7 @@ public class LWCplugin implements Protection {
}
public boolean protect(String name, Block block) {
if (lwc.findProtection(block) != null) return false;
lwc.getPhysicalDatabase().registerProtection(block.getTypeId(), ProtectionTypes.PRIVATE, block.getWorld().getName(), name, "", block.getX(), block.getY(), block.getZ());
return true;
}

View File

@ -1,8 +1,8 @@
package com.Acrobot.ChestShop.Protection;
import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.uLongName;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
@ -25,10 +25,9 @@ public class Security {
}
public static boolean canPlaceSign(Player p, Block block) {
Chest chest = uBlock.findChest(block);
Sign sign1 = uBlock.findSign(chest.getBlock());
Sign sign2 = uBlock.findSign(block);
Sign sign = uBlock.findSign(uBlock.findChest(block).getBlock());
if (sign == null) sign = uBlock.findSign(block);
return (sign1 == null || sign1.getLine(0).startsWith(p.getName())) && (sign2 == null || sign2.getLine(0).startsWith(p.getName()));
return (sign == null || sign.getLine(0).equals(uLongName.stripName(p.getName())));
}
}

View File

@ -18,10 +18,11 @@ import org.bukkit.inventory.ItemStack;
* @author Acrobot
*/
public class Shop {
public final ItemStack stock;
private final short durability;
public final int stockAmount;
private final ChestObject chest;
public final ItemStack stock;
public final int stockAmount;
public final float buyPrice;
public final float sellPrice;
public final String owner;
@ -45,7 +46,7 @@ public class Shop {
player.sendMessage(Config.getLocal(Language.NO_BUYING_HERE));
return;
}
if (!Permission.has(player, Permission.BUY)) {
if (!Permission.has(player, Permission.BUY) && !Permission.has(player, Permission.BUY_ID + Integer.toString(stock.getTypeId()))) {
player.sendMessage(Config.getLocal(Language.NO_PERMISSION));
return;
}
@ -63,6 +64,7 @@ public class Shop {
if (!isAdminShop() && !hasEnoughStock()) {
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_STOCK));
if (!Config.getBoolean(Property.SHOW_MESSAGE_OUT_OF_STOCK)) return;
sendMessageToOwner(Config.getLocal(Language.NOT_ENOUGH_STOCK_IN_YOUR_SHOP).replace("%material", materialName));
return;
}
@ -75,21 +77,25 @@ public class Shop {
if (!isAdminShop()) chest.removeItem(stock, durability, stockAmount);
String formatedPrice = Economy.formatBalance(buyPrice);
player.sendMessage(Config.getLocal(Language.YOU_BOUGHT_FROM_SHOP)
.replace("%amount", String.valueOf(stockAmount))
.replace("%item", materialName)
.replace("%owner", owner)
.replace("%price", formatedPrice));
if (Config.getBoolean(Property.SHOW_TRANSACTION_INFORMATION_CLIENT)) {
player.sendMessage(Config.getLocal(Language.YOU_BOUGHT_FROM_SHOP)
.replace("%amount", String.valueOf(stockAmount))
.replace("%item", materialName)
.replace("%owner", owner)
.replace("%price", formatedPrice));
}
uInventory.add(player.getInventory(), stock, stockAmount);
Logging.logTransaction(true, this, player);
player.updateInventory();
sendMessageToOwner(Config.getLocal(Language.SOMEBODY_BOUGHT_FROM_YOUR_SHOP)
.replace("%amount", String.valueOf(stockAmount))
.replace("%item", materialName)
.replace("%buyer", playerName)
.replace("%price", formatedPrice));
if (Config.getBoolean(Property.SHOW_TRANSACTION_INFORMATION_OWNER)) {
sendMessageToOwner(Config.getLocal(Language.SOMEBODY_BOUGHT_FROM_YOUR_SHOP)
.replace("%amount", String.valueOf(stockAmount))
.replace("%item", materialName)
.replace("%buyer", playerName)
.replace("%price", formatedPrice));
}
}
public void sell(Player player) {
@ -101,11 +107,11 @@ public class Shop {
player.sendMessage(Config.getLocal(Language.NO_SELLING_HERE));
return;
}
if (!Permission.has(player, Permission.SELL)) {
if (!Permission.has(player, Permission.SELL) && !Permission.has(player, Permission.SELL_ID + Integer.toString(stock.getTypeId()))) {
player.sendMessage(Config.getLocal(Language.NO_PERMISSION));
return;
}
String account = getOwnerAccount();
boolean accountExists = !account.isEmpty() && Economy.hasAccount(account);
@ -132,21 +138,25 @@ public class Shop {
String materialName = stock.getType().name();
String formatedBalance = Economy.formatBalance(sellPrice);
player.sendMessage(Config.getLocal(Language.YOU_SOLD_TO_SHOP)
.replace("%amount", String.valueOf(stockAmount))
.replace("%item", materialName)
.replace("%buyer", owner)
.replace("%price", formatedBalance));
if (Config.getBoolean(Property.SHOW_TRANSACTION_INFORMATION_CLIENT)) {
player.sendMessage(Config.getLocal(Language.YOU_SOLD_TO_SHOP)
.replace("%amount", String.valueOf(stockAmount))
.replace("%item", materialName)
.replace("%buyer", owner)
.replace("%price", formatedBalance));
}
uInventory.remove(player.getInventory(), stock, stockAmount, durability);
Logging.logTransaction(false, this, player);
player.updateInventory();
sendMessageToOwner(Config.getLocal(Language.SOMEBODY_SOLD_TO_YOUR_SHOP)
.replace("%amount", String.valueOf(stockAmount))
.replace("%item", materialName)
.replace("%seller", player.getName())
.replace("%price", formatedBalance));
if (Config.getBoolean(Property.SHOW_TRANSACTION_INFORMATION_OWNER)) {
sendMessageToOwner(Config.getLocal(Language.SOMEBODY_SOLD_TO_YOUR_SHOP)
.replace("%amount", String.valueOf(stockAmount))
.replace("%item", materialName)
.replace("%seller", player.getName())
.replace("%price", formatedBalance));
}
}
private String getOwnerAccount() {

View File

@ -23,9 +23,7 @@ public class uBlock {
public static Chest findChest(Block block) {
for (BlockFace bf : shopFaces) {
Block faceBlock = block.getRelative(bf);
if (faceBlock.getType() == Material.CHEST) {
return (Chest) faceBlock.getState();
}
if (faceBlock.getType() == Material.CHEST) return (Chest) faceBlock.getState();
}
return null;
}
@ -35,9 +33,7 @@ public class uBlock {
Block faceBlock = block.getRelative(bf);
if (uSign.isSign(faceBlock)) {
Sign sign = (Sign) faceBlock.getState();
if (uSign.isValid(sign)) {
return sign;
}
if (uSign.isValid(sign)) return sign;
}
}
return null;
@ -48,9 +44,7 @@ public class uBlock {
Block faceBlock = block.getRelative(bf);
if (uSign.isSign(faceBlock)) {
Sign sign = (Sign) faceBlock.getState();
if (restrictedSign.isRestricted(sign)) {
return sign;
}
if (restrictedSign.isRestricted(sign)) return sign;
}
}
return null;
@ -63,7 +57,7 @@ public class uBlock {
return (Chest) neighborBlock.getState();
}
}
return null; //Shame, we didn't find double chest :/
return null;
}
public static Chest findNeighbor(Chest chest) {

View File

@ -11,7 +11,7 @@ import java.util.HashMap;
* @author Acrobot
*/
public class uInventory {
public static int remove(Inventory inv, ItemStack item, int amount, short durability) {
amount = (amount > 0 ? amount : 1);
Material itemMaterial = item.getType();
@ -98,7 +98,7 @@ public class uInventory {
int currentAmount = currentItem.getAmount();
if (currentAmount != maxStackSize && currentItem.getType() == itemMaterial && (durability == -1 || currentItem.getDurability() == durability)) {
amountLeft = ((currentAmount + amountLeft) <= maxStackSize ? 0 : amountLeft - (maxStackSize - currentAmount));
amountLeft = currentAmount + amountLeft <= maxStackSize ? 0 : amountLeft - (maxStackSize - currentAmount);
}
}

View File

@ -1,21 +1,23 @@
package com.Acrobot.ChestShop.Utils;
import com.Acrobot.ChestShop.ChestShop;
import org.bukkit.util.config.Configuration;
import java.io.File;
/**
* @author Acrobot
*/
public class uLongName {
public static Configuration config;
public static Configuration config = new Configuration(new File(ChestShop.folder, "longName.storage"));
public static String getName(final String shortName){
public static String getName(final String shortName) {
return config.getString(shortName, shortName);
}
public static void saveName(String name){
if (!(name.length() > 15)) return;
String shortName = name.substring(0, 15);
config.setProperty(shortName, name);
public static void saveName(String name) {
if (name.length() != 16) return;
config.setProperty(name.substring(0, 15), name);
reloadConfig();
}
@ -23,7 +25,7 @@ public class uLongName {
return (name.length() > 15 ? name.substring(0, 15) : name);
}
private static void reloadConfig(){
private static void reloadConfig() {
config.save();
config.load();
}

View File

@ -41,49 +41,35 @@ public class uSign {
public static boolean isValidPreparedSign(String[] lines){
try{
boolean toReturn = true;
for(int i = 0; i < 4; i++){
toReturn = toReturn && patterns[i].matcher(lines[i]).matches();
}
return toReturn;
for(int i = 0; i < 4 && toReturn; i++) toReturn = patterns[i].matcher(lines[i]).matches();
return toReturn && lines[2].split(":").length <= 2;
} catch (Exception e){
return false;
}
}
public static float buyPrice(String text) {
text = text.replace(" ", "").toLowerCase();
String[] split = text.split(":");
int buyPart = (text.contains("b") ? (split[0].contains("b") ? 0 : 1) : -1);
if (buyPart == -1 || (buyPart == 1 && split.length != 2)) return -1;
split[buyPart] = split[buyPart].replace("b", "");
if (uNumber.isFloat(split[buyPart])) {
float buyPrice = Float.parseFloat(split[buyPart]);
return (buyPrice != 0 ? buyPrice : -1);
} else if (split[buyPart].equals("free")) {
return 0;
}
return -1;
return price(text, true);
}
public static float sellPrice(String text) {
return price(text, false);
}
private static float price(String text, boolean buy){
String toContain = buy ? "b" : "s";
text = text.replace(" ", "").toLowerCase();
String[] split = text.split(":");
int sellPart = (text.contains("s") ? (split[0].contains("s") ? 0 : 1) : -1);
if(sellPart == -1 || (sellPart == 1 && split.length != 2)) return -1;
int part = (text.contains(toContain) ? (split[0].contains(toContain) ? 0 : 1) : -1);
if(part == -1 || (part == 1 && split.length != 2)) return -1;
split[sellPart] = split[sellPart].replace("s", "");
if (uNumber.isFloat(split[sellPart])) {
Float sellPrice = Float.parseFloat(split[sellPart]);
return (sellPrice != 0 ? sellPrice : -1);
} else if (split[sellPart].equals("free")) {
return 0;
}
split[part] = split[part].replace(toContain, "");
if (uNumber.isFloat(split[part])) {
Float price = Float.parseFloat(split[part]);
return (price != 0 ? price : -1);
} else if (split[part].equals("free")) return 0;
return -1;
}

View File

@ -22,7 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class Database {
private JavaPlugin javaPlugin;
private final JavaPlugin javaPlugin;
private ClassLoader classLoader;
private Level loggerLevel;
private boolean usingSQLite;
@ -294,7 +294,7 @@ public abstract class Database {
}
//Turn all the lines back into a single string
StringBuilder newScript = new StringBuilder();
StringBuilder newScript = new StringBuilder(5);
for (String newLine : scriptLines) newScript.append(newLine).append('\n');
//Print the new script

View File

@ -3,27 +3,121 @@ package com.nijikokun.register.payment.forChestShop;
import org.bukkit.plugin.Plugin;
/**
* Method.java
* Interface for all sub-methods for payment.
* Interface to be implemented by a payment method.
*
* @author: Nijikokun<nijikokun@gmail.com> (@nijikokun)
* @copyright: Copyright (C) 2011
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright Copyright (C) 2011
* @license AOL license <http://aol.nexua.org>
*/
public interface Method {
/**
* Encodes the Plugin into an Object disguised as the Plugin.
* If you want the original Plugin Class you must cast it to the correct
* Plugin, to do so you have to verify the name and or version then cast.
*
* <pre>
* if(method.getName().equalsIgnoreCase("iConomy"))
* iConomy plugin = ((iConomy)method.getPlugin());</pre>
*
* @return <code>Object</code>
* @see #getName()
* @see #getVersion()
*/
public Object getPlugin();
/**
* Returns the actual name of this method.
*
* @return <code>String</code> Plugin name.
*/
public String getName();
/**
* Returns the actual version of this method.
*
* @return <code>String</code> Plugin version.
*/
public String getVersion();
/**
* Formats amounts into this payment methods style of currency display.
*
* @param amount Double
* @return <code>String</code> - Formatted Currency Display.
*/
public String format(double amount);
/**
* Allows the verification of bank API existence in this payment method.
*
* @return <code>boolean</code>
*/
public boolean hasBanks();
/**
* Determines the existence of a bank via name.
*
* @param bank Bank name
* @return <code>boolean</code>
* @see #hasBanks
*/
public boolean hasBank(String bank);
/**
* Determines the existence of an account via name.
*
* @param name Account name
* @return <code>boolean</code>
*/
public boolean hasAccount(String name);
/**
* Check to see if an account <code>name</code> is tied to a <code>bank</code>.
*
* @param bank Bank name
* @param name Account name
* @return <code>boolean</code>
*/
public boolean hasBankAccount(String bank, String name);
/**
* Returns a <code>MethodAccount</code> class for an account <code>name</code>.
*
* @param name Account name
* @return <code>MethodAccount</code> <em>or</em> <code>Null</code>
*/
public MethodAccount getAccount(String name);
/**
* Returns a <code>MethodBankAccount</code> class for an account <code>name</code>.
*
* @param bank Bank name
* @param name Account name
* @return <code>MethodBankAccount</code> <em>or</em> <code>Null</code>
*/
public MethodBankAccount getBankAccount(String bank, String name);
/**
* Checks to verify the compatibility between this Method and a plugin.
* Internal usage only, for the most part.
*
* @param plugin Plugin
* @return <code>boolean</code>
*/
public boolean isCompatible(Plugin plugin);
/**
* Set Plugin data.
*
* @param plugin Plugin
*/
public void setPlugin(Plugin plugin);
/**
* Contains Calculator and Balance functions for Accounts.
*/
public interface MethodAccount {
public double balance();
public boolean set(double amount);
@ -41,6 +135,9 @@ public interface Method {
public String toString();
}
/**
* Contains Calculator and Balance functions for Bank Accounts.
*/
public interface MethodBankAccount {
public double balance();
public String getBankName();

View File

@ -1,7 +1,5 @@
package com.nijikokun.register.payment.forChestShop;
import com.nijikokun.register.payment.forChestShop.methods.BOSE6;
import com.nijikokun.register.payment.forChestShop.methods.BOSE7;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@ -9,29 +7,46 @@ import java.util.HashSet;
import java.util.Set;
/**
* Methods.java
* Controls the getting / setting of methods & the method of payment used.
* The <code>Methods</code> initializes Methods that utilize the Method interface
* based on a "first come, first served" basis.
*
* @author: Nijikokun<nijikokun@gmail.com> (@nijikokun)
* Allowing you to check whether a payment method exists or not.
*
* <blockquote><pre>
* Methods methods = new Methods();
* </pre></blockquote>
*
* Methods also allows you to set a preferred method of payment before it captures
* payment plugins in the initialization process.
*
* <blockquote><pre>
* Methods methods = new Methods("iConomy");
* </pre></blockquote>
*
* @author: Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright: Copyright (C) 2011
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
* @license: AOL license <http://aol.nexua.org>
*/
public class Methods {
private boolean self = false;
private Method Method = null;
private String preferred = "";
private Set<Method> Methods = new HashSet<Method>();
private Set<String> Dependencies = new HashSet<String>();
private Set<Method> Attachables = new HashSet<Method>();
private final Set<Method> Methods = new HashSet<Method>();
private final Set<String> Dependencies = new HashSet<String>();
private final Set<Method> Attachables = new HashSet<Method>();
/**
* Initialize Method class
*/
public Methods() {
this._init();
}
/**
* Allows you to set which economy plugin is most preferred.
* Initializes <code>Methods</code> class utilizing a "preferred" payment method check before
* returning the first method that was initialized.
*
* @param preferred - preferred economy plugin
* @param preferred Payment method that is most preferred for this setup.
*/
public Methods(String preferred) {
this._init();
@ -41,19 +56,41 @@ public class Methods {
}
}
/**
* Implement all methods along with their respective name & class.
*
* @see #Methods()
* @see #Methods(java.lang.String)
*/
private void _init() {
this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo4());
this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo6());
this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo5());
this.addMethod("BOSEconomy", new BOSE6());
this.addMethod("BOSEconomy", new BOSE7());
this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo4());
this.addMethod("BOSEconomy", new com.nijikokun.register.payment.forChestShop.methods.BOSE6());
this.addMethod("BOSEconomy", new com.nijikokun.register.payment.forChestShop.methods.BOSE7());
this.addMethod("Essentials", new com.nijikokun.register.payment.forChestShop.methods.EE17());
this.addMethod("MultiCurrency", new com.nijikokun.register.payment.forChestShop.methods.MCUR());
}
/**
* Returns an array of payment method names that have been loaded
* through the <code>_init</code> method.
*
* @return <code>Set<String></code> - Array of payment methods that are loaded.
* @see #setMethod(org.bukkit.plugin.Plugin)
*/
public Set<String> getDependencies() {
return Dependencies;
}
Method createMethod(Plugin plugin) {
/**
* Interprets Plugin class data to verify whether it is compatible with an existing payment
* method to use for payments and other various economic activity.
*
* @param plugin Plugin data from bukkit, Internal Class file.
* @return Method <em>or</em> Null
*/
public Method createMethod(Plugin plugin) {
for (Method method: Methods) {
if (method.isCompatible(plugin)) {
method.setPlugin(plugin);
@ -69,10 +106,24 @@ public class Methods {
Methods.add(method);
}
/**
* Verifies if Register has set a payment method for usage yet.
*
* @return <code>boolean</code>
* @see #setMethod(org.bukkit.plugin.Plugin)
* @see #checkDisabled(org.bukkit.plugin.Plugin)
*/
public boolean hasMethod() {
return (Method != null);
}
/**
* Checks Plugin Class against a multitude of checks to verify it's usability
* as a payment method.
*
* @param method Plugin data from bukkit, Internal Class file.
* @return <code>boolean</code> True on success, False on failure.
*/
public boolean setMethod(Plugin method) {
if(hasMethod()) return true;
if(self) { self = false; return false; }
@ -128,10 +179,22 @@ public class Methods {
return hasMethod();
}
/**
* Grab the existing and initialized (hopefully) Method Class.
*
* @return <code>Method</code> <em>or</em> <code>Null</code>
*/
public Method getMethod() {
return Method;
}
/**
* Verify is a plugin is disabled, only does this if we there is an existing payment
* method initialized in Register.
*
* @param method Plugin data from bukkit, Internal Class file.
* @return <code>boolean</code>
*/
public boolean checkDisabled(Plugin method) {
if(!hasMethod()) return true;
if (Method.isCompatible(method)) Method = null;

View File

@ -4,6 +4,13 @@ import com.nijikokun.register.payment.forChestShop.Method;
import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin;
/**
* BOSEconomy 6 Implementation of Method
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class BOSE6 implements Method {
private BOSEconomy BOSEconomy;
@ -60,8 +67,8 @@ public class BOSE6 implements Method {
}
public static class BOSEAccount implements MethodAccount {
private String name;
private BOSEconomy BOSEconomy;
private final String name;
private final BOSEconomy BOSEconomy;
public BOSEAccount(String name, BOSEconomy bOSEconomy) {
this.name = name;
@ -122,8 +129,8 @@ public class BOSE6 implements Method {
}
public static class BOSEBankAccount implements MethodBankAccount {
private String bank;
private BOSEconomy BOSEconomy;
private final String bank;
private final BOSEconomy BOSEconomy;
public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) {
this.bank = bank;

View File

@ -5,9 +5,13 @@ import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin;
/**
* BOSEconomy 7 Implementation of Method
*
* @author Acrobot
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class BOSE7 implements Method {
private BOSEconomy BOSEconomy;
@ -64,8 +68,8 @@ public class BOSE7 implements Method {
}
public static class BOSEAccount implements MethodAccount {
private String name;
private BOSEconomy BOSEconomy;
private final String name;
private final BOSEconomy BOSEconomy;
public BOSEAccount(String name, BOSEconomy bOSEconomy) {
this.name = name;
@ -121,8 +125,8 @@ public class BOSE7 implements Method {
}
public static class BOSEBankAccount implements MethodBankAccount {
private String bank;
private BOSEconomy BOSEconomy;
private final String bank;
private final BOSEconomy BOSEconomy;
public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) {
this.bank = bank;

View File

@ -9,6 +9,16 @@ import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin;
/**
* Essentials 17 Implementation of Method
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @author Snowleo
* @author Acrobot
* @author KHobbits
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class EE17 implements Method {
private Essentials Essentials;
@ -65,7 +75,7 @@ public class EE17 implements Method {
}
public static class EEcoAccount implements MethodAccount {
private String name;
private final String name;
public EEcoAccount(String name) {
this.name = name;

View File

@ -0,0 +1,120 @@
package com.nijikokun.register.payment.forChestShop.methods;
import com.nijikokun.register.payment.forChestShop.Method;
import me.ashtheking.currency.Currency;
import me.ashtheking.currency.CurrencyList;
import org.bukkit.plugin.Plugin;
/**
* MultiCurrency Method implementation.
*
* @author Acrobot
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class MCUR implements Method {
private Currency currencyList;
public Object getPlugin() {
return this.currencyList;
}
public String getName() {
return "Currency";
}
public String getVersion() {
return "0.09";
}
public String format(double amount) {
return amount + " Currency";
}
public boolean hasBanks() {
return false;
}
public boolean hasBank(String bank) {
return false;
}
public boolean hasAccount(String name) {
return true;
}
public boolean hasBankAccount(String bank, String name) {
return false;
}
public MethodAccount getAccount(String name) {
return new MCurrencyAccount(name);
}
public MethodBankAccount getBankAccount(String bank, String name) {
return null;
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase(getName()) && plugin instanceof Currency;
}
public void setPlugin(Plugin plugin) {
currencyList = (Currency) plugin;
}
public static class MCurrencyAccount implements MethodAccount{
private final String name;
public MCurrencyAccount(String name) {
this.name = name;
}
public double balance() {
return CurrencyList.getValue((String) CurrencyList.maxCurrency(name)[0], name);
}
public boolean set(double amount) {
CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, amount);
return true;
}
public boolean add(double amount) {
return CurrencyList.add(name, amount);
}
public boolean subtract(double amount) {
return CurrencyList.subtract(name, amount);
}
public boolean multiply(double amount) {
return CurrencyList.multiply(name, amount);
}
public boolean divide(double amount) {
return CurrencyList.divide(name, amount);
}
public boolean hasEnough(double amount) {
return CurrencyList.hasEnough(name, amount);
}
public boolean hasOver(double amount) {
return CurrencyList.hasOver(name, amount);
}
public boolean hasUnder(double amount) {
return CurrencyList.hasUnder(name, amount);
}
public boolean isNegative() {
return CurrencyList.isNegative(name);
}
public boolean remove() {
return CurrencyList.remove(name);
}
}
}

View File

@ -7,6 +7,13 @@ import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin;
/**
* iConomy 4 Implementation of Method
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class iCo4 implements Method {
private iConomy iConomy;
@ -51,7 +58,7 @@ public class iCo4 implements Method {
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy;
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin.getDescription().getVersion().startsWith("4") && plugin instanceof iConomy;
}
public void setPlugin(Plugin plugin) {

View File

@ -10,6 +10,13 @@ import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin;
/**
* iConomy 5 Implementation of Method
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class iCo5 implements Method {
private iConomy iConomy;
@ -34,25 +41,25 @@ public class iCo5 implements Method {
}
public boolean hasBank(String bank) {
return (hasBanks()) && iConomy.Banks.exists(bank);
return (hasBanks()) && this.iConomy.Banks.exists(bank);
}
public boolean hasAccount(String name) {
return iConomy.hasAccount(name);
return this.iConomy.hasAccount(name);
}
public boolean hasBankAccount(String bank, String name) {
return (hasBank(bank)) && iConomy.getBank(bank).hasAccount(name);
return (hasBank(bank)) && this.iConomy.getBank(bank).hasAccount(name);
}
public MethodAccount getAccount(String name) {
return new iCoAccount(iConomy.getAccount(name));
return new iCoAccount(this.iConomy.getAccount(name));
}
public MethodBankAccount getBankAccount(String bank, String name) {
return new iCoBankAccount(iConomy.getBank(bank).getAccount(name));
return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name));
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy;
}
@ -208,4 +215,4 @@ public class iCo5 implements Method {
return true;
}
}
}
}

View File

@ -0,0 +1,142 @@
package com.nijikokun.register.payment.forChestShop.methods;
import com.iCo6.iConomy;
import com.iCo6.system.Account;
import com.iCo6.system.Accounts;
import com.iCo6.system.Holdings;
import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin;
/**
* iConomy 6 Implementation of Method
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class iCo6 implements Method {
private iConomy iConomy;
public iConomy getPlugin() {
return this.iConomy;
}
public String getName() {
return "iConomy";
}
public String getVersion() {
return "6";
}
public String format(double amount) {
return iConomy.format(amount);
}
public boolean hasBanks() {
return false;
}
public boolean hasBank(String bank) {
return false;
}
public boolean hasAccount(String name) {
return (new Accounts()).exists(name);
}
public boolean hasBankAccount(String bank, String name) {
return false;
}
public MethodAccount getAccount(String name) {
return new iCoAccount((new Accounts()).get(name));
}
public MethodBankAccount getBankAccount(String bank, String name) {
return null;
}
public boolean isCompatible(Plugin plugin) {
try { Class.forName("com.iCo6.IO.InventoryDB"); }
catch(Exception e) {return false;}
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iCo6.iConomy") && plugin instanceof iConomy;
}
public void setPlugin(Plugin plugin) {
iConomy = (iConomy)plugin;
}
public static class iCoAccount implements MethodAccount {
private final Account account;
private final Holdings holdings;
public iCoAccount(Account account) {
this.account = account;
this.holdings = account.getHoldings();
}
public Account getiCoAccount() {
return account;
}
public double balance() {
return this.holdings.getBalance();
}
public boolean set(double amount) {
if(this.holdings == null) return false;
this.holdings.setBalance(amount);
return true;
}
public boolean add(double amount) {
if(this.holdings == null) return false;
this.holdings.add(amount);
return true;
}
public boolean subtract(double amount) {
if(this.holdings == null) return false;
this.holdings.subtract(amount);
return true;
}
public boolean multiply(double amount) {
if(this.holdings == null) return false;
this.holdings.multiply(amount);
return true;
}
public boolean divide(double amount) {
if(this.holdings == null) return false;
this.holdings.divide(amount);
return true;
}
public boolean hasEnough(double amount) {
return this.holdings.hasEnough(amount);
}
public boolean hasOver(double amount) {
return this.holdings.hasOver(amount);
}
public boolean hasUnder(double amount) {
return this.holdings.hasUnder(amount);
}
public boolean isNegative() {
return this.holdings.isNegative();
}
public boolean remove() {
if(this.account == null) return false;
this.account.remove();
return true;
}
}
}

View File

@ -2,7 +2,7 @@ name: ChestShop
main: com.Acrobot.ChestShop.ChestShop
version: 3.00 BETA 11
version: 3.00
author: Acrobot
@ -13,13 +13,13 @@ commands:
aliases: [iinfo]
description: Lists item id and names
usage: |
/<command> (item name/item ID/alias)
() - optional
/<command> §2(what's the item in hand?)
/<command> §712§f §2(what's the item with ID §712§2?)
/<command> §7log§f §2(what's the item ID of §7LOG§2?)
csVersion:
aliases: [cv]
description: Shows the ChestShop's version
usage: |
/<command>
usage: /<command>
permissions:
ChestShop.*:
@ -37,8 +37,10 @@ permissions:
default: true
ChestShop.shop.create.(itemID):
description: Allows user to create a shop that sells item with itemID like in the permission node (replace (itemID) with NUMERICAL item ID)
ChestShop.shop.exclude.(itemID):
description: Denies creation of a shop that sells item with itemID like in the permission node (replace (itemID) with NUMERICAL item ID)
ChestShop.shop.buy.(itemID):
description: Allows user to buy certain (itemID) from a shop (replace (itemID) with NUMERICAL item ID)
ChestShop.shop.sell.(itemID):
description: Allows user to sell certain (itemID) from a shop (replace (itemID) with NUMERICAL item ID)
ChestShop.shop.create:
description: Allows user to create a shop that sells any item
ChestShop.shop.buy: