- Changed to the new, more robust event system
- Added partial transactions (You have 5 items, shop wants 10 - you can sell your items for half the price) - Added a warning to the HTML generator - Fixed Towny integration - Fixed occasional ArrayOutOfBoundsExceptions - Fixed an error when a shop couldn't be created because a sign (not shop sign) was on other side of the block - Added SCL (SimpleChestLock) protection plugin to supported plugins - Updated Metrics (and added a new asynch thread for startup) - Removed Bukkit-1.0 workaround - Fixed plugin.yml formatting
This commit is contained in:
parent
c3b084fd1a
commit
a49d51ce97
|
@ -13,8 +13,6 @@ import com.Acrobot.ChestShop.Logging.FileWriterQueue;
|
||||||
import com.avaje.ebean.EbeanServer;
|
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.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;
|
||||||
|
@ -77,24 +75,13 @@ public class ChestShop extends JavaPlugin {
|
||||||
|
|
||||||
////////////////// REGISTER EVENTS, SCHEDULER & STATS ///////////////////////////
|
////////////////// REGISTER EVENTS, SCHEDULER & STATS ///////////////////////////
|
||||||
private void registerEvents() {
|
private void registerEvents() {
|
||||||
blockBreak blockBreak = new blockBreak();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
registerEvent(Event.Type.BLOCK_BREAK, blockBreak);
|
|
||||||
registerEvent(Event.Type.BLOCK_PLACE, new blockPlace());
|
pm.registerEvents(new blockBreak(), this);
|
||||||
registerEvent(Event.Type.SIGN_CHANGE, new signChange());
|
pm.registerEvents(new blockPlace(), this);
|
||||||
registerEvent(Event.Type.PLAYER_INTERACT, new playerInteract(), Event.Priority.Highest);
|
pm.registerEvents(new signChange(), this);
|
||||||
registerEvent(Event.Type.PLUGIN_ENABLE, new pluginEnable());
|
pm.registerEvents(new playerInteract(), this);
|
||||||
if (!Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) return;
|
pm.registerEvents(new entityExplode(), this);
|
||||||
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) {
|
private void scheduleTask(Runnable runnable, long startTime, long repetetionTime) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class ItemInfo implements CommandExecutor {
|
||||||
if (integer == 3) return "III";
|
if (integer == 3) return "III";
|
||||||
if (integer == 4) return "IV";
|
if (integer == 4) return "IV";
|
||||||
if (integer == 5) return "V";
|
if (integer == 5) return "V";
|
||||||
return null;
|
return Integer.toString(integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,8 @@ public enum Property {
|
||||||
ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK(false, "Do you want to allow other players to build a shop on a block where there's one already?"),
|
ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK(false, "Do you want to allow other players to build a shop on a block where there's one already?"),
|
||||||
SHOP_INTERACTION_INTERVAL(100, "(In 1/1000th of a second) How often can a player use a shop sign?"),
|
SHOP_INTERACTION_INTERVAL(100, "(In 1/1000th of a second) How often can a player use a shop sign?"),
|
||||||
HEROES_EXP(100, "How much Heroes exp should people get for creating a ChestShop?"),
|
HEROES_EXP(100, "How much Heroes exp should people get for creating a ChestShop?"),
|
||||||
BLOCK_UPDATE(false, "EXPERIMENTAL: Should every ChestShop transaction result in a block update?");
|
BLOCK_UPDATE(false, "EXPERIMENTAL: Should every ChestShop transaction result in a block update?"),
|
||||||
|
ALLOW_PARTIAL_TRANSACTIONS(true, "Can shops be used even when the seller doesn't have enough items? (The price will be scaled adequatly to the item amount)");
|
||||||
|
|
||||||
|
|
||||||
private final Object value;
|
private final Object value;
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class Generator implements Runnable {
|
||||||
private static BufferedWriter buf;
|
private static BufferedWriter buf;
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (row.isEmpty()) System.out.println(ChestShop.chatPrefix + "You lack the necessary HTML files in your plugins/ChestShop/HTML folder!");
|
||||||
generateStats();
|
generateStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class Queue implements Runnable {
|
||||||
.getDB()
|
.getDB()
|
||||||
.find(Transaction.class)
|
.find(Transaction.class)
|
||||||
.where()
|
.where()
|
||||||
.lt("sec", System.currentTimeMillis() / 1000 - Config.getInteger(Property.RECORD_TIME_TO_LIVE))
|
.lt("sec", (System.currentTimeMillis() / 1000L) - Config.getInteger(Property.RECORD_TIME_TO_LIVE))
|
||||||
.findList();
|
.findList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class Economy {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void subtract(String name, float amount) {
|
public static void subtract(String name, float amount) {
|
||||||
economy.subtract(name, amount);
|
economy.subtract(uLongName.getName(name), amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasEnough(String name, float amount) {
|
public static boolean hasEnough(String name, float amount) {
|
||||||
|
|
|
@ -50,8 +50,12 @@ public class Items {
|
||||||
public static ItemStack getItemStack(String itemName) {
|
public static ItemStack getItemStack(String itemName) {
|
||||||
ItemStack toReturn = getFromOddItem(itemName);
|
ItemStack toReturn = getFromOddItem(itemName);
|
||||||
if (toReturn != null) return toReturn;
|
if (toReturn != null) return toReturn;
|
||||||
|
|
||||||
String first = itemName.split(":|-")[0];
|
if (itemName == null) itemName = "";
|
||||||
|
String[] split = itemName.split(":|-");
|
||||||
|
|
||||||
|
if (split.length == 0) return null;
|
||||||
|
String first = split[0];
|
||||||
|
|
||||||
String[] space = first.split(" ");
|
String[] space = first.split(" ");
|
||||||
Material material = getMaterial(first);
|
Material material = getMaterial(first);
|
||||||
|
|
|
@ -14,8 +14,9 @@ import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockListener;
|
|
||||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||||
import org.bukkit.material.PistonBaseMaterial;
|
import org.bukkit.material.PistonBaseMaterial;
|
||||||
|
@ -26,7 +27,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class blockBreak extends BlockListener {
|
public class blockBreak implements Listener {
|
||||||
public static boolean cancellingBlockBreak(Block block, Player player) {
|
public static boolean cancellingBlockBreak(Block block, Player player) {
|
||||||
if (block == null) return false;
|
if (block == null) return false;
|
||||||
if (player != null && (Permission.has(player, Permission.ADMIN) || Permission.has(player, Permission.MOD))) return false;
|
if (player != null && (Permission.has(player, Permission.ADMIN) || Permission.has(player, Permission.MOD))) return false;
|
||||||
|
@ -55,7 +56,8 @@ public class blockBreak extends BlockListener {
|
||||||
return uBlock.findRestrictedSign(block) != null;
|
return uBlock.findRestrictedSign(block) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
@EventHandler
|
||||||
|
public static void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (cancellingBlockBreak(event.getBlock(), event.getPlayer())) event.setCancelled(true);
|
if (cancellingBlockBreak(event.getBlock(), event.getPlayer())) event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +74,8 @@ public class blockBreak extends BlockListener {
|
||||||
&& !Permission.otherName(player, sign.getLine(0)));
|
&& !Permission.otherName(player, sign.getLine(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
@EventHandler
|
||||||
|
public static void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||||
for (Block b : getExtendBlocks(event)) {
|
for (Block b : getExtendBlocks(event)) {
|
||||||
if (cancellingBlockBreak(b, null)) {
|
if (cancellingBlockBreak(b, null)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -81,7 +84,8 @@ public class blockBreak extends BlockListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
@EventHandler
|
||||||
|
public static void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||||
if (cancellingBlockBreak(getRetractBlock(event), null)) event.setCancelled(true);
|
if (cancellingBlockBreak(getRetractBlock(event), null)) event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,16 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class blockPlace extends BlockListener {
|
public class blockPlace implements Listener {
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
@EventHandler
|
||||||
|
public static void onBlockPlace(BlockPlaceEvent event) {
|
||||||
Block block = event.getBlockAgainst();
|
Block block = event.getBlockAgainst();
|
||||||
if (uSign.isSign(block) && uSign.isValid((Sign) block.getState())) {
|
if (uSign.isSign(block) && uSign.isValid((Sign) block.getState())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package com.Acrobot.ChestShop.Listeners;
|
package com.Acrobot.ChestShop.Listeners;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class entityExplode extends EntityListener {
|
public class entityExplode implements Listener {
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
@EventHandler
|
||||||
|
public static void onEntityExplode(EntityExplodeEvent event) {
|
||||||
if (event.isCancelled() || event.blockList() == null) return;
|
if (event.isCancelled() || event.blockList() == null) return;
|
||||||
for (Block block : event.blockList()) {
|
for (Block block : event.blockList()) {
|
||||||
if (blockBreak.cancellingBlockBreak(block, null)) {
|
if (blockBreak.cancellingBlockBreak(block, null)) {
|
||||||
|
|
|
@ -19,21 +19,24 @@ import org.bukkit.block.Sign;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class playerInteract extends PlayerListener {
|
public class playerInteract implements Listener {
|
||||||
|
|
||||||
private static final HashMap<Player, Long> lastTransactionTime = new HashMap<Player, Long>(); //Last player's transaction
|
private static final HashMap<Player, Long> lastTransactionTime = new HashMap<Player, Long>(); //Last player's transaction
|
||||||
public static int interval = 100;//Minimal interval between transactions
|
public static int interval = 100;//Minimal interval between transactions
|
||||||
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
Action action = event.getAction();
|
Action action = event.getAction();
|
||||||
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK) return;
|
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package com.Acrobot.ChestShop.Listeners;
|
package com.Acrobot.ChestShop.Listeners;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
|
import com.Acrobot.ChestShop.Economy.NoProvider;
|
||||||
import com.Acrobot.ChestShop.Economy.Register;
|
import com.Acrobot.ChestShop.Economy.Register;
|
||||||
import com.Acrobot.ChestShop.Economy.Vault;
|
import com.Acrobot.ChestShop.Economy.Vault;
|
||||||
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.*;
|
||||||
import com.Acrobot.ChestShop.Protection.Plugins.Default;
|
|
||||||
import com.Acrobot.ChestShop.Protection.Plugins.LWCplugin;
|
|
||||||
import com.Acrobot.ChestShop.Protection.Plugins.LockettePlugin;
|
|
||||||
import com.Acrobot.ChestShop.Protection.Security;
|
import com.Acrobot.ChestShop.Protection.Security;
|
||||||
import com.Acrobot.ChestShop.Utils.uHeroes;
|
import com.Acrobot.ChestShop.Utils.uHeroes;
|
||||||
import com.Acrobot.ChestShop.Utils.uNumber;
|
import com.Acrobot.ChestShop.Utils.uNumber;
|
||||||
|
@ -22,8 +20,8 @@ import com.nijikokun.register.payment.forChestShop.Method;
|
||||||
import com.nijikokun.register.payment.forChestShop.Methods;
|
import com.nijikokun.register.payment.forChestShop.Methods;
|
||||||
import com.palmergames.bukkit.towny.Towny;
|
import com.palmergames.bukkit.towny.Towny;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.webkonsept.bukkit.simplechestlock.SCL;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.event.server.ServerListener;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
@ -32,7 +30,7 @@ import org.yi.acru.bukkit.Lockette.Lockette;
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class pluginEnable extends ServerListener {
|
public class pluginEnable {
|
||||||
|
|
||||||
public static void initializePlugins() {
|
public static void initializePlugins() {
|
||||||
Security.protections.add(new Default()); //Initialize basic protection
|
Security.protections.add(new Default()); //Initialize basic protection
|
||||||
|
@ -46,7 +44,10 @@ public class pluginEnable extends ServerListener {
|
||||||
private static void loadRegister(){
|
private static void loadRegister(){
|
||||||
if (com.Acrobot.ChestShop.Economy.Economy.economy == null) {
|
if (com.Acrobot.ChestShop.Economy.Economy.economy == null) {
|
||||||
Method m = Methods.load(ChestShop.pm);
|
Method m = Methods.load(ChestShop.pm);
|
||||||
if (m == null) return;
|
if (m == null) {
|
||||||
|
com.Acrobot.ChestShop.Economy.Economy.economy = new NoProvider();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Register.eco = m;
|
Register.eco = m;
|
||||||
com.Acrobot.ChestShop.Economy.Economy.economy = new Register();
|
com.Acrobot.ChestShop.Economy.Economy.economy = new Register();
|
||||||
System.out.println(ChestShop.chatPrefix + m.getName() + " loaded.");
|
System.out.println(ChestShop.chatPrefix + m.getName() + " loaded.");
|
||||||
|
@ -66,7 +67,6 @@ public class pluginEnable extends ServerListener {
|
||||||
DeadboltPlugin.deadbolt = (Deadbolt) plugin;
|
DeadboltPlugin.deadbolt = (Deadbolt) plugin;
|
||||||
Security.protections.add(new DeadboltPlugin());
|
Security.protections.add(new DeadboltPlugin());
|
||||||
} else if (name.equals("OddItem")) {
|
} else if (name.equals("OddItem")) {
|
||||||
if (Odd.isInitialized()) return;
|
|
||||||
if (plugin.getDescription().getVersion().startsWith("0.7")) { System.out.println(generateOutdatedVersion(name, plugin.getDescription().getVersion(), "0.8")); return; }
|
if (plugin.getDescription().getVersion().startsWith("0.7")) { System.out.println(generateOutdatedVersion(name, plugin.getDescription().getVersion(), "0.8")); return; }
|
||||||
Odd.isInitialized = true;
|
Odd.isInitialized = true;
|
||||||
} else if (name.equals("Towny")) {
|
} else if (name.equals("Towny")) {
|
||||||
|
@ -87,6 +87,9 @@ public class pluginEnable extends ServerListener {
|
||||||
return;
|
return;
|
||||||
} else if (name.equals("Heroes")){
|
} else if (name.equals("Heroes")){
|
||||||
uHeroes.heroes = (Heroes) plugin;
|
uHeroes.heroes = (Heroes) plugin;
|
||||||
|
} else if (name.equals("SimpleChestLock")) {
|
||||||
|
SCLplugin.scl = (SCL) plugin;
|
||||||
|
Security.protections.add(new SCLplugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginDescriptionFile description = plugin.getDescription();
|
PluginDescriptionFile description = plugin.getDescription();
|
||||||
|
|
|
@ -15,16 +15,18 @@ import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class signChange extends BlockListener {
|
public class signChange implements Listener {
|
||||||
|
|
||||||
public void onSignChange(SignChangeEvent event) {
|
@EventHandler
|
||||||
|
public static void onSignChange(SignChangeEvent event) {
|
||||||
Block signBlock = event.getBlock();
|
Block signBlock = event.getBlock();
|
||||||
String[] line = event.getLines();
|
String[] line = event.getLines();
|
||||||
|
|
||||||
|
|
|
@ -1,52 +1,40 @@
|
||||||
package com.Acrobot.ChestShop;
|
package com.Acrobot.ChestShop;/*
|
||||||
|
* Copyright 2011 Tyler Blair. All rights reserved.
|
||||||
/*
|
*
|
||||||
* Copyright 2011 Tyler Blair. All rights reserved.
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
*
|
* permitted provided that the following conditions are met:
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
*
|
||||||
* permitted provided that the following conditions are met:
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
*
|
* conditions and the following disclaimer.
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
*
|
||||||
* conditions and the following disclaimer.
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
*
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* provided with the distribution.
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
*
|
||||||
* provided with the distribution.
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
*
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
*
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* The views and conclusions contained in the software and documentation are those of the
|
||||||
*
|
* authors and contributors and should not be interpreted as representing official policies,
|
||||||
* The views and conclusions contained in the software and documentation are those of the
|
* either expressed or implied, of anybody else.
|
||||||
* authors and contributors and should not be interpreted as representing official policies,
|
*/
|
||||||
* either expressed or implied, of anybody else.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tooling to post to metrics.griefcraft.com
|
* Tooling to post to metrics.griefcraft.com
|
||||||
|
@ -72,6 +60,12 @@ public class Metrics {
|
||||||
*/
|
*/
|
||||||
public abstract int getValue();
|
public abstract int getValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after the website graphs have been updated
|
||||||
|
*/
|
||||||
|
public void reset() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getColumnName().hashCode() + getValue();
|
return getColumnName().hashCode() + getValue();
|
||||||
|
@ -92,7 +86,7 @@ public class Metrics {
|
||||||
/**
|
/**
|
||||||
* The metrics revision number
|
* The metrics revision number
|
||||||
*/
|
*/
|
||||||
private final static int REVISION = 3;
|
private final static int REVISION = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base url of the metrics domain
|
* The base url of the metrics domain
|
||||||
|
@ -172,10 +166,20 @@ public class Metrics {
|
||||||
*/
|
*/
|
||||||
public void beginMeasuringPlugin(final Plugin plugin) throws IOException {
|
public void beginMeasuringPlugin(final Plugin plugin) throws IOException {
|
||||||
// Did we opt out?
|
// Did we opt out?
|
||||||
if (configuration.getBoolean("opt-out", false)) return;
|
if (configuration.getBoolean("opt-out", false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// First tell the server about us
|
// First tell the server about us
|
||||||
postPlugin(plugin, false);
|
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
postPlugin(plugin, false);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("[Metrics] " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 20L);
|
||||||
|
|
||||||
// Ping the server in intervals
|
// Ping the server in intervals
|
||||||
plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
|
plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
|
||||||
|
@ -183,12 +187,76 @@ public class Metrics {
|
||||||
try {
|
try {
|
||||||
postPlugin(plugin, true);
|
postPlugin(plugin, true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("[ChestShop] There was an error while submitting statistics.");
|
System.out.println("[Metrics] " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, PING_INTERVAL * 1200, PING_INTERVAL * 1200);
|
}, PING_INTERVAL * 1200, PING_INTERVAL * 1200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic method that posts a plugin to the metrics website
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
*/
|
||||||
|
private void postPlugin(Plugin plugin, boolean isPing) throws IOException {
|
||||||
|
// Construct the post data
|
||||||
|
String response = "ERR No response";
|
||||||
|
StringBuilder data = new StringBuilder(10);
|
||||||
|
data.append(encode("guid")).append('=').append(encode(guid))
|
||||||
|
.append(gField("version", plugin.getDescription().getVersion()))
|
||||||
|
.append(gField("server", Bukkit.getVersion()))
|
||||||
|
.append(gField("players", String.valueOf(Bukkit.getServer().getOnlinePlayers().length)))
|
||||||
|
.append(gField("revision", String.valueOf(REVISION)));
|
||||||
|
|
||||||
|
// If we're pinging, append it
|
||||||
|
if (isPing) {
|
||||||
|
data.append(gField("ping", "true"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add any custom data (if applicable)
|
||||||
|
Set<Plotter> plotters = customData.get(plugin);
|
||||||
|
|
||||||
|
if (plotters != null) {
|
||||||
|
for (Plotter plotter : plotters) {
|
||||||
|
data.append(gField("Custom" + plotter.getColumnName(), Integer.toString(plotter.getValue())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the url
|
||||||
|
URL url = new URL(BASE_URL + String.format(REPORT_URL, plugin.getDescription().getName()));
|
||||||
|
|
||||||
|
// Connect to the website
|
||||||
|
URLConnection connection = url.openConnection();
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
|
// Write the data
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
||||||
|
writer.write(data.toString());
|
||||||
|
writer.flush();
|
||||||
|
|
||||||
|
// Now read the response
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
response = reader.readLine();
|
||||||
|
|
||||||
|
// close resources
|
||||||
|
writer.close();
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
if (response.startsWith("ERR")) {
|
||||||
|
throw new IOException(response); //Throw the exception
|
||||||
|
} else {
|
||||||
|
// Is this the first update this hour?
|
||||||
|
if (response.contains("OK This is your first update this hour")) {
|
||||||
|
if (plotters != null) {
|
||||||
|
for (Plotter plotter : plotters) {
|
||||||
|
plotter.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if (response.startsWith("OK")) - We should get "OK" followed by an optional description if everything goes right
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a field
|
* Generates a field
|
||||||
* @param name Field name
|
* @param name Field name
|
||||||
|
@ -200,56 +268,6 @@ public class Metrics {
|
||||||
return '&' + encode(name) + '=' + encode(data);
|
return '&' + encode(name) + '=' + encode(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic method that posts a plugin to the metrics website
|
|
||||||
*
|
|
||||||
* @param plugin
|
|
||||||
*/
|
|
||||||
private void postPlugin(Plugin plugin, boolean isPing) throws IOException {
|
|
||||||
// Construct the post data
|
|
||||||
String response = "ERR No response";
|
|
||||||
String data = encode("guid") + '=' + encode(guid)
|
|
||||||
+ gField("version", plugin.getDescription().getVersion())
|
|
||||||
+ gField("server", Bukkit.getVersion())
|
|
||||||
+ gField("players", String.valueOf(Bukkit.getServer().getOnlinePlayers().length))
|
|
||||||
+ gField("revision", String.valueOf(REVISION));
|
|
||||||
|
|
||||||
// If we're pinging, append it
|
|
||||||
if (isPing) {
|
|
||||||
data += gField("ping", "true");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add any custom data (if applicable)
|
|
||||||
Set<Plotter> plotters = customData.get(plugin);
|
|
||||||
|
|
||||||
if (plotters != null) {
|
|
||||||
for (Plotter plotter : plotters) {
|
|
||||||
data += gField("Custom" + plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the url
|
|
||||||
URL url = new URL(BASE_URL + String.format(REPORT_URL, plugin.getDescription().getName()));
|
|
||||||
|
|
||||||
// Connect to the website
|
|
||||||
URLConnection connection = url.openConnection();
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
// Write the data
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
|
||||||
writer.write(data);
|
|
||||||
writer.flush();
|
|
||||||
|
|
||||||
// Now read the response
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
response = reader.readLine();
|
|
||||||
|
|
||||||
// close resources
|
|
||||||
writer.close();
|
|
||||||
reader.close();
|
|
||||||
if (response.startsWith("ERR")) throw new IOException(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode text as UTF-8
|
* Encode text as UTF-8
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.Acrobot.ChestShop.Protection.Plugins;
|
||||||
|
|
||||||
|
import com.Acrobot.ChestShop.Protection.Protection;
|
||||||
|
import com.webkonsept.bukkit.simplechestlock.SCL;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Acrobot
|
||||||
|
*/
|
||||||
|
public class SCLplugin implements Protection {
|
||||||
|
public static SCL scl;
|
||||||
|
|
||||||
|
public boolean isProtected(Block block) {
|
||||||
|
return scl.chests.isLocked(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canAccess(Player player, Block block) {
|
||||||
|
return scl.chests.getOwner(block).equalsIgnoreCase(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean protect(String name, Block block) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ public class Security {
|
||||||
private static boolean thereIsAnotherSignByPlayer(Block baseBlock, Block signBlock, String shortName) {
|
private static boolean thereIsAnotherSignByPlayer(Block baseBlock, Block signBlock, String shortName) {
|
||||||
for (BlockFace bf : faces) {
|
for (BlockFace bf : faces) {
|
||||||
Block block = baseBlock.getRelative(bf);
|
Block block = baseBlock.getRelative(bf);
|
||||||
if (uSign.isSign(block) && !block.equals(signBlock) && blockBreak.getAttachedFace((Sign) block.getState()).equals(baseBlock) && !((Sign) block.getState()).getLine(0).equals(shortName))
|
if (uSign.isSign(block) && uSign.isValid((Sign) block.getState()) && !block.equals(signBlock) && blockBreak.getAttachedFace((Sign) block.getState()).equals(baseBlock) && !((Sign) block.getState()).getLine(0).equals(shortName))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -23,9 +23,9 @@ public class Shop {
|
||||||
private final ChestObject chest;
|
private final ChestObject chest;
|
||||||
|
|
||||||
public final ItemStack stock;
|
public final ItemStack stock;
|
||||||
public final int stockAmount;
|
public int stockAmount;
|
||||||
public final float buyPrice;
|
public float buyPrice;
|
||||||
public final float sellPrice;
|
public float sellPrice;
|
||||||
public final String owner;
|
public final String owner;
|
||||||
private final Sign sign;
|
private final Sign sign;
|
||||||
|
|
||||||
|
@ -55,8 +55,14 @@ public class Shop {
|
||||||
}
|
}
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
if (!Economy.hasEnough(playerName, buyPrice)) {
|
if (!Economy.hasEnough(playerName, buyPrice)) {
|
||||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY));
|
int items = calculateItemAmount(Economy.balance(playerName), true);
|
||||||
return;
|
if (!Config.getBoolean(Property.ALLOW_PARTIAL_TRANSACTIONS) || items < 1) {
|
||||||
|
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
buyPrice = (buyPrice / stockAmount) * items;
|
||||||
|
stockAmount = items;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!stockFitsPlayer(player)) {
|
if (!stockFitsPlayer(player)) {
|
||||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_INVENTORY));
|
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_INVENTORY));
|
||||||
|
@ -66,10 +72,17 @@ public class Shop {
|
||||||
String materialName = stock.getType().name();
|
String materialName = stock.getType().name();
|
||||||
|
|
||||||
if (!isAdminShop() && !hasEnoughStock()) {
|
if (!isAdminShop() && !hasEnoughStock()) {
|
||||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_STOCK));
|
int items = stockAmount(stock, durability);
|
||||||
if (!Config.getBoolean(Property.SHOW_MESSAGE_OUT_OF_STOCK)) return;
|
if (!Config.getBoolean(Property.ALLOW_PARTIAL_TRANSACTIONS) || items < 1) {
|
||||||
sendMessageToOwner(Config.getLocal(Language.NOT_ENOUGH_STOCK_IN_YOUR_SHOP).replace("%material", materialName));
|
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_STOCK));
|
||||||
return;
|
|
||||||
|
if (!Config.getBoolean(Property.SHOW_MESSAGE_OUT_OF_STOCK)) return;
|
||||||
|
sendMessageToOwner(Config.getLocal(Language.NOT_ENOUGH_STOCK_IN_YOUR_SHOP).replace("%material", materialName));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
buyPrice = (buyPrice / stockAmount) * items;
|
||||||
|
stockAmount = items;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String account = getOwnerAccount();
|
String account = getOwnerAccount();
|
||||||
|
@ -102,7 +115,7 @@ public class Shop {
|
||||||
.replace("%buyer", playerName)
|
.replace("%buyer", playerName)
|
||||||
.replace("%price", formatedPrice));
|
.replace("%price", formatedPrice));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.getBoolean(Property.BLOCK_UPDATE)) uBlock.blockUpdate(sign.getBlock());
|
if (Config.getBoolean(Property.BLOCK_UPDATE)) uBlock.blockUpdate(sign.getBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,20 +137,31 @@ public class Shop {
|
||||||
boolean accountExists = !account.isEmpty() && Economy.hasAccount(account);
|
boolean accountExists = !account.isEmpty() && Economy.hasAccount(account);
|
||||||
|
|
||||||
if (accountExists && !Economy.hasEnough(account, sellPrice)) {
|
if (accountExists && !Economy.hasEnough(account, sellPrice)) {
|
||||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY_SHOP));
|
int items = calculateItemAmount(Economy.balance(account), false);
|
||||||
return;
|
if (!Config.getBoolean(Property.ALLOW_PARTIAL_TRANSACTIONS) || items < 1) {
|
||||||
|
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY_SHOP));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
sellPrice = (sellPrice / stockAmount) * items;
|
||||||
|
stockAmount = items;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (uInventory.amount(player.getInventory(), stock, durability) < stockAmount) {
|
||||||
|
int items = uInventory.amount(player.getInventory(), stock, durability);
|
||||||
|
if (!Config.getBoolean(Property.ALLOW_PARTIAL_TRANSACTIONS) || items < 1) {
|
||||||
|
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_ITEMS_TO_SELL));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
sellPrice = (sellPrice / stockAmount) * items;
|
||||||
|
stockAmount = items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!isAdminShop() && !stockFitsChest(chest)) {
|
if (!isAdminShop() && !stockFitsChest(chest)) {
|
||||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_CHEST));
|
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_CHEST));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uInventory.amount(player.getInventory(), stock, durability) < stockAmount) {
|
|
||||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_ITEMS_TO_SELL));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (accountExists) Economy.subtract(account, sellPrice);
|
if (accountExists) Economy.subtract(account, sellPrice);
|
||||||
if (!isAdminShop()) chest.addItem(stock, stockAmount);
|
if (!isAdminShop()) chest.addItem(stock, stockAmount);
|
||||||
|
|
||||||
|
@ -180,6 +204,10 @@ public class Shop {
|
||||||
private boolean hasEnoughStock() {
|
private boolean hasEnoughStock() {
|
||||||
return chest.hasEnough(stock, stockAmount, durability);
|
return chest.hasEnough(stock, stockAmount, durability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int stockAmount(ItemStack item, short durability){
|
||||||
|
return chest.amount(item, durability);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean stockFitsPlayer(Player player) {
|
private boolean stockFitsPlayer(Player player) {
|
||||||
return uInventory.fits(player.getInventory(), stock, stockAmount, durability) <= 0;
|
return uInventory.fits(player.getInventory(), stock, stockAmount, durability) <= 0;
|
||||||
|
@ -189,6 +217,10 @@ public class Shop {
|
||||||
return chest.fits(stock, stockAmount, durability);
|
return chest.fits(stock, stockAmount, durability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int calculateItemAmount(double money, boolean buy) {
|
||||||
|
return (int) Math.floor(money / ((buy ? buyPrice : sellPrice) / stockAmount));
|
||||||
|
}
|
||||||
|
|
||||||
private void sendMessageToOwner(String msg) {
|
private void sendMessageToOwner(String msg) {
|
||||||
if (!isAdminShop()) {
|
if (!isAdminShop()) {
|
||||||
Player player = ChestShop.getBukkitServer().getPlayer(owner);
|
Player player = ChestShop.getBukkitServer().getPlayer(owner);
|
||||||
|
|
|
@ -6,6 +6,8 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
|
@ -45,29 +47,24 @@ 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);
|
if (Config.getBoolean(Property.STACK_UNSTACKABLES)) return addAndStackTo64(inv, item, amount);
|
||||||
/*ItemStack itemstack = new ItemStack(item.getType(), amount, item.getDurability());
|
ItemStack itemstack = new ItemStack(item.getType(), amount, item.getDurability());
|
||||||
itemstack.addEnchantments(item.getEnchantments());
|
itemstack.addEnchantments(item.getEnchantments());
|
||||||
|
|
||||||
HashMap<Integer, ItemStack> items = inv.addItem(itemstack);
|
HashMap<Integer, ItemStack> items = inv.addItem(itemstack);
|
||||||
amount = 0;
|
amount = 0;
|
||||||
for (ItemStack toAdd : items.values()) amount += toAdd.getAmount();
|
for (ItemStack toAdd : items.values()) amount += toAdd.getAmount();
|
||||||
|
|
||||||
return amount;*/ //TODO: revert when Bukkit releases new RB
|
return amount;
|
||||||
|
|
||||||
return addManually(inv, item, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int addManually(Inventory inv, ItemStack item, int amount) {
|
|
||||||
return addManually(inv, item, amount, (item.getType() != Material.POTION ? item.getType().getMaxStackSize() : 1)); //TODO Change it when it's repaired in Bukkit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int addAndStackTo64(Inventory inv, ItemStack item, int amount) {
|
public static int addAndStackTo64(Inventory inv, ItemStack item, int amount) {
|
||||||
return addManually(inv, item, amount, 64);
|
return addManually(inv, item, amount, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int addManually(Inventory inv, ItemStack item, int amount, int max){
|
public static int addManually(Inventory inv, ItemStack item, int amount, int max) {
|
||||||
if (amount <= 0) return 0;
|
if (amount <= 0) return 0;
|
||||||
|
|
||||||
for (int slot = 0; slot < inv.getSize() && amount > 0; slot++){
|
for (int slot = 0; slot < inv.getSize() && amount > 0; slot++) {
|
||||||
ItemStack curItem = inv.getItem(slot);
|
ItemStack curItem = inv.getItem(slot);
|
||||||
ItemStack dupe = item.clone();
|
ItemStack dupe = item.clone();
|
||||||
|
|
||||||
|
@ -101,7 +98,6 @@ 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) {
|
||||||
int maxStackSize = (Config.getBoolean(Property.STACK_UNSTACKABLES) ? 64 : item.getType().getMaxStackSize());
|
int maxStackSize = (Config.getBoolean(Property.STACK_UNSTACKABLES) ? 64 : item.getType().getMaxStackSize());
|
||||||
if (item.getType() == Material.POTION) maxStackSize = 1; //TODO Bukkit, can you fix that?
|
|
||||||
|
|
||||||
int amountLeft = amount;
|
int amountLeft = amount;
|
||||||
|
|
||||||
|
@ -122,8 +118,8 @@ public class uInventory {
|
||||||
|
|
||||||
return amountLeft;
|
return amountLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean equals(ItemStack i, ItemStack item, short durability){
|
private static boolean equals(ItemStack i, ItemStack item, short durability) {
|
||||||
return i != null
|
return i != null
|
||||||
&& i.getType() == item.getType()
|
&& i.getType() == item.getType()
|
||||||
&& i.getEnchantments().equals(item.getEnchantments())
|
&& i.getEnchantments().equals(item.getEnchantments())
|
||||||
|
|
|
@ -10,7 +10,7 @@ public class uNumber {
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(string);
|
Integer.parseInt(string);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (NumberFormatException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public class uNumber {
|
||||||
try {
|
try {
|
||||||
Float.parseFloat(string);
|
Float.parseFloat(string);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (NumberFormatException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class uNumber {
|
||||||
try {
|
try {
|
||||||
Double.parseDouble(string);
|
Double.parseDouble(string);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (NumberFormatException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.Acrobot.ChestShop.Config.Property;
|
||||||
import com.palmergames.bukkit.towny.NotRegisteredException;
|
import com.palmergames.bukkit.towny.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.TownBlockType;
|
import com.palmergames.bukkit.towny.object.TownBlockType;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,12 +22,16 @@ public class uTowny {
|
||||||
return isResident(player, chestLocation) && isResident(player, signLocation);
|
return isResident(player, chestLocation) && isResident(player, signLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNotInTheWilderness(Location chestLocation, Location signLocation) {
|
public static boolean isInWilderness(Location chestLocation, Location signLocation) {
|
||||||
return !uSign.towny.getTownyUniverse().isWilderness(chestLocation.getBlock()) && !uSign.towny.getTownyUniverse().isWilderness(signLocation.getBlock());
|
return isInWilderness(chestLocation.getBlock()) || isInWilderness(signLocation.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isInWilderness(Block block){
|
||||||
|
return uSign.towny.getTownyUniverse().isWilderness(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canBuild(Player player, Location chestLocation, Location signLocation) {
|
public static boolean canBuild(Player player, Location chestLocation, Location signLocation) {
|
||||||
return uSign.towny == null || !Config.getBoolean(Property.TOWNY_INTEGRATION) || (isNotInTheWilderness(chestLocation, signLocation) && isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation));
|
return uSign.towny == null || !Config.getBoolean(Property.TOWNY_INTEGRATION) || (!isInWilderness(chestLocation, signLocation) && isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isBlockOwner(Player player, Location location) {
|
private static boolean isBlockOwner(Player player, Location location) {
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class BOSE7 implements Method {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodAccount getAccount(String name) {
|
public MethodAccount getAccount(String name) {
|
||||||
if(!hasAccount(name))
|
if(!hasAccount(name))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new BOSEAccount(name, this.BOSEconomy);
|
return new BOSEAccount(name, this.BOSEconomy);
|
||||||
|
@ -98,7 +98,7 @@ public class BOSE7 implements Method {
|
||||||
BOSEconomy = (BOSEconomy)plugin;
|
BOSEconomy = (BOSEconomy)plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BOSEAccount implements MethodAccount {
|
public static class BOSEAccount implements MethodAccount {
|
||||||
private String name;
|
private String name;
|
||||||
private BOSEconomy BOSEconomy;
|
private BOSEconomy BOSEconomy;
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ public class BOSE7 implements Method {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BOSEBankAccount implements MethodBankAccount, MethodAccount {
|
public static class BOSEBankAccount implements MethodBankAccount, MethodAccount {
|
||||||
private String bank;
|
private String bank;
|
||||||
private BOSEconomy BOSEconomy;
|
private BOSEconomy BOSEconomy;
|
||||||
|
|
||||||
|
|
11
plugin.yml
11
plugin.yml
|
@ -2,7 +2,7 @@ name: ChestShop
|
||||||
|
|
||||||
main: com.Acrobot.ChestShop.ChestShop
|
main: com.Acrobot.ChestShop.ChestShop
|
||||||
|
|
||||||
version: 3.34
|
version: 3.35
|
||||||
|
|
||||||
|
|
||||||
author: Acrobot
|
author: Acrobot
|
||||||
|
@ -10,7 +10,8 @@ description: >
|
||||||
A chest shop for economy plugins.
|
A chest shop for economy plugins.
|
||||||
|
|
||||||
|
|
||||||
softdepend: [Permissions, LWC, Lockette, Deadbolt, OddItem, Towny, WorldGuard, Vault, Heroes]
|
softdepend: [Permissions, LWC, Lockette, Deadbolt, OddItem, Towny, WorldGuard, Vault, Heroes,
|
||||||
|
iConomy, BOSEconomy, Essentials, 3co, MultiCurrency, Currency, SimpleChestLock]
|
||||||
commands:
|
commands:
|
||||||
iteminfo:
|
iteminfo:
|
||||||
aliases: [iinfo]
|
aliases: [iinfo]
|
||||||
|
@ -106,7 +107,7 @@ permissions:
|
||||||
ChestShop.shop.create.292: true #IronHoe
|
ChestShop.shop.create.292: true #IronHoe
|
||||||
ChestShop.shop.create.goldgrade:
|
ChestShop.shop.create.goldgrade:
|
||||||
description: Allows to create a shop that sells gold gear
|
description: Allows to create a shop that sells gold gear
|
||||||
children:
|
children:
|
||||||
ChestShop.shop.create.314: true #GoldHelm
|
ChestShop.shop.create.314: true #GoldHelm
|
||||||
ChestShop.shop.create.315: true #GoldChestplate
|
ChestShop.shop.create.315: true #GoldChestplate
|
||||||
ChestShop.shop.create.316: true #GoldLeggings
|
ChestShop.shop.create.316: true #GoldLeggings
|
||||||
|
@ -118,7 +119,7 @@ permissions:
|
||||||
ChestShop.shop.create.294: true #GoldHoe
|
ChestShop.shop.create.294: true #GoldHoe
|
||||||
ChestShop.shop.create.stonegrade:
|
ChestShop.shop.create.stonegrade:
|
||||||
description: Allows to create a shop that sells stone tools and chain armor
|
description: Allows to create a shop that sells stone tools and chain armor
|
||||||
children:
|
children:
|
||||||
ChestShop.shop.create.302: true #ChainHelm
|
ChestShop.shop.create.302: true #ChainHelm
|
||||||
ChestShop.shop.create.303: true #ChainChestplate
|
ChestShop.shop.create.303: true #ChainChestplate
|
||||||
ChestShop.shop.create.304: true #ChainLeggings
|
ChestShop.shop.create.304: true #ChainLeggings
|
||||||
|
@ -130,7 +131,7 @@ permissions:
|
||||||
ChestShop.shop.create.291: true #StoneHoe
|
ChestShop.shop.create.291: true #StoneHoe
|
||||||
ChestShop.shop.create.woodgrade:
|
ChestShop.shop.create.woodgrade:
|
||||||
description: Allows to create a shop that sells wood tools and leather armor
|
description: Allows to create a shop that sells wood tools and leather armor
|
||||||
children:
|
children:
|
||||||
ChestShop.shop.create.298: true #LeatherHelm
|
ChestShop.shop.create.298: true #LeatherHelm
|
||||||
ChestShop.shop.create.299: true #LeatherChestplate
|
ChestShop.shop.create.299: true #LeatherChestplate
|
||||||
ChestShop.shop.create.300: true #LeatherLeggings
|
ChestShop.shop.create.300: true #LeatherLeggings
|
||||||
|
|
Loading…
Reference in New Issue