iConomyChestShop 3, not finished nor working version, for halvors

This commit is contained in:
Acrobot 2011-05-15 18:16:25 +02:00
commit 5e783fe430
33 changed files with 1796 additions and 0 deletions

5
README Normal file
View File

@ -0,0 +1,5 @@
iConomyChestShop
Shop plugin for Bukkit
http://forums.bukkit.org/threads/econ-iconomychestshop-2-3-chest-shop-for-iconomy-677.4150/

View File

@ -0,0 +1,22 @@
package com.Acrobot.iConomyChestShop.Chests;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
*/
public interface ChestObject {
public ItemStack[] getContents();
public void setSlot(int slot, ItemStack item);
public void clearSlot(int slot);
public void addItem(ItemStack item, short durability, int amount);
public void removeItem(ItemStack item, short durability, int amount);
public int amount(ItemStack item, short durability);
public boolean hasEnough(ItemStack item, int amount, short durability);
public boolean fits(ItemStack item, int amount, short durability);
public int getSize();
}

View File

@ -0,0 +1,221 @@
package com.Acrobot.iConomyChestShop.Chests;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
*/
public class MinecraftChest implements ChestObject{
Chest main;
Chest neighbor;
public MinecraftChest(Chest chest){
this.main = chest;
this.neighbor = getNeighbor();
}
public ItemStack[] getContents() {
ItemStack[] contents = new ItemStack[(neighbor != null ? 54 : 27)];
ItemStack[] chest1 = main.getInventory().getContents();
System.arraycopy(chest1, 0, contents, 0, chest1.length);
if(neighbor != null){
ItemStack[] chest2 = neighbor.getInventory().getContents();
System.arraycopy(chest2, 0, contents, chest1.length, chest2.length);
}
return contents;
}
public void setSlot(int slot, ItemStack item) {
if(slot < main.getInventory().getSize()){
main.getInventory().setItem(slot, item);
} else{
neighbor.getInventory().setItem(slot - main.getInventory().getSize(), item);
}
}
public void clearSlot(int slot) {
if(slot < main.getInventory().getSize()){
main.getInventory().setItem(slot, null);
} else{
neighbor.getInventory().setItem(slot - main.getInventory().getSize(), null);
}
}
public void addItem(ItemStack item, short durability, int amount) {
int left = addItem(item, durability, amount, main);
if(neighbor != null){
addItem(item, durability, left, neighbor);
}
}
public void removeItem(ItemStack item, short durability, int amount) {
int left = removeItem(item, durability, amount, main);
if(neighbor != null){
removeItem(item, durability, left, neighbor);
}
}
public int amount(ItemStack item, short durability) {
return amount(item, durability, main) + (neighbor != null ? amount(item, durability, neighbor) : 0);
}
public boolean hasEnough(ItemStack item, int amount, short durability) {
return amount(item, durability) >= amount;
}
public boolean fits(ItemStack item, int amount, short durability) {
return fits(item, amount, durability, main) && (neighbor == null || fits(item, amount, durability, neighbor));
}
public int getSize() {
return main.getInventory().getSize() + (neighbor != null ? neighbor.getInventory().getSize() : 0);
}
private Chest getNeighbor(){
BlockFace[] bf = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
Block chestBlock = main.getBlock();
for(BlockFace blockFace : bf){
Block neighborBlock = chestBlock.getFace(blockFace);
if(neighborBlock.getType() == Material.CHEST){
return (Chest) neighborBlock.getState();
}
}
return null; //Shame, we didn't find double chest :/
}
private int amount(ItemStack item, short durability, Chest chest){
ItemStack[] contents = chest.getInventory().getContents();
int amount = 0;
for(ItemStack i : contents){
if(i != null){
if(i.getType() == item.getType() && (durability == -1 || i.getDurability() == durability || (durability == 0 && i.getDurability() == -1))){
amount += i.getAmount();
}
}
}
return amount;
}
private boolean fits(ItemStack item, int amount, short durability, Chest chest){
Inventory inv = chest.getInventory();
Material itemMaterial = item.getType();
int maxStackSize = item.getMaxStackSize();
int amountLeft = amount;
for(int slot = 0; slot < inv.getSize(); slot++){
if(amountLeft <= 0){
return true;
}
ItemStack currentItem = inv.getItem(slot);
if(currentItem == null || currentItem.getType() == Material.AIR){
amountLeft -= maxStackSize;
continue;
}
if(currentItem.getType() == itemMaterial && (currentItem.getDurability() == durability)){
int currentAmount = currentItem.getAmount();
if(amountLeft == currentAmount){
amountLeft = 0;
} else if(amountLeft < currentAmount){
amountLeft = 0;
} else{
amountLeft -= currentAmount;
}
}
}
return amountLeft <= 0;
}
private int addItem(ItemStack item, short durability, int amount, Chest chest){
Inventory inv = chest.getInventory();
ItemStack[] contents = inv.getContents();
Material itemMaterial = item.getType();
int amountLeft = amount;
int maxStackSize = item.getMaxStackSize();
ItemStack baseItem = item.clone();
for(int slot = 0; slot < inv.getSize(); slot++){
ItemStack itemStack = contents[slot];
if(amountLeft <= 0){
return 0;
}
if(itemStack != null && itemStack.getType() != Material.AIR){ //Our slot is not free
int currentAmount = itemStack.getAmount();
Material currentMaterial = itemStack.getType();
short currentDurability = itemStack.getDurability();
if(currentMaterial == itemMaterial && (currentDurability == durability)){
if((currentAmount + amountLeft) <= maxStackSize){
baseItem.setAmount(currentAmount + amountLeft);
amountLeft = 0;
} else{
baseItem.setAmount(maxStackSize);
amountLeft -= (maxStackSize - currentAmount);
}
inv.setItem(slot, baseItem);
}
}else{ //Free slot
if(amountLeft <= maxStackSize){ //There is less to add than whole stack
baseItem.setAmount(amountLeft);
inv.setItem(slot, baseItem);
amountLeft = 0;
} else{ //We add whole stack
baseItem.setAmount(maxStackSize);
inv.setItem(slot, baseItem);
amountLeft -= maxStackSize;
}
}
}
return amountLeft;
}
private int removeItem(ItemStack item, short durability, int amount, Chest chest){
Inventory inv = chest.getInventory();
Material itemMaterial = item.getType();
int amountLeft = amount;
for(int slot = 0; slot < inv.getSize(); slot++){
if(amountLeft <= 0){
return 0;
}
ItemStack currentItem = inv.getItem(slot);
if(currentItem == null || currentItem.getType() == Material.AIR){
continue;
}
if(currentItem.getType() == itemMaterial && (currentItem.getDurability() == durability)){
int currentAmount = currentItem.getAmount();
if(amountLeft == currentAmount){
currentItem = null;
amountLeft = 0;
} else if(amountLeft < currentAmount){
currentItem.setAmount(currentAmount - amountLeft);
amountLeft = 0;
} else{
currentItem = null;
amountLeft -= currentAmount;
}
inv.setItem(slot, currentItem);
}
}
return amountLeft;
}
}

View File

@ -0,0 +1,34 @@
package com.Acrobot.iConomyChestShop;
import com.nijikokun.register.payment.Method;
/**
* @author Acrobot
* Economy management
*/
public class Economy {
public static Method economy;
public static boolean hasAccount(String p){
return economy.hasAccount(p);
}
public static void add(String name, float amount){
economy.getAccount(name).add(amount);
}
public static void substract(String name, float amount){
economy.getAccount(name).subtract(amount);
}
public static boolean hasEnough(String name, float amount) {
return economy.getAccount(name).hasEnough(amount);
}
public static double balance(String name){
return economy.getAccount(name).balance();
}
public static String formatBalance(double amount){
return economy.format(amount);
}
}

View File

@ -0,0 +1,37 @@
package com.Acrobot.iConomyChestShop.Items;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
* Manages ItemStack names and ID's
*/
public class ItemName {
public static String getItemName(ItemStack itemStack){
return getItemName(itemStack.getType().name());
}
public static String getItemName(String itemName){
return getMaterial(itemName).name();
}
public static Material getMaterial(String itemName){
int length = 256;
Material finalMat = null;
itemName = itemName.toLowerCase().replace("_","").replace(" ", "");
for(Material m: Material.values()){
String matName = m.name().toLowerCase().replace("_","").replace(" ", "");
if(matName.startsWith(itemName) && (matName.length() < length)){
length = matName.length();
finalMat = m;
}
}
return finalMat;
}
public static int getItemID(String itemName){
return getMaterial(itemName).getId();
}
}

View File

@ -0,0 +1,11 @@
package com.Acrobot.iConomyChestShop.Items;
import info.somethingodd.bukkit.odd.item.OddItem;
/**
* @author Acrobot
*/
public class Odd {
public static OddItem oddItem;
}

View File

@ -0,0 +1,10 @@
package com.Acrobot.iConomyChestShop.Listeners;
import org.bukkit.event.block.BlockListener;
/**
* @author Acrobot
*/
public class blockBreak extends BlockListener {
}

View File

@ -0,0 +1,19 @@
package com.Acrobot.iConomyChestShop.Listeners;
import com.Acrobot.iConomyChestShop.Utils.SignUtil;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
/**
* @author Acrobot
*/
public class blockPlace extends BlockListener {
public void onBlockPlace(BlockPlaceEvent event){
Block block = event.getBlockAgainst();
if(SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState())){
event.setCancelled(true);
}
}
}

View File

@ -0,0 +1,55 @@
package com.Acrobot.iConomyChestShop.Listeners;
import com.Acrobot.iConomyChestShop.Messaging.Message;
import com.Acrobot.iConomyChestShop.Protection.Security;
import com.Acrobot.iConomyChestShop.Utils.Config;
import com.Acrobot.iConomyChestShop.Utils.SignUtil;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
/**
* @author Acrobot
*/
public class playerInteract extends PlayerListener{
public void onPlayerInteract(PlayerInteractEvent event){
Action action = event.getAction();
Player player = event.getPlayer();
if(action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK){
return;
}
Block block = event.getClickedBlock();
if(block.getType() == Material.CHEST){
if(Security.isProtected(block) && !Security.canAccess(player, block)){
Message.sendMsg(player, "ACCESS_DENIED");
event.setCancelled(true);
return;
}
}
if(!SignUtil.isSign(block)){
return;
}
Sign sign = (Sign) block.getState();
if(!SignUtil.isValid(sign)){
return;
}
Action buy = (Config.getBoolean("reverse_buttons") ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK);
if(action == buy){
player.sendMessage("You are buying!");
} else{
player.sendMessage("You are selling!");
}
}
}

View File

@ -0,0 +1,81 @@
package com.Acrobot.iConomyChestShop.Listeners;
import com.Acrobot.iConomyChestShop.Economy;
import com.Acrobot.iConomyChestShop.Items.Odd;
import com.Acrobot.iConomyChestShop.Permission;
import com.Acrobot.iConomyChestShop.Protection.LWCplugin;
import com.Acrobot.iConomyChestShop.Protection.LockettePlugin;
import com.Acrobot.iConomyChestShop.Protection.Security;
import com.Acrobot.iConomyChestShop.iConomyChestShop;
import com.griefcraft.lwc.LWCPlugin;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.nijikokun.register.payment.Methods;
import info.somethingodd.bukkit.odd.item.OddItem;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.yi.acru.bukkit.Lockette.Lockette;
/**
* @author Acrobot
*/
public class pluginEnable extends ServerListener{
private Methods Methods = new Methods();
public void onPluginEnable(PluginEnableEvent event){
if(!this.Methods.hasMethod()){
if(this.Methods.setMethod(event.getPlugin())){
Economy.economy = this.Methods.getMethod();
System.out.println("[iConomyChestShop] " + Economy.economy.getName() + " " + Economy.economy.getVersion() + " loaded.");
}
}
//Permissions
if (Permission.permissions == null) {
Plugin permissions = iConomyChestShop.getBukkitServer().getPluginManager().getPlugin("Permissions");
if (permissions != null) {
Permission.permissions = ((Permissions) permissions).getHandler();
PluginDescriptionFile pDesc = permissions.getDescription();
System.out.println("[iConomyChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
}
//LWC
if (LWCplugin.lwc == null) {
Plugin lwcPlugin = iConomyChestShop.getBukkitServer().getPluginManager().getPlugin("LWC");
if (lwcPlugin != null) {
PluginDescriptionFile pDesc = lwcPlugin.getDescription();
LWCplugin.lwc = ((LWCPlugin) lwcPlugin).getLWC();
Security.protection = new LWCplugin();
System.out.println("[iConomyChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
}
//OddItem
if (Odd.oddItem == null) {
Plugin oddItem = iConomyChestShop.getBukkitServer().getPluginManager().getPlugin("OddItem");
if (oddItem != null) {
PluginDescriptionFile pDesc = oddItem.getDescription();
Odd.oddItem = (OddItem) iConomyChestShop.getBukkitServer().getPluginManager().getPlugin("OddItem");
System.out.println("[iConomyChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
}
//Lockette
if (LockettePlugin.lockette == null) {
Plugin lockette = iConomyChestShop.getBukkitServer().getPluginManager().getPlugin("Lockette");
if (lockette != null) {
PluginDescriptionFile pDesc = lockette.getDescription();
LockettePlugin.lockette = ((Lockette) lockette);
Security.protection = new LockettePlugin();
System.out.println("[iConomyChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
}
}
}

View File

@ -0,0 +1,9 @@
package com.Acrobot.iConomyChestShop.Listeners;
import org.bukkit.event.block.BlockListener;
/**
* @author Acrobot
*/
public class signChange extends BlockListener{
}

View File

@ -0,0 +1,10 @@
package com.Acrobot.iConomyChestShop.Logging;
/**
* @author Acrobot
*/
public class Logging {
public static void log(String string){
System.out.println("[iConomyChestShop] " + string);
}
}

View File

@ -0,0 +1,12 @@
package com.Acrobot.iConomyChestShop.Messaging;
import org.bukkit.entity.Player;
/**
* @author Acrobot
*/
public class Message {
public static void sendMsg(Player player, String msg){
player.sendMessage(msg);
}
}

View File

@ -0,0 +1,19 @@
package com.Acrobot.iConomyChestShop;
import com.nijiko.permissions.PermissionHandler;
import org.bukkit.entity.Player;
/**
* @author Acrobot
*/
public class Permission {
public static PermissionHandler permissions;
public static boolean has(Player player, String permission) {
if (permissions != null) {
return permissions.has(player, permission);
} else {
return !permission.contains("exclude") && (!permission.contains("admin") || player.isOp());
}
}
}

View File

@ -0,0 +1,21 @@
package com.Acrobot.iConomyChestShop.Protection;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
/**
* @author Acrobot
*/
public class Default implements Protection{
public boolean isProtected(Block block) {
return false; //TODO: Make it check the sign's first line
}
public boolean canAccess(Player player, Block block) {
return false; //TODO: Make it check the sign's first line
}
public boolean protect(String name, Block block) {
return false;
}
}

View File

@ -0,0 +1,27 @@
package com.Acrobot.iConomyChestShop.Protection;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.ProtectionTypes;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
/**
* @author Acrobot
*/
public class LWCplugin implements Protection{
public static LWC lwc;
public boolean isProtected(Block block) {
return lwc.findProtection(block) != null;
}
public boolean canAccess(Player player, Block block) {
return lwc.canAccessProtection(player, block);
}
public boolean protect(String name, Block block) {
lwc.getPhysicalDatabase().registerProtection(block.getTypeId(), ProtectionTypes.PRIVATE, block.getWorld().getName(), name, "", block.getX(), block.getY(), block.getZ());
return true;
}
}

View File

@ -0,0 +1,24 @@
package com.Acrobot.iConomyChestShop.Protection;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.yi.acru.bukkit.Lockette.Lockette;
/**
* @author Acrobot
*/
public class LockettePlugin implements Protection{
public static Lockette lockette;
public boolean isProtected(Block block) {
return Lockette.isProtected(block);
}
public boolean canAccess(Player player, Block block) {
return (player.getName().equals(Lockette.getProtectedOwner(block)));
}
public boolean protect(String name, Block block) {
return false;
}
}

View File

@ -0,0 +1,14 @@
package com.Acrobot.iConomyChestShop.Protection;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
/**
* @author Acrobot
*/
public interface Protection {
public boolean isProtected(Block block);
public boolean canAccess(Player player, Block block);
public boolean protect(String name, Block block);
}

View File

@ -0,0 +1,23 @@
package com.Acrobot.iConomyChestShop.Protection;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
/**
* @author Acrobot
*/
public class Security {
public static Protection protection = new Default();
public static boolean protect(String name, Block block){
return protection.protect(name, block);
}
public static boolean canAccess(Player player, Block block){
return protection.canAccess(player, block);
}
public static boolean isProtected(Block block){
return protection.isProtected(block);
}
}

View File

@ -0,0 +1,16 @@
package com.Acrobot.iConomyChestShop.Shop;
import com.Acrobot.iConomyChestShop.Chests.ChestObject;
import org.bukkit.block.Sign;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
*/
public class Shop {
private ItemStack[] items;
public Shop(ChestObject chest, Sign sign, ItemStack ... itemStacks){
items = itemStacks;
}
}

View File

@ -0,0 +1,44 @@
package com.Acrobot.iConomyChestShop.Utils;
import com.Acrobot.iConomyChestShop.Logging.Logging;
import org.bukkit.util.config.Configuration;
import java.io.File;
/**
* @author Acrobot
*/
public class Config {
private static File configFile = new File("plugins/iConomyChestShop/config.yml");
private static Configuration config = new Configuration(configFile);
public static void setUp(){
if(!configFile.exists()){
try {
configFile.createNewFile();
Logging.log("Successfully created blank configuration file");
} catch (Exception e) {
Logging.log("Couldn't create configuration file!");
}
}
load();
}
public static void load(){
config.load();
}
public static boolean getBoolean(String node){
return config.getBoolean(node, false);
}
public static int getInteger(String node){
return config.getInt(node, 0);
}
public static double getDouble(String node){
return config.getDouble(node, -1);
}
}

View File

@ -0,0 +1,34 @@
package com.Acrobot.iConomyChestShop.Utils;
/**
* Checks if string is a numerical value
* @author Acrobot
*/
public class Numerical {
public static boolean isInteger(String string){
try{
Integer.parseInt(string);
return true;
} catch (Exception e){
return false;
}
}
public static boolean isFloat(String string){
try{
Float.parseFloat(string);
return true;
} catch (Exception e){
return false;
}
}
public static boolean isDouble(String string){
try{
Double.parseDouble(string);
return true;
} catch (Exception e){
return false;
}
}
}

View File

@ -0,0 +1,13 @@
package com.Acrobot.iConomyChestShop.Utils;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
/**
* @author Acrobot
*/
public class SearchForBlock {
public static Chest findChest(Sign sign){
return null;
}
}

View File

@ -0,0 +1,29 @@
package com.Acrobot.iConomyChestShop.Utils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
/**
* @author Acrobot
*/
public class SignUtil {
public static boolean isSign(Block block){
return (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN);
}
public static boolean isValid(Sign sign){
return isValid(sign.getLines());
}
public static boolean isValid(String[] lines){
try{
String line1 = lines[0];
String line2 = lines[1];
String line3 = lines[2];
String line4 = lines[3];
return !line1.contains("[") && !line1.contains("]") && !line4.equals("") && Numerical.isInteger(line2) && (line3.contains("B") || line3.contains("S"));
} catch (Exception e){
return false;
}
}
}

View File

@ -0,0 +1,96 @@
package com.Acrobot.iConomyChestShop;
import com.Acrobot.iConomyChestShop.Items.ItemName;
import com.Acrobot.iConomyChestShop.Listeners.*;
import com.Acrobot.iConomyChestShop.Utils.Config;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Main file of the plugin
* @author Acrobot
*/
public class iConomyChestShop extends JavaPlugin {
private final pluginEnable pluginEnable = new pluginEnable();
private final blockBreak blockBreak = new blockBreak();
private final blockPlace blockPlace = new blockPlace();
private final signChange signChange = new signChange();
private final playerInteract playerInteract = new playerInteract();
private PluginDescriptionFile desc;
private static Server server;
public void onEnable() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_BREAK, blockBreak, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, blockPlace, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.SIGN_CHANGE, signChange, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerInteract, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLUGIN_ENABLE, pluginEnable, Event.Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, playerInteract, Event.Priority.Monitor, this);
desc = this.getDescription();
server = getServer();
Config.setUp();
System.out.println("[" + desc.getName() + "] version " + desc.getVersion() + " initialized!");
}
public void onDisable() {
System.out.println("[" + desc.getName() + "] version " + desc.getVersion() + " shutting down!");
}
public static Server getBukkitServer() {
return server;
}
public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args){
String commandName = cmd.getName().toLowerCase();
int argCount = args.length;
//iCSversion
if(commandName.equals("icsversion")){
sender.sendMessage("iConomyChestShop's version is: " + desc.getVersion());
return true;
}
if(!(sender instanceof Player)){
return false;
}
Player p = (Player) sender;
//ItemInfo
if(commandName.equals("iteminfo")){
if(argCount == 0){
p.sendMessage(ItemName.getItemID(p.getItemInHand().getType().name()) + " " + ItemName.getItemName(p.getItemInHand()));
return true;
}
if(argCount == 1){
String itemName = ItemName.getItemID(ItemName.getItemName(args[0])) + " " + ItemName.getItemName(args[0]);
p.sendMessage(itemName);
return true;
}
}
//Silly :)
if(commandName.equals("buy")){
p.sendMessage("Hey, there is no buy command! Just right click the sign!");
return true;
}
if(commandName.equals("sell")){
p.sendMessage("Hey, there is no sell command! Just left click the sign!");
return true;
}
return false;
}
}

View File

@ -0,0 +1,54 @@
package com.nijikokun.register.payment;
import org.bukkit.plugin.Plugin;
public interface Method {
public Object getPlugin();
public String getName();
public String getVersion();
public String format(double amount);
public boolean hasBanks();
public boolean hasBank(String bank);
public boolean hasAccount(String name);
public boolean hasBankAccount(String bank, String name);
public MethodAccount getAccount(String name);
public MethodBankAccount getBankAccount(String bank, String name);
public boolean isCompatible(Plugin plugin);
public void setPlugin(Plugin plugin);
public interface MethodAccount {
public double balance();
public boolean set(double amount);
public boolean add(double amount);
public boolean subtract(double amount);
public boolean multiply(double amount);
public boolean divide(double amount);
public boolean hasEnough(double amount);
public boolean hasOver(double amount);
public boolean hasUnder(double amount);
public boolean isNegative();
public boolean remove();
@Override
public String toString();
}
public interface MethodBankAccount {
public double balance();
public String getBankName();
public int getBankId();
public boolean set(double amount);
public boolean add(double amount);
public boolean subtract(double amount);
public boolean multiply(double amount);
public boolean divide(double amount);
public boolean hasEnough(double amount);
public boolean hasOver(double amount);
public boolean hasUnder(double amount);
public boolean isNegative();
public boolean remove();
@Override
public String toString();
}
}

View File

@ -0,0 +1,31 @@
package com.nijikokun.register.payment;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.plugin.Plugin;
public class MethodFactory {
private static Set<Method> Methods = new HashSet<Method>();
private static Set<String> Dependencies = new HashSet<String>();
public static Method createMethod(Plugin plugin) {
for (Method method: Methods) {
if (method.isCompatible(plugin)) {
method.setPlugin(plugin);
return method;
}
}
return null;
}
public static void addMethod(String name, Method method) {
Dependencies.add(name);
Methods.add(method);
}
public static Set<String> getDependencies() {
return Dependencies;
}
}

View File

@ -0,0 +1,46 @@
package com.nijikokun.register.payment;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class Methods {
private Method Method = null;
public boolean setMethod(Plugin method) {
PluginManager manager = method.getServer().getPluginManager();
if (method != null && method.isEnabled()) {
Method plugin = MethodFactory.createMethod(method);
if (plugin != null) Method = plugin;
} else {
for(String name: MethodFactory.getDependencies()) {
if(hasMethod()) break;
method = manager.getPlugin(name);
if(method == null) continue;
if(!method.isEnabled()) manager.enablePlugin(method);
if(!method.isEnabled()) continue;
Method plugin = MethodFactory.createMethod(method);
if (plugin != null) Method = plugin;
}
}
return hasMethod();
}
public boolean checkDisabled(Plugin method) {
if(!hasMethod()) return true;
if (Method.isCompatible(method)) Method = null;
return (Method == null);
}
public boolean hasMethod() {
return (Method != null);
}
public Method getMethod() {
return Method;
}
}

View File

@ -0,0 +1,202 @@
package com.nijikokun.register.payment.methods;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.MethodFactory;
import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin;
public class BOSE implements Method {
private BOSEconomy BOSEconomy;
static {
MethodFactory.addMethod("BOSEconomy", new BOSE());
}
public BOSEconomy getPlugin() {
return this.BOSEconomy;
}
public String getName() {
return "BOSEconomy";
}
public String getVersion() {
return "0.6.2";
}
public String format(double amount) {
String currency = this.BOSEconomy.getMoneyNamePlural();
if(amount == 1) currency = this.BOSEconomy.getMoneyName();
return amount + " " + currency;
}
public boolean hasBanks() {
return true;
}
public boolean hasBank(String bank) {
return this.BOSEconomy.bankExists(bank);
}
public boolean hasAccount(String name) {
return this.BOSEconomy.playerRegistered(name, false);
}
public boolean hasBankAccount(String bank, String name) {
return this.BOSEconomy.isBankOwner(bank, name);
}
public MethodAccount getAccount(String name) {
if(!hasAccount(name)) return null;
return new BOSEAccount(name, this.BOSEconomy);
}
public MethodBankAccount getBankAccount(String bank, String name) {
return new BOSEBankAccount(bank, name, BOSEconomy);
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") && plugin instanceof BOSEconomy;
}
public void setPlugin(Plugin plugin) {
BOSEconomy = (BOSEconomy)plugin;
}
public class BOSEAccount implements MethodAccount {
private String name;
private BOSEconomy BOSEconomy;
public BOSEAccount(String name, BOSEconomy bOSEconomy) {
this.name = name;
this.BOSEconomy = bOSEconomy;
}
public double balance() {
return (double) this.BOSEconomy.getPlayerMoney(this.name);
}
public boolean set(double amount) {
int IntAmount = (int)Math.ceil(amount);
return this.BOSEconomy.setPlayerMoney(this.name, IntAmount, false);
}
public boolean add(double amount) {
int IntAmount = (int)Math.ceil(amount);
//int balance = (int)this.balance();
return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false);
}
public boolean subtract(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setPlayerMoney(this.name, (balance - IntAmount), false);
}
public boolean multiply(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setPlayerMoney(this.name, (balance * IntAmount), false);
}
public boolean divide(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setPlayerMoney(this.name, (balance / IntAmount), false);
}
public boolean hasEnough(double amount) {
return (this.balance() >= amount);
}
public boolean hasOver(double amount) {
return (this.balance() > amount);
}
public boolean hasUnder(double amount) {
return (this.balance() < amount);
}
public boolean isNegative() {
return (this.balance() < 0);
}
public boolean remove() {
return false;
}
}
public class BOSEBankAccount implements MethodBankAccount {
private String bank;
private String name;
private BOSEconomy BOSEconomy;
public BOSEBankAccount(String bank, String name, BOSEconomy bOSEconomy) {
this.name = name;
this.bank = bank;
this.BOSEconomy = bOSEconomy;
}
public String getBankName() {
return this.bank;
}
public int getBankId() {
return -1;
}
public double balance() {
return (double) this.BOSEconomy.getBankMoney(name);
}
public boolean set(double amount) {
int IntAmount = (int)Math.ceil(amount);
return this.BOSEconomy.setBankMoney(name, IntAmount, true);
}
public boolean add(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setBankMoney(this.name, (balance + IntAmount), false);
}
public boolean subtract(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setBankMoney(this.name, (balance - IntAmount), false);
}
public boolean multiply(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setBankMoney(this.name, (balance * IntAmount), false);
}
public boolean divide(double amount) {
int IntAmount = (int)Math.ceil(amount);
int balance = (int)this.balance();
return this.BOSEconomy.setBankMoney(this.name, (balance / IntAmount), false);
}
public boolean hasEnough(double amount) {
return (this.balance() >= amount);
}
public boolean hasOver(double amount) {
return (this.balance() > amount);
}
public boolean hasUnder(double amount) {
return (this.balance() < amount);
}
public boolean isNegative() {
return (this.balance() < 0);
}
public boolean remove() {
return this.BOSEconomy.removeBank(bank);
}
}
}

View File

@ -0,0 +1,200 @@
package com.nijikokun.register.payment.methods;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.api.Economy;
import com.earth2me.essentials.api.NoLoanPermittedException;
import com.earth2me.essentials.api.UserDoesNotExistException;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.MethodFactory;
import org.bukkit.plugin.Plugin;
public class EE17 implements Method {
private Essentials Essentials;
static {
MethodFactory.addMethod("Essentials", new EE17());
}
public Essentials getPlugin() {
return this.Essentials;
}
public String getName() {
return "EssentialsEco";
}
public String getVersion() {
return "2.2";
}
public String format(double amount) {
return Economy.format(amount);
}
public boolean hasBanks() {
return false;
}
public boolean hasBank(String bank) {
return false;
}
public boolean hasAccount(String name) {
return Economy.playerExists(name);
}
public boolean hasBankAccount(String bank, String name) {
return false;
}
public MethodAccount getAccount(String name) {
if(!hasAccount(name)) return null;
return new EEcoAccount(name);
}
public MethodBankAccount getBankAccount(String bank, String name) {
return null;
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("essentials") && plugin instanceof Essentials;
}
public void setPlugin(Plugin plugin) {
Essentials = (Essentials)plugin;
}
public class EEcoAccount implements MethodAccount {
private String name;
public EEcoAccount(String name) {
this.name = name;
}
public double balance() {
Double balance = 0.0;
try {
balance = Economy.getMoney(this.name);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] Failed to grab balance in Essentials Economy: " + ex.getMessage());
}
return balance;
}
public boolean set(double amount) {
try {
Economy.setMoney(name, amount);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
return false;
} catch (NoLoanPermittedException ex) {
System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
return false;
}
return true;
}
public boolean add(double amount) {
try {
Economy.add(name, amount);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
return false;
} catch (NoLoanPermittedException ex) {
System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
return false;
}
return true;
}
public boolean subtract(double amount) {
try {
Economy.subtract(name, amount);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
return false;
} catch (NoLoanPermittedException ex) {
System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
return false;
}
return true;
}
public boolean multiply(double amount) {
try {
Economy.multiply(name, amount);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
return false;
} catch (NoLoanPermittedException ex) {
System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
return false;
}
return true;
}
public boolean divide(double amount) {
try {
Economy.divide(name, amount);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
return false;
} catch (NoLoanPermittedException ex) {
System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
return false;
}
return true;
}
public boolean hasEnough(double amount) {
try {
return Economy.hasEnough(name, amount);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
}
return false;
}
public boolean hasOver(double amount) {
try {
return Economy.hasMore(name, amount);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
}
return false;
}
public boolean hasUnder(double amount) {
try {
return Economy.hasLess(name, amount);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
}
return false;
}
public boolean isNegative() {
try {
return Economy.isNegative(name);
} catch (UserDoesNotExistException ex) {
System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
}
return false;
}
public boolean remove() {
return false;
}
}
}

View File

@ -0,0 +1,131 @@
package com.nijikokun.register.payment.methods;
import com.nijiko.coelho.iConomy.iConomy;
import com.nijiko.coelho.iConomy.system.Account;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.MethodFactory;
import org.bukkit.plugin.Plugin;
public class iCo4 implements Method {
private iConomy iConomy;
static {
MethodFactory.addMethod("iConomy", new iCo4());
}
public iConomy getPlugin() {
return this.iConomy;
}
public String getName() {
return "iConomy";
}
public String getVersion() {
return "4";
}
public String format(double amount) {
return this.iConomy.getBank().format(amount);
}
public boolean hasBanks() {
return false;
}
public boolean hasBank(String bank) {
return false;
}
public boolean hasAccount(String name) {
return this.iConomy.getBank().hasAccount(name);
}
public boolean hasBankAccount(String bank, String name) {
return false;
}
public MethodAccount getAccount(String name) {
return new iCoAccount(this.iConomy.getBank().getAccount(name));
}
public MethodBankAccount getBankAccount(String bank, String name) {
return null;
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin instanceof iConomy;
}
public void setPlugin(Plugin plugin) {
iConomy = (iConomy)plugin;
}
public class iCoAccount implements MethodAccount {
private Account account;
public iCoAccount(Account account) {
this.account = account;
}
public Account getiCoAccount() {
return account;
}
public double balance() {
return this.account.getBalance();
}
public boolean set(double amount) {
if(this.account == null) return false;
this.account.setBalance(amount);
return true;
}
public boolean add(double amount) {
if(this.account == null) return false;
this.account.add(amount);
return true;
}
public boolean subtract(double amount) {
if(this.account == null) return false;
this.account.subtract(amount);
return true;
}
public boolean multiply(double amount) {
if(this.account == null) return false;
this.account.multiply(amount);
return true;
}
public boolean divide(double amount) {
if(this.account == null) return false;
this.account.divide(amount);
return true;
}
public boolean hasEnough(double amount) {
return this.account.hasEnough(amount);
}
public boolean hasOver(double amount) {
return this.account.hasOver(amount);
}
public boolean hasUnder(double amount) {
return (this.balance() < amount);
}
public boolean isNegative() {
return this.account.isNegative();
}
public boolean remove() {
if(this.account == null) return false;
this.account.remove();
return true;
}
}
}

View File

@ -0,0 +1,214 @@
package com.nijikokun.register.payment.methods;
import com.iConomy.iConomy;
import com.iConomy.system.Account;
import com.iConomy.system.BankAccount;
import com.iConomy.system.Holdings;
import com.iConomy.util.Constants;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.MethodFactory;
import org.bukkit.plugin.Plugin;
public class iCo5 implements Method {
private iConomy iConomy;
static {
MethodFactory.addMethod("iConomy", new iCo5());
}
public iConomy getPlugin() {
return this.iConomy;
}
public String getName() {
return "iConomy";
}
public String getVersion() {
return "5";
}
public String format(double amount) {
return this.iConomy.format(amount);
}
public boolean hasBanks() {
return Constants.Banking;
}
public boolean hasBank(String bank) {
return (hasBanks()) && this.iConomy.Banks.exists(bank);
}
public boolean hasAccount(String name) {
return this.iConomy.hasAccount(name);
}
public boolean hasBankAccount(String bank, String name) {
return (!hasBank(bank)) && this.iConomy.getBank(name).hasAccount(name);
}
public MethodAccount getAccount(String name) {
return new iCoAccount(this.iConomy.getAccount(name));
}
public MethodBankAccount getBankAccount(String bank, String name) {
return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name));
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin instanceof iConomy;
}
public void setPlugin(Plugin plugin) {
iConomy = (iConomy)plugin;
}
public class iCoAccount implements MethodAccount {
private Account account;
private Holdings holdings;
public iCoAccount(Account account) {
this.account = account;
this.holdings = account.getHoldings();
}
public Account getiCoAccount() {
return account;
}
public double balance() {
return this.holdings.balance();
}
public boolean set(double amount) {
if(this.holdings == null) return false;
this.holdings.set(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;
}
}
public class iCoBankAccount implements MethodBankAccount {
private BankAccount account;
private Holdings holdings;
public iCoBankAccount(BankAccount account) {
this.account = account;
this.holdings = account.getHoldings();
}
public BankAccount getiCoBankAccount() {
return account;
}
public String getBankName() {
return this.account.getBankName();
}
public int getBankId() {
return this.account.getBankId();
}
public double balance() {
return this.holdings.balance();
}
public boolean set(double amount) {
if(this.holdings == null) return false;
this.holdings.set(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;
}
}
}

32
plugin.yml Normal file
View File

@ -0,0 +1,32 @@
name: iConomyChestShop
main: com.Acrobot.iConomyChestShop.iConomyChestShop
database: true
version: 3.00
author: Acrobot
description: >
A chest shop for iConomy.
commands:
buy:
aliases: chBuy
description: Toggles mode to buying
usage: |
/<command>
sell:
aliases: chSell
description: Toggles mode to selling
usage: |
/<command>
iteminfo:
aliases:
description: Lists item id and names
usage: |
/<command> <partial item name or id>
icsVersion:
aliases:
description: Shows the iConomyChestShop's version
usage: |
/<command>