- Changed how configuration works, so it works with plugin folder in different place

- Added support for Deadbolt
- By default, left clicking your own sign doesn't do anything
- Restricted signs now check if you've got permission ChestShop.group.groupName
- Added support for stacking unstackable things
- Updated Register
- Changed how plugins are loaded.
This commit is contained in:
Acrobot 2011-09-06 19:01:57 +02:00
parent e47632793a
commit a84c68d49d
33 changed files with 513 additions and 442 deletions

View File

@ -3,6 +3,7 @@ package com.Acrobot.ChestShop;
import com.Acrobot.ChestShop.Commands.ItemInfo; import com.Acrobot.ChestShop.Commands.ItemInfo;
import com.Acrobot.ChestShop.Commands.Version; import com.Acrobot.ChestShop.Commands.Version;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.ConfigObject;
import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Config.Property;
import com.Acrobot.ChestShop.DB.Generator; import com.Acrobot.ChestShop.DB.Generator;
import com.Acrobot.ChestShop.DB.Queue; import com.Acrobot.ChestShop.DB.Queue;
@ -14,6 +15,7 @@ import com.avaje.ebean.EbeanServer;
import com.lennardf1989.bukkitex.Database; import com.lennardf1989.bukkitex.Database;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -30,57 +32,34 @@ import java.util.List;
*/ */
public class ChestShop extends JavaPlugin { public class ChestShop extends JavaPlugin {
public static final File folder = new File("plugins/ChestShop"); public static File folder = new File("plugins/ChestShop");
public static final String chatPrefix = "[ChestShop] "; public static final String chatPrefix = "[ChestShop] ";
private static EbeanServer DB; private static EbeanServer DB;
private static PluginDescriptionFile description; private static PluginDescriptionFile description;
private static Server server; private static Server server;
public static PluginManager pm;
public void onEnable() { public void onEnable() {
PluginManager pm = getServer().getPluginManager(); pm = getServer().getPluginManager();
folder = getDataFolder();
//Set up our config file! //Set up our config file!
Config.setUp(); Config.setup(new ConfigObject());
//Register our events //Register our events
blockBreak blockBreak = new blockBreak(); registerEvents();
description = this.getDescription(); //Description of the plugin description = this.getDescription(); //Description of the plugin
server = getServer(); //Setting out server variable server = getServer(); //Setting out server variable
pm.registerEvent(Event.Type.BLOCK_BREAK, blockBreak, Event.Priority.Normal, this); pluginEnable.initializePlugins();
pm.registerEvent(Event.Type.BLOCK_PLACE, new blockPlace(), Event.Priority.Normal, this);
pm.registerEvent(Event.Type.SIGN_CHANGE, new signChange(), Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, new playerInteract(), Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLUGIN_ENABLE, new pluginEnable(), Event.Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, new pluginDisable(), Event.Priority.Monitor, this);
if(Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)){
pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, blockBreak, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, blockBreak, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, new entityExplode(), Event.Priority.Normal, this);
}
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) { //Now set up our database for storing transactions!
setupDB();
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L);
if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) {
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L);
}
}
//Now set up our logging to file!
if (Config.getBoolean(Property.LOG_TO_FILE)) {
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new FileWriterQueue(), 201L, 201L);
}
//And now for the chest masking
if (Config.getBoolean(Property.MASK_CHESTS_AS_OTHER_BLOCKS)) {
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new MaskChest(), 40L, 40L);
}
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.LOG_TO_FILE)) scheduleTask(new FileWriterQueue(), 201L, 201L);
if (Config.getBoolean(Property.MASK_CHESTS_AS_OTHER_BLOCKS)) scheduleTask(new MaskChest(), 40L, 40L);
//Register our commands! //Register our commands!
getCommand("iteminfo").setExecutor(new ItemInfo()); getCommand("iteminfo").setExecutor(new ItemInfo());
@ -93,6 +72,33 @@ public class ChestShop extends JavaPlugin {
System.out.println('[' + getPluginName() + "] version " + getVersion() + " shutting down!"); System.out.println('[' + getPluginName() + "] version " + getVersion() + " shutting down!");
} }
////////////////// REGISTER EVENTS & SCHEDULER ///////////////////////////
private void registerEvents() {
blockBreak blockBreak = new blockBreak();
registerEvent(Event.Type.BLOCK_BREAK, blockBreak);
registerEvent(Event.Type.BLOCK_PLACE, new blockPlace());
registerEvent(Event.Type.SIGN_CHANGE, new signChange());
registerEvent(Event.Type.PLAYER_INTERACT, new playerInteract(), Event.Priority.Highest);
registerEvent(Event.Type.PLUGIN_ENABLE, new pluginEnable());
registerEvent(Event.Type.PLUGIN_DISABLE, new pluginDisable());
if (!Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) return;
registerEvent(Event.Type.BLOCK_PISTON_EXTEND, blockBreak);
registerEvent(Event.Type.BLOCK_PISTON_RETRACT, blockBreak);
registerEvent(Event.Type.ENTITY_EXPLODE, new entityExplode());
}
private void registerEvent(Event.Type type, Listener listener) {
registerEvent(type, listener, Event.Priority.Normal);
}
private void registerEvent(Event.Type type, Listener listener, Event.Priority priority) {
pm.registerEvent(type, listener, priority, this);
}
private void scheduleTask(Runnable runnable, long startTime, long repetetionTime) {
server.getScheduler().scheduleAsyncRepeatingTask(this, runnable, startTime, repetetionTime);
}
///////////////////// DATABASE STUFF //////////////////////////////// ///////////////////// DATABASE STUFF ////////////////////////////////
private static Configuration getBukkitConfig() { private static Configuration getBukkitConfig() {
Configuration config = new Configuration(new File("bukkit.yml")); Configuration config = new Configuration(new File("bukkit.yml"));
@ -124,6 +130,7 @@ public class ChestShop extends JavaPlugin {
); );
DB = database.getDatabase(); DB = database.getDatabase();
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L);
} }
@Override @Override
@ -147,4 +154,8 @@ public class ChestShop extends JavaPlugin {
public static EbeanServer getDB() { public static EbeanServer getDB() {
return DB; return DB;
} }
public static ArrayList getDependencies() {
return (ArrayList) description.getSoftDepend();
}
} }

View File

@ -1,59 +1,16 @@
package com.Acrobot.ChestShop.Config; package com.Acrobot.ChestShop.Config;
import com.Acrobot.ChestShop.ChestShop; import com.LRFLEW.register.payment.forChestShop.Methods;
import com.Acrobot.ChestShop.Utils.uLongName;
import org.bukkit.util.config.Configuration;
import java.io.File;
import java.io.FileWriter;
/** /**
* @author Acrobot * @author Acrobot
*/ */
public class Config { public class Config {
private static final File configFile = new File(ChestShop.folder, "config.yml"); private static ConfigObject config;
private static final File langFile = new File(ChestShop.folder, "local.yml");
private static final Configuration config = new Configuration(configFile);
private static final Configuration language = new Configuration(langFile);
public static void setUp() { public static void setup(ConfigObject cfg) {
if(!ChestShop.folder.exists()) ChestShop.folder.mkdir(); config = cfg;
Methods.preferred = Config.getString(Property.PREFERRED_ECONOMY_PLUGIN);
reloadConfig();
config.load();
reloadLanguage();
language.load();
uLongName.config.load();
}
private static void reloadConfig(){
config.load();
for (Property def : Property.values()) {
if (config.getProperty(def.name()) == null) {
writeToFile('\n' + def.name() + ": " + def.getValue() + "\n#" + def.getComment(), configFile);
}
}
}
private static void reloadLanguage(){
language.load();
for (Language def : Language.values()) {
if (language.getProperty(def.name()) == null) {
writeToFile('\n' + def.name() + ": \"" + def.toString() + '\"', langFile);
}
}
}
private static void writeToFile(String string, File file) {
try {
FileWriter fw = new FileWriter(file, true);
fw.write(string + '\n');
fw.close();
} catch (Exception e) {
System.out.println("Couldn't write to file - " + file.getName());
}
} }
public static boolean getBoolean(Property value) { public static boolean getBoolean(Property value) {
@ -73,7 +30,7 @@ public class Config {
} }
public static double getDouble(Property value) { public static double getDouble(Property value) {
return config.getDouble(value.name(), -1); return Double.parseDouble(getValue(value.name()).toString());
} }
private static String getColored(String msg) { private static String getColored(String msg) {
@ -81,16 +38,10 @@ public class Config {
} }
public static String getLocal(Language lang) { public static String getLocal(Language lang) {
return getColored(language.getString(Language.prefix.name()) + language.getString(lang.name())); return getColored(config.getLanguageConfig().getString(Language.prefix.name()) + config.getLanguageConfig().getString(lang.name()));
} }
private static Object getValue(String node) { private static Object getValue(String node) {
return config.getProperty(node); return config.getProperty(node);
} }
public static String getPreferred() {
config.load();
return getString(Property.PREFERRED_ECONOMY_PLUGIN);
}
} }

View File

@ -0,0 +1,67 @@
package com.Acrobot.ChestShop.Config;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Utils.uLongName;
import org.bukkit.util.config.Configuration;
import java.io.File;
import java.io.FileWriter;
/**
* @author Acrobot
*/
public class ConfigObject {
private final File configFile = new File(ChestShop.folder, "config.yml");
private final File langFile = new File(ChestShop.folder, "local.yml");
private final Configuration config = new Configuration(configFile);
private final Configuration language = new Configuration(langFile);
public ConfigObject() {
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();
}
private void reloadConfig() {
config.load();
for (Property def : Property.values()) {
if (config.getProperty(def.name()) == null) {
writeToFile('\n' + def.name() + ": " + def.getValue() + "\n#" + def.getComment(), configFile);
}
}
}
private void reloadLanguage() {
language.load();
for (Language def : Language.values()) {
if (language.getProperty(def.name()) == null) {
writeToFile('\n' + def.name() + ": \"" + def.toString() + '\"', langFile);
}
}
}
private static void writeToFile(String string, File file) {
try {
FileWriter fw = new FileWriter(file, true);
fw.write(string);
fw.close();
} catch (Exception e) {
System.out.println("Couldn't write to file - " + file.getName());
}
}
public Configuration getLanguageConfig() {
return language;
}
public Object getProperty(String property) {
return config.getProperty(property);
}
}

View File

@ -6,7 +6,8 @@ package com.Acrobot.ChestShop.Config;
public enum Property { public enum Property {
PREFERRED_ECONOMY_PLUGIN("", "Preferred economy plugin (iConomy, BOSEconomy, Essentials). If you do not want to specify this, leave it blank."), PREFERRED_ECONOMY_PLUGIN("", "Preferred economy plugin (iConomy, BOSEconomy, Essentials). If you do not want to specify this, leave it blank."),
REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."), REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."),
//ALLOW_LEFT_CLICK_DESTROYING(false, "If true, if you left-click your own shop sign you won't open chest's inventory, but instead you will start destroying the sign."), ALLOW_LEFT_CLICK_DESTROYING(true, "If true, if you left-click your own shop sign you won't open chest's inventory, but instead you will start destroying the sign."),
STACK_UNSTACKABLES(false, "If true, ALL things (including food, etc.) will stack up to 64"),
SERVER_ECONOMY_ACCOUNT("", "Economy account's name you want Admin Shops to be assigned to"), 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"), 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"), SHOP_CREATION_PRICE(0, "Amount of money player must pay to create a shop"),

View File

@ -1,7 +1,7 @@
package com.Acrobot.ChestShop; package com.Acrobot.ChestShop;
import com.Acrobot.ChestShop.Utils.uLongName; import com.Acrobot.ChestShop.Utils.uLongName;
import com.nijikokun.register.payment.forChestShop.Method; import com.LRFLEW.register.payment.forChestShop.Method;
/** /**
* @author Acrobot * @author Acrobot

View File

@ -57,9 +57,9 @@ public class playerInteract extends PlayerListener {
lastTransactionTime.put(player, System.currentTimeMillis()); lastTransactionTime.put(player, System.currentTimeMillis());
event.setCancelled(true); if (action == Action.RIGHT_CLICK_BLOCK) event.setCancelled(true);
if (uLongName.stripName(player.getName()).equals(sign.getLine(0))) { if (uLongName.stripName(player.getName()).equals(sign.getLine(0)) && (action != Action.LEFT_CLICK_BLOCK || !Config.getBoolean(Property.ALLOW_LEFT_CLICK_DESTROYING))) {
showChestGUI(player, block); showChestGUI(player, block);
return; return;
} }

View File

@ -1,6 +1,7 @@
package com.Acrobot.ChestShop.Listeners; package com.Acrobot.ChestShop.Listeners;
import com.Acrobot.ChestShop.Economy; import com.Acrobot.ChestShop.Economy;
import com.LRFLEW.register.payment.forChestShop.Methods;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.ServerListener; import org.bukkit.event.server.ServerListener;
@ -9,13 +10,9 @@ import org.bukkit.event.server.ServerListener;
*/ */
public class pluginDisable extends ServerListener { public class pluginDisable extends ServerListener {
public void onPluginDisable(PluginDisableEvent event) { public void onPluginDisable(PluginDisableEvent event) {
if (Economy.economy != null && pluginEnable.methods.hasMethod()) { if (Economy.economy != null && Methods.hasMethod() && Methods.checkDisabled(event.getPlugin())) {
boolean check = pluginEnable.methods.checkDisabled(event.getPlugin());
if (check) {
Economy.economy = null; Economy.economy = null;
System.out.println("[ChestShop] Economy plugin disabled!"); System.out.println("[ChestShop] Economy plugin disabled!");
} }
} }
} }
}

View File

@ -1,17 +1,17 @@
package com.Acrobot.ChestShop.Listeners; package com.Acrobot.ChestShop.Listeners;
import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Economy; import com.Acrobot.ChestShop.Economy;
import com.Acrobot.ChestShop.Items.Odd; import com.Acrobot.ChestShop.Items.Odd;
import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Protection.Plugins.DeadboltPlugin;
import com.Acrobot.ChestShop.Protection.Plugins.LWCplugin; import com.Acrobot.ChestShop.Protection.Plugins.LWCplugin;
import com.Acrobot.ChestShop.Protection.Plugins.LockettePlugin; import com.Acrobot.ChestShop.Protection.Plugins.LockettePlugin;
import com.Acrobot.ChestShop.Protection.Plugins.OldLockettePlugin;
import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Protection.Security;
import com.LRFLEW.register.payment.forChestShop.Methods;
import com.daemitus.deadbolt.Deadbolt;
import com.griefcraft.lwc.LWCPlugin; import com.griefcraft.lwc.LWCPlugin;
import com.nijikokun.bukkit.Permissions.Permissions; import com.nijikokun.bukkit.Permissions.Permissions;
import com.nijikokun.register.payment.forChestShop.Methods;
import info.somethingodd.bukkit.OddItem.OddItem; import info.somethingodd.bukkit.OddItem.OddItem;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener; import org.bukkit.event.server.ServerListener;
@ -19,47 +19,26 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.yi.acru.bukkit.Lockette.Lockette; import org.yi.acru.bukkit.Lockette.Lockette;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
/** /**
* @author Acrobot * @author Acrobot
*/ */
public class pluginEnable extends ServerListener { public class pluginEnable extends ServerListener {
public static final Methods methods = new Methods(Config.getPreferred());
private static final List<String> pluginsToLoad = new LinkedList<String>(Arrays.asList(
"Permissions",
"LWC",
"Lockette",
"OddItem"
));
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
LinkedList<String> toRemove = new LinkedList(); if (!Methods.hasMethod() && Methods.setMethod(ChestShop.pm)) {
Economy.economy = Methods.getMethod();
//Economy plugins
if (!methods.hasMethod()) {
if (methods.setMethod(event.getPlugin())) {
Economy.economy = methods.getMethod();
System.out.println(ChestShop.chatPrefix + Economy.economy.getName() + ' ' + Economy.economy.getVersion() + " loaded."); System.out.println(ChestShop.chatPrefix + Economy.economy.getName() + ' ' + Economy.economy.getVersion() + " loaded.");
} }
} }
for (String pluginName : pluginsToLoad) { public static void initializePlugins() {
Plugin plugin = ChestShop.getBukkitServer().getPluginManager().getPlugin(pluginName); for (Object plugin : ChestShop.getDependencies()) {
if (plugin == null) continue; Plugin pl = ChestShop.pm.getPlugin((String) plugin);
initializePlugin(pluginName, plugin); if (pl != null) initializePlugin((String) plugin, pl);
toRemove.add(pluginName);
} }
for (String pluginName : toRemove) pluginsToLoad.remove(pluginName);
} }
private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :) 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 (name.equals("Permissions")) {
if (Permission.permissions != null) return; if (Permission.permissions != null) return;
Permission.permissions = ((Permissions) plugin).getHandler(); Permission.permissions = ((Permissions) plugin).getHandler();
@ -68,18 +47,18 @@ public class pluginEnable extends ServerListener {
LWCplugin.setLWC(((LWCPlugin) plugin).getLWC()); LWCplugin.setLWC(((LWCPlugin) plugin).getLWC());
Security.protection = new LWCplugin(); Security.protection = new LWCplugin();
} else if (name.equals("Lockette")) { } else if (name.equals("Lockette")) {
if (OldLockettePlugin.lockette != null || LockettePlugin.lockette != null) return; if (LockettePlugin.lockette != null) return;
if (plugin.getClass().getName().equals("com.daemitus.lockette.Lockette")) { LockettePlugin.lockette = (Lockette) plugin;
LockettePlugin.lockette = (com.daemitus.lockette.Lockette) plugin;
Security.protection = new LockettePlugin(); Security.protection = new LockettePlugin();
} else { } else if (name.equals("Deadbolt")) {
OldLockettePlugin.lockette = (Lockette) plugin; if (DeadboltPlugin.deadbolt != null) return;
Security.protection = new OldLockettePlugin(); DeadboltPlugin.deadbolt = (Deadbolt) plugin;
} Security.protection = new DeadboltPlugin();
} else if (name.equals("OddItem")) { } else if (name.equals("OddItem")) {
if (Odd.oddItem != null) return; if (Odd.oddItem != null) return;
Odd.oddItem = (OddItem) plugin; Odd.oddItem = (OddItem) plugin;
} }
PluginDescriptionFile description = plugin.getDescription();
System.out.println(ChestShop.chatPrefix + description.getName() + " version " + description.getVersion() + " loaded."); System.out.println(ChestShop.chatPrefix + description.getName() + " version " + description.getVersion() + " loaded.");
} }
} }

View File

@ -1,23 +1,23 @@
package com.Acrobot.ChestShop.Protection.Plugins; package com.Acrobot.ChestShop.Protection.Plugins;
import com.Acrobot.ChestShop.Protection.Protection; import com.Acrobot.ChestShop.Protection.Protection;
import com.daemitus.deadbolt.Deadbolt;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.yi.acru.bukkit.Lockette.Lockette;
/** /**
* @author Acrobot * @author Acrobot
*/ */
public class OldLockettePlugin implements Protection { public class DeadboltPlugin implements Protection {
public static Lockette lockette; public static Deadbolt deadbolt;
public boolean isProtected(Block block) { public boolean isProtected(Block block) {
return Lockette.isProtected(block); return Deadbolt.isProtected(block);
} }
public boolean canAccess(Player player, Block block) { public boolean canAccess(Player player, Block block) {
int length = (player.getName().length() > 15 ? 15 : player.getName().length()); int length = (player.getName().length() > 15 ? 15 : player.getName().length());
return player.getName().substring(0, length).equals(Lockette.getProtectedOwner(block)); return Deadbolt.getAllNames(block).contains(player.getName().substring(0, length));
} }
public boolean protect(String name, Block block) { public boolean protect(String name, Block block) {

View File

@ -5,7 +5,6 @@ import com.Acrobot.ChestShop.Protection.Protection;
import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWC;
import com.griefcraft.model.ProtectionTypes; import com.griefcraft.model.ProtectionTypes;
import com.griefcraft.modules.limits.LimitsModule; import com.griefcraft.modules.limits.LimitsModule;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,9 +1,9 @@
package com.Acrobot.ChestShop.Protection.Plugins; package com.Acrobot.ChestShop.Protection.Plugins;
import com.Acrobot.ChestShop.Protection.Protection; import com.Acrobot.ChestShop.Protection.Protection;
import com.daemitus.lockette.Lockette;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.yi.acru.bukkit.Lockette.Lockette;
/** /**
* @author Acrobot * @author Acrobot
@ -17,7 +17,7 @@ public class LockettePlugin implements Protection {
public boolean canAccess(Player player, Block block) { public boolean canAccess(Player player, Block block) {
int length = (player.getName().length() > 15 ? 15 : player.getName().length()); int length = (player.getName().length() > 15 ? 15 : player.getName().length());
return player.getName().substring(0, length).equals(Lockette.getOwnerName(block)); return player.getName().substring(0, length).equals(Lockette.getProtectedOwner(block));
} }
public boolean protect(String name, Block block) { public boolean protect(String name, Block block) {

View File

@ -34,7 +34,8 @@ public class restrictedSign {
sign = (Sign) blockUp.getState(); sign = (Sign) blockUp.getState();
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
if(Permission.permissions.inGroup(world, playerName, sign.getLine(i))) return true; if (Permission.permissions != null && Permission.permissions.inGroup(world, playerName, sign.getLine(i))) return true;
if (player.hasPermission("ChestShop.group." + sign.getLine(i))) return true;
} }
return false; return false;
} }

View File

@ -1,5 +1,7 @@
package com.Acrobot.ChestShop.Utils; package com.Acrobot.ChestShop.Utils;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -45,13 +47,29 @@ public class uInventory {
public static int add(Inventory inv, ItemStack item, int amount) { public static int add(Inventory inv, ItemStack item, int amount) {
amount = (amount > 0 ? amount : 1); amount = (amount > 0 ? amount : 1);
if (Config.getBoolean(Property.STACK_UNSTACKABLES)) return addAndStackTo64(inv, item, amount);
ItemStack itemToAdd = new ItemStack(item.getType(), amount, item.getDurability()); HashMap<Integer, ItemStack> items = inv.addItem(new ItemStack(item.getType(), amount, item.getDurability()));
HashMap<Integer, ItemStack> items = inv.addItem(itemToAdd);
amount = 0; amount = 0;
for(ItemStack toAdd : items.values()){ for (ItemStack toAdd : items.values()) amount += toAdd.getAmount();
amount += toAdd.getAmount();
return amount;
}
public static int addAndStackTo64(Inventory inv, ItemStack item, int amount) {
Material type = item.getType();
for (int slot = 0; slot < inv.getSize(); slot++) {
if (amount <= 0) return 0;
ItemStack curItem = inv.getItem(slot);
if (curItem == null || curItem.getType() == Material.AIR) {
item.setAmount((amount > 64 ? 64 : amount));
amount -= item.getAmount();
inv.setItem(slot, item);
} else if (curItem.getType() == type && curItem.getDurability() == item.getDurability() && curItem.getAmount() != 64) {
int toFill = (64 - curItem.getAmount());
item.setAmount((amount > toFill ? 64 : curItem.getAmount() + amount));
amount -= item.getAmount();
inv.setItem(slot, item);
}
} }
return amount; return amount;
} }
@ -68,7 +86,7 @@ public class uInventory {
public static int fits(Inventory inv, ItemStack item, int amount, short durability) { public static int fits(Inventory inv, ItemStack item, int amount, short durability) {
Material itemMaterial = item.getType(); Material itemMaterial = item.getType();
int maxStackSize = itemMaterial.getMaxStackSize(); int maxStackSize = (Config.getBoolean(Property.STACK_UNSTACKABLES) ? 64 : itemMaterial.getMaxStackSize());
int amountLeft = amount; int amountLeft = amount;
for (ItemStack currentItem : inv.getContents()) { for (ItemStack currentItem : inv.getContents()) {

View File

@ -9,7 +9,7 @@ import java.io.File;
* @author Acrobot * @author Acrobot
*/ */
public class uLongName { public class uLongName {
public static final Configuration config = new Configuration(new File(ChestShop.folder, "longName.storage")); 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); return config.getString(shortName, shortName);

View File

@ -1,4 +1,4 @@
package com.nijikokun.register.payment.forChestShop; package com.LRFLEW.register.payment.forChestShop;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -39,6 +39,13 @@ public interface Method {
*/ */
public String getVersion(); public String getVersion();
/**
* Returns the amount of decimal places that get stored
* NOTE: it will return -1 if there is no rounding
*
* @return <code>int</code> for each decimal place
*/
public int fractionalDigits();
/** /**
* Formats amounts into this payment methods style of currency display. * Formats amounts into this payment methods style of currency display.

View File

@ -0,0 +1,205 @@
package com.LRFLEW.register.payment.forChestShop;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import java.util.HashSet;
import java.util.Set;
/**
* The <code>Methods</code> initializes Methods that utilize the Method interface
* based on a "first come, first served" basis.
* <p/>
* Allowing you to check whether a payment method exists or not.
* <p/>
* Methods also allows you to set a preferred method of payment before it captures
* payment plugins in the initialization process.
* <p/>
* in server.properties:
* <blockquote><pre>
* economy=iConomy
* </pre></blockquote>
*
* @author: Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright: Copyright (C) 2011
* @license: AOL license <http://aol.nexua.org>
*/
public class Methods {
private static String version = null;
private static boolean self = false;
private static Method Method = null;
public static String preferred = "";
private static Set<Method> Methods = new HashSet<Method>();
private static Set<String> Dependencies = new HashSet<String>();
private static Set<Method> Attachables = new HashSet<Method>();
static { _init(); }
/**
* Implement all methods along with their respective name & class.
*/
private static void _init() {
addMethod("iConomy", new com.LRFLEW.register.payment.forChestShop.methods.iCo6());
addMethod("iConomy", new com.LRFLEW.register.payment.forChestShop.methods.iCo5());
addMethod("iConomy", new com.LRFLEW.register.payment.forChestShop.methods.iCo4());
addMethod("BOSEconomy", new com.LRFLEW.register.payment.forChestShop.methods.BOSE6());
addMethod("BOSEconomy", new com.LRFLEW.register.payment.forChestShop.methods.BOSE7());
addMethod("Essentials", new com.LRFLEW.register.payment.forChestShop.methods.EE17());
addMethod("Currency", new com.LRFLEW.register.payment.forChestShop.methods.MCUR());
Dependencies.add("MultiCurrency");
}
/**
* Used by the plugin to setup version
*
* @param v version
*/
public static void setVersion(String v) {
version = v;
}
/**
* Use to reset methods during disable
*/
public static void reset() {
version = null;
self = false;
Method = null;
preferred = "";
Attachables.clear();
}
/**
* Use to get version of Register plugin
*
* @return version
*/
public static String getVersion() {
return version;
}
/**
* 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.
*/
public static Set<String> getDependencies() {
return Dependencies;
}
/**
* 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 static Method createMethod(Plugin plugin) {
for (Method method : Methods) {
if (method.isCompatible(plugin)) {
method.setPlugin(plugin);
return method;
}
}
return null;
}
private static void addMethod(String name, Method method) {
Dependencies.add(name);
Methods.add(method);
}
/**
* Verifies if Register has set a payment method for usage yet.
*
* @return <code>boolean</code>
* @see #checkDisabled(org.bukkit.plugin.Plugin)
*/
public static boolean hasMethod() {
return (Method != null);
}
/**
* Checks Plugin Class against a multitude of checks to verify it's usability
* as a payment method.
*
* @return <code>boolean</code> True on success, False on failure.
*/
public static boolean setMethod(PluginManager manager) {
if (hasMethod()) return true;
if (self) { self = false; return false; }
int count = 0;
boolean match = false;
Plugin plugin;
for (String name : Dependencies) {
if (hasMethod()) break;
plugin = manager.getPlugin(name);
if (plugin == null) continue;
Method current = createMethod(plugin);
if (current == null) continue;
if (preferred.isEmpty())
Method = current;
else {
Attachables.add(current);
}
}
if (!preferred.isEmpty()) {
do {
if (hasMethod()) {
match = true;
} else {
for (Method attached : Attachables) {
if (attached == null) continue;
if (hasMethod()) {
match = true;
break;
}
if (preferred.isEmpty()) Method = attached;
if (count == 0) {
if (preferred.equalsIgnoreCase(attached.getName()))
Method = attached;
} else {
Method = attached;
}
}
count++;
}
} while (!match);
}
return hasMethod();
}
/**
* Grab the existing and initialized (hopefully) Method Class.
*
* @return <code>Method</code> <em>or</em> <code>Null</code>
*/
public static 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 static boolean checkDisabled(Plugin method) {
if (!hasMethod()) return true;
if (Method.isCompatible(method)) Method = null;
return (Method == null);
}
}

View File

@ -1,6 +1,7 @@
package com.nijikokun.register.payment.forChestShop.methods; package com.LRFLEW.register.payment.forChestShop.methods;
import com.LRFLEW.register.payment.forChestShop.Method;
import com.nijikokun.register.payment.forChestShop.Method;
import cosine.boseconomy.BOSEconomy; import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -11,7 +12,7 @@ import org.bukkit.plugin.Plugin;
* @copyright (c) 2011 * @copyright (c) 2011
* @license AOL license <http://aol.nexua.org> * @license AOL license <http://aol.nexua.org>
*/ */
@SuppressWarnings({"deprecation"}) @SuppressWarnings("deprecation")
public class BOSE6 implements Method { public class BOSE6 implements Method {
private BOSEconomy BOSEconomy; private BOSEconomy BOSEconomy;
@ -27,6 +28,10 @@ public class BOSE6 implements Method {
return "0.6.2"; return "0.6.2";
} }
public int fractionalDigits() {
return 0;
}
public String format(double amount) { public String format(double amount) {
String currency = this.BOSEconomy.getMoneyNamePlural(); String currency = this.BOSEconomy.getMoneyNamePlural();
if(amount == 1) currency = this.BOSEconomy.getMoneyName(); if(amount == 1) currency = this.BOSEconomy.getMoneyName();

View File

@ -1,6 +1,7 @@
package com.nijikokun.register.payment.forChestShop.methods; package com.LRFLEW.register.payment.forChestShop.methods;
import com.LRFLEW.register.payment.forChestShop.Method;
import com.nijikokun.register.payment.forChestShop.Method;
import cosine.boseconomy.BOSEconomy; import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -27,6 +28,10 @@ public class BOSE7 implements Method {
return "0.7.0"; return "0.7.0";
} }
public int fractionalDigits() {
return this.BOSEconomy.getFractionalDigits();
}
public String format(double amount) { public String format(double amount) {
String currency = this.BOSEconomy.getMoneyNamePlural(); String currency = this.BOSEconomy.getMoneyNamePlural();
if(amount == 1) currency = this.BOSEconomy.getMoneyName(); if(amount == 1) currency = this.BOSEconomy.getMoneyName();
@ -68,8 +73,8 @@ public class BOSE7 implements Method {
} }
public static class BOSEAccount implements MethodAccount { public static class BOSEAccount implements MethodAccount {
private final String name; private String name;
private final BOSEconomy BOSEconomy; private BOSEconomy BOSEconomy;
public BOSEAccount(String name, BOSEconomy bOSEconomy) { public BOSEAccount(String name, BOSEconomy bOSEconomy) {
this.name = name; this.name = name;
@ -125,8 +130,8 @@ public class BOSE7 implements Method {
} }
public static class BOSEBankAccount implements MethodBankAccount { public static class BOSEBankAccount implements MethodBankAccount {
private final String bank; private String bank;
private final BOSEconomy BOSEconomy; private BOSEconomy BOSEconomy;
public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) {
this.bank = bank; this.bank = bank;

View File

@ -1,11 +1,11 @@
package com.nijikokun.register.payment.forChestShop.methods; package com.LRFLEW.register.payment.forChestShop.methods;
import com.LRFLEW.register.payment.forChestShop.Method;
import com.earth2me.essentials.Essentials; import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.api.Economy; import com.earth2me.essentials.api.Economy;
import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.NoLoanPermittedException;
import com.earth2me.essentials.api.UserDoesNotExistException; import com.earth2me.essentials.api.UserDoesNotExistException;
import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -34,6 +34,10 @@ public class EE17 implements Method {
return "2.2"; return "2.2";
} }
public int fractionalDigits() {
return -1;
}
public String format(double amount) { public String format(double amount) {
return Economy.format(amount); return Economy.format(amount);
} }
@ -75,7 +79,7 @@ public class EE17 implements Method {
} }
public static class EEcoAccount implements MethodAccount { public static class EEcoAccount implements MethodAccount {
private final String name; private String name;
public EEcoAccount(String name) { public EEcoAccount(String name) {
this.name = name; this.name = name;

View File

@ -1,6 +1,6 @@
package com.nijikokun.register.payment.forChestShop.methods; package com.LRFLEW.register.payment.forChestShop.methods;
import com.nijikokun.register.payment.forChestShop.Method; import com.LRFLEW.register.payment.forChestShop.Method;
import me.ashtheking.currency.Currency; import me.ashtheking.currency.Currency;
import me.ashtheking.currency.CurrencyList; import me.ashtheking.currency.CurrencyList;
@ -22,13 +22,17 @@ public class MCUR implements Method {
} }
public String getName() { public String getName() {
return "Currency"; return "MultiCurrency";
} }
public String getVersion() { public String getVersion() {
return "0.09"; return "0.09";
} }
public int fractionalDigits() {
return -1;
}
public String format(double amount) { public String format(double amount) {
return amount + " Currency"; return amount + " Currency";
} }
@ -58,7 +62,9 @@ public class MCUR implements Method {
} }
public boolean isCompatible(Plugin plugin) { public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase(getName()) && plugin instanceof Currency; return (plugin.getDescription().getName().equalsIgnoreCase("Currency")
|| plugin.getDescription().getName().equalsIgnoreCase("MultiCurrency"))
&& plugin instanceof Currency;
} }
public void setPlugin(Plugin plugin) { public void setPlugin(Plugin plugin) {
@ -66,7 +72,7 @@ public class MCUR implements Method {
} }
public static class MCurrencyAccount implements MethodAccount{ public static class MCurrencyAccount implements MethodAccount{
private final String name; private String name;
public MCurrencyAccount(String name) { public MCurrencyAccount(String name) {
this.name = name; this.name = name;

View File

@ -1,9 +1,9 @@
package com.nijikokun.register.payment.forChestShop.methods; package com.LRFLEW.register.payment.forChestShop.methods;
import com.LRFLEW.register.payment.forChestShop.Method;
import com.nijiko.coelho.iConomy.iConomy; import com.nijiko.coelho.iConomy.iConomy;
import com.nijiko.coelho.iConomy.system.Account; import com.nijiko.coelho.iConomy.system.Account;
import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -29,8 +29,12 @@ public class iCo4 implements Method {
return "4"; return "4";
} }
public int fractionalDigits() {
return 2;
}
public String format(double amount) { public String format(double amount) {
return iConomy.getBank().format(amount); return com.nijiko.coelho.iConomy.iConomy.getBank().format(amount);
} }
public boolean hasBanks() { public boolean hasBanks() {
@ -42,7 +46,7 @@ public class iCo4 implements Method {
} }
public boolean hasAccount(String name) { public boolean hasAccount(String name) {
return iConomy.getBank().hasAccount(name); return com.nijiko.coelho.iConomy.iConomy.getBank().hasAccount(name);
} }
public boolean hasBankAccount(String bank, String name) { public boolean hasBankAccount(String bank, String name) {
@ -50,7 +54,7 @@ public class iCo4 implements Method {
} }
public MethodAccount getAccount(String name) { public MethodAccount getAccount(String name) {
return new iCoAccount(iConomy.getBank().getAccount(name)); return new iCoAccount(com.nijiko.coelho.iConomy.iConomy.getBank().getAccount(name));
} }
public MethodBankAccount getBankAccount(String bank, String name) { public MethodBankAccount getBankAccount(String bank, String name) {
@ -58,7 +62,9 @@ public class iCo4 implements Method {
} }
public boolean isCompatible(Plugin plugin) { public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin.getDescription().getVersion().length() > 0 && plugin.getDescription().getVersion().charAt(0) == '4' && plugin instanceof iConomy; return plugin.getDescription().getName().equalsIgnoreCase("iconomy")
&& plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy")
&& plugin instanceof iConomy;
} }
public void setPlugin(Plugin plugin) { public void setPlugin(Plugin plugin) {

View File

@ -1,12 +1,12 @@
package com.nijikokun.register.payment.forChestShop.methods; package com.LRFLEW.register.payment.forChestShop.methods;
import com.LRFLEW.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;
@ -32,8 +32,12 @@ public class iCo5 implements Method {
return "5"; return "5";
} }
public int fractionalDigits() {
return 2;
}
public String format(double amount) { public String format(double amount) {
return iConomy.format(amount); return com.iConomy.iConomy.format(amount);
} }
public boolean hasBanks() { public boolean hasBanks() {
@ -41,27 +45,29 @@ public class iCo5 implements Method {
} }
public boolean hasBank(String bank) { public boolean hasBank(String bank) {
return (hasBanks()) && this.iConomy.Banks.exists(bank); return (hasBanks()) && com.iConomy.iConomy.Banks.exists(bank);
} }
public boolean hasAccount(String name) { public boolean hasAccount(String name) {
return this.iConomy.hasAccount(name); return com.iConomy.iConomy.hasAccount(name);
} }
public boolean hasBankAccount(String bank, String name) { public boolean hasBankAccount(String bank, String name) {
return (hasBank(bank)) && this.iConomy.getBank(bank).hasAccount(name); return (hasBank(bank)) && com.iConomy.iConomy.getBank(bank).hasAccount(name);
} }
public MethodAccount getAccount(String name) { public MethodAccount getAccount(String name) {
return new iCoAccount(this.iConomy.getAccount(name)); return new iCoAccount(com.iConomy.iConomy.getAccount(name));
} }
public MethodBankAccount getBankAccount(String bank, String name) { public MethodBankAccount getBankAccount(String bank, String name) {
return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name)); return new iCoBankAccount(com.iConomy.iConomy.getBank(bank).getAccount(name));
} }
public boolean isCompatible(Plugin plugin) { 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 instanceof iConomy;
} }
public void setPlugin(Plugin plugin) { public void setPlugin(Plugin plugin) {

View File

@ -1,11 +1,11 @@
package com.nijikokun.register.payment.forChestShop.methods; package com.LRFLEW.register.payment.forChestShop.methods;
import com.LRFLEW.register.payment.forChestShop.Method;
import com.iCo6.iConomy; import com.iCo6.iConomy;
import com.iCo6.system.Account; import com.iCo6.system.Account;
import com.iCo6.system.Accounts; import com.iCo6.system.Accounts;
import com.iCo6.system.Holdings; import com.iCo6.system.Holdings;
import com.nijikokun.register.payment.forChestShop.Method;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -31,8 +31,12 @@ public class iCo6 implements Method {
return "6"; return "6";
} }
public int fractionalDigits() {
return 2;
}
public String format(double amount) { public String format(double amount) {
return iConomy.format(amount); return com.iCo6.iConomy.format(amount);
} }
public boolean hasBanks() { public boolean hasBanks() {
@ -60,10 +64,9 @@ public class iCo6 implements Method {
} }
public boolean isCompatible(Plugin plugin) { public boolean isCompatible(Plugin plugin) {
try { Class.forName("com.iCo6.IO.InventoryDB"); } return plugin.getDescription().getName().equalsIgnoreCase("iconomy")
catch(Exception e) {return false;} && plugin.getClass().getName().equals("com.iCo6.iConomy")
&& plugin instanceof iConomy;
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iCo6.iConomy") && plugin instanceof iConomy;
} }
public void setPlugin(Plugin plugin) { public void setPlugin(Plugin plugin) {
@ -71,8 +74,8 @@ public class iCo6 implements Method {
} }
public static class iCoAccount implements MethodAccount { public static class iCoAccount implements MethodAccount {
private final Account account; private Account account;
private final Holdings holdings; private Holdings holdings;
public iCoAccount(Account account) { public iCoAccount(Account account) {
this.account = account; this.account = account;

View File

@ -1,203 +0,0 @@
package com.nijikokun.register.payment.forChestShop;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import java.util.HashSet;
import java.util.Set;
/**
* The <code>Methods</code> initializes Methods that utilize the Method interface
* based on a "first come, first served" basis.
*
* 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: AOL license <http://aol.nexua.org>
*/
public class Methods {
private boolean self = false;
private Method Method = null;
private String preferred = "";
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();
}
/**
* Initializes <code>Methods</code> class utilizing a "preferred" payment method check before
* returning the first method that was initialized.
*
* @param preferred Payment method that is most preferred for this setup.
*/
public Methods(String preferred) {
this._init();
if(this.Dependencies.contains(preferred)) {
this.preferred = preferred;
}
}
/**
* 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.iCo6());
this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo5());
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;
}
/**
* 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);
return method;
}
}
return null;
}
private void addMethod(String name, Method method) {
Dependencies.add(name);
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; }
int count = 0;
boolean match = false;
Plugin plugin;
PluginManager manager = method.getServer().getPluginManager();
for(String name: this.Dependencies) {
if(hasMethod()) break;
if(method.getDescription().getName().equals(name)) plugin = method; else plugin = manager.getPlugin(name);
if(plugin == null) continue;
Method current = this.createMethod(plugin);
if(current == null) continue;
if(this.preferred.isEmpty())
this.Method = current;
else {
this.Attachables.add(current);
}
}
if(!this.preferred.isEmpty()) {
do {
if(hasMethod()) {
match = true;
} else {
for(Method attached: this.Attachables) {
if(attached == null) continue;
if(hasMethod()) {
match = true;
break;
}
if(this.preferred.isEmpty()) this.Method = attached;
if(count == 0) {
if(this.preferred.equalsIgnoreCase(attached.getName()))
this.Method = attached;
} else {
this.Method = attached;
}
}
count++;
}
} while(!match);
}
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;
return (Method == null);
}
}

View File

@ -2,12 +2,15 @@ name: ChestShop
main: com.Acrobot.ChestShop.ChestShop main: com.Acrobot.ChestShop.ChestShop
version: 3.04 version: 3.1
author: Acrobot author: Acrobot
description: > description: >
A chest shop for economy plugins. A chest shop for economy plugins.
softdepend: [Permissions, LWC, Lockette, Deadbolt, OddItem]
commands: commands:
iteminfo: iteminfo:
aliases: [iinfo] aliases: [iinfo]