mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-02-21 12:31:43 +01:00
- Fixed >64 item selling/buying
- Fixed block destroying - Broke signChange into more methods
This commit is contained in:
parent
77bbf5de00
commit
0418629062
@ -30,7 +30,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ChestShop extends JavaPlugin {
|
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 EbeanServer DB;
|
||||||
|
|
||||||
private static PluginDescriptionFile description;
|
private static PluginDescriptionFile description;
|
||||||
@ -45,6 +45,9 @@ public class ChestShop extends JavaPlugin {
|
|||||||
//Register our events
|
//Register our events
|
||||||
blockBreak blockBreak = new blockBreak();
|
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_BREAK, blockBreak, Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PLACE, new blockPlace(), 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);
|
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);
|
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!
|
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) { //Now set up our database for storing transactions!
|
||||||
setupDB();
|
setupDB();
|
||||||
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L);
|
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L);
|
||||||
|
@ -11,10 +11,10 @@ import java.io.FileWriter;
|
|||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class Config {
|
public class Config {
|
||||||
private static File configFile = new File(ChestShop.folder, "config.yml");
|
private static final File configFile = new File(ChestShop.folder, "config.yml");
|
||||||
private static File langFile = new File(ChestShop.folder, "local.yml");
|
private static final File langFile = new File(ChestShop.folder, "local.yml");
|
||||||
private static Configuration config = new Configuration(configFile);
|
private static final Configuration config = new Configuration(configFile);
|
||||||
private static Configuration language = new Configuration(langFile);
|
private static final Configuration language = new Configuration(langFile);
|
||||||
|
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
if(!ChestShop.folder.exists()) ChestShop.folder.mkdir();
|
if(!ChestShop.folder.exists()) ChestShop.folder.mkdir();
|
||||||
|
@ -22,16 +22,24 @@ public class blockBreak extends BlockListener {
|
|||||||
if (uSign.isSign(block)) block.getState().update();
|
if (uSign.isSign(block)) block.getState().update();
|
||||||
|
|
||||||
Sign sign = uBlock.findRestrictedSign(block);
|
Sign sign = uBlock.findRestrictedSign(block);
|
||||||
if (sign != null) return true;
|
if (sign != null && getAttachedFace(sign) == block) return true;
|
||||||
|
|
||||||
sign = uBlock.findSign(block);
|
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) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (cancellingBlockBreak(event.getBlock(), event.getPlayer())) event.setCancelled(true);
|
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) {
|
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||||
for (Block b : event.getBlocks()) {
|
for (Block b : event.getBlocks()) {
|
||||||
if (cancellingBlockBreak(b, null)) {
|
if (cancellingBlockBreak(b, null)) {
|
||||||
@ -42,6 +50,6 @@ public class blockBreak extends BlockListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class pluginEnable extends ServerListener {
|
|||||||
public static final Methods methods = new Methods(Config.getPreferred());
|
public static final Methods methods = new Methods(Config.getPreferred());
|
||||||
private static final String lineStart = "[ChestShop] ";
|
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",
|
"Permissions",
|
||||||
"LWC",
|
"LWC",
|
||||||
"Lockette",
|
"Lockette",
|
||||||
|
@ -74,22 +74,11 @@ public class signChange extends BlockListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setLine(2, thirdLine);
|
event.setLine(2, thirdLine);
|
||||||
|
event.setLine(3, formatFourthLine(line[3], mat));
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
Chest chest = uBlock.findChest(signBlock);
|
Chest chest = uBlock.findChest(signBlock);
|
||||||
|
|
||||||
line = event.getLines();
|
boolean isAdminShop = uSign.isAdminShop(event.getLine(0));
|
||||||
boolean isAdminShop = uSign.isAdminShop(line[0]);
|
|
||||||
if (!isAdminShop) {
|
if (!isAdminShop) {
|
||||||
if (chest == null) {
|
if (chest == null) {
|
||||||
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
|
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
|
||||||
@ -160,6 +149,20 @@ public class signChange extends BlockListener {
|
|||||||
return (thirdLine.length() > 15 ? null : thirdLine);
|
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) {
|
private static boolean formatFirstLine(String line1, Player player) {
|
||||||
return line1.isEmpty() ||
|
return line1.isEmpty() ||
|
||||||
(!line1.equals(uLongName.stripName(player.getName())) && !Permission.has(player, Permission.ADMIN));
|
(!line1.equals(uLongName.stripName(player.getName())) && !Permission.has(player, Permission.ADMIN));
|
||||||
|
@ -4,7 +4,6 @@ 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.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,28 +46,13 @@ 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);
|
||||||
|
|
||||||
int maxStackSize = item.getType().getMaxStackSize();
|
ItemStack itemToAdd = new ItemStack(item.getType(), amount, item.getDurability());
|
||||||
|
HashMap<Integer, ItemStack> items = inv.addItem(itemToAdd);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
amount = 0;
|
amount = 0;
|
||||||
for (ItemStack itemToAdd : items) amount += (!inv.addItem(itemToAdd).isEmpty() ? itemToAdd.getAmount() : 0);
|
for(ItemStack toAdd : items.values()){
|
||||||
|
amount += toAdd.getAmount();
|
||||||
|
}
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import java.io.File;
|
|||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class uLongName {
|
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) {
|
public static String getName(final String shortName) {
|
||||||
return config.getString(shortName, shortName);
|
return config.getString(shortName, shortName);
|
||||||
|
@ -68,7 +68,7 @@ public class uSign {
|
|||||||
|
|
||||||
if (uNumber.isFloat(split[part])) {
|
if (uNumber.isFloat(split[part])) {
|
||||||
Float price = Float.parseFloat(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;
|
} else if (split[part].equals("free")) return 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ public abstract class Database {
|
|||||||
//Found a table, so get its name and remember the line it has been encountered on
|
//Found a table, so get its name and remember the line it has been encountered on
|
||||||
currentTable = currentLine.split(" ", 4)[2];
|
currentTable = currentLine.split(" ", 4)[2];
|
||||||
foundTables.put(currentLine.split(" ", 3)[2], scriptLines.size() - 1);
|
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
|
//Found the end of a table definition, so update the entry
|
||||||
int index = scriptLines.size() - 1;
|
int index = scriptLines.size() - 1;
|
||||||
foundTables.put(currentTable, index);
|
foundTables.put(currentTable, index);
|
||||||
|
@ -58,7 +58,7 @@ public class iCo4 implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatible(Plugin plugin) {
|
public boolean isCompatible(Plugin plugin) {
|
||||||
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin.getDescription().getVersion().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) {
|
public void setPlugin(Plugin plugin) {
|
||||||
|
@ -2,7 +2,7 @@ name: ChestShop
|
|||||||
|
|
||||||
main: com.Acrobot.ChestShop.ChestShop
|
main: com.Acrobot.ChestShop.ChestShop
|
||||||
|
|
||||||
version: 3.01
|
version: 3.02
|
||||||
|
|
||||||
|
|
||||||
author: Acrobot
|
author: Acrobot
|
||||||
|
Loading…
Reference in New Issue
Block a user