- Fixed >64 item selling/buying

- Fixed block destroying
- Broke signChange into more methods
This commit is contained in:
Acrobot 2011-08-26 23:12:32 +02:00
parent 77bbf5de00
commit 0418629062
12 changed files with 48 additions and 53 deletions

View File

@ -30,7 +30,7 @@ import java.util.List;
*/
public class ChestShop extends JavaPlugin {
public static File folder = new File("plugins/ChestShop");
public static final File folder = new File("plugins/ChestShop");
private static EbeanServer DB;
private static PluginDescriptionFile description;
@ -45,6 +45,9 @@ public class ChestShop extends JavaPlugin {
//Register our events
blockBreak blockBreak = new blockBreak();
description = this.getDescription(); //Description of the plugin
server = getServer(); //Setting out server variable
pm.registerEvent(Event.Type.BLOCK_BREAK, blockBreak, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, new blockPlace(), Event.Priority.Normal, this);
pm.registerEvent(Event.Type.SIGN_CHANGE, new signChange(), Event.Priority.Normal, this);
@ -58,9 +61,6 @@ public class ChestShop extends JavaPlugin {
pm.registerEvent(Event.Type.ENTITY_EXPLODE, new entityExplode(), Event.Priority.Normal, this);
}
description = this.getDescription(); //Description of the plugin
server = getServer(); //Setting out server variable
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) { //Now set up our database for storing transactions!
setupDB();
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L);

View File

@ -11,10 +11,10 @@ import java.io.FileWriter;
* @author Acrobot
*/
public class Config {
private static File configFile = new File(ChestShop.folder, "config.yml");
private static File langFile = new File(ChestShop.folder, "local.yml");
private static Configuration config = new Configuration(configFile);
private static Configuration language = new Configuration(langFile);
private static final File configFile = new File(ChestShop.folder, "config.yml");
private static final File langFile = new File(ChestShop.folder, "local.yml");
private static final Configuration config = new Configuration(configFile);
private static final Configuration language = new Configuration(langFile);
public static void setUp() {
if(!ChestShop.folder.exists()) ChestShop.folder.mkdir();

View File

@ -22,16 +22,24 @@ public class blockBreak extends BlockListener {
if (uSign.isSign(block)) block.getState().update();
Sign sign = uBlock.findRestrictedSign(block);
if (sign != null) return true;
if (sign != null && getAttachedFace(sign) == block) return true;
sign = uBlock.findSign(block);
return sign != null && (player == null || (!uLongName.stripName(player.getName()).equals(sign.getLine(0))));
return sign != null && getAttachedFace(sign) == block && playerIsNotOwner(player, sign);
}
public void onBlockBreak(BlockBreakEvent event) {
if (cancellingBlockBreak(event.getBlock(), event.getPlayer())) event.setCancelled(true);
}
private static Block getAttachedFace(Sign sign){
return sign.getBlock().getRelative(((org.bukkit.material.Sign) sign.getData()).getAttachedFace());
}
private static boolean playerIsNotOwner(Player player, Sign sign){
return player == null || !uLongName.stripName(player.getName()).equals(sign.getLine(0));
}
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
for (Block b : event.getBlocks()) {
if (cancellingBlockBreak(b, null)) {
@ -42,6 +50,6 @@ public class blockBreak extends BlockListener {
}
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if (cancellingBlockBreak(event.getRetractLocation().getBlock(), null)) event.setCancelled(true);
if (!uSign.isSign(event.getRetractLocation().getBlock()) && cancellingBlockBreak(event.getRetractLocation().getBlock(), null)) event.setCancelled(true);
}
}

View File

@ -68,7 +68,7 @@ public class playerInteract extends PlayerListener {
player.sendMessage(Config.getLocal(Language.ACCESS_DENIED));
return;
}
Action buy = (Config.getBoolean(Property.REVERSE_BUTTONS) ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK);
if (action == buy) {

View File

@ -30,7 +30,7 @@ public class pluginEnable extends ServerListener {
public static final Methods methods = new Methods(Config.getPreferred());
private static final String lineStart = "[ChestShop] ";
private static List<String> pluginsToLoad = new LinkedList<String>(Arrays.asList(
private static final List<String> pluginsToLoad = new LinkedList<String>(Arrays.asList(
"Permissions",
"LWC",
"Lockette",

View File

@ -74,22 +74,11 @@ public class signChange extends BlockListener {
return;
}
event.setLine(2, thirdLine);
String[] split = line[3].split(":");
if (uNumber.isInteger(split[0])) {
String materialLine = mat.name();
if (split.length == 2) {
int maxLength = (15 - split[1].length() - 1);
if (materialLine.length() > maxLength) materialLine = materialLine.substring(0, maxLength);
materialLine = materialLine + ':' + split[1];
}
event.setLine(3, materialLine);
}
event.setLine(3, formatFourthLine(line[3], mat));
Chest chest = uBlock.findChest(signBlock);
line = event.getLines();
boolean isAdminShop = uSign.isAdminShop(line[0]);
boolean isAdminShop = uSign.isAdminShop(event.getLine(0));
if (!isAdminShop) {
if (chest == null) {
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
@ -160,6 +149,20 @@ public class signChange extends BlockListener {
return (thirdLine.length() > 15 ? null : thirdLine);
}
private static String formatFourthLine(String fourthLine, Material material){
String[] split = fourthLine.split(":");
if (uNumber.isInteger(split[0])) {
String materialLine = material.name();
if (split.length == 2) {
int maxLength = (14 - split[1].length()); //15 - length - 1
if (materialLine.length() > maxLength) materialLine = materialLine.substring(0, maxLength);
materialLine = materialLine + ':' + split[1];
}
return materialLine;
}
return fourthLine;
}
private static boolean formatFirstLine(String line1, Player player) {
return line1.isEmpty() ||
(!line1.equals(uLongName.stripName(player.getName())) && !Permission.has(player, Permission.ADMIN));

View File

@ -4,7 +4,6 @@ import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
/**
@ -47,28 +46,13 @@ public class uInventory {
public static int add(Inventory inv, ItemStack item, int amount) {
amount = (amount > 0 ? amount : 1);
int maxStackSize = item.getType().getMaxStackSize();
if (amount <= maxStackSize) {
item.setAmount(amount);
HashMap<Integer, ItemStack> left = inv.addItem(item);
return (left.isEmpty() ? 0 : left.get(0).getAmount());
}
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
for (int i = 0; i < Math.ceil(amount / maxStackSize); i++) {
if (amount <= maxStackSize) {
item.setAmount(amount);
return 0;
} else {
item.setAmount(maxStackSize);
items.add(item);
}
}
ItemStack itemToAdd = new ItemStack(item.getType(), amount, item.getDurability());
HashMap<Integer, ItemStack> items = inv.addItem(itemToAdd);
amount = 0;
for (ItemStack itemToAdd : items) amount += (!inv.addItem(itemToAdd).isEmpty() ? itemToAdd.getAmount() : 0);
for(ItemStack toAdd : items.values()){
amount += toAdd.getAmount();
}
return amount;
}

View File

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

View File

@ -68,7 +68,7 @@ public class uSign {
if (uNumber.isFloat(split[part])) {
Float price = Float.parseFloat(split[part]);
return (price != 0 ? price : -1);
return (price > 0 ? price : -1);
} else if (split[part].equals("free")) return 0;
return -1;
}

View File

@ -247,7 +247,7 @@ public abstract class Database {
//Found a table, so get its name and remember the line it has been encountered on
currentTable = currentLine.split(" ", 4)[2];
foundTables.put(currentLine.split(" ", 3)[2], scriptLines.size() - 1);
} else if (currentLine.startsWith(";") && currentTable != null && !currentTable.isEmpty()) {
} else if (currentLine.length() > 0 && currentLine.charAt(0) == ';' && currentTable != null && !currentTable.isEmpty()) {
//Found the end of a table definition, so update the entry
int index = scriptLines.size() - 1;
foundTables.put(currentTable, index);

View File

@ -58,7 +58,7 @@ public class iCo4 implements Method {
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin.getDescription().getVersion().startsWith("4") && plugin instanceof iConomy;
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin.getDescription().getVersion().length() > 0 && plugin.getDescription().getVersion().charAt(0) == '4' && plugin instanceof iConomy;
}
public void setPlugin(Plugin plugin) {

View File

@ -2,7 +2,7 @@ name: ChestShop
main: com.Acrobot.ChestShop.ChestShop
version: 3.01
version: 3.02
author: Acrobot