mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-11-22 01:58:54 +00:00
格式化代码 修复商店创建BUG(7老板)...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
062534af1f
commit
b00e35dc17
@ -14,32 +14,32 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandBuy extends BaseCommand {
|
public class CommandBuy extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandBuy(final QuickShop plugin) {
|
public CommandBuy(final QuickShop plugin) {
|
||||||
super("b");
|
super("b");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setOnlyPlayerExecutable();
|
setOnlyPlayerExecutable();
|
||||||
setPermission("quickshop.create.buy");
|
setPermission("quickshop.create.buy");
|
||||||
setDescription(MsgUtil.p("command.description.buy"));
|
setDescription(MsgUtil.p("command.description.buy"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null && shop.getOwner().equals(((Player) sender).getName())) {
|
if (shop != null && shop.getOwner().equals(((Player) sender).getName())) {
|
||||||
shop.setShopType(ShopType.BUYING);
|
shop.setShopType(ShopType.BUYING);
|
||||||
shop.setSignText();
|
shop.setSignText();
|
||||||
shop.update();
|
shop.update();
|
||||||
sender.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
|
sender.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,37 +13,37 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandClean extends BaseCommand {
|
public class CommandClean extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandClean(final QuickShop plugin) {
|
public CommandClean(final QuickShop plugin) {
|
||||||
super("c");
|
super("c");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setPermission("quickshop.clean");
|
setPermission("quickshop.clean");
|
||||||
setDescription(MsgUtil.p("command.description.clean"));
|
setDescription(MsgUtil.p("command.description.clean"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
sender.sendMessage(MsgUtil.p("command.cleaning"));
|
sender.sendMessage(MsgUtil.p("command.cleaning"));
|
||||||
final Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
|
final Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (shIt.hasNext()) {
|
while (shIt.hasNext()) {
|
||||||
final Shop shop = shIt.next();
|
final Shop shop = shIt.next();
|
||||||
try {
|
try {
|
||||||
if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) {
|
if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) {
|
||||||
final ContainerShop cs = (ContainerShop) shop;
|
final ContainerShop cs = (ContainerShop) shop;
|
||||||
if (cs.isDoubleShop()) {
|
if (cs.isDoubleShop()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
shIt.remove(); // Is selling, but has no stock, and is a chest shop, but is not a double shop. Can be deleted safely.
|
shIt.remove(); // Is selling, but has no stock, and is a chest shop, but is not a double shop. Can be deleted safely.
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} catch (final IllegalStateException e) {
|
} catch (final IllegalStateException e) {
|
||||||
// shIt.remove(); // The shop is not there anymore, remove it
|
// shIt.remove(); // The shop is not there anymore, remove it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MsgUtil.clean();
|
MsgUtil.clean();
|
||||||
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
|
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,33 +14,33 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandEmpty extends BaseCommand {
|
public class CommandEmpty extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandEmpty(final QuickShop plugin) {
|
public CommandEmpty(final QuickShop plugin) {
|
||||||
super("e");
|
super("e");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setPermission("quickshop.empty");
|
setPermission("quickshop.empty");
|
||||||
setDescription(MsgUtil.p("command.description.empty"));
|
setDescription(MsgUtil.p("command.description.empty"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
if (shop instanceof ContainerShop) {
|
if (shop instanceof ContainerShop) {
|
||||||
final ContainerShop cs = (ContainerShop) shop;
|
final ContainerShop cs = (ContainerShop) shop;
|
||||||
cs.getInventory().clear();
|
cs.getInventory().clear();
|
||||||
sender.sendMessage(MsgUtil.p("empty-success"));
|
sender.sendMessage(MsgUtil.p("empty-success"));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,64 +16,64 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandExport extends BaseCommand {
|
public class CommandExport extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandExport(final QuickShop plugin) {
|
public CommandExport(final QuickShop plugin) {
|
||||||
super("export");
|
super("export");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setPermission("quickshop.export");
|
setPermission("quickshop.export");
|
||||||
setMinimumArguments(1);
|
setMinimumArguments(1);
|
||||||
setPossibleArguments("[mysql|sqlite]");
|
setPossibleArguments("[mysql|sqlite]");
|
||||||
setDescription(MsgUtil.p("command.description.export"));
|
setDescription(MsgUtil.p("command.description.export"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final String type = args[0].toLowerCase();
|
final String type = args[0].toLowerCase();
|
||||||
if (type.startsWith("mysql")) {
|
if (type.startsWith("mysql")) {
|
||||||
if (plugin.getDB().getCore() instanceof MySQLCore) {
|
if (plugin.getDB().getCore() instanceof MySQLCore) {
|
||||||
sender.sendMessage(ChatColor.RED + "数据已保存在 MySQL 无需转换!");
|
sender.sendMessage(ChatColor.RED + "数据已保存在 MySQL 无需转换!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("database");
|
final ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("database");
|
||||||
final String host = cfg.getString("host");
|
final String host = cfg.getString("host");
|
||||||
final String port = cfg.getString("port");
|
final String port = cfg.getString("port");
|
||||||
final String user = cfg.getString("user");
|
final String user = cfg.getString("user");
|
||||||
final String pass = cfg.getString("password");
|
final String pass = cfg.getString("password");
|
||||||
final String name = cfg.getString("database");
|
final String name = cfg.getString("database");
|
||||||
final MySQLCore core = new MySQLCore(host, user, pass, name, port);
|
final MySQLCore core = new MySQLCore(host, user, pass, name, port);
|
||||||
Database target;
|
Database target;
|
||||||
try {
|
try {
|
||||||
target = new Database(core);
|
target = new Database(core);
|
||||||
QuickShop.instance.getDB().copyTo(target);
|
QuickShop.instance.getDB().copyTo(target);
|
||||||
sender.sendMessage(ChatColor.GREEN + "导出成功 - 数据已保存至 MySQL " + user + "@" + host + "." + name);
|
sender.sendMessage(ChatColor.GREEN + "导出成功 - 数据已保存至 MySQL " + user + "@" + host + "." + name);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
sender.sendMessage(ChatColor.RED + "导出数据到 MySQL 失败 " + user + "@" + host + "." + name + ChatColor.DARK_RED + " 由于: " + e.getMessage());
|
sender.sendMessage(ChatColor.RED + "导出数据到 MySQL 失败 " + user + "@" + host + "." + name + ChatColor.DARK_RED + " 由于: " + e.getMessage());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type.startsWith("sql") || type.contains("file")) {
|
if (type.startsWith("sql") || type.contains("file")) {
|
||||||
if (plugin.getDB().getCore() instanceof SQLiteCore) {
|
if (plugin.getDB().getCore() instanceof SQLiteCore) {
|
||||||
sender.sendMessage(ChatColor.RED + "数据已保存在 SQLite 无需转换!");
|
sender.sendMessage(ChatColor.RED + "数据已保存在 SQLite 无需转换!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final File file = new File(plugin.getDataFolder(), "shops.db");
|
final File file = new File(plugin.getDataFolder(), "shops.db");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
if (file.delete() == false) {
|
if (file.delete() == false) {
|
||||||
sender.sendMessage(ChatColor.RED + "警告: 删除旧的数据文件 shops.db 失败. 可能会导致部分信息错误.");
|
sender.sendMessage(ChatColor.RED + "警告: 删除旧的数据文件 shops.db 失败. 可能会导致部分信息错误.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final SQLiteCore core = new SQLiteCore(file);
|
final SQLiteCore core = new SQLiteCore(file);
|
||||||
try {
|
try {
|
||||||
final Database target = new Database(core);
|
final Database target = new Database(core);
|
||||||
QuickShop.instance.getDB().copyTo(target);
|
QuickShop.instance.getDB().copyTo(target);
|
||||||
sender.sendMessage(ChatColor.GREEN + "导出成功 - 数据已保存至 SQLite: " + file.toString());
|
sender.sendMessage(ChatColor.GREEN + "导出成功 - 数据已保存至 SQLite: " + file.toString());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
sender.sendMessage(ChatColor.RED + "导出数据到 SQLite: " + file.toString() + " 失败 由于: " + e.getMessage());
|
sender.sendMessage(ChatColor.RED + "导出数据到 SQLite: " + file.toString() + " 失败 由于: " + e.getMessage());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,92 +17,92 @@ import cn.citycraft.PluginHelper.commands.BaseCommand;
|
|||||||
import cn.citycraft.PluginHelper.utils.StringUtil;
|
import cn.citycraft.PluginHelper.utils.StringUtil;
|
||||||
|
|
||||||
public class CommandFind extends BaseCommand {
|
public class CommandFind extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandFind(final QuickShop plugin) {
|
public CommandFind(final QuickShop plugin) {
|
||||||
super("f");
|
super("f");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setMinimumArguments(2);
|
setMinimumArguments(2);
|
||||||
setOnlyPlayerExecutable();
|
setOnlyPlayerExecutable();
|
||||||
setPermission("quickshop.find");
|
setPermission("quickshop.find");
|
||||||
setDescription(MsgUtil.p("command.description.find"));
|
setDescription(MsgUtil.p("command.description.find"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
String lookFor = StringUtil.consolidateStrings(args, 0);
|
String lookFor = StringUtil.consolidateStrings(args, 0);
|
||||||
lookFor = lookFor.toLowerCase();
|
lookFor = lookFor.toLowerCase();
|
||||||
final Player p = (Player) sender;
|
final Player p = (Player) sender;
|
||||||
final Location loc = p.getEyeLocation().clone();
|
final Location loc = p.getEyeLocation().clone();
|
||||||
final double minDistance = plugin.getConfig().getInt("shop.find-distance");
|
final double minDistance = plugin.getConfig().getInt("shop.find-distance");
|
||||||
double minDistanceSquared = minDistance * minDistance;
|
double minDistanceSquared = minDistance * minDistance;
|
||||||
final int chunkRadius = (int) minDistance / 16 + 1;
|
final int chunkRadius = (int) minDistance / 16 + 1;
|
||||||
Shop closest = null;
|
Shop closest = null;
|
||||||
final Chunk c = loc.getChunk();
|
final Chunk c = loc.getChunk();
|
||||||
for (int x = -chunkRadius + c.getX(); x < chunkRadius + c.getX(); x++) {
|
for (int x = -chunkRadius + c.getX(); x < chunkRadius + c.getX(); x++) {
|
||||||
for (int z = -chunkRadius + c.getZ(); z < chunkRadius + c.getZ(); z++) {
|
for (int z = -chunkRadius + c.getZ(); z < chunkRadius + c.getZ(); z++) {
|
||||||
final Chunk d = c.getWorld().getChunkAt(x, z);
|
final Chunk d = c.getWorld().getChunkAt(x, z);
|
||||||
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(d);
|
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(d);
|
||||||
if (inChunk == null) {
|
if (inChunk == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (final Shop shop : inChunk.values()) {
|
for (final Shop shop : inChunk.values()) {
|
||||||
if (shop.getDataName().toLowerCase().contains(lookFor) && shop.getLocation().distanceSquared(loc) < minDistanceSquared) {
|
if (shop.getDataName().toLowerCase().contains(lookFor) && shop.getLocation().distanceSquared(loc) < minDistanceSquared) {
|
||||||
closest = shop;
|
closest = shop;
|
||||||
minDistanceSquared = shop.getLocation().distanceSquared(loc);
|
minDistanceSquared = shop.getLocation().distanceSquared(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (closest == null) {
|
if (closest == null) {
|
||||||
sender.sendMessage(MsgUtil.p("no-nearby-shop", args[0]));
|
sender.sendMessage(MsgUtil.p("no-nearby-shop", args[0]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location lookat = closest.getLocation().clone().add(0.5, 0.5, 0.5);
|
final Location lookat = closest.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
// Hack fix to make /qs find not used by /back
|
// Hack fix to make /qs find not used by /back
|
||||||
p.teleport(this.lookAt(loc, lookat).add(0, -1.62, 0), TeleportCause.PLUGIN);
|
p.teleport(this.lookAt(loc, lookat).add(0, -1.62, 0), TeleportCause.PLUGIN);
|
||||||
p.sendMessage(MsgUtil.p("nearby-shop-this-way", "" + (int) Math.floor(Math.sqrt(minDistanceSquared))));
|
p.sendMessage(MsgUtil.p("nearby-shop-this-way", "" + (int) Math.floor(Math.sqrt(minDistanceSquared))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns loc with modified pitch/yaw angles so it faces lookat
|
* Returns loc with modified pitch/yaw angles so it faces lookat
|
||||||
*
|
*
|
||||||
* @param loc
|
* @param loc
|
||||||
* The location a players head is
|
* The location a players head is
|
||||||
* @param lookat
|
* @param lookat
|
||||||
* The location they should be looking
|
* The location they should be looking
|
||||||
* @return The location the player should be facing to have their crosshairs
|
* @return The location the player should be facing to have their crosshairs
|
||||||
* on the location lookAt Kudos to bergerkiller for most of this
|
* on the location lookAt Kudos to bergerkiller for most of this
|
||||||
* function
|
* function
|
||||||
*/
|
*/
|
||||||
public Location lookAt(Location loc, final Location lookat) {
|
public Location lookAt(Location loc, final Location lookat) {
|
||||||
// Clone the loc to prevent applied changes to the input loc
|
// Clone the loc to prevent applied changes to the input loc
|
||||||
loc = loc.clone();
|
loc = loc.clone();
|
||||||
// Values of change in distance (make it relative)
|
// Values of change in distance (make it relative)
|
||||||
final double dx = lookat.getX() - loc.getX();
|
final double dx = lookat.getX() - loc.getX();
|
||||||
final double dy = lookat.getY() - loc.getY();
|
final double dy = lookat.getY() - loc.getY();
|
||||||
final double dz = lookat.getZ() - loc.getZ();
|
final double dz = lookat.getZ() - loc.getZ();
|
||||||
// Set yaw
|
// Set yaw
|
||||||
if (dx != 0) {
|
if (dx != 0) {
|
||||||
// Set yaw start value based on dx
|
// Set yaw start value based on dx
|
||||||
if (dx < 0) {
|
if (dx < 0) {
|
||||||
loc.setYaw((float) (1.5 * Math.PI));
|
loc.setYaw((float) (1.5 * Math.PI));
|
||||||
} else {
|
} else {
|
||||||
loc.setYaw((float) (0.5 * Math.PI));
|
loc.setYaw((float) (0.5 * Math.PI));
|
||||||
}
|
}
|
||||||
loc.setYaw(loc.getYaw() - (float) Math.atan(dz / dx));
|
loc.setYaw(loc.getYaw() - (float) Math.atan(dz / dx));
|
||||||
} else if (dz < 0) {
|
} else if (dz < 0) {
|
||||||
loc.setYaw((float) Math.PI);
|
loc.setYaw((float) Math.PI);
|
||||||
}
|
}
|
||||||
// Get the distance from dx/dz
|
// Get the distance from dx/dz
|
||||||
final double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));
|
final double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));
|
||||||
final float pitch = (float) -Math.atan(dy / dxz);
|
final float pitch = (float) -Math.atan(dy / dxz);
|
||||||
// Set values, convert to degrees
|
// Set values, convert to degrees
|
||||||
// Minecraft yaw (vertical) angles are inverted (negative)
|
// Minecraft yaw (vertical) angles are inverted (negative)
|
||||||
loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI + 360);
|
loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI + 360);
|
||||||
// But pitch angles are normal
|
// But pitch angles are normal
|
||||||
loc.setPitch(pitch * 180f / (float) Math.PI);
|
loc.setPitch(pitch * 180f / (float) Math.PI);
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,47 +16,47 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandInfo extends BaseCommand {
|
public class CommandInfo extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandInfo(final QuickShop plugin) {
|
public CommandInfo(final QuickShop plugin) {
|
||||||
super("i");
|
super("i");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setPermission("quickshop.info");
|
setPermission("quickshop.info");
|
||||||
setDescription(MsgUtil.p("command.description.info"));
|
setDescription(MsgUtil.p("command.description.info"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
int buying, selling, doubles, chunks, worlds, unlimited;
|
int buying, selling, doubles, chunks, worlds, unlimited;
|
||||||
buying = selling = doubles = chunks = worlds = unlimited = 0;
|
buying = selling = doubles = chunks = worlds = unlimited = 0;
|
||||||
int nostock = 0;
|
int nostock = 0;
|
||||||
sender.sendMessage(ChatColor.RED + "开始检索商店信息中...");
|
sender.sendMessage(ChatColor.RED + "开始检索商店信息中...");
|
||||||
for (final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld : plugin.getShopManager().getShops().values()) {
|
for (final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld : plugin.getShopManager().getShops().values()) {
|
||||||
worlds++;
|
worlds++;
|
||||||
for (final HashMap<Location, Shop> inChunk : inWorld.values()) {
|
for (final HashMap<Location, Shop> inChunk : inWorld.values()) {
|
||||||
chunks++;
|
chunks++;
|
||||||
for (final Shop shop : inChunk.values()) {
|
for (final Shop shop : inChunk.values()) {
|
||||||
if (shop.isUnlimited()) {
|
if (shop.isUnlimited()) {
|
||||||
unlimited++;
|
unlimited++;
|
||||||
}
|
}
|
||||||
if (shop.isBuying()) {
|
if (shop.isBuying()) {
|
||||||
buying++;
|
buying++;
|
||||||
} else if (shop.isSelling()) {
|
} else if (shop.isSelling()) {
|
||||||
selling++;
|
selling++;
|
||||||
}
|
}
|
||||||
if (shop instanceof ContainerShop && ((ContainerShop) shop).isDoubleShop()) {
|
if (shop instanceof ContainerShop && ((ContainerShop) shop).isDoubleShop()) {
|
||||||
doubles++;
|
doubles++;
|
||||||
} else if (shop.isSelling() && shop.getRemainingStock() == 0) {
|
} else if (shop.isSelling() && shop.getRemainingStock() == 0) {
|
||||||
nostock++;
|
nostock++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("info.title", chunks, buying + selling, worlds));
|
sender.sendMessage(MsgUtil.p("info.title", chunks, buying + selling, worlds));
|
||||||
sender.sendMessage(MsgUtil.p("info.selling", selling));
|
sender.sendMessage(MsgUtil.p("info.selling", selling));
|
||||||
sender.sendMessage(MsgUtil.p("info.buying", buying));
|
sender.sendMessage(MsgUtil.p("info.buying", buying));
|
||||||
sender.sendMessage(MsgUtil.p("info.unlimited", unlimited));
|
sender.sendMessage(MsgUtil.p("info.unlimited", unlimited));
|
||||||
sender.sendMessage(MsgUtil.p("info.double", doubles));
|
sender.sendMessage(MsgUtil.p("info.double", doubles));
|
||||||
sender.sendMessage(MsgUtil.p("info.canclean", nostock));
|
sender.sendMessage(MsgUtil.p("info.canclean", nostock));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,86 +14,86 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandPrice extends BaseCommand {
|
public class CommandPrice extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandPrice(final QuickShop plugin) {
|
public CommandPrice(final QuickShop plugin) {
|
||||||
super("p");
|
super("p");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setMinimumArguments(1);
|
setMinimumArguments(1);
|
||||||
setOnlyPlayerExecutable();
|
setOnlyPlayerExecutable();
|
||||||
setPossibleArguments("<价格>");
|
setPossibleArguments("<价格>");
|
||||||
setPermission("quickshop.create.changeprice");
|
setPermission("quickshop.create.changeprice");
|
||||||
setDescription(MsgUtil.p("command.description.price"));
|
setDescription(MsgUtil.p("command.description.price"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final Player p = (Player) sender;
|
final Player p = (Player) sender;
|
||||||
double price;
|
double price;
|
||||||
try {
|
try {
|
||||||
price = Double.parseDouble(args[0]);
|
price = Double.parseDouble(args[0]);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
|
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (price < 0.01) {
|
if (price < 0.01) {
|
||||||
sender.sendMessage(MsgUtil.p("price-too-cheap"));
|
sender.sendMessage(MsgUtil.p("price-too-cheap"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double fee = 0;
|
double fee = 0;
|
||||||
if (plugin.getConfigManager().isPriceChangeRequiresFee()) {
|
if (plugin.getConfigManager().isPriceChangeRequiresFee()) {
|
||||||
fee = plugin.getConfigManager().getFeeForPriceChange();
|
fee = plugin.getConfigManager().getFeeForPriceChange();
|
||||||
if (fee > 0 && plugin.getEcon().getBalance(p.getName()) < fee) {
|
if (fee > 0 && plugin.getEcon().getBalance(p.getName()) < fee) {
|
||||||
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
|
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final BlockIterator bIt = new BlockIterator(p, 10);
|
final BlockIterator bIt = new BlockIterator(p, 10);
|
||||||
// Loop through every block they're looking at upto 10 blocks away
|
// Loop through every block they're looking at upto 10 blocks away
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null && (shop.getOwner().equals(p.getName()) || sender.hasPermission("quickshop.other.price"))) {
|
if (shop != null && (shop.getOwner().equals(p.getName()) || sender.hasPermission("quickshop.other.price"))) {
|
||||||
if (shop.getPrice() == price) {
|
if (shop.getPrice() == price) {
|
||||||
// Stop here if there isn't a price change
|
// Stop here if there isn't a price change
|
||||||
sender.sendMessage(MsgUtil.p("no-price-change"));
|
sender.sendMessage(MsgUtil.p("no-price-change"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fee > 0) {
|
if (fee > 0) {
|
||||||
if (!plugin.getEcon().withdraw(p.getName(), fee)) {
|
if (!plugin.getEcon().withdraw(p.getName(), fee)) {
|
||||||
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
|
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("fee-charged-for-price-change", plugin.getEcon().format(fee)));
|
sender.sendMessage(MsgUtil.p("fee-charged-for-price-change", plugin.getEcon().format(fee)));
|
||||||
plugin.getEcon().deposit(plugin.getConfig().getString("tax-account"), fee);
|
plugin.getEcon().deposit(plugin.getConfig().getString("tax-account"), fee);
|
||||||
}
|
}
|
||||||
// Update the shop
|
// Update the shop
|
||||||
shop.setPrice(price);
|
shop.setPrice(price);
|
||||||
shop.setSignText();
|
shop.setSignText();
|
||||||
shop.update();
|
shop.update();
|
||||||
sender.sendMessage(MsgUtil.p("price-is-now", plugin.getEcon().format(shop.getPrice())));
|
sender.sendMessage(MsgUtil.p("price-is-now", plugin.getEcon().format(shop.getPrice())));
|
||||||
// Chest shops can be double shops.
|
// Chest shops can be double shops.
|
||||||
if (shop instanceof ContainerShop) {
|
if (shop instanceof ContainerShop) {
|
||||||
final ContainerShop cs = (ContainerShop) shop;
|
final ContainerShop cs = (ContainerShop) shop;
|
||||||
if (cs.isDoubleShop()) {
|
if (cs.isDoubleShop()) {
|
||||||
final Shop nextTo = cs.getAttachedShop();
|
final Shop nextTo = cs.getAttachedShop();
|
||||||
if (cs.isSelling()) {
|
if (cs.isSelling()) {
|
||||||
if (cs.getPrice() < nextTo.getPrice()) {
|
if (cs.getPrice() < nextTo.getPrice()) {
|
||||||
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
|
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Buying
|
// Buying
|
||||||
if (cs.getPrice() > nextTo.getPrice()) {
|
if (cs.getPrice() > nextTo.getPrice()) {
|
||||||
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
|
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,37 +13,37 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandRefill extends BaseCommand {
|
public class CommandRefill extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandRefill(final QuickShop plugin) {
|
public CommandRefill(final QuickShop plugin) {
|
||||||
super("r");
|
super("r");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setMinimumArguments(1);
|
setMinimumArguments(1);
|
||||||
setPossibleArguments("<数量>");
|
setPossibleArguments("<数量>");
|
||||||
setPermission("quickshop.refill");
|
setPermission("quickshop.refill");
|
||||||
setDescription(MsgUtil.p("command.description.refill"));
|
setDescription(MsgUtil.p("command.description.refill"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
int add;
|
int add;
|
||||||
try {
|
try {
|
||||||
add = Integer.parseInt(args[0]);
|
add = Integer.parseInt(args[0]);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
|
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
shop.add(shop.getItem(), add);
|
shop.add(shop.getItem(), add);
|
||||||
sender.sendMessage(MsgUtil.p("refill-success"));
|
sender.sendMessage(MsgUtil.p("refill-success"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,21 +10,21 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandReload extends BaseCommand {
|
public class CommandReload extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandReload(final QuickShop plugin) {
|
public CommandReload(final QuickShop plugin) {
|
||||||
super("reload");
|
super("reload");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setPermission("quickshop.reload");
|
setPermission("quickshop.reload");
|
||||||
setDescription(MsgUtil.p("command.description.reload"));
|
setDescription(MsgUtil.p("command.description.reload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
sender.sendMessage(MsgUtil.p("command.reloading"));
|
sender.sendMessage(MsgUtil.p("command.reloading"));
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||||
Bukkit.getPluginManager().enablePlugin(plugin);
|
Bukkit.getPluginManager().enablePlugin(plugin);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,33 +14,33 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandRemove extends BaseCommand {
|
public class CommandRemove extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandRemove(final QuickShop plugin) {
|
public CommandRemove(final QuickShop plugin) {
|
||||||
super("r");
|
super("r");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setOnlyPlayerExecutable();
|
setOnlyPlayerExecutable();
|
||||||
setPermission("quickshop.delete");
|
setPermission("quickshop.delete");
|
||||||
setDescription(MsgUtil.p("command.description.remove"));
|
setDescription(MsgUtil.p("command.description.remove"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final Player p = (Player) sender;
|
final Player p = (Player) sender;
|
||||||
final BlockIterator bIt = new BlockIterator(p, 10);
|
final BlockIterator bIt = new BlockIterator(p, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
if (shop.getOwner().equals(p.getName())) {
|
if (shop.getOwner().equals(p.getName())) {
|
||||||
shop.delete();
|
shop.delete();
|
||||||
sender.sendMessage(ChatColor.GREEN + "商店已成功移除");
|
sender.sendMessage(ChatColor.GREEN + "商店已成功移除");
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(ChatColor.RED + "这个不是你的商店!");
|
p.sendMessage(ChatColor.RED + "这个不是你的商店!");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.sendMessage(ChatColor.RED + "未找到商店!");
|
p.sendMessage(ChatColor.RED + "未找到商店!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,31 +14,31 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandSell extends BaseCommand {
|
public class CommandSell extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandSell(final QuickShop plugin) {
|
public CommandSell(final QuickShop plugin) {
|
||||||
super("s");
|
super("s");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setPermission("quickshop.create.sell");
|
setPermission("quickshop.create.sell");
|
||||||
setOnlyPlayerExecutable();
|
setOnlyPlayerExecutable();
|
||||||
setDescription(MsgUtil.p("command.description.sell"));
|
setDescription(MsgUtil.p("command.description.sell"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null && shop.getOwner().equals(((Player) sender).getName())) {
|
if (shop != null && shop.getOwner().equals(((Player) sender).getName())) {
|
||||||
shop.setShopType(ShopType.SELLING);
|
shop.setShopType(ShopType.SELLING);
|
||||||
shop.setSignText();
|
shop.setSignText();
|
||||||
shop.update();
|
shop.update();
|
||||||
sender.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
|
sender.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,32 +13,32 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandSetOwner extends BaseCommand {
|
public class CommandSetOwner extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandSetOwner(final QuickShop plugin) {
|
public CommandSetOwner(final QuickShop plugin) {
|
||||||
super("so");
|
super("so");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setOnlyPlayerExecutable();
|
setOnlyPlayerExecutable();
|
||||||
setMinimumArguments(1);
|
setMinimumArguments(1);
|
||||||
setPermission("quickshop.setowner");
|
setPermission("quickshop.setowner");
|
||||||
setDescription(MsgUtil.p("command.description.setowner"));
|
setDescription(MsgUtil.p("command.description.setowner"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
shop.setOwner(args[0]);
|
shop.setOwner(args[0]);
|
||||||
shop.update();
|
shop.update();
|
||||||
sender.sendMessage(MsgUtil.p("command.new-owner", args[0]));
|
sender.sendMessage(MsgUtil.p("command.new-owner", args[0]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,31 +13,31 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
|
|
||||||
public class CommandUnlimited extends BaseCommand {
|
public class CommandUnlimited extends BaseCommand {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public CommandUnlimited(final QuickShop plugin) {
|
public CommandUnlimited(final QuickShop plugin) {
|
||||||
super("u");
|
super("u");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
setOnlyPlayerExecutable();
|
setOnlyPlayerExecutable();
|
||||||
setPermission("quickshop.unlimited");
|
setPermission("quickshop.unlimited");
|
||||||
setDescription(MsgUtil.p("command.description.unlimited"));
|
setDescription(MsgUtil.p("command.description.unlimited"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
shop.setUnlimited(!shop.isUnlimited());
|
shop.setUnlimited(!shop.isUnlimited());
|
||||||
shop.update();
|
shop.update();
|
||||||
sender.sendMessage(MsgUtil.p("command.toggle-unlimited", (shop.isUnlimited() ? "无限模式" : "有限模式")));
|
sender.sendMessage(MsgUtil.p("command.toggle-unlimited", (shop.isUnlimited() ? "无限模式" : "有限模式")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,31 +9,31 @@ import cn.citycraft.PluginHelper.commands.DefaultCommand;
|
|||||||
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
|
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
|
||||||
|
|
||||||
public class QuickShopCommands implements DefaultCommand {
|
public class QuickShopCommands implements DefaultCommand {
|
||||||
HandlerSubCommand hsc;
|
HandlerSubCommand hsc;
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public QuickShopCommands(final QuickShop plugin) {
|
public QuickShopCommands(final QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
hsc = new HandlerSubCommand(plugin, "qs");
|
hsc = new HandlerSubCommand(plugin, "qs");
|
||||||
hsc.setDefaultCommand(this);
|
hsc.setDefaultCommand(this);
|
||||||
hsc.registerCommand(new CommandClean(plugin));
|
hsc.registerCommand(new CommandClean(plugin));
|
||||||
hsc.registerCommand(new CommandEmpty(plugin));
|
hsc.registerCommand(new CommandEmpty(plugin));
|
||||||
hsc.registerCommand(new CommandExport(plugin));
|
hsc.registerCommand(new CommandExport(plugin));
|
||||||
hsc.registerCommand(new CommandFind(plugin));
|
hsc.registerCommand(new CommandFind(plugin));
|
||||||
hsc.registerCommand(new CommandInfo(plugin));
|
hsc.registerCommand(new CommandInfo(plugin));
|
||||||
hsc.registerCommand(new CommandPrice(plugin));
|
hsc.registerCommand(new CommandPrice(plugin));
|
||||||
hsc.registerCommand(new CommandRefill(plugin));
|
hsc.registerCommand(new CommandRefill(plugin));
|
||||||
hsc.registerCommand(new CommandReload(plugin));
|
hsc.registerCommand(new CommandReload(plugin));
|
||||||
hsc.registerCommand(new CommandRemove(plugin));
|
hsc.registerCommand(new CommandRemove(plugin));
|
||||||
hsc.registerCommand(new CommandBuy(plugin));
|
hsc.registerCommand(new CommandBuy(plugin));
|
||||||
hsc.registerCommand(new CommandSetOwner(plugin));
|
hsc.registerCommand(new CommandSetOwner(plugin));
|
||||||
hsc.registerCommand(new CommandSell(plugin));
|
hsc.registerCommand(new CommandSell(plugin));
|
||||||
hsc.registerCommand(new CommandUnlimited(plugin));
|
hsc.registerCommand(new CommandUnlimited(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defaultExecute(final CommandSender sender, final Command command, final String label) throws CommandException {
|
public void defaultExecute(final CommandSender sender, final Command command, final String label) throws CommandException {
|
||||||
hsc.sendHelp(sender, label);
|
hsc.sendHelp(sender, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -13,200 +13,200 @@ import cn.citycraft.PluginHelper.config.FileConfig;
|
|||||||
import cn.citycraft.PluginHelper.tellraw.FancyMessage;
|
import cn.citycraft.PluginHelper.tellraw.FancyMessage;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private boolean enableMagicLib = false;
|
private boolean enableMagicLib = false;
|
||||||
/** Whether debug info should be shown in the console */
|
/** Whether debug info should be shown in the console */
|
||||||
private final boolean debug = false;
|
private final boolean debug = false;
|
||||||
|
|
||||||
/** Whether we should use display items or not */
|
/** Whether we should use display items or not */
|
||||||
private boolean display = true;
|
private boolean display = true;
|
||||||
private double feeForPriceChange = 0.0;
|
private double feeForPriceChange = 0.0;
|
||||||
private int findDistance = 30;
|
private int findDistance = 30;
|
||||||
private String guiTitle = "§6[§b快捷商店§6]§r";
|
private String guiTitle = "§6[§b快捷商店§6]§r";
|
||||||
/** Whether or not to limit players shop amounts */
|
/** Whether or not to limit players shop amounts */
|
||||||
private boolean limit = false;
|
private boolean limit = false;
|
||||||
|
|
||||||
private int limitdefault = 0;
|
private int limitdefault = 0;
|
||||||
private final HashMap<String, Integer> limits = new HashMap<>();
|
private final HashMap<String, Integer> limits = new HashMap<>();
|
||||||
private boolean logAction = true;
|
private boolean logAction = true;
|
||||||
private boolean preventhopper = false;
|
private boolean preventhopper = false;
|
||||||
/**
|
/**
|
||||||
* Whether we players are charged a fee to change the price on their shop
|
* Whether we players are charged a fee to change the price on their shop
|
||||||
* (To help deter endless undercutting
|
* (To help deter endless undercutting
|
||||||
*/
|
*/
|
||||||
private boolean priceChangeRequiresFee = false;
|
private boolean priceChangeRequiresFee = false;
|
||||||
private boolean shopLock = true;
|
private boolean shopLock = true;
|
||||||
private boolean showTax = false;
|
private boolean showTax = false;
|
||||||
/** Whether players are required to sneak to create/buy from a shop */
|
/** Whether players are required to sneak to create/buy from a shop */
|
||||||
private boolean sneak = false;
|
private boolean sneak = false;
|
||||||
/** Whether players are required to sneak to create a shop */
|
/** Whether players are required to sneak to create a shop */
|
||||||
private boolean sneakCreate = false;
|
private boolean sneakCreate = false;
|
||||||
/** Whether players are required to sneak to trade with a shop */
|
/** Whether players are required to sneak to trade with a shop */
|
||||||
private boolean sneakTrade = false;
|
private boolean sneakTrade = false;
|
||||||
private Material superItem = Material.GOLD_AXE;
|
private Material superItem = Material.GOLD_AXE;
|
||||||
private double tax = 0;
|
private double tax = 0;
|
||||||
private final String taxAccount;
|
private final String taxAccount;
|
||||||
private boolean fakeItem = false;
|
private boolean fakeItem = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of players who have been warned
|
* A set of players who have been warned
|
||||||
* ("Your shop isn't automatically locked")
|
* ("Your shop isn't automatically locked")
|
||||||
*/
|
*/
|
||||||
private final HashSet<String> warnings = new HashSet<>();
|
private final HashSet<String> warnings = new HashSet<>();
|
||||||
|
|
||||||
public ConfigManager(final QuickShop plugin) {
|
public ConfigManager(final QuickShop plugin) {
|
||||||
final FileConfig config = (FileConfig) plugin.getConfig();
|
final FileConfig config = (FileConfig) plugin.getConfig();
|
||||||
ConfigurationSection limitCfg = config.getConfigurationSection("limits");
|
ConfigurationSection limitCfg = config.getConfigurationSection("limits");
|
||||||
if (limitCfg != null) {
|
if (limitCfg != null) {
|
||||||
this.limit = limitCfg.getBoolean("use", false);
|
this.limit = limitCfg.getBoolean("use", false);
|
||||||
this.limitdefault = config.getInt("limits.default");
|
this.limitdefault = config.getInt("limits.default");
|
||||||
limitCfg = limitCfg.getConfigurationSection("ranks");
|
limitCfg = limitCfg.getConfigurationSection("ranks");
|
||||||
for (final String key : limitCfg.getKeys(true)) {
|
for (final String key : limitCfg.getKeys(true)) {
|
||||||
limits.put(key, limitCfg.getInt(key));
|
limits.put(key, limitCfg.getInt(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.superItem = Material.valueOf(config.getString("superitem"));
|
this.superItem = Material.valueOf(config.getString("superitem"));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
}
|
}
|
||||||
this.tax = config.getDouble("tax");
|
this.tax = config.getDouble("tax");
|
||||||
this.showTax = config.getBoolean("show-tax");
|
this.showTax = config.getBoolean("show-tax");
|
||||||
this.taxAccount = config.getString("tax-account");
|
this.taxAccount = config.getString("tax-account");
|
||||||
this.logAction = config.getBoolean("log-actions");
|
this.logAction = config.getBoolean("log-actions");
|
||||||
this.shopLock = config.getBoolean("shop.lock");
|
this.shopLock = config.getBoolean("shop.lock");
|
||||||
this.display = config.getBoolean("shop.display-items");
|
this.display = config.getBoolean("shop.display-items");
|
||||||
this.sneak = config.getBoolean("shop.sneak-only");
|
this.sneak = config.getBoolean("shop.sneak-only");
|
||||||
this.sneakCreate = config.getBoolean("shop.sneak-to-create");
|
this.sneakCreate = config.getBoolean("shop.sneak-to-create");
|
||||||
this.sneakTrade = config.getBoolean("shop.sneak-to-trade");
|
this.sneakTrade = config.getBoolean("shop.sneak-to-trade");
|
||||||
this.priceChangeRequiresFee = config.getBoolean("shop.price-change-requires-fee");
|
this.priceChangeRequiresFee = config.getBoolean("shop.price-change-requires-fee");
|
||||||
this.findDistance = config.getInt("shop.find-distance");
|
this.findDistance = config.getInt("shop.find-distance");
|
||||||
this.feeForPriceChange = config.getDouble("shop.fee-for-price-change");
|
this.feeForPriceChange = config.getDouble("shop.fee-for-price-change");
|
||||||
this.preventhopper = config.getBoolean("preventhopper");
|
this.preventhopper = config.getBoolean("preventhopper");
|
||||||
this.guiTitle = config.getMessage("guititle", guiTitle);
|
this.guiTitle = config.getMessage("guititle", guiTitle);
|
||||||
this.fakeItem = config.getBoolean("fakeitem", true);
|
this.fakeItem = config.getBoolean("fakeitem", true);
|
||||||
if (config.getBoolean("fakeitem", true)) {
|
if (config.getBoolean("fakeitem", true)) {
|
||||||
try {
|
try {
|
||||||
plugin.getLogger().info("启用虚拟悬浮物 尝试启动中...");
|
plugin.getLogger().info("启用虚拟悬浮物 尝试启动中...");
|
||||||
FakeItem.register(plugin);
|
FakeItem.register(plugin);
|
||||||
plugin.getLogger().info("虚拟悬浮物功能测试正常...");
|
plugin.getLogger().info("虚拟悬浮物功能测试正常...");
|
||||||
fakeItem = true;
|
fakeItem = true;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
plugin.getLogger().warning("+=========================================");
|
plugin.getLogger().warning("+=========================================");
|
||||||
plugin.getLogger().warning("| 警告: 虚拟物品启动失败 使用原版悬浮物品...");
|
plugin.getLogger().warning("| 警告: 虚拟物品启动失败 使用原版悬浮物品...");
|
||||||
plugin.getLogger().warning("+=========================================");
|
plugin.getLogger().warning("+=========================================");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.getBoolean("usemagiclib", true)) {
|
if (config.getBoolean("usemagiclib", true)) {
|
||||||
try {
|
try {
|
||||||
plugin.getLogger().info("启用魔改库 尝试启动中...");
|
plugin.getLogger().info("启用魔改库 尝试启动中...");
|
||||||
final FancyMessage fm = FancyMessage.newFM("test");
|
final FancyMessage fm = FancyMessage.newFM("test");
|
||||||
fm.then("item").itemTooltip(new ItemStack(Material.DIAMOND_SWORD));
|
fm.then("item").itemTooltip(new ItemStack(Material.DIAMOND_SWORD));
|
||||||
fm.then("link").link("ci.citycraft.cn");
|
fm.then("link").link("ci.citycraft.cn");
|
||||||
fm.then("suggest").suggest("qs help");
|
fm.then("suggest").suggest("qs help");
|
||||||
fm.toJSONString();
|
fm.toJSONString();
|
||||||
plugin.getLogger().info("魔改库功能测试正常...");
|
plugin.getLogger().info("魔改库功能测试正常...");
|
||||||
this.enableMagicLib = true;
|
this.enableMagicLib = true;
|
||||||
} catch (final Error | Exception e) {
|
} catch (final Error | Exception e) {
|
||||||
plugin.getLogger().warning("+=========================================");
|
plugin.getLogger().warning("+=========================================");
|
||||||
plugin.getLogger().warning("| 警告: 启动魔改库失败 将使用GUI商店界面...");
|
plugin.getLogger().warning("| 警告: 启动魔改库失败 将使用GUI商店界面...");
|
||||||
plugin.getLogger().warning("+=========================================");
|
plugin.getLogger().warning("+=========================================");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getFeeForPriceChange() {
|
public double getFeeForPriceChange() {
|
||||||
return feeForPriceChange;
|
return feeForPriceChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFindDistance() {
|
public int getFindDistance() {
|
||||||
return findDistance;
|
return findDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGuiTitle() {
|
public String getGuiTitle() {
|
||||||
return guiTitle;
|
return guiTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLimitdefault() {
|
public int getLimitdefault() {
|
||||||
return limitdefault;
|
return limitdefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Integer> getLimits() {
|
public HashMap<String, Integer> getLimits() {
|
||||||
return limits;
|
return limits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getSuperItem() {
|
public Material getSuperItem() {
|
||||||
return superItem;
|
return superItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTax() {
|
public double getTax() {
|
||||||
return tax;
|
return tax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTaxAccount() {
|
public String getTaxAccount() {
|
||||||
return taxAccount;
|
return taxAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<String> getWarnings() {
|
public HashSet<String> getWarnings() {
|
||||||
return warnings;
|
return warnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDebug() {
|
public boolean isDebug() {
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDisplay() {
|
public boolean isDisplay() {
|
||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnableMagicLib() {
|
public boolean isEnableMagicLib() {
|
||||||
return enableMagicLib;
|
return enableMagicLib;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFakeItem() {
|
public boolean isFakeItem() {
|
||||||
return fakeItem;
|
return fakeItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLimit() {
|
public boolean isLimit() {
|
||||||
return limit;
|
return limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLogAction() {
|
public boolean isLogAction() {
|
||||||
return logAction;
|
return logAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreventHopper() {
|
public boolean isPreventHopper() {
|
||||||
return preventhopper;
|
return preventhopper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPriceChangeRequiresFee() {
|
public boolean isPriceChangeRequiresFee() {
|
||||||
return priceChangeRequiresFee;
|
return priceChangeRequiresFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShopLock() {
|
public boolean isShopLock() {
|
||||||
return shopLock;
|
return shopLock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShowTax() {
|
public boolean isShowTax() {
|
||||||
return showTax;
|
return showTax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSneak() {
|
public boolean isSneak() {
|
||||||
return sneak;
|
return sneak;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSneakCreate() {
|
public boolean isSneakCreate() {
|
||||||
return sneakCreate;
|
return sneakCreate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSneakTrade() {
|
public boolean isSneakTrade() {
|
||||||
return sneakTrade;
|
return sneakTrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnableMagicLib(final boolean enableMagicLib) {
|
public void setEnableMagicLib(final boolean enableMagicLib) {
|
||||||
this.enableMagicLib = enableMagicLib;
|
this.enableMagicLib = enableMagicLib;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFakeItem(final boolean fakeItem) {
|
public void setFakeItem(final boolean fakeItem) {
|
||||||
this.fakeItem = fakeItem;
|
this.fakeItem = fakeItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,69 +6,69 @@ import java.sql.SQLException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class BufferStatement {
|
public class BufferStatement {
|
||||||
private Object[] values;
|
private Object[] values;
|
||||||
private String query;
|
private String query;
|
||||||
private Exception stacktrace;
|
private Exception stacktrace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a PreparedStatement in a state before preparing it (E.g. No
|
* Represents a PreparedStatement in a state before preparing it (E.g. No
|
||||||
* file I/O Required)
|
* file I/O Required)
|
||||||
*
|
*
|
||||||
* @param query
|
* @param query
|
||||||
* The query to execute. E.g. INSERT INTO accounts (user, passwd)
|
* The query to execute. E.g. INSERT INTO accounts (user, passwd)
|
||||||
* VALUES (?, ?)
|
* VALUES (?, ?)
|
||||||
* @param values
|
* @param values
|
||||||
* The values to replace <bold>?</bold> with in
|
* The values to replace <bold>?</bold> with in
|
||||||
* <bold>query</bold>. These are in order.
|
* <bold>query</bold>. These are in order.
|
||||||
*/
|
*/
|
||||||
public BufferStatement(String query, Object... values) {
|
public BufferStatement(String query, Object... values) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.values = values;
|
this.values = values;
|
||||||
this.stacktrace = new Exception(); // For error handling
|
this.stacktrace = new Exception(); // For error handling
|
||||||
this.stacktrace.fillInStackTrace(); // We can declare where this
|
this.stacktrace.fillInStackTrace(); // We can declare where this
|
||||||
// statement came from.
|
// statement came from.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a prepared statement using the given connection. Will try to
|
* Returns a prepared statement using the given connection. Will try to
|
||||||
* return an empty statement if something went wrong. If that fails, returns
|
* return an empty statement if something went wrong. If that fails, returns
|
||||||
* null.
|
* null.
|
||||||
*
|
*
|
||||||
* This method escapes everything automatically.
|
* This method escapes everything automatically.
|
||||||
*
|
*
|
||||||
* @param con
|
* @param con
|
||||||
* The connection to prepare this on using
|
* The connection to prepare this on using
|
||||||
* con.prepareStatement(..)
|
* con.prepareStatement(..)
|
||||||
* @return The prepared statement, ready for execution.
|
* @return The prepared statement, ready for execution.
|
||||||
*/
|
*/
|
||||||
public PreparedStatement prepareStatement(Connection con) throws SQLException {
|
public PreparedStatement prepareStatement(Connection con) throws SQLException {
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
ps = con.prepareStatement(query);
|
ps = con.prepareStatement(query);
|
||||||
for (int i = 1; i <= values.length; i++) {
|
for (int i = 1; i <= values.length; i++) {
|
||||||
ps.setObject(i, values[i - 1]);
|
ps.setObject(i, values[i - 1]);
|
||||||
}
|
}
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for debugging. This stacktrace is recorded when the statement is
|
* Used for debugging. This stacktrace is recorded when the statement is
|
||||||
* created, so printing it to the screen will provide useful debugging
|
* created, so printing it to the screen will provide useful debugging
|
||||||
* information about where the query came from, if something went wrong
|
* information about where the query came from, if something went wrong
|
||||||
* while executing it.
|
* while executing it.
|
||||||
*
|
*
|
||||||
* @return The stacktrace elements.
|
* @return The stacktrace elements.
|
||||||
*/
|
*/
|
||||||
public StackTraceElement[] getStackTrace() {
|
public StackTraceElement[] getStackTrace() {
|
||||||
return stacktrace.getStackTrace();
|
return stacktrace.getStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A string representation of this statement. Returns
|
* @return A string representation of this statement. Returns
|
||||||
* <italic>"Query: " + query + ", values: " +
|
* <italic>"Query: " + query + ", values: " +
|
||||||
* Arrays.toString(values).</italic>
|
* Arrays.toString(values).</italic>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Query: " + query + ", values: " + Arrays.toString(values);
|
return "Query: " + query + ", values: " + Arrays.toString(values);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,192 +8,192 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Database {
|
public class Database {
|
||||||
private DatabaseCore core;
|
private DatabaseCore core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new database and validates its connection.
|
* Creates a new database and validates its connection.
|
||||||
*
|
*
|
||||||
* If the connection is invalid, this will throw a ConnectionException.
|
* If the connection is invalid, this will throw a ConnectionException.
|
||||||
*
|
*
|
||||||
* @param core
|
* @param core
|
||||||
* The core for the database, either MySQL or SQLite.
|
* The core for the database, either MySQL or SQLite.
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
* If the connection was invalid
|
* If the connection was invalid
|
||||||
*/
|
*/
|
||||||
public Database(DatabaseCore core) throws ConnectionException {
|
public Database(DatabaseCore core) throws ConnectionException {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if (!core.getConnection().isValid(10)) {
|
if (!core.getConnection().isValid(10)) {
|
||||||
throw new ConnectionException("Database doesn not appear to be valid!");
|
throw new ConnectionException("Database doesn not appear to be valid!");
|
||||||
}
|
}
|
||||||
} catch (AbstractMethodError e) {
|
} catch (AbstractMethodError e) {
|
||||||
// You don't need to validate this core.
|
// You don't need to validate this core.
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new ConnectionException(e.getMessage());
|
throw new ConnectionException(e.getMessage());
|
||||||
}
|
}
|
||||||
this.core = core;
|
this.core = core;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the database core object, that this database runs on.
|
* Returns the database core object, that this database runs on.
|
||||||
*
|
*
|
||||||
* @return the database core object, that this database runs on.
|
* @return the database core object, that this database runs on.
|
||||||
*/
|
*/
|
||||||
public DatabaseCore getCore() {
|
public DatabaseCore getCore() {
|
||||||
return core;
|
return core;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the connection to this database for querying. Try to avoid doing
|
* Fetches the connection to this database for querying. Try to avoid doing
|
||||||
* this in the main thread.
|
* this in the main thread.
|
||||||
*
|
*
|
||||||
* @return Fetches the connection to this database for querying.
|
* @return Fetches the connection to this database for querying.
|
||||||
*/
|
*/
|
||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
return core.getConnection();
|
return core.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the given statement either immediately, or soon.
|
* Executes the given statement either immediately, or soon.
|
||||||
*
|
*
|
||||||
* @param query
|
* @param query
|
||||||
* The query
|
* The query
|
||||||
* @param objs
|
* @param objs
|
||||||
* The string values for each ? in the given query.
|
* The string values for each ? in the given query.
|
||||||
*/
|
*/
|
||||||
public void execute(String query, Object... objs) {
|
public void execute(String query, Object... objs) {
|
||||||
BufferStatement bs = new BufferStatement(query, objs);
|
BufferStatement bs = new BufferStatement(query, objs);
|
||||||
core.queue(bs);
|
core.queue(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the table exists
|
* Returns true if the table exists
|
||||||
*
|
*
|
||||||
* @param table
|
* @param table
|
||||||
* The table to check for
|
* The table to check for
|
||||||
* @return True if the table is found
|
* @return True if the table is found
|
||||||
*/
|
*/
|
||||||
public boolean hasTable(String table) throws SQLException {
|
public boolean hasTable(String table) throws SQLException {
|
||||||
ResultSet rs = getConnection().getMetaData().getTables(null, null, "%", null);
|
ResultSet rs = getConnection().getMetaData().getTables(null, null, "%", null);
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if (table.equalsIgnoreCase(rs.getString("TABLE_NAME"))) {
|
if (table.equalsIgnoreCase(rs.getString("TABLE_NAME"))) {
|
||||||
rs.close();
|
rs.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the database
|
* Closes the database
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public void close() {
|
||||||
this.core.close();
|
this.core.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the given table has the given column
|
* Returns true if the given table has the given column
|
||||||
*
|
*
|
||||||
* @param table
|
* @param table
|
||||||
* The table
|
* The table
|
||||||
* @param column
|
* @param column
|
||||||
* The column
|
* The column
|
||||||
* @return True if the given table has the given column
|
* @return True if the given table has the given column
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
* If the database isn't connected
|
* If the database isn't connected
|
||||||
*/
|
*/
|
||||||
public boolean hasColumn(String table, String column) throws SQLException {
|
public boolean hasColumn(String table, String column) throws SQLException {
|
||||||
if (!hasTable(table))
|
if (!hasTable(table))
|
||||||
return false;
|
return false;
|
||||||
String query = "SELECT * FROM " + table + " LIMIT 0,1";
|
String query = "SELECT * FROM " + table + " LIMIT 0,1";
|
||||||
try {
|
try {
|
||||||
PreparedStatement ps = this.getConnection().prepareStatement(query);
|
PreparedStatement ps = this.getConnection().prepareStatement(query);
|
||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
rs.getString(column); // Throws an exception if it can't find
|
rs.getString(column); // Throws an exception if it can't find
|
||||||
// that column
|
// that column
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false; // Uh, wtf.
|
return false; // Uh, wtf.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a connection error, generally when the server can't connect to
|
* Represents a connection error, generally when the server can't connect to
|
||||||
* MySQL or something.
|
* MySQL or something.
|
||||||
*/
|
*/
|
||||||
public static class ConnectionException extends Exception {
|
public static class ConnectionException extends Exception {
|
||||||
private static final long serialVersionUID = 8348749992936357317L;
|
private static final long serialVersionUID = 8348749992936357317L;
|
||||||
|
|
||||||
public ConnectionException(String msg) {
|
public ConnectionException(String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies the contents of this database into the given database. Does not
|
* Copies the contents of this database into the given database. Does not
|
||||||
* delete the contents of this database, or change any settings. This may
|
* delete the contents of this database, or change any settings. This may
|
||||||
* take a long time, and will print out progress reports to System.out
|
* take a long time, and will print out progress reports to System.out
|
||||||
*
|
*
|
||||||
* This method does not create the tables in the new database. You need to
|
* This method does not create the tables in the new database. You need to
|
||||||
* do that yourself.
|
* do that yourself.
|
||||||
*
|
*
|
||||||
* @param db
|
* @param db
|
||||||
* The database to copy data to
|
* The database to copy data to
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
* if an error occurs.
|
* if an error occurs.
|
||||||
*/
|
*/
|
||||||
public void copyTo(Database db) throws SQLException {
|
public void copyTo(Database db) throws SQLException {
|
||||||
ResultSet rs = getConnection().getMetaData().getTables(null, null, "%", null);
|
ResultSet rs = getConnection().getMetaData().getTables(null, null, "%", null);
|
||||||
List<String> tables = new LinkedList<String>();
|
List<String> tables = new LinkedList<String>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
tables.add(rs.getString("TABLE_NAME"));
|
tables.add(rs.getString("TABLE_NAME"));
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
core.flush();
|
core.flush();
|
||||||
// For each table
|
// For each table
|
||||||
for (String table : tables) {
|
for (String table : tables) {
|
||||||
if (table.toLowerCase().startsWith("sqlite_autoindex_"))
|
if (table.toLowerCase().startsWith("sqlite_autoindex_"))
|
||||||
continue;
|
continue;
|
||||||
System.out.println("Copying " + table);
|
System.out.println("Copying " + table);
|
||||||
// Wipe the old records
|
// Wipe the old records
|
||||||
db.getConnection().prepareStatement("DELETE FROM " + table).execute();
|
db.getConnection().prepareStatement("DELETE FROM " + table).execute();
|
||||||
// Fetch all the data from the existing database
|
// Fetch all the data from the existing database
|
||||||
rs = getConnection().prepareStatement("SELECT * FROM " + table).executeQuery();
|
rs = getConnection().prepareStatement("SELECT * FROM " + table).executeQuery();
|
||||||
int n = 0;
|
int n = 0;
|
||||||
// Build the query
|
// Build the query
|
||||||
String query = "INSERT INTO " + table + " VALUES (";
|
String query = "INSERT INTO " + table + " VALUES (";
|
||||||
// Append another placeholder for the value
|
// Append another placeholder for the value
|
||||||
query += "?";
|
query += "?";
|
||||||
for (int i = 2; i <= rs.getMetaData().getColumnCount(); i++) {
|
for (int i = 2; i <= rs.getMetaData().getColumnCount(); i++) {
|
||||||
// Add the rest of the placeholders and values. This is so we
|
// Add the rest of the placeholders and values. This is so we
|
||||||
// have (?, ?, ?) and not (?, ?, ?, ).
|
// have (?, ?, ?) and not (?, ?, ?, ).
|
||||||
query += ", ?";
|
query += ", ?";
|
||||||
}
|
}
|
||||||
// End the query
|
// End the query
|
||||||
query += ")";
|
query += ")";
|
||||||
PreparedStatement ps = db.getConnection().prepareStatement(query);
|
PreparedStatement ps = db.getConnection().prepareStatement(query);
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
n++;
|
n++;
|
||||||
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
|
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
|
||||||
ps.setObject(i, rs.getObject(i));
|
ps.setObject(i, rs.getObject(i));
|
||||||
}
|
}
|
||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
if (n % 100 == 0) {
|
if (n % 100 == 0) {
|
||||||
ps.executeBatch();
|
ps.executeBatch();
|
||||||
System.out.println(n + " records copied...");
|
System.out.println(n + " records copied...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ps.executeBatch();
|
ps.executeBatch();
|
||||||
// Close the resultset of that table
|
// Close the resultset of that table
|
||||||
rs.close();
|
rs.close();
|
||||||
}
|
}
|
||||||
// Success!
|
// Success!
|
||||||
db.getConnection().close();
|
db.getConnection().close();
|
||||||
this.getConnection().close();
|
this.getConnection().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,11 +3,11 @@ package org.maxgamer.QuickShop.Database;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
||||||
public interface DatabaseCore {
|
public interface DatabaseCore {
|
||||||
public Connection getConnection();
|
public Connection getConnection();
|
||||||
|
|
||||||
public void queue(BufferStatement bs);
|
public void queue(BufferStatement bs);
|
||||||
|
|
||||||
public void flush();
|
public void flush();
|
||||||
|
|
||||||
public void close();
|
public void close();
|
||||||
}
|
}
|
@ -5,58 +5,59 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
public class DatabaseHelper {
|
public class DatabaseHelper {
|
||||||
public static void setup(Database db) throws SQLException {
|
public static void setup(Database db) throws SQLException {
|
||||||
if (!db.hasTable("shops")) {
|
if (!db.hasTable("shops")) {
|
||||||
createShopsTable(db);
|
createShopsTable(db);
|
||||||
}
|
}
|
||||||
if (!db.hasTable("messages")) {
|
if (!db.hasTable("messages")) {
|
||||||
createMessagesTable(db);
|
createMessagesTable(db);
|
||||||
}
|
}
|
||||||
checkColumns(db);
|
checkColumns(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that all required columns exist.
|
* Verifies that all required columns exist.
|
||||||
*/
|
*/
|
||||||
public static void checkColumns(Database db) {
|
public static void checkColumns(Database db) {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
// V3.4.2
|
// V3.4.2
|
||||||
ps = db.getConnection().prepareStatement("ALTER TABLE shops MODIFY COLUMN price double(32,2) NOT NULL AFTER owner");
|
ps = db.getConnection().prepareStatement("ALTER TABLE shops MODIFY COLUMN price double(32,2) NOT NULL AFTER owner");
|
||||||
ps.execute();
|
ps.execute();
|
||||||
ps.close();
|
ps.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// V3.4.3
|
// V3.4.3
|
||||||
ps = db.getConnection().prepareStatement("ALTER TABLE messages MODIFY COLUMN time BIGINT(32) NOT NULL AFTER message");
|
ps = db.getConnection().prepareStatement("ALTER TABLE messages MODIFY COLUMN time BIGINT(32) NOT NULL AFTER message");
|
||||||
ps.execute();
|
ps.execute();
|
||||||
ps.close();
|
ps.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the database table 'shops'.
|
* Creates the database table 'shops'.
|
||||||
*
|
*
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
* If the connection is invalid.
|
* If the connection is invalid.
|
||||||
*/
|
*/
|
||||||
public static void createShopsTable(Database db) throws SQLException {
|
public static void createShopsTable(Database db) throws SQLException {
|
||||||
Statement st = db.getConnection().createStatement();
|
Statement st = db.getConnection().createStatement();
|
||||||
String createTable = "CREATE TABLE shops (" + "owner TEXT(32) NOT NULL, " + "price double(32, 2) NOT NULL, " + "itemConfig TEXT CHARSET utf8 NOT NULL, " + "x INTEGER(32) NOT NULL, " + "y INTEGER(32) NOT NULL, " + "z INTEGER(32) NOT NULL, " + "world VARCHAR(32) NOT NULL, " + "unlimited boolean, " + "type boolean, " + "PRIMARY KEY (x, y, z, world) " + ");";
|
String createTable = "CREATE TABLE shops (" + "owner TEXT(32) NOT NULL, " + "price double(32, 2) NOT NULL, " + "itemConfig TEXT CHARSET utf8 NOT NULL, " + "x INTEGER(32) NOT NULL, "
|
||||||
st.execute(createTable);
|
+ "y INTEGER(32) NOT NULL, " + "z INTEGER(32) NOT NULL, " + "world VARCHAR(32) NOT NULL, " + "unlimited boolean, " + "type boolean, " + "PRIMARY KEY (x, y, z, world) " + ");";
|
||||||
}
|
st.execute(createTable);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the database table 'messages'
|
* Creates the database table 'messages'
|
||||||
*
|
*
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
* If the connection is invalid
|
* If the connection is invalid
|
||||||
*/
|
*/
|
||||||
public static void createMessagesTable(Database db) throws SQLException {
|
public static void createMessagesTable(Database db) throws SQLException {
|
||||||
Statement st = db.getConnection().createStatement();
|
Statement st = db.getConnection().createStatement();
|
||||||
String createTable = "CREATE TABLE messages (" + "owner TEXT(32) NOT NULL, " + "message TEXT(200) NOT NULL, " + "time BIGINT(32) NOT NULL " + ");";
|
String createTable = "CREATE TABLE messages (" + "owner TEXT(32) NOT NULL, " + "message TEXT(200) NOT NULL, " + "time BIGINT(32) NOT NULL " + ");";
|
||||||
st.execute(createTable);
|
st.execute(createTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,78 +8,78 @@ import java.util.ArrayList;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class MySQLCore implements DatabaseCore {
|
public class MySQLCore implements DatabaseCore {
|
||||||
private String url;
|
private String url;
|
||||||
/** The connection properties... user, pass, autoReconnect.. */
|
/** The connection properties... user, pass, autoReconnect.. */
|
||||||
private Properties info;
|
private Properties info;
|
||||||
private static final int MAX_CONNECTIONS = 8;
|
private static final int MAX_CONNECTIONS = 8;
|
||||||
private static ArrayList<Connection> pool = new ArrayList<Connection>();
|
private static ArrayList<Connection> pool = new ArrayList<Connection>();
|
||||||
|
|
||||||
public MySQLCore(String host, String user, String pass, String database, String port) {
|
public MySQLCore(String host, String user, String pass, String database, String port) {
|
||||||
info = new Properties();
|
info = new Properties();
|
||||||
info.put("autoReconnect", "true");
|
info.put("autoReconnect", "true");
|
||||||
info.put("user", user);
|
info.put("user", user);
|
||||||
info.put("password", pass);
|
info.put("password", pass);
|
||||||
info.put("useUnicode", "true");
|
info.put("useUnicode", "true");
|
||||||
info.put("characterEncoding", "utf8");
|
info.put("characterEncoding", "utf8");
|
||||||
this.url = "jdbc:mysql://" + host + ":" + port + "/" + database;
|
this.url = "jdbc:mysql://" + host + ":" + port + "/" + database;
|
||||||
for (int i = 0; i < MAX_CONNECTIONS; i++)
|
for (int i = 0; i < MAX_CONNECTIONS; i++)
|
||||||
pool.add(null);
|
pool.add(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the database connection for executing queries on.
|
* Gets the database connection for executing queries on.
|
||||||
*
|
*
|
||||||
* @return The database connection
|
* @return The database connection
|
||||||
*/
|
*/
|
||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
for (int i = 0; i < MAX_CONNECTIONS; i++) {
|
for (int i = 0; i < MAX_CONNECTIONS; i++) {
|
||||||
Connection connection = pool.get(i);
|
Connection connection = pool.get(i);
|
||||||
try {
|
try {
|
||||||
// If we have a current connection, fetch it
|
// If we have a current connection, fetch it
|
||||||
if (connection != null && !connection.isClosed()) {
|
if (connection != null && !connection.isClosed()) {
|
||||||
if (connection.isValid(10)) {
|
if (connection.isValid(10)) {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
// Else, it is invalid, so we return another connection.
|
// Else, it is invalid, so we return another connection.
|
||||||
}
|
}
|
||||||
connection = DriverManager.getConnection(this.url, info);
|
connection = DriverManager.getConnection(this.url, info);
|
||||||
pool.set(i, connection);
|
pool.set(i, connection);
|
||||||
return connection;
|
return connection;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queue(BufferStatement bs) {
|
public void queue(BufferStatement bs) {
|
||||||
try {
|
try {
|
||||||
Connection con = this.getConnection();
|
Connection con = this.getConnection();
|
||||||
while (con == null) {
|
while (con == null) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(15);
|
Thread.sleep(15);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
// Try again
|
// Try again
|
||||||
this.getConnection();
|
this.getConnection();
|
||||||
}
|
}
|
||||||
PreparedStatement ps = bs.prepareStatement(con);
|
PreparedStatement ps = bs.prepareStatement(con);
|
||||||
ps.execute();
|
ps.execute();
|
||||||
ps.close();
|
ps.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// Nothing, because queries are executed immediately for MySQL
|
// Nothing, because queries are executed immediately for MySQL
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush() {
|
public void flush() {
|
||||||
// Nothing, because queries are executed immediately for MySQL
|
// Nothing, because queries are executed immediately for MySQL
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,102 +9,102 @@ import java.sql.SQLException;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class SQLiteCore implements DatabaseCore {
|
public class SQLiteCore implements DatabaseCore {
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private final File dbFile;
|
private final File dbFile;
|
||||||
private volatile Thread watcher;
|
private volatile Thread watcher;
|
||||||
private volatile LinkedList<BufferStatement> queue = new LinkedList<BufferStatement>();
|
private volatile LinkedList<BufferStatement> queue = new LinkedList<BufferStatement>();
|
||||||
|
|
||||||
public SQLiteCore(final File dbFile) {
|
public SQLiteCore(final File dbFile) {
|
||||||
this.dbFile = dbFile;
|
this.dbFile = dbFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush() {
|
public void flush() {
|
||||||
while (queue.isEmpty() == false) {
|
while (queue.isEmpty() == false) {
|
||||||
BufferStatement bs;
|
BufferStatement bs;
|
||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
bs = queue.removeFirst();
|
bs = queue.removeFirst();
|
||||||
}
|
}
|
||||||
synchronized (dbFile) {
|
synchronized (dbFile) {
|
||||||
try {
|
try {
|
||||||
final PreparedStatement ps = bs.prepareStatement(getConnection());
|
final PreparedStatement ps = bs.prepareStatement(getConnection());
|
||||||
ps.execute();
|
ps.execute();
|
||||||
ps.close();
|
ps.close();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the database connection for executing queries on.
|
* Gets the database connection for executing queries on.
|
||||||
*
|
*
|
||||||
* @return The database connection
|
* @return The database connection
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
try {
|
try {
|
||||||
// If we have a current connection, fetch it
|
// If we have a current connection, fetch it
|
||||||
if (this.connection != null && !this.connection.isClosed()) {
|
if (this.connection != null && !this.connection.isClosed()) {
|
||||||
return this.connection;
|
return this.connection;
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (this.dbFile.exists()) {
|
if (this.dbFile.exists()) {
|
||||||
// So we need a new connection
|
// So we need a new connection
|
||||||
try {
|
try {
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbFile);
|
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbFile);
|
||||||
return this.connection;
|
return this.connection;
|
||||||
} catch (final ClassNotFoundException e) {
|
} catch (final ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// So we need a new file too.
|
// So we need a new file too.
|
||||||
try {
|
try {
|
||||||
// Create the file
|
// Create the file
|
||||||
this.dbFile.createNewFile();
|
this.dbFile.createNewFile();
|
||||||
// Now we won't need a new file, just a connection.
|
// Now we won't need a new file, just a connection.
|
||||||
// This will return that new connection.
|
// This will return that new connection.
|
||||||
return this.getConnection();
|
return this.getConnection();
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queue(final BufferStatement bs) {
|
public void queue(final BufferStatement bs) {
|
||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
queue.add(bs);
|
queue.add(bs);
|
||||||
}
|
}
|
||||||
if (watcher == null || !watcher.isAlive()) {
|
if (watcher == null || !watcher.isAlive()) {
|
||||||
startWatcher();
|
startWatcher();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startWatcher() {
|
private void startWatcher() {
|
||||||
watcher = new Thread() {
|
watcher = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30000);
|
Thread.sleep(30000);
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
}
|
}
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
watcher.start();
|
watcher.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,129 +3,129 @@ package org.maxgamer.QuickShop.Economy;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Economy implements EconomyCore {
|
public class Economy implements EconomyCore {
|
||||||
private final EconomyCore core;
|
private final EconomyCore core;
|
||||||
|
|
||||||
public Economy(final EconomyCore core) {
|
public Economy(final EconomyCore core) {
|
||||||
this.core = core;
|
this.core = core;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String currencyNamePlural() {
|
public String currencyNamePlural() {
|
||||||
return this.core.currencyNamePlural();
|
return this.core.currencyNamePlural();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deposits a given amount of money from thin air to the given username.
|
* Deposits a given amount of money from thin air to the given username.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The exact (case insensitive) username to give money to
|
* The exact (case insensitive) username to give money to
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to give them
|
* The amount to give them
|
||||||
* @return True if success (Should be almost always)
|
* @return True if success (Should be almost always)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean deposit(final String name, final double amount) {
|
public boolean deposit(final String name, final double amount) {
|
||||||
return this.core.deposit(name, amount);
|
return this.core.deposit(name, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deposit(final UUID name, final double amount) {
|
public boolean deposit(final UUID name, final double amount) {
|
||||||
return this.core.deposit(name, amount);
|
return this.core.deposit(name, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the given number... E.g. 50.5 becomes $50.5 Dollars, or 50
|
* Formats the given number... E.g. 50.5 becomes $50.5 Dollars, or 50
|
||||||
* Dollars 5 Cents
|
* Dollars 5 Cents
|
||||||
*
|
*
|
||||||
* @param balance
|
* @param balance
|
||||||
* The given number
|
* The given number
|
||||||
* @return The balance in human readable text.
|
* @return The balance in human readable text.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String format(final double balance) {
|
public String format(final double balance) {
|
||||||
return this.core.format(balance);
|
return this.core.format(balance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the balance of the given account name
|
* Fetches the balance of the given account name
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The name of the account
|
* The name of the account
|
||||||
* @return Their current balance.
|
* @return Their current balance.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public double getBalance(final String name) {
|
public double getBalance(final String name) {
|
||||||
return this.core.getBalance(name);
|
return this.core.getBalance(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBalance(final UUID name) {
|
public double getBalance(final UUID name) {
|
||||||
return this.core.getBalance(name);
|
return this.core.getBalance(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean has(final String name, final double amount) {
|
public boolean has(final String name, final double amount) {
|
||||||
return this.core.getBalance(name) >= amount;
|
return this.core.getBalance(name) >= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that this economy is valid. Returns false if it is not valid.
|
* Checks that this economy is valid. Returns false if it is not valid.
|
||||||
*
|
*
|
||||||
* @return True if this economy will work, false if it will not.
|
* @return True if this economy will work, false if it will not.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return this.core.isValid();
|
return this.core.isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.core.getClass().getName().split("_")[1];
|
return this.core.getClass().getName().split("_")[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfers the given amount of money from Player1 to Player2
|
* Transfers the given amount of money from Player1 to Player2
|
||||||
*
|
*
|
||||||
* @param from
|
* @param from
|
||||||
* The player who is paying money
|
* The player who is paying money
|
||||||
* @param to
|
* @param to
|
||||||
* The player who is receiving money
|
* The player who is receiving money
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to transfer
|
* The amount to transfer
|
||||||
* @return true if success (Payer had enough cash, receiver was able to
|
* @return true if success (Payer had enough cash, receiver was able to
|
||||||
* receive the funds)
|
* receive the funds)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean transfer(final String from, final String to, final double amount) {
|
public boolean transfer(final String from, final String to, final double amount) {
|
||||||
return this.core.transfer(from, to, amount);
|
return this.core.transfer(from, to, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean transfer(final UUID from, final UUID to, final double amount) {
|
public boolean transfer(final UUID from, final UUID to, final double amount) {
|
||||||
return this.core.transfer(from, to, amount);
|
return this.core.transfer(from, to, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Withdraws a given amount of money from the given username and turns it to
|
* Withdraws a given amount of money from the given username and turns it to
|
||||||
* thin air.
|
* thin air.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The exact (case insensitive) username to take money from
|
* The exact (case insensitive) username to take money from
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to take from them
|
* The amount to take from them
|
||||||
* @return True if success, false if they didn't have enough cash
|
* @return True if success, false if they didn't have enough cash
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean withdraw(final String name, final double amount) {
|
public boolean withdraw(final String name, final double amount) {
|
||||||
return this.core.withdraw(name, amount);
|
return this.core.withdraw(name, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean withdraw(final UUID name, final double amount) {
|
public boolean withdraw(final UUID name, final double amount) {
|
||||||
return this.core.withdraw(name, amount);
|
return this.core.withdraw(name, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,118 +6,118 @@ import java.util.UUID;
|
|||||||
* @author netherfoam Represents an economy.
|
* @author netherfoam Represents an economy.
|
||||||
*/
|
*/
|
||||||
public interface EconomyCore {
|
public interface EconomyCore {
|
||||||
public String currencyNamePlural();
|
public String currencyNamePlural();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deposits a given amount of money from thin air to the given username.
|
* Deposits a given amount of money from thin air to the given username.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The exact (case insensitive) username to give money to
|
* The exact (case insensitive) username to give money to
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to give them
|
* The amount to give them
|
||||||
* @return True if success (Should be almost always)
|
* @return True if success (Should be almost always)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean deposit(String name, double amount);
|
public boolean deposit(String name, double amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deposits a given amount of money from thin air to the given username.
|
* Deposits a given amount of money from thin air to the given username.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The exact (case insensitive) username to give money to
|
* The exact (case insensitive) username to give money to
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to give them
|
* The amount to give them
|
||||||
* @return True if success (Should be almost always)
|
* @return True if success (Should be almost always)
|
||||||
*/
|
*/
|
||||||
public boolean deposit(UUID name, double amount);
|
public boolean deposit(UUID name, double amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the given number... E.g. 50.5 becomes $50.5 Dollars, or 50
|
* Formats the given number... E.g. 50.5 becomes $50.5 Dollars, or 50
|
||||||
* Dollars 5 Cents
|
* Dollars 5 Cents
|
||||||
*
|
*
|
||||||
* @param balance
|
* @param balance
|
||||||
* The given number
|
* The given number
|
||||||
* @return The balance in human readable text.
|
* @return The balance in human readable text.
|
||||||
*/
|
*/
|
||||||
public String format(double balance);
|
public String format(double balance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the balance of the given account name
|
* Fetches the balance of the given account name
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The name of the account
|
* The name of the account
|
||||||
* @return Their current balance.
|
* @return Their current balance.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public double getBalance(String name);
|
public double getBalance(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the balance of the given account name
|
* Fetches the balance of the given account name
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The name of the account
|
* The name of the account
|
||||||
* @return Their current balance.
|
* @return Their current balance.
|
||||||
*/
|
*/
|
||||||
public double getBalance(UUID name);
|
public double getBalance(UUID name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that this economy is valid. Returns false if it is not valid.
|
* Checks that this economy is valid. Returns false if it is not valid.
|
||||||
*
|
*
|
||||||
* @return True if this economy will work, false if it will not.
|
* @return True if this economy will work, false if it will not.
|
||||||
*/
|
*/
|
||||||
public boolean isValid();
|
public boolean isValid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfers the given amount of money from Player1 to Player2
|
* Transfers the given amount of money from Player1 to Player2
|
||||||
*
|
*
|
||||||
* @param from
|
* @param from
|
||||||
* The player who is paying money
|
* The player who is paying money
|
||||||
* @param to
|
* @param to
|
||||||
* The player who is receiving money
|
* The player who is receiving money
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to transfer
|
* The amount to transfer
|
||||||
* @return true if success (Payer had enough cash, receiver was able to
|
* @return true if success (Payer had enough cash, receiver was able to
|
||||||
* receive the funds)
|
* receive the funds)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean transfer(String from, String to, double amount);
|
public boolean transfer(String from, String to, double amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfers the given amount of money from Player1 to Player2
|
* Transfers the given amount of money from Player1 to Player2
|
||||||
*
|
*
|
||||||
* @param from
|
* @param from
|
||||||
* The player who is paying money
|
* The player who is paying money
|
||||||
* @param to
|
* @param to
|
||||||
* The player who is receiving money
|
* The player who is receiving money
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to transfer
|
* The amount to transfer
|
||||||
* @return true if success (Payer had enough cash, receiver was able to
|
* @return true if success (Payer had enough cash, receiver was able to
|
||||||
* receive the funds)
|
* receive the funds)
|
||||||
*/
|
*/
|
||||||
public boolean transfer(UUID from, UUID to, double amount);
|
public boolean transfer(UUID from, UUID to, double amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Withdraws a given amount of money from the given username and turns it to
|
* Withdraws a given amount of money from the given username and turns it to
|
||||||
* thin air.
|
* thin air.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The exact (case insensitive) username to take money from
|
* The exact (case insensitive) username to take money from
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to take from them
|
* The amount to take from them
|
||||||
* @return True if success, false if they didn't have enough cash
|
* @return True if success, false if they didn't have enough cash
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean withdraw(String name, double amount);
|
public boolean withdraw(String name, double amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Withdraws a given amount of money from the given username and turns it to
|
* Withdraws a given amount of money from the given username and turns it to
|
||||||
* thin air.
|
* thin air.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The exact (case insensitive) username to take money from
|
* The exact (case insensitive) username to take money from
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount to take from them
|
* The amount to take from them
|
||||||
* @return True if success, false if they didn't have enough cash
|
* @return True if success, false if they didn't have enough cash
|
||||||
*/
|
*/
|
||||||
public boolean withdraw(UUID name, double amount);
|
public boolean withdraw(UUID name, double amount);
|
||||||
}
|
}
|
||||||
|
@ -9,108 +9,108 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
|||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
public class Economy_Vault implements EconomyCore {
|
public class Economy_Vault implements EconomyCore {
|
||||||
private Economy vault;
|
private Economy vault;
|
||||||
|
|
||||||
public Economy_Vault() {
|
public Economy_Vault() {
|
||||||
setupEconomy();
|
setupEconomy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String currencyNamePlural() {
|
public String currencyNamePlural() {
|
||||||
return this.vault.currencyNamePlural();
|
return this.vault.currencyNamePlural();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean deposit(final String name, final double amount) {
|
public boolean deposit(final String name, final double amount) {
|
||||||
return this.vault.depositPlayer(name, amount).transactionSuccess();
|
return this.vault.depositPlayer(name, amount).transactionSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deposit(final UUID name, final double amount) {
|
public boolean deposit(final UUID name, final double amount) {
|
||||||
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
||||||
return this.vault.depositPlayer(p, amount).transactionSuccess();
|
return this.vault.depositPlayer(p, amount).transactionSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(final double balance) {
|
public String format(final double balance) {
|
||||||
try {
|
try {
|
||||||
return this.vault.format(balance);
|
return this.vault.format(balance);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
}
|
}
|
||||||
return "" + balance;
|
return "" + balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public double getBalance(final String name) {
|
public double getBalance(final String name) {
|
||||||
return this.vault.getBalance(name);
|
return this.vault.getBalance(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBalance(final UUID name) {
|
public double getBalance(final UUID name) {
|
||||||
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
||||||
return this.vault.getBalance(p);
|
return this.vault.getBalance(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return this.vault != null;
|
return this.vault != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean transfer(final String from, final String to, final double amount) {
|
public boolean transfer(final String from, final String to, final double amount) {
|
||||||
if (this.vault.getBalance(from) >= amount) {
|
if (this.vault.getBalance(from) >= amount) {
|
||||||
if (this.vault.withdrawPlayer(from, amount).transactionSuccess()) {
|
if (this.vault.withdrawPlayer(from, amount).transactionSuccess()) {
|
||||||
if (!this.vault.depositPlayer(to, amount).transactionSuccess()) {
|
if (!this.vault.depositPlayer(to, amount).transactionSuccess()) {
|
||||||
this.vault.depositPlayer(from, amount);
|
this.vault.depositPlayer(from, amount);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean transfer(final UUID from, final UUID to, final double amount) {
|
public boolean transfer(final UUID from, final UUID to, final double amount) {
|
||||||
final OfflinePlayer pFrom = Bukkit.getOfflinePlayer(from);
|
final OfflinePlayer pFrom = Bukkit.getOfflinePlayer(from);
|
||||||
final OfflinePlayer pTo = Bukkit.getOfflinePlayer(to);
|
final OfflinePlayer pTo = Bukkit.getOfflinePlayer(to);
|
||||||
if (this.vault.getBalance(pFrom) >= amount) {
|
if (this.vault.getBalance(pFrom) >= amount) {
|
||||||
if (this.vault.withdrawPlayer(pFrom, amount).transactionSuccess()) {
|
if (this.vault.withdrawPlayer(pFrom, amount).transactionSuccess()) {
|
||||||
if (!this.vault.depositPlayer(pTo, amount).transactionSuccess()) {
|
if (!this.vault.depositPlayer(pTo, amount).transactionSuccess()) {
|
||||||
this.vault.depositPlayer(pFrom, amount);
|
this.vault.depositPlayer(pFrom, amount);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean withdraw(final String name, final double amount) {
|
public boolean withdraw(final String name, final double amount) {
|
||||||
return this.vault.withdrawPlayer(name, amount).transactionSuccess();
|
return this.vault.withdrawPlayer(name, amount).transactionSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean withdraw(final UUID name, final double amount) {
|
public boolean withdraw(final UUID name, final double amount) {
|
||||||
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
||||||
return this.vault.withdrawPlayer(p, amount).transactionSuccess();
|
return this.vault.withdrawPlayer(p, amount).transactionSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupEconomy() {
|
private boolean setupEconomy() {
|
||||||
try {
|
try {
|
||||||
final RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServicesManager().getRegistration(Economy.class);
|
final RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServicesManager().getRegistration(Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
vault = (economyProvider.getProvider());
|
vault = (economyProvider.getProvider());
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
}
|
}
|
||||||
return vault != null;
|
return vault != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,100 +23,100 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import org.maxgamer.QuickShop.Util.Util;
|
import org.maxgamer.QuickShop.Util.Util;
|
||||||
|
|
||||||
public class BlockListener implements Listener {
|
public class BlockListener implements Listener {
|
||||||
private final QuickShop plugin;
|
private final QuickShop plugin;
|
||||||
|
|
||||||
public BlockListener(final QuickShop plugin) {
|
public BlockListener(final QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes chests when they're destroyed.
|
* Removes chests when they're destroyed.
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBreak(final BlockBreakEvent e) {
|
public void onBreak(final BlockBreakEvent e) {
|
||||||
final Block b = e.getBlock();
|
final Block b = e.getBlock();
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
// If the shop was a chest
|
// If the shop was a chest
|
||||||
if (b.getState() instanceof InventoryHolder) {
|
if (b.getState() instanceof InventoryHolder) {
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If they're either survival or the owner, they can break it
|
// If they're either survival or the owner, they can break it
|
||||||
final ItemStack pinh = p.getItemInHand();
|
final ItemStack pinh = p.getItemInHand();
|
||||||
if (p.getName().equals(shop.getOwner()) || p.getGameMode() == GameMode.SURVIVAL || pinh == null || pinh.getType() == plugin.getConfigManager().getSuperItem()) {
|
if (p.getName().equals(shop.getOwner()) || p.getGameMode() == GameMode.SURVIVAL || pinh == null || pinh.getType() == plugin.getConfigManager().getSuperItem()) {
|
||||||
// Cancel their current menu... Doesnt cancel other's menu's.
|
// Cancel their current menu... Doesnt cancel other's menu's.
|
||||||
final Info action = plugin.getShopManager().getActions().get(p.getName());
|
final Info action = plugin.getShopManager().getActions().get(p.getName());
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
action.setAction(ShopAction.CANCELLED);
|
action.setAction(ShopAction.CANCELLED);
|
||||||
}
|
}
|
||||||
shop.delete();
|
shop.delete();
|
||||||
p.sendMessage(MsgUtil.p("success-removed-shop"));
|
p.sendMessage(MsgUtil.p("success-removed-shop"));
|
||||||
} else {
|
} else {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.sendMessage(MsgUtil.p("no-creative-break"));
|
p.sendMessage(MsgUtil.p("no-creative-break"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (b.getType() == Material.WALL_SIGN) {
|
} else if (b.getType() == Material.WALL_SIGN) {
|
||||||
final Shop shop = getShopNextTo(b.getLocation());
|
final Shop shop = getShopNextTo(b.getLocation());
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles shops breaking through explosions
|
* Handles shops breaking through explosions
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onExplode(final EntityExplodeEvent e) {
|
public void onExplode(final EntityExplodeEvent e) {
|
||||||
if (e.isCancelled()) {
|
if (e.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < e.blockList().size(); i++) {
|
for (int i = 0; i < e.blockList().size(); i++) {
|
||||||
final Block b = e.blockList().get(i);
|
final Block b = e.blockList().get(i);
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
shop.delete();
|
shop.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for chest placement, so a doublechest shop can't be created.
|
* Listens for chest placement, so a doublechest shop can't be created.
|
||||||
*/
|
*/
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlace(final BlockPlaceEvent e) {
|
public void onPlace(final BlockPlaceEvent e) {
|
||||||
if (e.isCancelled()) {
|
if (e.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final BlockState bs = e.getBlock().getState();
|
final BlockState bs = e.getBlock().getState();
|
||||||
if (bs instanceof DoubleChest == false) {
|
if (bs instanceof DoubleChest == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Block b = e.getBlock();
|
final Block b = e.getBlock();
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
final Block chest = Util.getSecondHalf(b);
|
final Block chest = Util.getSecondHalf(b);
|
||||||
if (chest != null && plugin.getShopManager().getShop(chest.getLocation()) != null && !p.hasPermission("quickshop.create.double")) {
|
if (chest != null && plugin.getShopManager().getShop(chest.getLocation()) != null && !p.hasPermission("quickshop.create.double")) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.sendMessage(MsgUtil.p("no-double-chests"));
|
p.sendMessage(MsgUtil.p("no-double-chests"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the shop a sign is attached to
|
* Gets the shop a sign is attached to
|
||||||
*
|
*
|
||||||
* @param loc
|
* @param loc
|
||||||
* The location of the sign
|
* The location of the sign
|
||||||
* @return The shop
|
* @return The shop
|
||||||
*/
|
*/
|
||||||
private Shop getShopNextTo(final Location loc) {
|
private Shop getShopNextTo(final Location loc) {
|
||||||
final Block b = Util.getAttached(loc.getBlock());
|
final Block b = Util.getAttached(loc.getBlock());
|
||||||
// Util.getAttached(b)
|
// Util.getAttached(b)
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return plugin.getShopManager().getShop(b.getLocation());
|
return plugin.getShopManager().getShop(b.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,18 +12,18 @@ import org.maxgamer.QuickShop.QuickShop;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ChatListener implements Listener {
|
public class ChatListener implements Listener {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public ChatListener(final QuickShop plugin) {
|
public ChatListener(final QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onChat(final AsyncPlayerChatEvent e) {
|
public void onChat(final AsyncPlayerChatEvent e) {
|
||||||
if (!plugin.getShopManager().getActions().containsKey(e.getPlayer().getName())) {
|
if (!plugin.getShopManager().getActions().containsKey(e.getPlayer().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage());
|
plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage());
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,33 +13,33 @@ import org.maxgamer.QuickShop.QuickShop;
|
|||||||
import org.maxgamer.QuickShop.Shop.Shop;
|
import org.maxgamer.QuickShop.Shop.Shop;
|
||||||
|
|
||||||
public class ChunkListener implements Listener {
|
public class ChunkListener implements Listener {
|
||||||
private QuickShop plugin;
|
private QuickShop plugin;
|
||||||
|
|
||||||
public ChunkListener(QuickShop plugin) {
|
public ChunkListener(QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onChunkLoad(ChunkLoadEvent e) {
|
public void onChunkLoad(ChunkLoadEvent e) {
|
||||||
Chunk c = e.getChunk();
|
Chunk c = e.getChunk();
|
||||||
if (plugin.getShopManager().getShops() == null)
|
if (plugin.getShopManager().getShops() == null)
|
||||||
return;
|
return;
|
||||||
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(c);
|
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(c);
|
||||||
if (inChunk == null)
|
if (inChunk == null)
|
||||||
return;
|
return;
|
||||||
for (Shop shop : inChunk.values()) {
|
for (Shop shop : inChunk.values()) {
|
||||||
shop.onLoad();
|
shop.onLoad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onChunkUnload(ChunkUnloadEvent e) {
|
public void onChunkUnload(ChunkUnloadEvent e) {
|
||||||
Chunk c = e.getChunk();
|
Chunk c = e.getChunk();
|
||||||
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(c);
|
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(c);
|
||||||
if (inChunk == null)
|
if (inChunk == null)
|
||||||
return;
|
return;
|
||||||
for (Shop shop : inChunk.values()) {
|
for (Shop shop : inChunk.values()) {
|
||||||
shop.onUnload();
|
shop.onUnload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,133 +17,133 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import org.maxgamer.QuickShop.Util.Util;
|
import org.maxgamer.QuickShop.Util.Util;
|
||||||
|
|
||||||
public class LockListener implements Listener {
|
public class LockListener implements Listener {
|
||||||
private final QuickShop plugin;
|
private final QuickShop plugin;
|
||||||
|
|
||||||
public LockListener(final QuickShop plugin) {
|
public LockListener(final QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes chests when they're destroyed.
|
* Removes chests when they're destroyed.
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onBreak(final BlockBreakEvent e) {
|
public void onBreak(final BlockBreakEvent e) {
|
||||||
Block b = e.getBlock();
|
Block b = e.getBlock();
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
// If the chest was a chest
|
// If the chest was a chest
|
||||||
if (Util.canBeShop(b)) {
|
if (Util.canBeShop(b)) {
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
return; // Wasn't a shop
|
return; // Wasn't a shop
|
||||||
}
|
}
|
||||||
// If they owned it or have bypass perms, they can destroy it
|
// If they owned it or have bypass perms, they can destroy it
|
||||||
if (!shop.getOwner().equals(p.getName()) && !p.hasPermission("quickshop.other.destroy")) {
|
if (!shop.getOwner().equals(p.getName()) && !p.hasPermission("quickshop.other.destroy")) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.sendMessage(MsgUtil.p("no-permission"));
|
p.sendMessage(MsgUtil.p("no-permission"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (b.getType() == Material.WALL_SIGN) {
|
} else if (b.getType() == Material.WALL_SIGN) {
|
||||||
b = Util.getAttached(b);
|
b = Util.getAttached(b);
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onClick(final PlayerInteractEvent e) {
|
public void onClick(final PlayerInteractEvent e) {
|
||||||
Block b = e.getClickedBlock();
|
Block b = e.getClickedBlock();
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||||
return; // Didn't right click it, we dont care.
|
return; // Didn't right click it, we dont care.
|
||||||
}
|
}
|
||||||
if (!Util.canBeShop(b)) {
|
if (!Util.canBeShop(b)) {
|
||||||
return; // Interacted with air
|
return; // Interacted with air
|
||||||
}
|
}
|
||||||
Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
// Make sure they're not using the non-shop half of a double chest.
|
// Make sure they're not using the non-shop half of a double chest.
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
b = Util.getSecondHalf(b);
|
b = Util.getSecondHalf(b);
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
shop = plugin.getShopManager().getShop(b.getLocation());
|
shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!shop.getOwner().equals(p.getName())) {
|
if (!shop.getOwner().equals(p.getName())) {
|
||||||
if (p.hasPermission("quickshop.other.open")) {
|
if (p.hasPermission("quickshop.other.open")) {
|
||||||
p.sendMessage(MsgUtil.p("bypassing-lock"));
|
p.sendMessage(MsgUtil.p("bypassing-lock"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
p.sendMessage(MsgUtil.p("that-is-locked"));
|
p.sendMessage(MsgUtil.p("that-is-locked"));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles shops breaking through explosions
|
* Handles shops breaking through explosions
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onExplode(final EntityExplodeEvent e) {
|
public void onExplode(final EntityExplodeEvent e) {
|
||||||
if (e.isCancelled()) {
|
if (e.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < e.blockList().size(); i++) {
|
for (int i = 0; i < e.blockList().size(); i++) {
|
||||||
final Block b = e.blockList().get(i);
|
final Block b = e.blockList().get(i);
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
// ToDo: Shouldn't I be decrementing 1 here? Concurrency and
|
// ToDo: Shouldn't I be decrementing 1 here? Concurrency and
|
||||||
// all..
|
// all..
|
||||||
e.blockList().remove(b);
|
e.blockList().remove(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles hopper placement
|
* Handles hopper placement
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlace(final BlockPlaceEvent e) {
|
public void onPlace(final BlockPlaceEvent e) {
|
||||||
final Block b = e.getBlock();
|
final Block b = e.getBlock();
|
||||||
try {
|
try {
|
||||||
if (b.getType() != Material.HOPPER) {
|
if (b.getType() != Material.HOPPER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (final NoSuchFieldError er) {
|
} catch (final NoSuchFieldError er) {
|
||||||
return; // Your server doesn't have hoppers
|
return; // Your server doesn't have hoppers
|
||||||
}
|
}
|
||||||
Block c = e.getBlockAgainst();
|
Block c = e.getBlockAgainst();
|
||||||
if (Util.canBeShop(c) == false) {
|
if (Util.canBeShop(c) == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
Shop shop = plugin.getShopManager().getShop(c.getLocation());
|
Shop shop = plugin.getShopManager().getShop(c.getLocation());
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
c = Util.getSecondHalf(c);
|
c = Util.getSecondHalf(c);
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
return; // You didn't place a hopper on a shop. Meh.
|
return; // You didn't place a hopper on a shop. Meh.
|
||||||
}
|
}
|
||||||
shop = plugin.getShopManager().getShop(c.getLocation());
|
shop = plugin.getShopManager().getShop(c.getLocation());
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p.getName().equals(shop.getOwner()) == false) {
|
if (p.getName().equals(shop.getOwner()) == false) {
|
||||||
if (p.hasPermission("quickshop.other.open")) {
|
if (p.hasPermission("quickshop.other.open")) {
|
||||||
p.sendMessage(MsgUtil.p("bypassing-lock"));
|
p.sendMessage(MsgUtil.p("bypassing-lock"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
p.sendMessage(MsgUtil.p("that-is-locked"));
|
p.sendMessage(MsgUtil.p("that-is-locked"));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,173 +29,173 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
|
|||||||
import org.maxgamer.QuickShop.Util.Util;
|
import org.maxgamer.QuickShop.Util.Util;
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
private final QuickShop plugin;
|
private final QuickShop plugin;
|
||||||
|
|
||||||
public PlayerListener(final QuickShop plugin) {
|
public PlayerListener(final QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
/**
|
/**
|
||||||
* Handles players left clicking a chest. Left click a NORMAL chest with
|
* Handles players left clicking a chest. Left click a NORMAL chest with
|
||||||
* item : Send creation menu Left click a SHOP chest : Send purchase menu
|
* item : Send creation menu Left click a SHOP chest : Send purchase menu
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onClick(final PlayerInteractEvent e) {
|
public void onClick(final PlayerInteractEvent e) {
|
||||||
final Block b = e.getClickedBlock();
|
final Block b = e.getClickedBlock();
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
if (e.getAction() != Action.LEFT_CLICK_BLOCK || (e.getMaterial() == plugin.getConfigManager().getSuperItem() && b.getType() == Material.WALL_SIGN)) {
|
if (e.getAction() != Action.LEFT_CLICK_BLOCK || (e.getMaterial() == plugin.getConfigManager().getSuperItem() && b.getType() == Material.WALL_SIGN)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location loc = b.getLocation();
|
final Location loc = b.getLocation();
|
||||||
final ItemStack item = e.getItem();
|
final ItemStack item = e.getItem();
|
||||||
// Get the shop
|
// Get the shop
|
||||||
Shop shop = plugin.getShopManager().getShop(loc);
|
Shop shop = plugin.getShopManager().getShop(loc);
|
||||||
// If that wasn't a shop, search nearby shops
|
// If that wasn't a shop, search nearby shops
|
||||||
if (shop == null && b.getType() == Material.WALL_SIGN) {
|
if (shop == null && b.getType() == Material.WALL_SIGN) {
|
||||||
final Block attached = Util.getAttached(b);
|
final Block attached = Util.getAttached(b);
|
||||||
if (attached != null) {
|
if (attached != null) {
|
||||||
shop = plugin.getShopManager().getShop(attached.getLocation());
|
shop = plugin.getShopManager().getShop(attached.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Purchase handling
|
// Purchase handling
|
||||||
if (shop != null && p.hasPermission("quickshop.use") && (plugin.getConfigManager().isSneakTrade() == p.isSneaking())) {
|
if (shop != null && p.hasPermission("quickshop.use") && (plugin.getConfigManager().isSneakTrade() == p.isSneaking())) {
|
||||||
shop.onClick();
|
shop.onClick();
|
||||||
// Text menu
|
// Text menu
|
||||||
MsgUtil.sendShopInfo(p, shop);
|
MsgUtil.sendShopInfo(p, shop);
|
||||||
if (!plugin.getConfigManager().isEnableMagicLib() && b.getType() == Material.WALL_SIGN) {
|
if (!plugin.getConfigManager().isEnableMagicLib() && b.getType() == Material.WALL_SIGN) {
|
||||||
final Inventory in = Bukkit.createInventory(null, 9, plugin.getConfigManager().getGuiTitle());
|
final Inventory in = Bukkit.createInventory(null, 9, plugin.getConfigManager().getGuiTitle());
|
||||||
in.setItem(4, shop.getItem());
|
in.setItem(4, shop.getItem());
|
||||||
p.openInventory(in);
|
p.openInventory(in);
|
||||||
}
|
}
|
||||||
// Add the new action
|
// Add the new action
|
||||||
final HashMap<String, Info> actions = plugin.getShopManager().getActions();
|
final HashMap<String, Info> actions = plugin.getShopManager().getActions();
|
||||||
final Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop);
|
final Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop);
|
||||||
actions.put(p.getName(), info);
|
actions.put(p.getName(), info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Handles creating shops
|
// Handles creating shops
|
||||||
else if (shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE
|
else if (shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE
|
||||||
&& (plugin.getConfigManager().isSneakCreate() == p.isSneaking())) {
|
&& (plugin.getConfigManager().isSneakCreate() == p.isSneaking())) {
|
||||||
if (!plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
|
if (!plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
|
||||||
// As of the new checking system, most plugins will tell the
|
// As of the new checking system, most plugins will tell the
|
||||||
// player why they can't create a shop there.
|
// player why they can't create a shop there.
|
||||||
// So telling them a message would cause spam etc.
|
// So telling them a message would cause spam etc.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Util.getSecondHalf(b) != null && !p.hasPermission("quickshop.create.double")) {
|
if (Util.getSecondHalf(b) != null && !p.hasPermission("quickshop.create.double")) {
|
||||||
p.sendMessage(MsgUtil.p("no-double-chests"));
|
p.sendMessage(MsgUtil.p("no-double-chests"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Util.isBlacklisted(item.getType()) && !p.hasPermission("quickshop.bypass." + item.getTypeId())) {
|
if (Util.isBlacklisted(item.getType()) && !p.hasPermission("quickshop.bypass." + item.getTypeId())) {
|
||||||
p.sendMessage(MsgUtil.p("blacklisted-item"));
|
p.sendMessage(MsgUtil.p("blacklisted-item"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Finds out where the sign should be placed for the shop
|
// Finds out where the sign should be placed for the shop
|
||||||
Block last = null;
|
Block last = null;
|
||||||
final Location from = p.getLocation().clone();
|
final Location from = p.getLocation().clone();
|
||||||
from.setY(b.getY());
|
from.setY(b.getY());
|
||||||
from.setPitch(0);
|
from.setPitch(0);
|
||||||
final BlockIterator bIt = new BlockIterator(from, 0, 7);
|
final BlockIterator bIt = new BlockIterator(from, 0, 7);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block n = bIt.next();
|
final Block n = bIt.next();
|
||||||
if (n.equals(b)) {
|
if (n.equals(b)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
last = n;
|
last = n;
|
||||||
}
|
}
|
||||||
// Send creation menu.
|
// Send creation menu.
|
||||||
final Info info = new Info(b.getLocation(), ShopAction.CREATE, e.getItem(), last);
|
final Info info = new Info(b.getLocation(), ShopAction.CREATE, e.getItem(), last);
|
||||||
plugin.getShopManager().getActions().put(p.getName(), info);
|
plugin.getShopManager().getActions().put(p.getName(), info);
|
||||||
p.sendMessage(MsgUtil.p("how-much-to-trade-for", Util.getName(info.getItem())));
|
p.sendMessage(MsgUtil.p("how-much-to-trade-for", Util.getName(info.getItem())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(final PlayerJoinEvent e) {
|
public void onJoin(final PlayerJoinEvent e) {
|
||||||
// Notify the player any messages they were sent
|
// Notify the player any messages they were sent
|
||||||
Bukkit.getScheduler().runTaskLater(QuickShop.instance, new Runnable() {
|
Bukkit.getScheduler().runTaskLater(QuickShop.instance, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MsgUtil.flush(e.getPlayer());
|
MsgUtil.flush(e.getPlayer());
|
||||||
}
|
}
|
||||||
}, 60);
|
}, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for a player to move too far from a shop, then cancels the menu.
|
* Waits for a player to move too far from a shop, then cancels the menu.
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onMove(final PlayerMoveEvent e) {
|
public void onMove(final PlayerMoveEvent e) {
|
||||||
final Info info = plugin.getShopManager().getActions().get(e.getPlayer().getName());
|
final Info info = plugin.getShopManager().getActions().get(e.getPlayer().getName());
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
final Location loc1 = info.getLocation();
|
final Location loc1 = info.getLocation();
|
||||||
final Location loc2 = p.getLocation();
|
final Location loc2 = p.getLocation();
|
||||||
if (loc1.getWorld() != loc2.getWorld() || loc1.distanceSquared(loc2) > 25) {
|
if (loc1.getWorld() != loc2.getWorld() || loc1.distanceSquared(loc2) > 25) {
|
||||||
if (info.getAction() == ShopAction.CREATE) {
|
if (info.getAction() == ShopAction.CREATE) {
|
||||||
p.sendMessage(MsgUtil.p("shop-creation-cancelled"));
|
p.sendMessage(MsgUtil.p("shop-creation-cancelled"));
|
||||||
} else if (info.getAction() == ShopAction.BUY) {
|
} else if (info.getAction() == ShopAction.BUY) {
|
||||||
p.sendMessage(MsgUtil.p("shop-purchase-cancelled"));
|
p.sendMessage(MsgUtil.p("shop-purchase-cancelled"));
|
||||||
}
|
}
|
||||||
plugin.getShopManager().getActions().remove(p.getName());
|
plugin.getShopManager().getActions().remove(p.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(final PlayerQuitEvent e) {
|
public void onPlayerQuit(final PlayerQuitEvent e) {
|
||||||
// Remove them from the menu
|
// Remove them from the menu
|
||||||
plugin.getShopManager().getActions().remove(e.getPlayer().getName());
|
plugin.getShopManager().getActions().remove(e.getPlayer().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onSuperItemClick(final PlayerInteractEvent e) {
|
public void onSuperItemClick(final PlayerInteractEvent e) {
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
if (p.getGameMode() != GameMode.SURVIVAL || e.getMaterial() != plugin.getConfigManager().getSuperItem()) {
|
if (p.getGameMode() != GameMode.SURVIVAL || e.getMaterial() != plugin.getConfigManager().getSuperItem()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Block b = e.getClickedBlock();
|
final Block b = e.getClickedBlock();
|
||||||
if (b == null || b.getType() == null) {
|
if (b == null || b.getType() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If that wasn't a shop, search nearby shops
|
// If that wasn't a shop, search nearby shops
|
||||||
if (b.getType() == Material.WALL_SIGN) {
|
if (b.getType() == Material.WALL_SIGN) {
|
||||||
final Block attached = Util.getAttached(b);
|
final Block attached = Util.getAttached(b);
|
||||||
final Shop shop = attached == null ? null : plugin.getShopManager().getShop(attached.getLocation());
|
final Shop shop = attached == null ? null : plugin.getShopManager().getShop(attached.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
final Location loc = shop.getLocation();
|
final Location loc = shop.getLocation();
|
||||||
String shopmode = "";
|
String shopmode = "";
|
||||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
if (p.hasPermission("quickshop.unlimited") && (shop.getOwner().equalsIgnoreCase(p.getName()) || p.isOp())) {
|
if (p.hasPermission("quickshop.unlimited") && (shop.getOwner().equalsIgnoreCase(p.getName()) || p.isOp())) {
|
||||||
shop.setUnlimited(!shop.isUnlimited());
|
shop.setUnlimited(!shop.isUnlimited());
|
||||||
shopmode = shop.isUnlimited() ? "§e无限模式" : "§c有限模式";
|
shopmode = shop.isUnlimited() ? "§e无限模式" : "§c有限模式";
|
||||||
p.sendMessage(MsgUtil.p("command.toggle-unlimited", shopmode));
|
p.sendMessage(MsgUtil.p("command.toggle-unlimited", shopmode));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (shop.getShopType() == ShopType.BUYING && p.hasPermission("quickshop.create.sell") && (shop.getOwner().equalsIgnoreCase(p.getName()) || p.isOp())) {
|
if (shop.getShopType() == ShopType.BUYING && p.hasPermission("quickshop.create.sell") && (shop.getOwner().equalsIgnoreCase(p.getName()) || p.isOp())) {
|
||||||
shop.setShopType(ShopType.SELLING);
|
shop.setShopType(ShopType.SELLING);
|
||||||
p.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
|
p.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
|
||||||
shopmode = "出售模式";
|
shopmode = "出售模式";
|
||||||
} else if (shop.getShopType() == ShopType.SELLING && p.hasPermission("quickshop.create.buy") && (shop.getOwner().equalsIgnoreCase(p.getName()) || p.isOp())) {
|
} else if (shop.getShopType() == ShopType.SELLING && p.hasPermission("quickshop.create.buy") && (shop.getOwner().equalsIgnoreCase(p.getName()) || p.isOp())) {
|
||||||
shop.setShopType(ShopType.BUYING);
|
shop.setShopType(ShopType.BUYING);
|
||||||
p.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
|
p.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
|
||||||
shopmode = "收购模式";
|
shopmode = "收购模式";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!shopmode.isEmpty()) {
|
if (!shopmode.isEmpty()) {
|
||||||
plugin.log(String.format("玩家: %s 将 %s(%s,%s,%s) 的商店切换为 %s !", p.getName(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), shopmode));
|
plugin.log(String.format("玩家: %s 将 %s(%s,%s,%s) 的商店切换为 %s !", p.getName(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), shopmode));
|
||||||
}
|
}
|
||||||
shop.setSignText();
|
shop.setSignText();
|
||||||
shop.update();
|
shop.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onTeleport(final PlayerTeleportEvent e) {
|
public void onTeleport(final PlayerTeleportEvent e) {
|
||||||
final PlayerMoveEvent me = new PlayerMoveEvent(e.getPlayer(), e.getFrom(), e.getTo());
|
final PlayerMoveEvent me = new PlayerMoveEvent(e.getPlayer(), e.getFrom(), e.getTo());
|
||||||
onMove(me);
|
onMove(me);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,138 +24,138 @@ import org.maxgamer.QuickShop.Util.MarkUtil;
|
|||||||
|
|
||||||
public class ProtectListener implements Listener {
|
public class ProtectListener implements Listener {
|
||||||
|
|
||||||
private final QuickShop plugin;
|
private final QuickShop plugin;
|
||||||
|
|
||||||
public ProtectListener(final QuickShop plugin) {
|
public ProtectListener(final QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shop getShop(final Inventory inv) {
|
public Shop getShop(final Inventory inv) {
|
||||||
if (inv == null) {
|
if (inv == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
InventoryHolder holder = inv.getHolder();
|
InventoryHolder holder = inv.getHolder();
|
||||||
if (holder instanceof DoubleChest) {
|
if (holder instanceof DoubleChest) {
|
||||||
holder = ((DoubleChest) holder).getLeftSide();
|
holder = ((DoubleChest) holder).getLeftSide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (holder instanceof BlockState) {
|
if (holder instanceof BlockState) {
|
||||||
final Block block = ((BlockState) holder).getBlock();
|
final Block block = ((BlockState) holder).getBlock();
|
||||||
final Shop sp = plugin.getShopManager().getShop(block.getLocation());
|
final Shop sp = plugin.getShopManager().getShop(block.getLocation());
|
||||||
if (sp != null) {
|
if (sp != null) {
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInvMove(final InventoryMoveItemEvent e) {
|
public void onInvMove(final InventoryMoveItemEvent e) {
|
||||||
final ItemStack ci = e.getItem();
|
final ItemStack ci = e.getItem();
|
||||||
if (MarkUtil.hasMark(ci)) {
|
if (MarkUtil.hasMark(ci)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
final Inventory src = e.getSource();
|
final Inventory src = e.getSource();
|
||||||
final Inventory me = e.getInitiator();
|
final Inventory me = e.getInitiator();
|
||||||
final Inventory des = e.getDestination();
|
final Inventory des = e.getDestination();
|
||||||
final Shop srcshop = getShop(src);
|
final Shop srcshop = getShop(src);
|
||||||
final Shop meshop = getShop(me);
|
final Shop meshop = getShop(me);
|
||||||
final Shop desshop = getShop(des);
|
final Shop desshop = getShop(des);
|
||||||
if ((srcshop != null && meshop == null) || (meshop != null && desshop == null) || (srcshop != null && desshop != null && srcshop.getOwner().equalsIgnoreCase(desshop.getOwner()))) {
|
if ((srcshop != null && meshop == null) || (meshop != null && desshop == null) || (srcshop != null && desshop != null && srcshop.getOwner().equalsIgnoreCase(desshop.getOwner()))) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInvPickup(final InventoryPickupItemEvent e) {
|
public void onInvPickup(final InventoryPickupItemEvent e) {
|
||||||
if (!plugin.getConfigManager().isPreventHopper()) {
|
if (!plugin.getConfigManager().isPreventHopper()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ItemStack ci = e.getItem().getItemStack();
|
final ItemStack ci = e.getItem().getItemStack();
|
||||||
if (MarkUtil.hasMark(ci)) {
|
if (MarkUtil.hasMark(ci)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onItemClick(final InventoryClickEvent e) {
|
public void onItemClick(final InventoryClickEvent e) {
|
||||||
final Player p = (Player) e.getWhoClicked();
|
final Player p = (Player) e.getWhoClicked();
|
||||||
final ItemStack ci = e.getCurrentItem();
|
final ItemStack ci = e.getCurrentItem();
|
||||||
final Inventory inv = e.getInventory();
|
final Inventory inv = e.getInventory();
|
||||||
final int solt = e.getSlot();
|
final int solt = e.getSlot();
|
||||||
if (inv.getType() != InventoryType.PLAYER && inv.getType() != InventoryType.HOPPER) {
|
if (inv.getType() != InventoryType.PLAYER && inv.getType() != InventoryType.HOPPER) {
|
||||||
if (inv.getTitle().equalsIgnoreCase(plugin.getConfigManager().getGuiTitle())) {
|
if (inv.getTitle().equalsIgnoreCase(plugin.getConfigManager().getGuiTitle())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.closeInventory();
|
p.closeInventory();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (MarkUtil.hasMark(ci)) {
|
if (MarkUtil.hasMark(ci)) {
|
||||||
inv.setItem(solt, new ItemStack(Material.AIR));
|
inv.setItem(solt, new ItemStack(Material.AIR));
|
||||||
sendWarning(p, ci, "§d§l获取");
|
sendWarning(p, ci, "§d§l获取");
|
||||||
p.closeInventory();
|
p.closeInventory();
|
||||||
}
|
}
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerHandlerItem(final PlayerItemHeldEvent e) {
|
public void onPlayerHandlerItem(final PlayerItemHeldEvent e) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
final PlayerInventory inv = p.getInventory();
|
final PlayerInventory inv = p.getInventory();
|
||||||
final ItemStack[] cis = inv.getArmorContents();
|
final ItemStack[] cis = inv.getArmorContents();
|
||||||
for (int i = 0; i < cis.length; i++) {
|
for (int i = 0; i < cis.length; i++) {
|
||||||
final ItemStack itemStack = cis[i];
|
final ItemStack itemStack = cis[i];
|
||||||
if (MarkUtil.hasMark(itemStack)) {
|
if (MarkUtil.hasMark(itemStack)) {
|
||||||
cis[i] = new ItemStack(Material.AIR);
|
cis[i] = new ItemStack(Material.AIR);
|
||||||
sendWarning(p, itemStack, "§e§l穿戴");
|
sendWarning(p, itemStack, "§e§l穿戴");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inv.setArmorContents(cis);
|
inv.setArmorContents(cis);
|
||||||
final int newslot = e.getNewSlot();
|
final int newslot = e.getNewSlot();
|
||||||
final ItemStack newItem = inv.getItem(newslot);
|
final ItemStack newItem = inv.getItem(newslot);
|
||||||
if (MarkUtil.hasMark(newItem)) {
|
if (MarkUtil.hasMark(newItem)) {
|
||||||
inv.setItem(newslot, new ItemStack(Material.AIR));
|
inv.setItem(newslot, new ItemStack(Material.AIR));
|
||||||
sendWarning(p, newItem, "§3§l使用");
|
sendWarning(p, newItem, "§3§l使用");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerPickup(final PlayerPickupItemEvent e) {
|
public void onPlayerPickup(final PlayerPickupItemEvent e) {
|
||||||
final ItemStack ci = e.getItem().getItemStack();
|
final ItemStack ci = e.getItem().getItemStack();
|
||||||
if (MarkUtil.hasMark(ci)) {
|
if (MarkUtil.hasMark(ci)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearIllegalItem(final Player player) {
|
private void clearIllegalItem(final Player player) {
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final Inventory inv = player.getInventory();
|
final Inventory inv = player.getInventory();
|
||||||
int clearnum = 0;
|
int clearnum = 0;
|
||||||
for (final ItemStack itemStack : inv) {
|
for (final ItemStack itemStack : inv) {
|
||||||
if (MarkUtil.hasMark(itemStack)) {
|
if (MarkUtil.hasMark(itemStack)) {
|
||||||
inv.remove(itemStack);
|
inv.remove(itemStack);
|
||||||
clearnum++;
|
clearnum++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (clearnum != 0) {
|
if (clearnum != 0) {
|
||||||
Bukkit.broadcastMessage(plugin.getConfigManager().getGuiTitle() + " §4提示 §d扫描完毕 §d已清理 §a" + player.getName() + " §c非法获取的物品 §4" + clearnum + " §c个物品...");
|
Bukkit.broadcastMessage(plugin.getConfigManager().getGuiTitle() + " §4提示 §d扫描完毕 §d已清理 §a" + player.getName() + " §c非法获取的物品 §4" + clearnum + " §c个物品...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendWarning(final Player p, final ItemStack ci, final String action) {
|
private void sendWarning(final Player p, final ItemStack ci, final String action) {
|
||||||
Bukkit.broadcastMessage(plugin.getConfigManager().getGuiTitle() + " §4警告 " + p.getDisplayName() + " §c非法 " + action + " " + ci.getItemMeta().getDisplayName());
|
Bukkit.broadcastMessage(plugin.getConfigManager().getGuiTitle() + " §4警告 " + p.getDisplayName() + " §c非法 " + action + " " + ci.getItemMeta().getDisplayName());
|
||||||
Bukkit.broadcastMessage(plugin.getConfigManager().getGuiTitle() + " §4提示 §d系统 §d已清理 §a" + p.getName() + " §c非法获取的物品 §a并扫描玩家背包...");
|
Bukkit.broadcastMessage(plugin.getConfigManager().getGuiTitle() + " §4提示 §d系统 §d已清理 §a" + p.getName() + " §c非法获取的物品 §a并扫描玩家背包...");
|
||||||
clearIllegalItem(p);
|
clearIllegalItem(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,70 +15,70 @@ import org.maxgamer.QuickShop.Shop.Shop;
|
|||||||
import org.maxgamer.QuickShop.Shop.ShopChunk;
|
import org.maxgamer.QuickShop.Shop.ShopChunk;
|
||||||
|
|
||||||
public class WorldListener implements Listener {
|
public class WorldListener implements Listener {
|
||||||
QuickShop plugin;
|
QuickShop plugin;
|
||||||
|
|
||||||
public WorldListener(final QuickShop plugin) {
|
public WorldListener(final QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onWorldLoad(final WorldLoadEvent e) {
|
public void onWorldLoad(final WorldLoadEvent e) {
|
||||||
/*
|
/*
|
||||||
* *************************************
|
* *************************************
|
||||||
* This listener fixes any broken world references. Such as hashmap
|
* This listener fixes any broken world references. Such as hashmap
|
||||||
* lookups will fail, because the World reference is different, but the
|
* lookups will fail, because the World reference is different, but the
|
||||||
* world value is the same.
|
* world value is the same.
|
||||||
* *************************************
|
* *************************************
|
||||||
*/
|
*/
|
||||||
final World world = e.getWorld();
|
final World world = e.getWorld();
|
||||||
// New world data
|
// New world data
|
||||||
final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = new HashMap<ShopChunk, HashMap<Location, Shop>>(1);
|
final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = new HashMap<ShopChunk, HashMap<Location, Shop>>(1);
|
||||||
// Old world data
|
// Old world data
|
||||||
final HashMap<ShopChunk, HashMap<Location, Shop>> oldInWorld = plugin.getShopManager().getShops(world.getName());
|
final HashMap<ShopChunk, HashMap<Location, Shop>> oldInWorld = plugin.getShopManager().getShops(world.getName());
|
||||||
// Nothing in the old world, therefore we don't care. No locations to
|
// Nothing in the old world, therefore we don't care. No locations to
|
||||||
// update.
|
// update.
|
||||||
if (oldInWorld == null) {
|
if (oldInWorld == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (final Entry<ShopChunk, HashMap<Location, Shop>> oldInChunk : oldInWorld.entrySet()) {
|
for (final Entry<ShopChunk, HashMap<Location, Shop>> oldInChunk : oldInWorld.entrySet()) {
|
||||||
final HashMap<Location, Shop> inChunk = new HashMap<Location, Shop>(1);
|
final HashMap<Location, Shop> inChunk = new HashMap<Location, Shop>(1);
|
||||||
// Put the new chunk were the old chunk was
|
// Put the new chunk were the old chunk was
|
||||||
inWorld.put(oldInChunk.getKey(), inChunk);
|
inWorld.put(oldInChunk.getKey(), inChunk);
|
||||||
for (final Entry<Location, Shop> entry : oldInChunk.getValue().entrySet()) {
|
for (final Entry<Location, Shop> entry : oldInChunk.getValue().entrySet()) {
|
||||||
final Shop shop = entry.getValue();
|
final Shop shop = entry.getValue();
|
||||||
shop.getLocation().setWorld(world);
|
shop.getLocation().setWorld(world);
|
||||||
inChunk.put(shop.getLocation(), shop);
|
inChunk.put(shop.getLocation(), shop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Done - Now we can store the new world dataz!
|
// Done - Now we can store the new world dataz!
|
||||||
plugin.getShopManager().getShops().put(world.getName(), inWorld);
|
plugin.getShopManager().getShops().put(world.getName(), inWorld);
|
||||||
// This is a workaround, because I don't get parsed chunk events when a
|
// This is a workaround, because I don't get parsed chunk events when a
|
||||||
// world first loads....
|
// world first loads....
|
||||||
// So manually tell all of these shops they're loaded.
|
// So manually tell all of these shops they're loaded.
|
||||||
for (final Chunk chunk : world.getLoadedChunks()) {
|
for (final Chunk chunk : world.getLoadedChunks()) {
|
||||||
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
|
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
|
||||||
if (inChunk == null) {
|
if (inChunk == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (final Shop shop : inChunk.values()) {
|
for (final Shop shop : inChunk.values()) {
|
||||||
shop.onLoad();
|
shop.onLoad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onWorldUnload(final WorldUnloadEvent e) {
|
public void onWorldUnload(final WorldUnloadEvent e) {
|
||||||
// This is a workaround, because I don't get parsed chunk events when a
|
// This is a workaround, because I don't get parsed chunk events when a
|
||||||
// world unloads, I think...
|
// world unloads, I think...
|
||||||
// So manually tell all of these shops they're unloaded.
|
// So manually tell all of these shops they're unloaded.
|
||||||
for (final Chunk chunk : e.getWorld().getLoadedChunks()) {
|
for (final Chunk chunk : e.getWorld().getLoadedChunks()) {
|
||||||
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
|
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(chunk);
|
||||||
if (inChunk == null) {
|
if (inChunk == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (final Shop shop : inChunk.values()) {
|
for (final Shop shop : inChunk.values()) {
|
||||||
shop.onUnload();
|
shop.onUnload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -57,337 +57,337 @@ import cn.citycraft.PluginHelper.utils.LocalUtil;
|
|||||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||||
|
|
||||||
public class QuickShop extends JavaPlugin {
|
public class QuickShop extends JavaPlugin {
|
||||||
/** 初始化 QuickShop 的接口 */
|
/** 初始化 QuickShop 的接口 */
|
||||||
public static QuickShop instance;
|
public static QuickShop instance;
|
||||||
/** 插件的配置文件 */
|
/** 插件的配置文件 */
|
||||||
public FileConfig config;
|
public FileConfig config;
|
||||||
// private HeroChatListener heroChatListener;
|
// private HeroChatListener heroChatListener;
|
||||||
// Listeners (These don't)
|
// Listeners (These don't)
|
||||||
/** The Config Manager used to read config */
|
/** The Config Manager used to read config */
|
||||||
private ConfigManager configManager;
|
private ConfigManager configManager;
|
||||||
/** The database for storing all our data for persistence */
|
/** The database for storing all our data for persistence */
|
||||||
private Database database;
|
private Database database;
|
||||||
/** The economy we hook into for transactions */
|
/** The economy we hook into for transactions */
|
||||||
private Economy economy;
|
private Economy economy;
|
||||||
private BukkitTask itemWatcherTask;
|
private BukkitTask itemWatcherTask;
|
||||||
private LogWatcher logWatcher;
|
private LogWatcher logWatcher;
|
||||||
/** The Shop Manager used to store shops */
|
/** The Shop Manager used to store shops */
|
||||||
private ShopManager shopManager;
|
private ShopManager shopManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints debug information if QuickShop is configured to do so.
|
* Prints debug information if QuickShop is configured to do so.
|
||||||
*
|
*
|
||||||
* @param s
|
* @param s
|
||||||
* The string to print.
|
* The string to print.
|
||||||
*/
|
*/
|
||||||
public void debug(final String s) {
|
public void debug(final String s) {
|
||||||
if (!configManager.isDebug()) {
|
if (!configManager.isDebug()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.getLogger().info(ChatColor.YELLOW + "[Debug] " + s);
|
this.getLogger().info(ChatColor.YELLOW + "[Debug] " + s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigManager getConfigManager() {
|
public ConfigManager getConfigManager() {
|
||||||
return configManager;
|
return configManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the database handler for queries etc.
|
* @return Returns the database handler for queries etc.
|
||||||
*/
|
*/
|
||||||
public Database getDB() {
|
public Database getDB() {
|
||||||
return this.database;
|
return this.database;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the economy for moving currency around
|
* Returns the economy for moving currency around
|
||||||
*
|
*
|
||||||
* @return The economy for moving currency around
|
* @return The economy for moving currency around
|
||||||
*/
|
*/
|
||||||
public EconomyCore getEcon() {
|
public EconomyCore getEcon() {
|
||||||
return economy;
|
return economy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getShopLimit(final Player p) {
|
public int getShopLimit(final Player p) {
|
||||||
int max = configManager.getLimitdefault();
|
int max = configManager.getLimitdefault();
|
||||||
for (final Entry<String, Integer> entry : configManager.getLimits().entrySet()) {
|
for (final Entry<String, Integer> entry : configManager.getLimits().entrySet()) {
|
||||||
if (entry.getValue() > max && p.hasPermission(entry.getKey())) {
|
if (entry.getValue() > max && p.hasPermission(entry.getKey())) {
|
||||||
max = entry.getValue();
|
max = entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ShopManager. This is used for fetching, adding and removing
|
* Returns the ShopManager. This is used for fetching, adding and removing
|
||||||
* shops.
|
* shops.
|
||||||
*
|
*
|
||||||
* @return The ShopManager.
|
* @return The ShopManager.
|
||||||
*/
|
*/
|
||||||
public ShopManager getShopManager() {
|
public ShopManager getShopManager() {
|
||||||
return this.shopManager;
|
return this.shopManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to load the economy and its core. If this fails, it will try to use
|
* Tries to load the economy and its core. If this fails, it will try to use
|
||||||
* vault. If that fails, it will return false.
|
* vault. If that fails, it will return false.
|
||||||
*
|
*
|
||||||
* @return true if successful, false if the core is invalid or is not found,
|
* @return true if successful, false if the core is invalid or is not found,
|
||||||
* and vault cannot be used.
|
* and vault cannot be used.
|
||||||
*/
|
*/
|
||||||
public boolean loadEcon() {
|
public boolean loadEcon() {
|
||||||
final EconomyCore core = new Economy_Vault();
|
final EconomyCore core = new Economy_Vault();
|
||||||
if (!core.isValid()) {
|
if (!core.isValid()) {
|
||||||
getLogger().warning("无法找到经济管理类插件...");
|
getLogger().warning("无法找到经济管理类插件...");
|
||||||
getLogger().warning("卸载插件!!!");
|
getLogger().warning("卸载插件!!!");
|
||||||
this.getPluginLoader().disablePlugin(this);
|
this.getPluginLoader().disablePlugin(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.economy = new Economy(core);
|
this.economy = new Economy(core);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadShop() {
|
public void loadShop() {
|
||||||
if (!LocalUtil.isInit()) {
|
if (!LocalUtil.isInit()) {
|
||||||
this.getLogger().warning("本地化工具尚未初始化完成 商店汉化信息将在稍后刷新...");
|
this.getLogger().warning("本地化工具尚未初始化完成 商店汉化信息将在稍后刷新...");
|
||||||
this.getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
this.getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int error = 0;
|
int error = 0;
|
||||||
try {
|
try {
|
||||||
while (!LocalUtil.isInit()) {
|
while (!LocalUtil.isInit()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getLogger().info("本地化工具载入完成 刷新汉化信息...");
|
getLogger().info("本地化工具载入完成 刷新汉化信息...");
|
||||||
final Iterator<Shop> shops = shopManager.getShopIterator();
|
final Iterator<Shop> shops = shopManager.getShopIterator();
|
||||||
while (shops.hasNext()) {
|
while (shops.hasNext()) {
|
||||||
shops.next().onClick();
|
shops.next().onClick();
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
error++;
|
error++;
|
||||||
}
|
}
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
getLogger().info("信息刷新完成 期间发生 " + error + " 个错误 已忽略(不是BUG 无需反馈)...");
|
getLogger().info("信息刷新完成 期间发生 " + error + " 个错误 已忽略(不是BUG 无需反馈)...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/* 从数据库载入商店信息到内存 */
|
/* 从数据库载入商店信息到内存 */
|
||||||
int count = 0; // 商店个数
|
int count = 0; // 商店个数
|
||||||
int unload = 0;
|
int unload = 0;
|
||||||
Connection con;
|
Connection con;
|
||||||
try {
|
try {
|
||||||
getLogger().info("开始从数据库载入商店数据...");
|
getLogger().info("开始从数据库载入商店数据...");
|
||||||
con = database.getConnection();
|
con = database.getConnection();
|
||||||
final PreparedStatement ps = con.prepareStatement("SELECT * FROM shops");
|
final PreparedStatement ps = con.prepareStatement("SELECT * FROM shops");
|
||||||
final ResultSet rs = ps.executeQuery();
|
final ResultSet rs = ps.executeQuery();
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int z = 0;
|
int z = 0;
|
||||||
String worldName = null;
|
String worldName = null;
|
||||||
try {
|
try {
|
||||||
x = rs.getInt("x");
|
x = rs.getInt("x");
|
||||||
y = rs.getInt("y");
|
y = rs.getInt("y");
|
||||||
z = rs.getInt("z");
|
z = rs.getInt("z");
|
||||||
worldName = rs.getString("world");
|
worldName = rs.getString("world");
|
||||||
final World world = Bukkit.getWorld(worldName);
|
final World world = Bukkit.getWorld(worldName);
|
||||||
final ItemStack item = Util.deserialize(rs.getString("itemConfig"));
|
final ItemStack item = Util.deserialize(rs.getString("itemConfig"));
|
||||||
final String owner = rs.getString("owner");
|
final String owner = rs.getString("owner");
|
||||||
final double price = rs.getDouble("price");
|
final double price = rs.getDouble("price");
|
||||||
final Location loc = new Location(world, x, y, z);
|
final Location loc = new Location(world, x, y, z);
|
||||||
/* Skip invalid shops, if we know of any */
|
/* Skip invalid shops, if we know of any */
|
||||||
if (world != null && loc.getChunk().isLoaded() && (loc.getBlock().getState() instanceof InventoryHolder) == false) {
|
if (world != null && loc.getChunk().isLoaded() && (loc.getBlock().getState() instanceof InventoryHolder) == false) {
|
||||||
getLogger().info("商店不是一个可存储的方块 坐标 " + rs.getString("world") + ", " + x + ", " + y + ", " + z + ". 删除...");
|
getLogger().info("商店不是一个可存储的方块 坐标 " + rs.getString("world") + ", " + x + ", " + y + ", " + z + ". 删除...");
|
||||||
database.execute("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?", x, y, z, worldName);
|
database.execute("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?", x, y, z, worldName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int type = rs.getInt("type");
|
final int type = rs.getInt("type");
|
||||||
final Shop shop = new ContainerShop(loc, price, item, owner);
|
final Shop shop = new ContainerShop(loc, price, item, owner);
|
||||||
shop.setUnlimited(rs.getBoolean("unlimited"));
|
shop.setUnlimited(rs.getBoolean("unlimited"));
|
||||||
shop.setShopType(ShopType.fromID(type));
|
shop.setShopType(ShopType.fromID(type));
|
||||||
shopManager.loadShop(rs.getString("world"), shop);
|
shopManager.loadShop(rs.getString("world"), shop);
|
||||||
if (loc.getWorld() != null && loc.getChunk().isLoaded()) {
|
if (loc.getWorld() != null && loc.getChunk().isLoaded()) {
|
||||||
shop.onLoad();
|
shop.onLoad();
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
} catch (final IllegalStateException e) {
|
} catch (final IllegalStateException e) {
|
||||||
unload++;
|
unload++;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
errors++;
|
errors++;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getLogger().warning("载入商店数据时发生错误! 商店位置: " + worldName + " (" + x + ", " + y + ", " + z + ")...");
|
getLogger().warning("载入商店数据时发生错误! 商店位置: " + worldName + " (" + x + ", " + y + ", " + z + ")...");
|
||||||
if (errors < 3) {
|
if (errors < 3) {
|
||||||
getLogger().warning("删除错误的商店数据...");
|
getLogger().warning("删除错误的商店数据...");
|
||||||
database.execute("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?", x, y, z, worldName);
|
database.execute("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?", x, y, z, worldName);
|
||||||
} else {
|
} else {
|
||||||
getLogger().warning("过多的错误数据 可能您的数据库文件已损坏! 请检查数据库文件!");
|
getLogger().warning("过多的错误数据 可能您的数据库文件已损坏! 请检查数据库文件!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
getLogger().warning("无法载入商店数据...");
|
getLogger().warning("无法载入商店数据...");
|
||||||
getLogger().warning("错误信息: " + e.getMessage());
|
getLogger().warning("错误信息: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
getLogger().info("已载入 " + count + " 个商店 剩余 " + unload + " 个商店将在区块载入后加载...");
|
getLogger().info("已载入 " + count + " 个商店 剩余 " + unload + " 个商店将在区块载入后加载...");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs the given string to qs.log, if QuickShop is configured to do so.
|
* Logs the given string to qs.log, if QuickShop is configured to do so.
|
||||||
*
|
*
|
||||||
* @param s
|
* @param s
|
||||||
* The string to log. It will be prefixed with the date and time.
|
* The string to log. It will be prefixed with the date and time.
|
||||||
*/
|
*/
|
||||||
public void log(final String s) {
|
public void log(final String s) {
|
||||||
if (this.logWatcher == null) {
|
if (this.logWatcher == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Date date = Calendar.getInstance().getTime();
|
final Date date = Calendar.getInstance().getTime();
|
||||||
final Timestamp time = new Timestamp(date.getTime());
|
final Timestamp time = new Timestamp(date.getTime());
|
||||||
this.logWatcher.add("[" + time.toString() + "] " + s);
|
this.logWatcher.add("[" + time.toString() + "] " + s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (itemWatcherTask != null) {
|
if (itemWatcherTask != null) {
|
||||||
itemWatcherTask.cancel();
|
itemWatcherTask.cancel();
|
||||||
}
|
}
|
||||||
if (logWatcher != null) {
|
if (logWatcher != null) {
|
||||||
logWatcher.task.cancel();
|
logWatcher.task.cancel();
|
||||||
logWatcher.close(); // Closes the file
|
logWatcher.close(); // Closes the file
|
||||||
}
|
}
|
||||||
/* Remove all display items, and any dupes we can find */
|
/* Remove all display items, and any dupes we can find */
|
||||||
if (shopManager != null) {
|
if (shopManager != null) {
|
||||||
shopManager.clear();
|
shopManager.clear();
|
||||||
}
|
}
|
||||||
/* Empty the buffer */
|
/* Empty the buffer */
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
database.close();
|
database.close();
|
||||||
try {
|
try {
|
||||||
database.getConnection().close();
|
database.getConnection().close();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (configManager != null) {
|
if (configManager != null) {
|
||||||
configManager.getWarnings().clear();
|
configManager.getWarnings().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
if (loadEcon() == false) {
|
if (loadEcon() == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LocalUtil.init(this);
|
LocalUtil.init(this);
|
||||||
// Initialize Util
|
// Initialize Util
|
||||||
Util.initialize();
|
Util.initialize();
|
||||||
// Create the shop manager.
|
// Create the shop manager.
|
||||||
configManager = new ConfigManager(this);
|
configManager = new ConfigManager(this);
|
||||||
shopManager = new ShopManager(this);
|
shopManager = new ShopManager(this);
|
||||||
if (configManager.isFakeItem()) {
|
if (configManager.isFakeItem()) {
|
||||||
if (!FakeItem.isRegistered()) {
|
if (!FakeItem.isRegistered()) {
|
||||||
try {
|
try {
|
||||||
FakeItem.register(this);
|
FakeItem.register(this);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (configManager.isLogAction()) {
|
if (configManager.isLogAction()) {
|
||||||
// Logger Handler
|
// Logger Handler
|
||||||
this.logWatcher = new LogWatcher(this, new File(this.getDataFolder(), "qs.log"));
|
this.logWatcher = new LogWatcher(this, new File(this.getDataFolder(), "qs.log"));
|
||||||
logWatcher.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, this.logWatcher, 150, 150);
|
logWatcher.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, this.logWatcher, 150, 150);
|
||||||
}
|
}
|
||||||
if (configManager.isShopLock()) {
|
if (configManager.isShopLock()) {
|
||||||
final LockListener ll = new LockListener(this);
|
final LockListener ll = new LockListener(this);
|
||||||
getServer().getPluginManager().registerEvents(ll, this);
|
getServer().getPluginManager().registerEvents(ll, this);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final ConfigurationSection dbCfg = getConfig().getConfigurationSection("database");
|
final ConfigurationSection dbCfg = getConfig().getConfigurationSection("database");
|
||||||
DatabaseCore dbCore;
|
DatabaseCore dbCore;
|
||||||
if (dbCfg.getBoolean("mysql")) {
|
if (dbCfg.getBoolean("mysql")) {
|
||||||
getLogger().info("启用MySQL 开始连接数据库...");
|
getLogger().info("启用MySQL 开始连接数据库...");
|
||||||
// MySQL database - Required database be created first.
|
// MySQL database - Required database be created first.
|
||||||
final String user = dbCfg.getString("user");
|
final String user = dbCfg.getString("user");
|
||||||
final String pass = dbCfg.getString("password");
|
final String pass = dbCfg.getString("password");
|
||||||
final String host = dbCfg.getString("host");
|
final String host = dbCfg.getString("host");
|
||||||
final String port = dbCfg.getString("port");
|
final String port = dbCfg.getString("port");
|
||||||
final String database = dbCfg.getString("database");
|
final String database = dbCfg.getString("database");
|
||||||
dbCore = new MySQLCore(host, user, pass, database, port);
|
dbCore = new MySQLCore(host, user, pass, database, port);
|
||||||
} else {
|
} else {
|
||||||
// SQLite database - Doing this handles file creation
|
// SQLite database - Doing this handles file creation
|
||||||
dbCore = new SQLiteCore(new File(this.getDataFolder(), "shops.db"));
|
dbCore = new SQLiteCore(new File(this.getDataFolder(), "shops.db"));
|
||||||
}
|
}
|
||||||
this.database = new Database(dbCore);
|
this.database = new Database(dbCore);
|
||||||
// Make the database up to date
|
// Make the database up to date
|
||||||
DatabaseHelper.setup(getDB());
|
DatabaseHelper.setup(getDB());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
getLogger().warning("数据库连接错误或配置错误...");
|
getLogger().warning("数据库连接错误或配置错误...");
|
||||||
getLogger().warning("错误信息: " + e.getMessage());
|
getLogger().warning("错误信息: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getLogger().warning("关闭插件!!!");
|
getLogger().warning("关闭插件!!!");
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loadShop();
|
loadShop();
|
||||||
MsgUtil.loadTransactionMessages();
|
MsgUtil.loadTransactionMessages();
|
||||||
MsgUtil.clean();
|
MsgUtil.clean();
|
||||||
// Register events
|
// Register events
|
||||||
final PluginManager pm = this.getServer().getPluginManager();
|
final PluginManager pm = this.getServer().getPluginManager();
|
||||||
final Plugin wsc = pm.getPlugin("WowSuchCleaner");
|
final Plugin wsc = pm.getPlugin("WowSuchCleaner");
|
||||||
if (wsc != null && wsc.isEnabled()) {
|
if (wsc != null && wsc.isEnabled()) {
|
||||||
getLogger().info("发现 WowSuchCleaner 插件 开启相关功能...");
|
getLogger().info("发现 WowSuchCleaner 插件 开启相关功能...");
|
||||||
try {
|
try {
|
||||||
Class.forName("io.github.Cnly.WowSuchCleaner.WowSuchCleaner.ItemPreCleanEvent");
|
Class.forName("io.github.Cnly.WowSuchCleaner.WowSuchCleaner.ItemPreCleanEvent");
|
||||||
pm.registerEvents(new WowSuchCleanerListener(), this);
|
pm.registerEvents(new WowSuchCleanerListener(), this);
|
||||||
} catch (final ClassNotFoundException e) {
|
} catch (final ClassNotFoundException e) {
|
||||||
getLogger().info("WowSuchCleaner 版本过低 可能造成悬浮物上架...");
|
getLogger().info("WowSuchCleaner 版本过低 可能造成悬浮物上架...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pm.registerEvents(new BlockListener(this), this);
|
pm.registerEvents(new BlockListener(this), this);
|
||||||
pm.registerEvents(new PlayerListener(this), this);
|
pm.registerEvents(new PlayerListener(this), this);
|
||||||
pm.registerEvents(new WorldListener(this), this);
|
pm.registerEvents(new WorldListener(this), this);
|
||||||
pm.registerEvents(new ProtectListener(this), this);
|
pm.registerEvents(new ProtectListener(this), this);
|
||||||
pm.registerEvents(new ChatListener(this), this);
|
pm.registerEvents(new ChatListener(this), this);
|
||||||
if (configManager.isDisplay()) {
|
if (configManager.isDisplay()) {
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new ChunkListener(this), this);
|
Bukkit.getServer().getPluginManager().registerEvents(new ChunkListener(this), this);
|
||||||
// Display item handler thread
|
// Display item handler thread
|
||||||
getLogger().info("开启商店检查以及悬浮物刷新线程...");
|
getLogger().info("开启商店检查以及悬浮物刷新线程...");
|
||||||
final ItemWatcher itemWatcher = new ItemWatcher(this);
|
final ItemWatcher itemWatcher = new ItemWatcher(this);
|
||||||
itemWatcherTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 20, 1800);
|
itemWatcherTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 20, 1800);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command handlers
|
// Command handlers
|
||||||
new QuickShopCommands(this);
|
new QuickShopCommands(this);
|
||||||
|
|
||||||
if (configManager.getFindDistance() > 100) {
|
if (configManager.getFindDistance() > 100) {
|
||||||
getLogger().warning("商店查找半径过大 可能导致服务器Lag! 推荐使用低于 100 的配置!");
|
getLogger().warning("商店查找半径过大 可能导致服务器Lag! 推荐使用低于 100 的配置!");
|
||||||
}
|
}
|
||||||
this.getLogger().info("载入完成! 版本: " + this.getDescription().getVersion() + " 重制 by 喵♂呜");
|
this.getLogger().info("载入完成! 版本: " + this.getDescription().getVersion() + " 重制 by 喵♂呜");
|
||||||
new VersionChecker(this);
|
new VersionChecker(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
config = new FileConfig(this);
|
config = new FileConfig(this);
|
||||||
MsgUtil.init(this);
|
MsgUtil.init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reloads QuickShops config */
|
/** Reloads QuickShops config */
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
config.reload();
|
config.reload();
|
||||||
LocalUtil.reload(this);
|
LocalUtil.reload(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -8,37 +8,37 @@ import org.bukkit.entity.Item;
|
|||||||
* cannot be interacted with.
|
* cannot be interacted with.
|
||||||
*/
|
*/
|
||||||
public interface DisplayItem {
|
public interface DisplayItem {
|
||||||
/**
|
/**
|
||||||
* 获得悬浮物地点
|
* 获得悬浮物地点
|
||||||
*
|
*
|
||||||
* @return 获得悬浮地点
|
* @return 获得悬浮地点
|
||||||
*/
|
*/
|
||||||
public Location getDisplayLocation();
|
public Location getDisplayLocation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {@link Item}
|
* @return {@link Item}
|
||||||
*/
|
*/
|
||||||
public Item getItem();
|
public Item getItem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除悬浮物
|
* 移除悬浮物
|
||||||
*/
|
*/
|
||||||
public void remove();
|
public void remove();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除多余物品
|
* 移除多余物品
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean removeDupe();
|
public boolean removeDupe();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新悬浮物
|
* 更新悬浮物
|
||||||
*/
|
*/
|
||||||
public void respawn();
|
public void respawn();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷出悬浮物
|
* 刷出悬浮物
|
||||||
*/
|
*/
|
||||||
public void spawn();
|
public void spawn();
|
||||||
}
|
}
|
@ -31,207 +31,209 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
|||||||
*/
|
*/
|
||||||
public class FakeItem implements DisplayItem {
|
public class FakeItem implements DisplayItem {
|
||||||
|
|
||||||
private static Map<String, List<FakeItem>> fakes = new HashMap<String, List<FakeItem>>();
|
private static Map<String, List<FakeItem>> fakes = new HashMap<String, List<FakeItem>>();
|
||||||
private static boolean registered = false;
|
private static boolean registered = false;
|
||||||
private static int lastId = Integer.MAX_VALUE;
|
private static int lastId = Integer.MAX_VALUE;
|
||||||
|
|
||||||
private final ItemStack itemStack;
|
private final ItemStack itemStack;
|
||||||
private final Location location;
|
private final Location location;
|
||||||
private final int eid;
|
private final int eid;
|
||||||
private boolean created = false;
|
private boolean created = false;
|
||||||
|
|
||||||
public static boolean isRegistered() {
|
public static boolean isRegistered() {
|
||||||
return registered;
|
return registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register(final Plugin plugin) {
|
public static void register(final Plugin plugin) {
|
||||||
if (registered) {
|
if (registered) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final PluginManager pm = Bukkit.getPluginManager();
|
final PluginManager pm = Bukkit.getPluginManager();
|
||||||
final Plugin p = pm.getPlugin("ProtocolLib");
|
final Plugin p = pm.getPlugin("ProtocolLib");
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
if (!p.isEnabled()) {
|
if (!p.isEnabled()) {
|
||||||
pm.enablePlugin(p);
|
pm.enablePlugin(p);
|
||||||
}
|
}
|
||||||
if (!p.isEnabled()) {
|
if (!p.isEnabled()) {
|
||||||
throw new IllegalStateException("The ProtocolLib enable Failed.");
|
throw new IllegalStateException("The ProtocolLib enable Failed.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("The Server Not Found ProtocolLib.");
|
throw new IllegalStateException("The Server Not Found ProtocolLib.");
|
||||||
}
|
}
|
||||||
final PacketAdapter chunkPacketListener = new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK) {
|
final PacketAdapter chunkPacketListener = new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(final PacketEvent event) {
|
public void onPacketSending(final PacketEvent event) {
|
||||||
final PacketContainer packet = event.getPacket();
|
final PacketContainer packet = event.getPacket();
|
||||||
final Player p = event.getPlayer();
|
final Player p = event.getPlayer();
|
||||||
final int chunkX = packet.getIntegers().read(0);
|
final int chunkX = packet.getIntegers().read(0);
|
||||||
final int chunkZ = packet.getIntegers().read(1);
|
final int chunkZ = packet.getIntegers().read(1);
|
||||||
final List<FakeItem> fakesInChunk = fakes.get(getChunkIdentifyString(p.getWorld().getChunkAt(chunkX, chunkZ)));
|
final List<FakeItem> fakesInChunk = fakes.get(getChunkIdentifyString(p.getWorld().getChunkAt(chunkX, chunkZ)));
|
||||||
if (fakesInChunk != null) {
|
if (fakesInChunk != null) {
|
||||||
try {
|
try {
|
||||||
for (final FakeItem fake : fakesInChunk) {
|
for (final FakeItem fake : fakesInChunk) {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket());
|
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket());
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket());
|
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket());
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket());
|
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket());
|
||||||
}
|
}
|
||||||
} catch (final InvocationTargetException e) {
|
} catch (final InvocationTargetException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final PacketAdapter chunkBulkPacketListener = new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK_BULK) {
|
final PacketAdapter chunkBulkPacketListener = new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK_BULK) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(final PacketEvent event) {
|
public void onPacketSending(final PacketEvent event) {
|
||||||
final PacketContainer packet = event.getPacket();
|
final PacketContainer packet = event.getPacket();
|
||||||
final Player p = event.getPlayer();
|
final Player p = event.getPlayer();
|
||||||
final int[] chunksX = packet.getIntegerArrays().read(0);
|
final int[] chunksX = packet.getIntegerArrays().read(0);
|
||||||
final int[] chunksZ = packet.getIntegerArrays().read(1);
|
final int[] chunksZ = packet.getIntegerArrays().read(1);
|
||||||
for (int i = 0; i < chunksX.length; i++) {
|
for (int i = 0; i < chunksX.length; i++) {
|
||||||
final List<FakeItem> fakesInChunk = fakes.get(getChunkIdentifyString(p.getWorld().getChunkAt(chunksX[i], chunksZ[i])));
|
final List<FakeItem> fakesInChunk = fakes.get(getChunkIdentifyString(p.getWorld().getChunkAt(chunksX[i], chunksZ[i])));
|
||||||
if (fakesInChunk != null) {
|
if (fakesInChunk != null) {
|
||||||
try {
|
try {
|
||||||
for (final FakeItem fake : fakesInChunk) {
|
for (final FakeItem fake : fakesInChunk) {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket());
|
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket());
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket());
|
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket());
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket());
|
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket());
|
||||||
}
|
}
|
||||||
} catch (final InvocationTargetException e) {
|
} catch (final InvocationTargetException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(chunkPacketListener);
|
ProtocolLibrary.getProtocolManager().addPacketListener(chunkPacketListener);
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(chunkBulkPacketListener);
|
ProtocolLibrary.getProtocolManager().addPacketListener(chunkBulkPacketListener);
|
||||||
registered = true;
|
registered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getChunkIdentifyString(final Chunk chunk) {
|
private static String getChunkIdentifyString(final Chunk chunk) {
|
||||||
return chunk.getWorld().getName() + "@@" + chunk.getX() + "@@" + chunk.getZ();
|
return chunk.getWorld().getName() + "@@" + chunk.getX() + "@@" + chunk.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getFakeEntityId() {
|
private static int getFakeEntityId() {
|
||||||
return lastId--;
|
return lastId--;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getNormalizedDistance(final double value) {
|
private static int getNormalizedDistance(final double value) {
|
||||||
return (int) Math.floor(value * 32.0D);
|
return (int) Math.floor(value * 32.0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FakeItem(final ContainerShop containerShop, final ItemStack item) {
|
public FakeItem(final ContainerShop containerShop, final ItemStack item) {
|
||||||
this.itemStack = item;
|
this.itemStack = item;
|
||||||
this.location = containerShop.getLocation().add(0.5, 1, 0.5);
|
this.location = containerShop.getLocation().clone().add(0.5, 1, 0.5);
|
||||||
this.eid = getFakeEntityId();
|
this.eid = getFakeEntityId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FakeItem(final ItemStack itemStack, final Location loc) {
|
public FakeItem(final ItemStack itemStack, final Location loc) {
|
||||||
this.itemStack = itemStack;
|
this.itemStack = itemStack;
|
||||||
this.location = loc;
|
this.location = loc;
|
||||||
this.eid = getFakeEntityId();
|
this.eid = getFakeEntityId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location getDisplayLocation() {
|
public Location getDisplayLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item getItem() {
|
public Item getItem() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
destory();
|
destory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeDupe() {
|
public boolean removeDupe() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void respawn() {
|
public void respawn() {
|
||||||
destory();
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDestoryPacket());
|
||||||
create();
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnPacket());
|
||||||
}
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getVelocityPacket());
|
||||||
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getMetadataPacket());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void spawn() {
|
public void spawn() {
|
||||||
create();
|
create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void create() {
|
private void create() {
|
||||||
if (!registered) {
|
if (!registered) {
|
||||||
throw new IllegalStateException("You have to call the register method first.");
|
throw new IllegalStateException("You have to call the register method first.");
|
||||||
}
|
}
|
||||||
if (created) {
|
if (created) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnPacket());
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnPacket());
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getVelocityPacket());
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getVelocityPacket());
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getMetadataPacket());
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getMetadataPacket());
|
||||||
|
|
||||||
final String chunkId = getChunkIdentifyString(location.getChunk());
|
final String chunkId = getChunkIdentifyString(location.getChunk());
|
||||||
List<FakeItem> fakesInChunk = fakes.get(chunkId);
|
List<FakeItem> fakesInChunk = fakes.get(chunkId);
|
||||||
if (fakesInChunk == null) {
|
if (fakesInChunk == null) {
|
||||||
fakesInChunk = new ArrayList<FakeItem>();
|
fakesInChunk = new ArrayList<FakeItem>();
|
||||||
}
|
}
|
||||||
fakesInChunk.add(this);
|
fakesInChunk.add(this);
|
||||||
fakes.put(chunkId, fakesInChunk);
|
fakes.put(chunkId, fakesInChunk);
|
||||||
created = true;
|
created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void destory() {
|
private void destory() {
|
||||||
if (!created) {
|
if (!created) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDestoryPacket());
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDestoryPacket());
|
||||||
|
|
||||||
final String chunkId = getChunkIdentifyString(location.getChunk());
|
final String chunkId = getChunkIdentifyString(location.getChunk());
|
||||||
final List<FakeItem> fakesInChunk = fakes.get(chunkId);
|
final List<FakeItem> fakesInChunk = fakes.get(chunkId);
|
||||||
if (fakesInChunk == null) {
|
if (fakesInChunk == null) {
|
||||||
// NOTE: This is what should not happens if everything is correct.
|
// NOTE: This is what should not happens if everything is correct.
|
||||||
created = false;
|
created = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fakesInChunk.remove(this);
|
fakesInChunk.remove(this);
|
||||||
fakes.put(chunkId, fakesInChunk);
|
fakes.put(chunkId, fakesInChunk);
|
||||||
created = false;
|
created = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getDestoryPacket() {
|
private PacketContainer getDestoryPacket() {
|
||||||
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY, true);
|
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY, true);
|
||||||
fakePacket.getIntegerArrays().write(0, new int[] { eid });
|
fakePacket.getIntegerArrays().write(0, new int[] { eid });
|
||||||
return fakePacket;
|
return fakePacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getMetadataPacket() {
|
private PacketContainer getMetadataPacket() {
|
||||||
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
|
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
|
||||||
fakePacket.getIntegers().write(0, eid);
|
fakePacket.getIntegers().write(0, eid);
|
||||||
final WrappedWatchableObject itemMeta = new WrappedWatchableObject(10, itemStack);
|
final WrappedWatchableObject itemMeta = new WrappedWatchableObject(10, itemStack);
|
||||||
final List<WrappedWatchableObject> entityMetaList = new ArrayList<WrappedWatchableObject>(1);
|
final List<WrappedWatchableObject> entityMetaList = new ArrayList<WrappedWatchableObject>(1);
|
||||||
entityMetaList.add(itemMeta);
|
entityMetaList.add(itemMeta);
|
||||||
fakePacket.getWatchableCollectionModifier().write(0, entityMetaList);
|
fakePacket.getWatchableCollectionModifier().write(0, entityMetaList);
|
||||||
return fakePacket;
|
return fakePacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getSpawnPacket() {
|
private PacketContainer getSpawnPacket() {
|
||||||
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);
|
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);
|
||||||
fakePacket.getIntegers().write(0, eid);
|
fakePacket.getIntegers().write(0, eid);
|
||||||
fakePacket.getIntegers().write(1, getNormalizedDistance(location.getX()));
|
fakePacket.getIntegers().write(1, getNormalizedDistance(location.getX()));
|
||||||
fakePacket.getIntegers().write(2, getNormalizedDistance(location.getY()));
|
fakePacket.getIntegers().write(2, getNormalizedDistance(location.getY()));
|
||||||
fakePacket.getIntegers().write(3, getNormalizedDistance(location.getZ()));
|
fakePacket.getIntegers().write(3, getNormalizedDistance(location.getZ()));
|
||||||
fakePacket.getIntegers().write(9, 2);
|
fakePacket.getIntegers().write(9, 2);
|
||||||
return fakePacket;
|
return fakePacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getVelocityPacket() {
|
private PacketContainer getVelocityPacket() {
|
||||||
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY);
|
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY);
|
||||||
fakePacket.getIntegers().write(0, eid);
|
fakePacket.getIntegers().write(0, eid);
|
||||||
return fakePacket;
|
return fakePacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,94 +5,94 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class Info {
|
public class Info {
|
||||||
private Location loc;
|
private Location loc;
|
||||||
private ShopAction action;
|
private ShopAction action;
|
||||||
private ItemStack item;
|
private ItemStack item;
|
||||||
private Block last;
|
private Block last;
|
||||||
private Shop shop;
|
private Shop shop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores info for the players last shop interact.
|
* Stores info for the players last shop interact.
|
||||||
*
|
*
|
||||||
* @param loc
|
* @param loc
|
||||||
* The location they clicked (Block.getLocation())
|
* The location they clicked (Block.getLocation())
|
||||||
* @param action
|
* @param action
|
||||||
* The action (ShopAction.*)
|
* The action (ShopAction.*)
|
||||||
* @param material
|
* @param material
|
||||||
* The material they were holding
|
* The material they were holding
|
||||||
* @param data
|
* @param data
|
||||||
* The data value of the material
|
* The data value of the material
|
||||||
*/
|
*/
|
||||||
public Info(Location loc, ShopAction action, ItemStack item, Block last) {
|
public Info(Location loc, ShopAction action, ItemStack item, Block last) {
|
||||||
this.loc = loc;
|
this.loc = loc;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.last = last;
|
this.last = last;
|
||||||
if (item != null)
|
if (item != null)
|
||||||
this.item = item.clone();
|
this.item = item.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores info for the players last shop interact.
|
* Stores info for the players last shop interact.
|
||||||
*
|
*
|
||||||
* @param loc
|
* @param loc
|
||||||
* The location they clicked (Block.getLocation())
|
* The location they clicked (Block.getLocation())
|
||||||
* @param action
|
* @param action
|
||||||
* The action (ShopAction.*)
|
* The action (ShopAction.*)
|
||||||
* @param material
|
* @param material
|
||||||
* The material they were holding
|
* The material they were holding
|
||||||
* @param data
|
* @param data
|
||||||
* The data value of the material
|
* The data value of the material
|
||||||
* @param shop
|
* @param shop
|
||||||
* The shop they interacted with, or null if none
|
* The shop they interacted with, or null if none
|
||||||
*/
|
*/
|
||||||
public Info(Location loc, ShopAction action, ItemStack item, Block last, Shop shop) {
|
public Info(Location loc, ShopAction action, ItemStack item, Block last, Shop shop) {
|
||||||
this.loc = loc;
|
this.loc = loc;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.last = last;
|
this.last = last;
|
||||||
if (item != null)
|
if (item != null)
|
||||||
this.item = item.clone();
|
this.item = item.clone();
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
this.shop = shop.clone();
|
this.shop = shop.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasChanged(Shop shop) {
|
public boolean hasChanged(Shop shop) {
|
||||||
if (this.shop.isUnlimited() != shop.isUnlimited())
|
if (this.shop.isUnlimited() != shop.isUnlimited())
|
||||||
return true;
|
return true;
|
||||||
if (this.shop.getShopType() != shop.getShopType())
|
if (this.shop.getShopType() != shop.getShopType())
|
||||||
return true;
|
return true;
|
||||||
if (!this.shop.getOwner().equals(shop.getOwner()))
|
if (!this.shop.getOwner().equals(shop.getOwner()))
|
||||||
return true;
|
return true;
|
||||||
if (this.shop.getPrice() != shop.getPrice())
|
if (this.shop.getPrice() != shop.getPrice())
|
||||||
return true;
|
return true;
|
||||||
if (!this.shop.getLocation().equals(shop.getLocation()))
|
if (!this.shop.getLocation().equals(shop.getLocation()))
|
||||||
return true;
|
return true;
|
||||||
if (!this.shop.matches(shop.getItem()))
|
if (!this.shop.matches(shop.getItem()))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShopAction getAction() {
|
public ShopAction getAction() {
|
||||||
return this.action;
|
return this.action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return this.loc;
|
return this.loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* public Material getMaterial(){ return this.item.getType(); } public byte
|
* public Material getMaterial(){ return this.item.getType(); } public byte
|
||||||
* getData(){ return this.getData(); }
|
* getData(){ return this.getData(); }
|
||||||
*/
|
*/
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
return this.item;
|
return this.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAction(ShopAction action) {
|
public void setAction(ShopAction action) {
|
||||||
this.action = action;
|
this.action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block getSignBlock() {
|
public Block getSignBlock() {
|
||||||
return this.last;
|
return this.last;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,104 +13,104 @@ import org.maxgamer.QuickShop.Util.NMS;
|
|||||||
* cannot be interacted with.
|
* cannot be interacted with.
|
||||||
*/
|
*/
|
||||||
public class NormalItem implements DisplayItem {
|
public class NormalItem implements DisplayItem {
|
||||||
private final ItemStack iStack;
|
private final ItemStack iStack;
|
||||||
private Item item;
|
private Item item;
|
||||||
private final Shop shop;
|
private final Shop shop;
|
||||||
|
|
||||||
// private Location displayLoc;
|
// private Location displayLoc;
|
||||||
/**
|
/**
|
||||||
* Creates a new display item.
|
* Creates a new display item.
|
||||||
*
|
*
|
||||||
* @param shop
|
* @param shop
|
||||||
* The shop (See Shop)
|
* The shop (See Shop)
|
||||||
* @param iStack
|
* @param iStack
|
||||||
* The item stack to clone properties of the display item from.
|
* The item stack to clone properties of the display item from.
|
||||||
*/
|
*/
|
||||||
public NormalItem(final Shop shop, final ItemStack iStack) {
|
public NormalItem(final Shop shop, final ItemStack iStack) {
|
||||||
this.shop = shop;
|
this.shop = shop;
|
||||||
this.iStack = iStack.clone();
|
this.iStack = iStack.clone();
|
||||||
// this.displayLoc = shop.getLocation().clone().add(0.5, 1.2, 0.5);
|
// this.displayLoc = shop.getLocation().clone().add(0.5, 1.2, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the exact location of the display item. (1 above shop
|
* @return Returns the exact location of the display item. (1 above shop
|
||||||
* block, in the center)
|
* block, in the center)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Location getDisplayLocation() {
|
public Location getDisplayLocation() {
|
||||||
return this.shop.getLocation().clone().add(0.5, 1.2, 0.5);
|
return this.shop.getLocation().clone().add(0.5, 1.2, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the reference to this shops item. Do not modify.
|
* Returns the reference to this shops item. Do not modify.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Item getItem() {
|
public Item getItem() {
|
||||||
return this.item;
|
return this.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the display item.
|
* Removes the display item.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if (this.item == null) {
|
if (this.item == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.item.remove();
|
this.item.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all items floating ontop of the chest that aren't the display
|
* Removes all items floating ontop of the chest that aren't the display
|
||||||
* item.
|
* item.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean removeDupe() {
|
public boolean removeDupe() {
|
||||||
if (shop.getLocation().getWorld() == null) {
|
if (shop.getLocation().getWorld() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation();
|
final Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation();
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
final Chunk c = displayLoc.getChunk();
|
final Chunk c = displayLoc.getChunk();
|
||||||
for (final Entity e : c.getEntities()) {
|
for (final Entity e : c.getEntities()) {
|
||||||
if (!(e instanceof Item)) {
|
if (!(e instanceof Item)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (this.item != null && e.getEntityId() == this.item.getEntityId()) {
|
if (this.item != null && e.getEntityId() == this.item.getEntityId()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Location eLoc = e.getLocation().getBlock().getLocation();
|
final Location eLoc = e.getLocation().getBlock().getLocation();
|
||||||
if (eLoc.equals(displayLoc) || eLoc.equals(shop.getLocation())) {
|
if (eLoc.equals(displayLoc) || eLoc.equals(shop.getLocation())) {
|
||||||
e.remove();
|
e.remove();
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spawns the new display item. Does not remove duplicate items.
|
* Spawns the new display item. Does not remove duplicate items.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void respawn() {
|
public void respawn() {
|
||||||
remove();
|
remove();
|
||||||
spawn();
|
spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spawns the dummy item on top of the shop.
|
* Spawns the dummy item on top of the shop.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void spawn() {
|
public void spawn() {
|
||||||
if (shop.getLocation().getWorld() == null) {
|
if (shop.getLocation().getWorld() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location dispLoc = this.getDisplayLocation();
|
final Location dispLoc = this.getDisplayLocation();
|
||||||
try {
|
try {
|
||||||
this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack);
|
this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack);
|
||||||
this.item.setVelocity(new Vector(0, 0.1, 0));
|
this.item.setVelocity(new Vector(0, 0.1, 0));
|
||||||
NMS.safeGuard(this.item);
|
NMS.safeGuard(this.item);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,69 +9,69 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public abstract interface Shop {
|
public abstract interface Shop {
|
||||||
public abstract void add(ItemStack paramItemStack, int paramInt);
|
public abstract void add(ItemStack paramItemStack, int paramInt);
|
||||||
|
|
||||||
public abstract void buy(Player paramPlayer, int paramInt);
|
public abstract void buy(Player paramPlayer, int paramInt);
|
||||||
|
|
||||||
public abstract Shop clone();
|
public abstract Shop clone();
|
||||||
|
|
||||||
public abstract void delete();
|
public abstract void delete();
|
||||||
|
|
||||||
public abstract void delete(boolean paramBoolean);
|
public abstract void delete(boolean paramBoolean);
|
||||||
|
|
||||||
public abstract String getDataName();
|
public abstract String getDataName();
|
||||||
|
|
||||||
public abstract short getDurability();
|
public abstract short getDurability();
|
||||||
|
|
||||||
public abstract ItemStack getItem();
|
public abstract ItemStack getItem();
|
||||||
|
|
||||||
public abstract Location getLocation();
|
public abstract Location getLocation();
|
||||||
|
|
||||||
public abstract String getOwner();
|
public abstract String getOwner();
|
||||||
|
|
||||||
public abstract double getPrice();
|
public abstract double getPrice();
|
||||||
|
|
||||||
public abstract int getRemainingSpace();
|
public abstract int getRemainingSpace();
|
||||||
|
|
||||||
public abstract int getRemainingStock();
|
public abstract int getRemainingStock();
|
||||||
|
|
||||||
public abstract ShopType getShopType();
|
public abstract ShopType getShopType();
|
||||||
|
|
||||||
public abstract List<Sign> getSigns();
|
public abstract List<Sign> getSigns();
|
||||||
|
|
||||||
public abstract boolean isAttached(Block paramBlock);
|
public abstract boolean isAttached(Block paramBlock);
|
||||||
|
|
||||||
public abstract boolean isBuying();
|
public abstract boolean isBuying();
|
||||||
|
|
||||||
public abstract boolean isSelling();
|
public abstract boolean isSelling();
|
||||||
|
|
||||||
public abstract boolean isUnlimited();
|
public abstract boolean isUnlimited();
|
||||||
|
|
||||||
public abstract boolean isValid();
|
public abstract boolean isValid();
|
||||||
|
|
||||||
public abstract boolean matches(ItemStack paramItemStack);
|
public abstract boolean matches(ItemStack paramItemStack);
|
||||||
|
|
||||||
public abstract void onClick();
|
public abstract void onClick();
|
||||||
|
|
||||||
public abstract void onLoad();
|
public abstract void onLoad();
|
||||||
|
|
||||||
public abstract void onUnload();
|
public abstract void onUnload();
|
||||||
|
|
||||||
public abstract void remove(ItemStack paramItemStack, int paramInt);
|
public abstract void remove(ItemStack paramItemStack, int paramInt);
|
||||||
|
|
||||||
public abstract void sell(Player paramPlayer, int paramInt);
|
public abstract void sell(Player paramPlayer, int paramInt);
|
||||||
|
|
||||||
public abstract void setOwner(String paramString);
|
public abstract void setOwner(String paramString);
|
||||||
|
|
||||||
public abstract void setPrice(double paramDouble);
|
public abstract void setPrice(double paramDouble);
|
||||||
|
|
||||||
public abstract void setShopType(ShopType paramShopType);
|
public abstract void setShopType(ShopType paramShopType);
|
||||||
|
|
||||||
public abstract void setSignText();
|
public abstract void setSignText();
|
||||||
|
|
||||||
public abstract void setSignText(String[] paramArrayOfString);
|
public abstract void setSignText(String[] paramArrayOfString);
|
||||||
|
|
||||||
public abstract void setUnlimited(boolean paramBoolean);
|
public abstract void setUnlimited(boolean paramBoolean);
|
||||||
|
|
||||||
public abstract void update();
|
public abstract void update();
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package org.maxgamer.QuickShop.Shop;
|
package org.maxgamer.QuickShop.Shop;
|
||||||
|
|
||||||
public enum ShopAction {
|
public enum ShopAction {
|
||||||
BUY(), CREATE(), CANCELLED();
|
BUY(),
|
||||||
|
CREATE(),
|
||||||
|
CANCELLED();
|
||||||
}
|
}
|
@ -1,43 +1,43 @@
|
|||||||
package org.maxgamer.QuickShop.Shop;
|
package org.maxgamer.QuickShop.Shop;
|
||||||
|
|
||||||
public class ShopChunk {
|
public class ShopChunk {
|
||||||
private final String world;
|
private final String world;
|
||||||
private final int x;
|
private final int x;
|
||||||
private final int z;
|
private final int z;
|
||||||
private int hash = 0;
|
private int hash = 0;
|
||||||
|
|
||||||
public ShopChunk(final String world, final int x, final int z) {
|
public ShopChunk(final String world, final int x, final int z) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.hash = this.x * this.z; // We don't need to use the world's hash,
|
this.hash = this.x * this.z; // We don't need to use the world's hash,
|
||||||
// as these are seperated by world in
|
// as these are seperated by world in
|
||||||
// memory
|
// memory
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
if (obj.getClass() != this.getClass()) {
|
if (obj.getClass() != this.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ShopChunk shopChunk = (ShopChunk) obj;
|
final ShopChunk shopChunk = (ShopChunk) obj;
|
||||||
return (this.getWorld().equals(shopChunk.getWorld()) && this.getX() == shopChunk.getX() && this.getZ() == shopChunk.getZ());
|
return (this.getWorld().equals(shopChunk.getWorld()) && this.getX() == shopChunk.getX() && this.getZ() == shopChunk.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWorld() {
|
public String getWorld() {
|
||||||
return this.world;
|
return this.world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return this.x;
|
return this.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getZ() {
|
public int getZ() {
|
||||||
return this.z;
|
return this.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,50 +6,50 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
public class ShopCreateEvent extends Event implements Cancellable {
|
public class ShopCreateEvent extends Event implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private Shop shop;
|
private Shop shop;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
private Player p;
|
private Player p;
|
||||||
|
|
||||||
public ShopCreateEvent(Shop shop, Player p) {
|
public ShopCreateEvent(Shop shop, Player p) {
|
||||||
this.shop = shop;
|
this.shop = shop;
|
||||||
this.p = p;
|
this.p = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The shop to be created
|
* The shop to be created
|
||||||
*
|
*
|
||||||
* @return The shop to be created
|
* @return The shop to be created
|
||||||
*/
|
*/
|
||||||
public Shop getShop() {
|
public Shop getShop() {
|
||||||
return this.shop;
|
return this.shop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player who is creating this shop
|
* The player who is creating this shop
|
||||||
*
|
*
|
||||||
* @return The player who is creating this shop
|
* @return The player who is creating this shop
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancelled = cancel;
|
this.cancelled = cancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -12,50 +12,50 @@ import org.bukkit.event.HandlerList;
|
|||||||
* much they wish to trade for.
|
* much they wish to trade for.
|
||||||
*/
|
*/
|
||||||
public class ShopPreCreateEvent extends Event implements Cancellable {
|
public class ShopPreCreateEvent extends Event implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
private Player p;
|
private Player p;
|
||||||
private Location loc;
|
private Location loc;
|
||||||
|
|
||||||
public ShopPreCreateEvent(Player p, Location loc) {
|
public ShopPreCreateEvent(Player p, Location loc) {
|
||||||
this.loc = loc;
|
this.loc = loc;
|
||||||
this.p = p;
|
this.p = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The location of the shop that will be created.
|
* The location of the shop that will be created.
|
||||||
*
|
*
|
||||||
* @return The location of the shop that will be created.
|
* @return The location of the shop that will be created.
|
||||||
*/
|
*/
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player who is creating this shop
|
* The player who is creating this shop
|
||||||
*
|
*
|
||||||
* @return The player who is creating this shop
|
* @return The player who is creating this shop
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancelled = cancel;
|
this.cancelled = cancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,71 +6,71 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
public class ShopPurchaseEvent extends Event implements Cancellable {
|
public class ShopPurchaseEvent extends Event implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private Shop shop;
|
private Shop shop;
|
||||||
private Player p;
|
private Player p;
|
||||||
private int amount;
|
private int amount;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a new shop purchase event
|
* Builds a new shop purchase event
|
||||||
*
|
*
|
||||||
* @param shop
|
* @param shop
|
||||||
* The shop bought from
|
* The shop bought from
|
||||||
* @param p
|
* @param p
|
||||||
* The player buying
|
* The player buying
|
||||||
* @param amount
|
* @param amount
|
||||||
* The amount they're buying
|
* The amount they're buying
|
||||||
*/
|
*/
|
||||||
public ShopPurchaseEvent(Shop shop, Player p, int amount) {
|
public ShopPurchaseEvent(Shop shop, Player p, int amount) {
|
||||||
this.shop = shop;
|
this.shop = shop;
|
||||||
this.p = p;
|
this.p = p;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The shop used in this event
|
* The shop used in this event
|
||||||
*
|
*
|
||||||
* @return The shop used in this event
|
* @return The shop used in this event
|
||||||
*/
|
*/
|
||||||
public Shop getShop() {
|
public Shop getShop() {
|
||||||
return this.shop;
|
return this.shop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player trading with the shop
|
* The player trading with the shop
|
||||||
*
|
*
|
||||||
* @return The player trading with the shop
|
* @return The player trading with the shop
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return this.p;
|
return this.p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The amount the purchase was for
|
* The amount the purchase was for
|
||||||
*
|
*
|
||||||
* @return The amount the purchase was for
|
* @return The amount the purchase was for
|
||||||
*/
|
*/
|
||||||
public int getAmount() {
|
public int getAmount() {
|
||||||
return this.amount;
|
return this.amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancelled = cancel;
|
this.cancelled = cancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,26 +1,28 @@
|
|||||||
package org.maxgamer.QuickShop.Shop;
|
package org.maxgamer.QuickShop.Shop;
|
||||||
|
|
||||||
public enum ShopType {
|
public enum ShopType {
|
||||||
SELLING(0), BUYING(1);
|
SELLING(0),
|
||||||
private int id;
|
BUYING(1);
|
||||||
private ShopType(int id){
|
private int id;
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ShopType fromID(int id) {
|
|
||||||
for(ShopType type:ShopType.values()){
|
|
||||||
if(type.id==id){
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int toID(ShopType shopType) {
|
private ShopType(int id) {
|
||||||
return shopType.id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int toID() {
|
public static ShopType fromID(int id) {
|
||||||
return id;
|
for (ShopType type : ShopType.values()) {
|
||||||
}
|
if (type.id == id) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int toID(ShopType shopType) {
|
||||||
|
return shopType.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int toID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,20 +4,20 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
public class MarkUtil {
|
public class MarkUtil {
|
||||||
static String mark = "§q§s§6[§b快捷商店§6] §c悬浮物品§r ";
|
static String mark = "§q§s§6[§b快捷商店§6] §c悬浮物品§r ";
|
||||||
static int conut = 0;
|
static int conut = 0;
|
||||||
|
|
||||||
public static void addMark(final ItemStack ci) {
|
public static void addMark(final ItemStack ci) {
|
||||||
final ItemMeta meta = ci.getItemMeta();
|
final ItemMeta meta = ci.getItemMeta();
|
||||||
meta.setDisplayName(mark + " " + Util.getName(ci) + " " + conut++);
|
meta.setDisplayName(mark + " " + Util.getName(ci) + " " + conut++);
|
||||||
ci.setItemMeta(meta);
|
ci.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasMark(final ItemStack ci) {
|
public static boolean hasMark(final ItemStack ci) {
|
||||||
try {
|
try {
|
||||||
return ci.getItemMeta().getDisplayName().startsWith(mark);
|
return ci.getItemMeta().getDisplayName().startsWith(mark);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,192 +17,192 @@ import cn.citycraft.PluginHelper.config.FileConfig;
|
|||||||
import cn.citycraft.PluginHelper.tellraw.FancyMessage;
|
import cn.citycraft.PluginHelper.tellraw.FancyMessage;
|
||||||
|
|
||||||
public class MsgUtil {
|
public class MsgUtil {
|
||||||
private static FileConfig messages;
|
private static FileConfig messages;
|
||||||
private static HashMap<String, LinkedList<String>> player_messages = new HashMap<String, LinkedList<String>>();
|
private static HashMap<String, LinkedList<String>> player_messages = new HashMap<String, LinkedList<String>>();
|
||||||
private static QuickShop plugin;
|
private static QuickShop plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes any messages that are older than a week in the database, to save
|
* Deletes any messages that are older than a week in the database, to save
|
||||||
* on space.
|
* on space.
|
||||||
*/
|
*/
|
||||||
public static void clean() {
|
public static void clean() {
|
||||||
plugin.getLogger().info("清理超过 一周 的 商店交易记录...");
|
plugin.getLogger().info("清理超过 一周 的 商店交易记录...");
|
||||||
// 604800,000 msec = 1 week.
|
// 604800,000 msec = 1 week.
|
||||||
final long weekAgo = System.currentTimeMillis() - 604800000;
|
final long weekAgo = System.currentTimeMillis() - 604800000;
|
||||||
plugin.getDB().execute("DELETE FROM messages WHERE time < ?", weekAgo);
|
plugin.getDB().execute("DELETE FROM messages WHERE time < ?", weekAgo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empties the queue of messages a player has and sends them to the player.
|
* Empties the queue of messages a player has and sends them to the player.
|
||||||
*
|
*
|
||||||
* @param p
|
* @param p
|
||||||
* The player to message
|
* The player to message
|
||||||
* @return true if success, false if the player is offline or null
|
* @return true if success, false if the player is offline or null
|
||||||
*/
|
*/
|
||||||
public static boolean flush(final OfflinePlayer p) {
|
public static boolean flush(final OfflinePlayer p) {
|
||||||
if (p != null && p.isOnline()) {
|
if (p != null && p.isOnline()) {
|
||||||
final String pName = p.getName();
|
final String pName = p.getName();
|
||||||
final LinkedList<String> msgs = player_messages.get(pName);
|
final LinkedList<String> msgs = player_messages.get(pName);
|
||||||
if (msgs != null) {
|
if (msgs != null) {
|
||||||
for (final String msg : msgs) {
|
for (final String msg : msgs) {
|
||||||
p.getPlayer().sendMessage(msg);
|
p.getPlayer().sendMessage(msg);
|
||||||
}
|
}
|
||||||
plugin.getDB().execute("DELETE FROM messages WHERE owner = ?", pName);
|
plugin.getDB().execute("DELETE FROM messages WHERE owner = ?", pName);
|
||||||
msgs.clear();
|
msgs.clear();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(final QuickShop plugin) {
|
public static void init(final QuickShop plugin) {
|
||||||
MsgUtil.plugin = plugin;
|
MsgUtil.plugin = plugin;
|
||||||
// Load messages.yml
|
// Load messages.yml
|
||||||
messages = new FileConfig(plugin, "messages.yml");
|
messages = new FileConfig(plugin, "messages.yml");
|
||||||
// Parse colour codes
|
// Parse colour codes
|
||||||
Util.parseColours(messages);
|
Util.parseColours(messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loads all player purchase messages from the database.
|
* loads all player purchase messages from the database.
|
||||||
*/
|
*/
|
||||||
public static void loadTransactionMessages() {
|
public static void loadTransactionMessages() {
|
||||||
player_messages.clear(); // Delete old messages
|
player_messages.clear(); // Delete old messages
|
||||||
try {
|
try {
|
||||||
final ResultSet rs = plugin.getDB().getConnection().prepareStatement("SELECT * FROM messages").executeQuery();
|
final ResultSet rs = plugin.getDB().getConnection().prepareStatement("SELECT * FROM messages").executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
final String owner = rs.getString("owner");
|
final String owner = rs.getString("owner");
|
||||||
final String message = rs.getString("message");
|
final String message = rs.getString("message");
|
||||||
LinkedList<String> msgs = player_messages.get(owner);
|
LinkedList<String> msgs = player_messages.get(owner);
|
||||||
if (msgs == null) {
|
if (msgs == null) {
|
||||||
msgs = new LinkedList<String>();
|
msgs = new LinkedList<String>();
|
||||||
player_messages.put(owner, msgs);
|
player_messages.put(owner, msgs);
|
||||||
}
|
}
|
||||||
msgs.add(message);
|
msgs.add(message);
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
plugin.getLogger().warning("无法从数据库获得玩家的交易记录 跳过...");
|
plugin.getLogger().warning("无法从数据库获得玩家的交易记录 跳过...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String p(final String loc, final Object... args) {
|
public static String p(final String loc, final Object... args) {
|
||||||
String raw = messages.getString(loc);
|
String raw = messages.getString(loc);
|
||||||
if (raw == null || raw.isEmpty()) {
|
if (raw == null || raw.isEmpty()) {
|
||||||
return ChatColor.RED + "语言文件词条丢失: " + loc;
|
return ChatColor.RED + "语言文件词条丢失: " + loc;
|
||||||
}
|
}
|
||||||
if (args == null) {
|
if (args == null) {
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
raw = raw.replace("{" + i + "}", args[i] == null ? "null" : args[i].toString());
|
raw = raw.replace("{" + i + "}", args[i] == null ? "null" : args[i].toString());
|
||||||
}
|
}
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
messages.reload();
|
messages.reload();
|
||||||
Util.parseColours(messages);
|
Util.parseColours(messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player
|
* @param player
|
||||||
* The name of the player to message
|
* The name of the player to message
|
||||||
* @param message
|
* @param message
|
||||||
* The message to send them Sends the given player a message if
|
* The message to send them Sends the given player a message if
|
||||||
* they're online. Else, if they're not online, queues it for
|
* they're online. Else, if they're not online, queues it for
|
||||||
* them in the database.
|
* them in the database.
|
||||||
*/
|
*/
|
||||||
public static void send(final String player, final String message) {
|
public static void send(final String player, final String message) {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
final OfflinePlayer p = Bukkit.getOfflinePlayer(player);
|
final OfflinePlayer p = Bukkit.getOfflinePlayer(player);
|
||||||
if (p == null || !p.isOnline()) {
|
if (p == null || !p.isOnline()) {
|
||||||
LinkedList<String> msgs = player_messages.get(player);
|
LinkedList<String> msgs = player_messages.get(player);
|
||||||
if (msgs == null) {
|
if (msgs == null) {
|
||||||
msgs = new LinkedList<String>();
|
msgs = new LinkedList<String>();
|
||||||
player_messages.put(player, msgs);
|
player_messages.put(player, msgs);
|
||||||
}
|
}
|
||||||
msgs.add(message);
|
msgs.add(message);
|
||||||
final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)";
|
final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)";
|
||||||
plugin.getDB().execute(q, player.toString(), message, System.currentTimeMillis());
|
plugin.getDB().execute(q, player.toString(), message, System.currentTimeMillis());
|
||||||
} else {
|
} else {
|
||||||
p.getPlayer().sendMessage(message);
|
p.getPlayer().sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendItemMessage(final Player p, final ItemStack is, final String msg) {
|
public static void sendItemMessage(final Player p, final ItemStack is, final String msg) {
|
||||||
try {
|
try {
|
||||||
final FancyMessage fm = FancyMessage.newFM();
|
final FancyMessage fm = FancyMessage.newFM();
|
||||||
fm.text(msg).itemTooltip(is).send(p);
|
fm.text(msg).itemTooltip(is).send(p);
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchMethodError e) {
|
} catch (Exception | NoClassDefFoundError | NoSuchMethodError e) {
|
||||||
plugin.getConfigManager().setEnableMagicLib(false);
|
plugin.getConfigManager().setEnableMagicLib(false);
|
||||||
p.sendMessage(msg);
|
p.sendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPurchaseSuccess(final Player p, final Shop shop, final int amount) {
|
public static void sendPurchaseSuccess(final Player p, final Shop shop, final int amount) {
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.successful-purchase"));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.successful-purchase"));
|
||||||
final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item-name-and-price", "" + amount, shop.getDataName(), Util.format((amount * shop.getPrice())));
|
final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item-name-and-price", "" + amount, shop.getDataName(), Util.format((amount * shop.getPrice())));
|
||||||
sendItemMessage(p, shop.getItem(), msg);
|
sendItemMessage(p, shop.getItem(), msg);
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendSellSuccess(final Player p, final Shop shop, final int amount) {
|
public static void sendSellSuccess(final Player p, final Shop shop, final int amount) {
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.successfully-sold"));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.successfully-sold"));
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item-name-and-price", "" + amount, shop.getDataName(), Util.format((amount * shop.getPrice()))));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item-name-and-price", "" + amount, shop.getDataName(), Util.format((amount * shop.getPrice()))));
|
||||||
if (plugin.getConfig().getBoolean("show-tax")) {
|
if (plugin.getConfig().getBoolean("show-tax")) {
|
||||||
final double tax = plugin.getConfig().getDouble("tax");
|
final double tax = plugin.getConfig().getDouble("tax");
|
||||||
final double total = amount * shop.getPrice();
|
final double total = amount * shop.getPrice();
|
||||||
if (tax != 0) {
|
if (tax != 0) {
|
||||||
if (!p.getName().equals(shop.getOwner())) {
|
if (!p.getName().equals(shop.getOwner())) {
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.sell-tax", "" + Util.format((tax * total))));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.sell-tax", "" + Util.format((tax * total))));
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.sell-tax-self"));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.sell-tax-self"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendShopInfo(final Player p, final Shop shop) {
|
public static void sendShopInfo(final Player p, final Shop shop) {
|
||||||
sendShopInfo(p, shop, shop.getRemainingStock());
|
sendShopInfo(p, shop, shop.getRemainingStock());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static void sendShopInfo(final Player p, final Shop shop, final int stock) {
|
public static void sendShopInfo(final Player p, final Shop shop, final int stock) {
|
||||||
// Potentially faster with an array?
|
// Potentially faster with an array?
|
||||||
final ItemStack item = shop.getItem();
|
final ItemStack item = shop.getItem();
|
||||||
p.sendMessage("");
|
p.sendMessage("");
|
||||||
p.sendMessage("");
|
p.sendMessage("");
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information"));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information"));
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| "
|
p.sendMessage(ChatColor.DARK_PURPLE + "| "
|
||||||
+ MsgUtil.p("menu.owner", Bukkit.getOfflinePlayer(shop.getOwner()).getName() == null ? (shop.isUnlimited() ? "系统商店" : "未知") : Bukkit.getOfflinePlayer(shop.getOwner()).getName()));
|
+ MsgUtil.p("menu.owner", Bukkit.getOfflinePlayer(shop.getOwner()).getName() == null ? (shop.isUnlimited() ? "系统商店" : "未知") : Bukkit.getOfflinePlayer(shop.getOwner()).getName()));
|
||||||
final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item", shop.getDataName());
|
final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item", shop.getDataName());
|
||||||
sendItemMessage(p, shop.getItem(), msg);
|
sendItemMessage(p, shop.getItem(), msg);
|
||||||
if (Util.isTool(item.getType())) {
|
if (Util.isTool(item.getType())) {
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.damage-percent-remaining", Util.getToolPercentage(item)));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.damage-percent-remaining", Util.getToolPercentage(item)));
|
||||||
}
|
}
|
||||||
if (shop.isSelling()) {
|
if (shop.isSelling()) {
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.stock", "" + (stock == 10000 ? "无限" : stock)));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.stock", "" + (stock == 10000 ? "无限" : stock)));
|
||||||
} else {
|
} else {
|
||||||
final int space = shop.getRemainingSpace();
|
final int space = shop.getRemainingSpace();
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.space", "" + (space == 10000 ? "无限" : space)));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.space", "" + (space == 10000 ? "无限" : space)));
|
||||||
}
|
}
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.price-per", shop.getDataName(), Util.format(shop.getPrice())));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.price-per", shop.getDataName(), Util.format(shop.getPrice())));
|
||||||
if (shop.isBuying()) {
|
if (shop.isBuying()) {
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-buying"));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-buying"));
|
||||||
} else {
|
} else {
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-selling"));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-selling"));
|
||||||
}
|
}
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||||
if (shop.isSelling()) {
|
if (shop.isSelling()) {
|
||||||
p.sendMessage(MsgUtil.p("how-many-buy"));
|
p.sendMessage(MsgUtil.p("how-many-buy"));
|
||||||
} else {
|
} else {
|
||||||
final int items = Util.countItems(p.getInventory(), shop.getItem());
|
final int items = Util.countItems(p.getInventory(), shop.getItem());
|
||||||
p.sendMessage(MsgUtil.p("how-many-sell", items));
|
p.sendMessage(MsgUtil.p("how-many-sell", items));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,12 +5,12 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
public class NMS {
|
public class NMS {
|
||||||
|
|
||||||
public static void safeGuard(final Item item) throws ClassNotFoundException {
|
public static void safeGuard(final Item item) throws ClassNotFoundException {
|
||||||
rename(item.getItemStack());
|
rename(item.getItemStack());
|
||||||
item.setPickupDelay(2147483647);
|
item.setPickupDelay(2147483647);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void rename(final ItemStack iStack) {
|
private static void rename(final ItemStack iStack) {
|
||||||
MarkUtil.addMark(iStack);
|
MarkUtil.addMark(iStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,511 +27,511 @@ import cn.citycraft.PluginHelper.utils.LocalUtil;
|
|||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class Util {
|
public class Util {
|
||||||
private static HashSet<Material> blacklist = new HashSet<Material>();
|
private static HashSet<Material> blacklist = new HashSet<Material>();
|
||||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
|
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
|
||||||
private static QuickShop plugin;
|
private static QuickShop plugin;
|
||||||
private static HashSet<Material> shoppables = new HashSet<Material>();
|
private static HashSet<Material> shoppables = new HashSet<Material>();
|
||||||
private static HashSet<Material> tools = new HashSet<Material>();
|
private static HashSet<Material> tools = new HashSet<Material>();
|
||||||
private static HashSet<Material> transparent = new HashSet<Material>();
|
private static HashSet<Material> transparent = new HashSet<Material>();
|
||||||
|
|
||||||
public static void addTransparentBlock(final Material m) {
|
public static void addTransparentBlock(final Material m) {
|
||||||
if (transparent.add(m) == false) {
|
if (transparent.add(m) == false) {
|
||||||
System.out.println("已添加透明方块: " + m.toString());
|
System.out.println("已添加透明方块: " + m.toString());
|
||||||
}
|
}
|
||||||
if (!m.isBlock()) {
|
if (!m.isBlock()) {
|
||||||
System.out.println(m + " 不是一个方块!");
|
System.out.println(m + " 不是一个方块!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the given block could be used to make a shop out of.
|
* Returns true if the given block could be used to make a shop out of.
|
||||||
*
|
*
|
||||||
* @param b
|
* @param b
|
||||||
* The block to check. Possibly a chest, dispenser, etc.
|
* The block to check. Possibly a chest, dispenser, etc.
|
||||||
* @return True if it can be made into a shop, otherwise false.
|
* @return True if it can be made into a shop, otherwise false.
|
||||||
*/
|
*/
|
||||||
public static boolean canBeShop(final Block b) {
|
public static boolean canBeShop(final Block b) {
|
||||||
try {
|
try {
|
||||||
final BlockState bs = b.getState();
|
final BlockState bs = b.getState();
|
||||||
if (bs instanceof InventoryHolder == false) {
|
if (bs instanceof InventoryHolder == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return shoppables.contains(bs.getType());
|
return shoppables.contains(bs.getType());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts the number of items in the given inventory where
|
* Counts the number of items in the given inventory where
|
||||||
* Util.matches(inventory item, item) is true.
|
* Util.matches(inventory item, item) is true.
|
||||||
*
|
*
|
||||||
* @param inv
|
* @param inv
|
||||||
* The inventory to search
|
* The inventory to search
|
||||||
* @param item
|
* @param item
|
||||||
* The ItemStack to search for
|
* The ItemStack to search for
|
||||||
* @return The number of items that match in this inventory.
|
* @return The number of items that match in this inventory.
|
||||||
*/
|
*/
|
||||||
public static int countItems(final Inventory inv, final ItemStack item) {
|
public static int countItems(final Inventory inv, final ItemStack item) {
|
||||||
int items = 0;
|
int items = 0;
|
||||||
for (final ItemStack iStack : inv.getContents()) {
|
for (final ItemStack iStack : inv.getContents()) {
|
||||||
if (iStack == null) {
|
if (iStack == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Util.matches(item, iStack)) {
|
if (Util.matches(item, iStack)) {
|
||||||
items += iStack.getAmount();
|
items += iStack.getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of items that can be given to the inventory safely.
|
* Returns the number of items that can be given to the inventory safely.
|
||||||
*
|
*
|
||||||
* @param inv
|
* @param inv
|
||||||
* The inventory to count
|
* The inventory to count
|
||||||
* @param item
|
* @param item
|
||||||
* The item prototype. Material, durabiltiy and enchants must
|
* The item prototype. Material, durabiltiy and enchants must
|
||||||
* match for 'stackability' to occur.
|
* match for 'stackability' to occur.
|
||||||
* @return The number of items that can be given to the inventory safely.
|
* @return The number of items that can be given to the inventory safely.
|
||||||
*/
|
*/
|
||||||
public static int countSpace(final Inventory inv, final ItemStack item) {
|
public static int countSpace(final Inventory inv, final ItemStack item) {
|
||||||
int space = 0;
|
int space = 0;
|
||||||
for (final ItemStack iStack : inv.getContents()) {
|
for (final ItemStack iStack : inv.getContents()) {
|
||||||
if (iStack == null || iStack.getType() == Material.AIR) {
|
if (iStack == null || iStack.getType() == Material.AIR) {
|
||||||
space += item.getMaxStackSize();
|
space += item.getMaxStackSize();
|
||||||
} else if (matches(item, iStack)) {
|
} else if (matches(item, iStack)) {
|
||||||
space += item.getMaxStackSize() - iStack.getAmount();
|
space += item.getMaxStackSize() - iStack.getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack deserialize(final String config) throws InvalidConfigurationException {
|
public static ItemStack deserialize(final String config) throws InvalidConfigurationException {
|
||||||
final YamlConfiguration cfg = new YamlConfiguration();
|
final YamlConfiguration cfg = new YamlConfiguration();
|
||||||
cfg.loadFromString(config);
|
cfg.loadFromString(config);
|
||||||
final ItemStack stack = cfg.getItemStack("item");
|
final ItemStack stack = cfg.getItemStack("item");
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String firstUppercase(final String string) {
|
public static String firstUppercase(final String string) {
|
||||||
if (string.length() > 1) {
|
if (string.length() > 1) {
|
||||||
return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase();
|
return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase();
|
||||||
}
|
}
|
||||||
return string.toUpperCase();
|
return string.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the given number according to how vault would like it. E.g. $50
|
* Formats the given number according to how vault would like it. E.g. $50
|
||||||
* or 5 dollars.
|
* or 5 dollars.
|
||||||
*
|
*
|
||||||
* @return The formatted string.
|
* @return The formatted string.
|
||||||
*/
|
*/
|
||||||
public static String format(final double n) {
|
public static String format(final double n) {
|
||||||
try {
|
try {
|
||||||
return DECIMAL_FORMAT.format(n) + plugin.getEcon().currencyNamePlural();
|
return DECIMAL_FORMAT.format(n) + plugin.getEcon().currencyNamePlural();
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
return n + "元";
|
return n + "元";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the block which the given sign is attached to
|
* Fetches the block which the given sign is attached to
|
||||||
*
|
*
|
||||||
* @param sign
|
* @param sign
|
||||||
* The sign which is attached
|
* The sign which is attached
|
||||||
* @return The block the sign is attached to
|
* @return The block the sign is attached to
|
||||||
*/
|
*/
|
||||||
public static Block getAttached(final Block b) {
|
public static Block getAttached(final Block b) {
|
||||||
try {
|
try {
|
||||||
final Sign sign = (Sign) b.getState().getData(); // Throws a NPE
|
final Sign sign = (Sign) b.getState().getData(); // Throws a NPE
|
||||||
// sometimes??
|
// sometimes??
|
||||||
final BlockFace attached = sign.getAttachedFace();
|
final BlockFace attached = sign.getAttachedFace();
|
||||||
return attached == null ? null : b.getRelative(attached);
|
return attached == null ? null : b.getRelative(attached);
|
||||||
} catch (final NullPointerException e) {
|
} catch (final NullPointerException e) {
|
||||||
return null; // /Not sure what causes this.
|
return null; // /Not sure what causes this.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches an ItemStack's name - For example, converting INK_SAC:11 to
|
* Fetches an ItemStack's name - For example, converting INK_SAC:11 to
|
||||||
* Dandellion Yellow, or WOOL:14 to Red Wool
|
* Dandellion Yellow, or WOOL:14 to Red Wool
|
||||||
*
|
*
|
||||||
* @param i
|
* @param i
|
||||||
* The itemstack to fetch the name of
|
* The itemstack to fetch the name of
|
||||||
* @return The human readable item name.
|
* @return The human readable item name.
|
||||||
*/
|
*/
|
||||||
public static String getName(final ItemStack i) {
|
public static String getName(final ItemStack i) {
|
||||||
final String vanillaName = LocalUtil.getItemFullName(i);
|
final String vanillaName = LocalUtil.getItemFullName(i);
|
||||||
return vanillaName;
|
return vanillaName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's make very long names shorter for our sign
|
// Let's make very long names shorter for our sign
|
||||||
public static String getNameForSign(final ItemStack itemStack) {
|
public static String getNameForSign(final ItemStack itemStack) {
|
||||||
String name = getName(itemStack);
|
String name = getName(itemStack);
|
||||||
if (name.length() > 16) {
|
if (name.length() > 16) {
|
||||||
name = name.substring(0, 16);
|
name = name.substring(0, 16);
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the chest attached to the given chest. The given block must be a
|
* Returns the chest attached to the given chest. The given block must be a
|
||||||
* chest.
|
* chest.
|
||||||
*
|
*
|
||||||
* @param b
|
* @param b
|
||||||
* The chest to check.
|
* The chest to check.
|
||||||
* @return the block which is also a chest and connected to b.
|
* @return the block which is also a chest and connected to b.
|
||||||
*/
|
*/
|
||||||
public static Block getSecondHalf(final Block b) {
|
public static Block getSecondHalf(final Block b) {
|
||||||
if (b.getType().toString().contains("CHEST") == false) {
|
if (b.getType().toString().contains("CHEST") == false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Block[] blocks = new Block[4];
|
final Block[] blocks = new Block[4];
|
||||||
blocks[0] = b.getRelative(1, 0, 0);
|
blocks[0] = b.getRelative(1, 0, 0);
|
||||||
blocks[1] = b.getRelative(-1, 0, 0);
|
blocks[1] = b.getRelative(-1, 0, 0);
|
||||||
blocks[2] = b.getRelative(0, 0, 1);
|
blocks[2] = b.getRelative(0, 0, 1);
|
||||||
blocks[3] = b.getRelative(0, 0, -1);
|
blocks[3] = b.getRelative(0, 0, -1);
|
||||||
for (final Block c : blocks) {
|
for (final Block c : blocks) {
|
||||||
if (c.getType() == b.getType()) {
|
if (c.getType() == b.getType()) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the percentage (Without trailing %) damage on a tool.
|
* Gets the percentage (Without trailing %) damage on a tool.
|
||||||
*
|
*
|
||||||
* @param item
|
* @param item
|
||||||
* The ItemStack of tools to check
|
* The ItemStack of tools to check
|
||||||
* @return The percentage 'health' the tool has. (Opposite of total damage)
|
* @return The percentage 'health' the tool has. (Opposite of total damage)
|
||||||
*/
|
*/
|
||||||
public static String getToolPercentage(final ItemStack item) {
|
public static String getToolPercentage(final ItemStack item) {
|
||||||
final double dura = item.getDurability();
|
final double dura = item.getDurability();
|
||||||
final double max = item.getType().getMaxDurability();
|
final double max = item.getType().getMaxDurability();
|
||||||
return String.format("%.2f%%(剩余耐久%s/总耐久%s)", (1 - dura / max) * 100.0, max - dura, max);
|
return String.format("%.2f%%(剩余耐久%s/总耐久%s)", (1 - dura / max) * 100.0, max - dura, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
tools.clear();
|
tools.clear();
|
||||||
blacklist.clear();
|
blacklist.clear();
|
||||||
shoppables.clear();
|
shoppables.clear();
|
||||||
transparent.clear();
|
transparent.clear();
|
||||||
|
|
||||||
plugin = QuickShop.instance;
|
plugin = QuickShop.instance;
|
||||||
for (final String s : plugin.getConfig().getStringList("shop-blocks")) {
|
for (final String s : plugin.getConfig().getStringList("shop-blocks")) {
|
||||||
Material mat = Material.getMaterial(s.toUpperCase());
|
Material mat = Material.getMaterial(s.toUpperCase());
|
||||||
if (mat == null) {
|
if (mat == null) {
|
||||||
try {
|
try {
|
||||||
mat = Material.getMaterial(Integer.parseInt(s));
|
mat = Material.getMaterial(Integer.parseInt(s));
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mat == null) {
|
if (mat == null) {
|
||||||
plugin.getLogger().info("Invalid shop-block: " + s);
|
plugin.getLogger().info("Invalid shop-block: " + s);
|
||||||
} else {
|
} else {
|
||||||
shoppables.add(mat);
|
shoppables.add(mat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tools.add(Material.BOW);
|
tools.add(Material.BOW);
|
||||||
tools.add(Material.SHEARS);
|
tools.add(Material.SHEARS);
|
||||||
tools.add(Material.FISHING_ROD);
|
tools.add(Material.FISHING_ROD);
|
||||||
tools.add(Material.FLINT_AND_STEEL);
|
tools.add(Material.FLINT_AND_STEEL);
|
||||||
tools.add(Material.CHAINMAIL_BOOTS);
|
tools.add(Material.CHAINMAIL_BOOTS);
|
||||||
tools.add(Material.CHAINMAIL_CHESTPLATE);
|
tools.add(Material.CHAINMAIL_CHESTPLATE);
|
||||||
tools.add(Material.CHAINMAIL_HELMET);
|
tools.add(Material.CHAINMAIL_HELMET);
|
||||||
tools.add(Material.CHAINMAIL_LEGGINGS);
|
tools.add(Material.CHAINMAIL_LEGGINGS);
|
||||||
tools.add(Material.WOOD_AXE);
|
tools.add(Material.WOOD_AXE);
|
||||||
tools.add(Material.WOOD_HOE);
|
tools.add(Material.WOOD_HOE);
|
||||||
tools.add(Material.WOOD_PICKAXE);
|
tools.add(Material.WOOD_PICKAXE);
|
||||||
tools.add(Material.WOOD_SPADE);
|
tools.add(Material.WOOD_SPADE);
|
||||||
tools.add(Material.WOOD_SWORD);
|
tools.add(Material.WOOD_SWORD);
|
||||||
tools.add(Material.LEATHER_BOOTS);
|
tools.add(Material.LEATHER_BOOTS);
|
||||||
tools.add(Material.LEATHER_CHESTPLATE);
|
tools.add(Material.LEATHER_CHESTPLATE);
|
||||||
tools.add(Material.LEATHER_HELMET);
|
tools.add(Material.LEATHER_HELMET);
|
||||||
tools.add(Material.LEATHER_LEGGINGS);
|
tools.add(Material.LEATHER_LEGGINGS);
|
||||||
tools.add(Material.DIAMOND_AXE);
|
tools.add(Material.DIAMOND_AXE);
|
||||||
tools.add(Material.DIAMOND_HOE);
|
tools.add(Material.DIAMOND_HOE);
|
||||||
tools.add(Material.DIAMOND_PICKAXE);
|
tools.add(Material.DIAMOND_PICKAXE);
|
||||||
tools.add(Material.DIAMOND_SPADE);
|
tools.add(Material.DIAMOND_SPADE);
|
||||||
tools.add(Material.DIAMOND_SWORD);
|
tools.add(Material.DIAMOND_SWORD);
|
||||||
tools.add(Material.DIAMOND_BOOTS);
|
tools.add(Material.DIAMOND_BOOTS);
|
||||||
tools.add(Material.DIAMOND_CHESTPLATE);
|
tools.add(Material.DIAMOND_CHESTPLATE);
|
||||||
tools.add(Material.DIAMOND_HELMET);
|
tools.add(Material.DIAMOND_HELMET);
|
||||||
tools.add(Material.DIAMOND_LEGGINGS);
|
tools.add(Material.DIAMOND_LEGGINGS);
|
||||||
tools.add(Material.STONE_AXE);
|
tools.add(Material.STONE_AXE);
|
||||||
tools.add(Material.STONE_HOE);
|
tools.add(Material.STONE_HOE);
|
||||||
tools.add(Material.STONE_PICKAXE);
|
tools.add(Material.STONE_PICKAXE);
|
||||||
tools.add(Material.STONE_SPADE);
|
tools.add(Material.STONE_SPADE);
|
||||||
tools.add(Material.STONE_SWORD);
|
tools.add(Material.STONE_SWORD);
|
||||||
tools.add(Material.GOLD_AXE);
|
tools.add(Material.GOLD_AXE);
|
||||||
tools.add(Material.GOLD_HOE);
|
tools.add(Material.GOLD_HOE);
|
||||||
tools.add(Material.GOLD_PICKAXE);
|
tools.add(Material.GOLD_PICKAXE);
|
||||||
tools.add(Material.GOLD_SPADE);
|
tools.add(Material.GOLD_SPADE);
|
||||||
tools.add(Material.GOLD_SWORD);
|
tools.add(Material.GOLD_SWORD);
|
||||||
tools.add(Material.GOLD_BOOTS);
|
tools.add(Material.GOLD_BOOTS);
|
||||||
tools.add(Material.GOLD_CHESTPLATE);
|
tools.add(Material.GOLD_CHESTPLATE);
|
||||||
tools.add(Material.GOLD_HELMET);
|
tools.add(Material.GOLD_HELMET);
|
||||||
tools.add(Material.GOLD_LEGGINGS);
|
tools.add(Material.GOLD_LEGGINGS);
|
||||||
tools.add(Material.IRON_AXE);
|
tools.add(Material.IRON_AXE);
|
||||||
tools.add(Material.IRON_HOE);
|
tools.add(Material.IRON_HOE);
|
||||||
tools.add(Material.IRON_PICKAXE);
|
tools.add(Material.IRON_PICKAXE);
|
||||||
tools.add(Material.IRON_SPADE);
|
tools.add(Material.IRON_SPADE);
|
||||||
tools.add(Material.IRON_SWORD);
|
tools.add(Material.IRON_SWORD);
|
||||||
tools.add(Material.IRON_BOOTS);
|
tools.add(Material.IRON_BOOTS);
|
||||||
tools.add(Material.IRON_CHESTPLATE);
|
tools.add(Material.IRON_CHESTPLATE);
|
||||||
tools.add(Material.IRON_HELMET);
|
tools.add(Material.IRON_HELMET);
|
||||||
tools.add(Material.IRON_LEGGINGS);
|
tools.add(Material.IRON_LEGGINGS);
|
||||||
final List<String> configBlacklist = plugin.getConfig().getStringList("blacklist");
|
final List<String> configBlacklist = plugin.getConfig().getStringList("blacklist");
|
||||||
for (final String s : configBlacklist) {
|
for (final String s : configBlacklist) {
|
||||||
Material mat = Material.getMaterial(s.toUpperCase());
|
Material mat = Material.getMaterial(s.toUpperCase());
|
||||||
if (mat == null) {
|
if (mat == null) {
|
||||||
mat = Material.getMaterial(Integer.parseInt(s));
|
mat = Material.getMaterial(Integer.parseInt(s));
|
||||||
if (mat == null) {
|
if (mat == null) {
|
||||||
plugin.getLogger().info(s + " is not a valid material. Check your spelling or ID");
|
plugin.getLogger().info(s + " is not a valid material. Check your spelling or ID");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blacklist.add(mat);
|
blacklist.add(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: add extras to config file
|
// ToDo: add extras to config file
|
||||||
addTransparentBlock(Material.AIR);
|
addTransparentBlock(Material.AIR);
|
||||||
/* Misc */
|
/* Misc */
|
||||||
addTransparentBlock(Material.CAKE_BLOCK);
|
addTransparentBlock(Material.CAKE_BLOCK);
|
||||||
/* Redstone Material */
|
/* Redstone Material */
|
||||||
addTransparentBlock(Material.REDSTONE_WIRE);
|
addTransparentBlock(Material.REDSTONE_WIRE);
|
||||||
/* Redstone Torches */
|
/* Redstone Torches */
|
||||||
addTransparentBlock(Material.REDSTONE_TORCH_OFF);
|
addTransparentBlock(Material.REDSTONE_TORCH_OFF);
|
||||||
addTransparentBlock(Material.REDSTONE_TORCH_ON);
|
addTransparentBlock(Material.REDSTONE_TORCH_ON);
|
||||||
/* Diodes (Repeaters) */
|
/* Diodes (Repeaters) */
|
||||||
addTransparentBlock(Material.DIODE_BLOCK_OFF);
|
addTransparentBlock(Material.DIODE_BLOCK_OFF);
|
||||||
addTransparentBlock(Material.DIODE_BLOCK_ON);
|
addTransparentBlock(Material.DIODE_BLOCK_ON);
|
||||||
/* Power Sources */
|
/* Power Sources */
|
||||||
addTransparentBlock(Material.DETECTOR_RAIL);
|
addTransparentBlock(Material.DETECTOR_RAIL);
|
||||||
addTransparentBlock(Material.LEVER);
|
addTransparentBlock(Material.LEVER);
|
||||||
addTransparentBlock(Material.STONE_BUTTON);
|
addTransparentBlock(Material.STONE_BUTTON);
|
||||||
addTransparentBlock(Material.WOOD_BUTTON);
|
addTransparentBlock(Material.WOOD_BUTTON);
|
||||||
addTransparentBlock(Material.STONE_PLATE);
|
addTransparentBlock(Material.STONE_PLATE);
|
||||||
addTransparentBlock(Material.WOOD_PLATE);
|
addTransparentBlock(Material.WOOD_PLATE);
|
||||||
/* Nature Material */
|
/* Nature Material */
|
||||||
addTransparentBlock(Material.RED_MUSHROOM);
|
addTransparentBlock(Material.RED_MUSHROOM);
|
||||||
addTransparentBlock(Material.BROWN_MUSHROOM);
|
addTransparentBlock(Material.BROWN_MUSHROOM);
|
||||||
addTransparentBlock(Material.RED_ROSE);
|
addTransparentBlock(Material.RED_ROSE);
|
||||||
addTransparentBlock(Material.YELLOW_FLOWER);
|
addTransparentBlock(Material.YELLOW_FLOWER);
|
||||||
addTransparentBlock(Material.FLOWER_POT);
|
addTransparentBlock(Material.FLOWER_POT);
|
||||||
/* Greens */
|
/* Greens */
|
||||||
addTransparentBlock(Material.LONG_GRASS);
|
addTransparentBlock(Material.LONG_GRASS);
|
||||||
addTransparentBlock(Material.VINE);
|
addTransparentBlock(Material.VINE);
|
||||||
addTransparentBlock(Material.WATER_LILY);
|
addTransparentBlock(Material.WATER_LILY);
|
||||||
/* Seedy things */
|
/* Seedy things */
|
||||||
addTransparentBlock(Material.MELON_STEM);
|
addTransparentBlock(Material.MELON_STEM);
|
||||||
addTransparentBlock(Material.PUMPKIN_STEM);
|
addTransparentBlock(Material.PUMPKIN_STEM);
|
||||||
addTransparentBlock(Material.CROPS);
|
addTransparentBlock(Material.CROPS);
|
||||||
addTransparentBlock(Material.NETHER_WARTS);
|
addTransparentBlock(Material.NETHER_WARTS);
|
||||||
/* Semi-nature */
|
/* Semi-nature */
|
||||||
addTransparentBlock(Material.SNOW);
|
addTransparentBlock(Material.SNOW);
|
||||||
addTransparentBlock(Material.FIRE);
|
addTransparentBlock(Material.FIRE);
|
||||||
addTransparentBlock(Material.WEB);
|
addTransparentBlock(Material.WEB);
|
||||||
addTransparentBlock(Material.TRIPWIRE);
|
addTransparentBlock(Material.TRIPWIRE);
|
||||||
addTransparentBlock(Material.TRIPWIRE_HOOK);
|
addTransparentBlock(Material.TRIPWIRE_HOOK);
|
||||||
/* Stairs */
|
/* Stairs */
|
||||||
addTransparentBlock(Material.COBBLESTONE_STAIRS);
|
addTransparentBlock(Material.COBBLESTONE_STAIRS);
|
||||||
addTransparentBlock(Material.BRICK_STAIRS);
|
addTransparentBlock(Material.BRICK_STAIRS);
|
||||||
addTransparentBlock(Material.SANDSTONE_STAIRS);
|
addTransparentBlock(Material.SANDSTONE_STAIRS);
|
||||||
addTransparentBlock(Material.NETHER_BRICK_STAIRS);
|
addTransparentBlock(Material.NETHER_BRICK_STAIRS);
|
||||||
addTransparentBlock(Material.SMOOTH_STAIRS);
|
addTransparentBlock(Material.SMOOTH_STAIRS);
|
||||||
/* Wood Stairs */
|
/* Wood Stairs */
|
||||||
addTransparentBlock(Material.BIRCH_WOOD_STAIRS);
|
addTransparentBlock(Material.BIRCH_WOOD_STAIRS);
|
||||||
addTransparentBlock(Material.WOOD_STAIRS);
|
addTransparentBlock(Material.WOOD_STAIRS);
|
||||||
addTransparentBlock(Material.JUNGLE_WOOD_STAIRS);
|
addTransparentBlock(Material.JUNGLE_WOOD_STAIRS);
|
||||||
addTransparentBlock(Material.SPRUCE_WOOD_STAIRS);
|
addTransparentBlock(Material.SPRUCE_WOOD_STAIRS);
|
||||||
/* Lava & Water */
|
/* Lava & Water */
|
||||||
addTransparentBlock(Material.LAVA);
|
addTransparentBlock(Material.LAVA);
|
||||||
addTransparentBlock(Material.STATIONARY_LAVA);
|
addTransparentBlock(Material.STATIONARY_LAVA);
|
||||||
addTransparentBlock(Material.WATER);
|
addTransparentBlock(Material.WATER);
|
||||||
addTransparentBlock(Material.STATIONARY_WATER);
|
addTransparentBlock(Material.STATIONARY_WATER);
|
||||||
/* Saplings and bushes */
|
/* Saplings and bushes */
|
||||||
addTransparentBlock(Material.SAPLING);
|
addTransparentBlock(Material.SAPLING);
|
||||||
addTransparentBlock(Material.DEAD_BUSH);
|
addTransparentBlock(Material.DEAD_BUSH);
|
||||||
/* Construction Material */
|
/* Construction Material */
|
||||||
/* Fences */
|
/* Fences */
|
||||||
addTransparentBlock(Material.FENCE);
|
addTransparentBlock(Material.FENCE);
|
||||||
addTransparentBlock(Material.FENCE_GATE);
|
addTransparentBlock(Material.FENCE_GATE);
|
||||||
addTransparentBlock(Material.IRON_FENCE);
|
addTransparentBlock(Material.IRON_FENCE);
|
||||||
addTransparentBlock(Material.NETHER_FENCE);
|
addTransparentBlock(Material.NETHER_FENCE);
|
||||||
/* Ladders, Signs */
|
/* Ladders, Signs */
|
||||||
addTransparentBlock(Material.LADDER);
|
addTransparentBlock(Material.LADDER);
|
||||||
addTransparentBlock(Material.SIGN_POST);
|
addTransparentBlock(Material.SIGN_POST);
|
||||||
addTransparentBlock(Material.WALL_SIGN);
|
addTransparentBlock(Material.WALL_SIGN);
|
||||||
/* Bed */
|
/* Bed */
|
||||||
addTransparentBlock(Material.BED_BLOCK);
|
addTransparentBlock(Material.BED_BLOCK);
|
||||||
/* Pistons */
|
/* Pistons */
|
||||||
addTransparentBlock(Material.PISTON_EXTENSION);
|
addTransparentBlock(Material.PISTON_EXTENSION);
|
||||||
addTransparentBlock(Material.PISTON_MOVING_PIECE);
|
addTransparentBlock(Material.PISTON_MOVING_PIECE);
|
||||||
addTransparentBlock(Material.RAILS);
|
addTransparentBlock(Material.RAILS);
|
||||||
/* Torch & Trapdoor */
|
/* Torch & Trapdoor */
|
||||||
addTransparentBlock(Material.TORCH);
|
addTransparentBlock(Material.TORCH);
|
||||||
addTransparentBlock(Material.TRAP_DOOR);
|
addTransparentBlock(Material.TRAP_DOOR);
|
||||||
/* New */
|
/* New */
|
||||||
addTransparentBlock(Material.BREWING_STAND);
|
addTransparentBlock(Material.BREWING_STAND);
|
||||||
addTransparentBlock(Material.WOODEN_DOOR);
|
addTransparentBlock(Material.WOODEN_DOOR);
|
||||||
addTransparentBlock(Material.WOOD_STEP);
|
addTransparentBlock(Material.WOOD_STEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param m
|
* @param m
|
||||||
* The material to check if it is blacklisted
|
* The material to check if it is blacklisted
|
||||||
* @return true if the material is black listed. False if not.
|
* @return true if the material is black listed. False if not.
|
||||||
*/
|
*/
|
||||||
public static boolean isBlacklisted(final Material m) {
|
public static boolean isBlacklisted(final Material m) {
|
||||||
return blacklist.contains(m);
|
return blacklist.contains(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the given location is loaded or not.
|
* Returns true if the given location is loaded or not.
|
||||||
*
|
*
|
||||||
* @param loc
|
* @param loc
|
||||||
* The location
|
* The location
|
||||||
* @return true if the given location is loaded or not.
|
* @return true if the given location is loaded or not.
|
||||||
*/
|
*/
|
||||||
public static boolean isLoaded(final Location loc) {
|
public static boolean isLoaded(final Location loc) {
|
||||||
// System.out.println("Checking isLoaded(Location loc)");
|
// System.out.println("Checking isLoaded(Location loc)");
|
||||||
if (loc.getWorld() == null) {
|
if (loc.getWorld() == null) {
|
||||||
// System.out.println("Is not loaded. (No world)");
|
// System.out.println("Is not loaded. (No world)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Calculate the chunks coordinates. These are 1,2,3 for each chunk, NOT
|
// Calculate the chunks coordinates. These are 1,2,3 for each chunk, NOT
|
||||||
// location rounded to the nearest 16.
|
// location rounded to the nearest 16.
|
||||||
final int x = (int) Math.floor((loc.getBlockX()) / 16.0);
|
final int x = (int) Math.floor((loc.getBlockX()) / 16.0);
|
||||||
final int z = (int) Math.floor((loc.getBlockZ()) / 16.0);
|
final int z = (int) Math.floor((loc.getBlockZ()) / 16.0);
|
||||||
if (loc.getWorld().isChunkLoaded(x, z)) {
|
if (loc.getWorld().isChunkLoaded(x, z)) {
|
||||||
// System.out.println("Chunk is loaded " + x + ", " + z);
|
// System.out.println("Chunk is loaded " + x + ", " + z);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// System.out.println("Chunk is NOT loaded " + x + ", " + z);
|
// System.out.println("Chunk is NOT loaded " + x + ", " + z);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mat
|
* @param mat
|
||||||
* The material to check
|
* The material to check
|
||||||
* @return Returns true if the item is a tool (Has durability) or false if
|
* @return Returns true if the item is a tool (Has durability) or false if
|
||||||
* it doesn't.
|
* it doesn't.
|
||||||
*/
|
*/
|
||||||
public static boolean isTool(final Material mat) {
|
public static boolean isTool(final Material mat) {
|
||||||
return tools.contains(mat);
|
return tools.contains(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTransparent(final Material m) {
|
public static boolean isTransparent(final Material m) {
|
||||||
final boolean trans = transparent.contains(m);
|
final boolean trans = transparent.contains(m);
|
||||||
return trans;
|
return trans;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a string into an item from the database.
|
* Converts a string into an item from the database.
|
||||||
*
|
*
|
||||||
* @param itemString
|
* @param itemString
|
||||||
* The database string. Is the result of makeString(ItemStack
|
* The database string. Is the result of makeString(ItemStack
|
||||||
* item).
|
* item).
|
||||||
* @return A new itemstack, with the properties given in the string
|
* @return A new itemstack, with the properties given in the string
|
||||||
*/
|
*/
|
||||||
public static ItemStack makeItem(final String itemString) {
|
public static ItemStack makeItem(final String itemString) {
|
||||||
final String[] itemInfo = itemString.split(":");
|
final String[] itemInfo = itemString.split(":");
|
||||||
final ItemStack item = new ItemStack(Material.getMaterial(itemInfo[0]));
|
final ItemStack item = new ItemStack(Material.getMaterial(itemInfo[0]));
|
||||||
final MaterialData data = new MaterialData(Integer.parseInt(itemInfo[1]));
|
final MaterialData data = new MaterialData(Integer.parseInt(itemInfo[1]));
|
||||||
item.setData(data);
|
item.setData(data);
|
||||||
item.setDurability(Short.parseShort(itemInfo[2]));
|
item.setDurability(Short.parseShort(itemInfo[2]));
|
||||||
item.setAmount(Integer.parseInt(itemInfo[3]));
|
item.setAmount(Integer.parseInt(itemInfo[3]));
|
||||||
for (int i = 4; i < itemInfo.length; i = i + 2) {
|
for (int i = 4; i < itemInfo.length; i = i + 2) {
|
||||||
int level = Integer.parseInt(itemInfo[i + 1]);
|
int level = Integer.parseInt(itemInfo[i + 1]);
|
||||||
final Enchantment ench = Enchantment.getByName(itemInfo[i]);
|
final Enchantment ench = Enchantment.getByName(itemInfo[i]);
|
||||||
if (ench == null) {
|
if (ench == null) {
|
||||||
continue; // Invalid
|
continue; // Invalid
|
||||||
}
|
}
|
||||||
if (ench.canEnchantItem(item)) {
|
if (ench.canEnchantItem(item)) {
|
||||||
if (level <= 0) {
|
if (level <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
level = Math.min(ench.getMaxLevel(), level);
|
level = Math.min(ench.getMaxLevel(), level);
|
||||||
item.addEnchantment(ench, level);
|
item.addEnchantment(ench, level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares two items to each other. Returns true if they match.
|
* Compares two items to each other. Returns true if they match.
|
||||||
*
|
*
|
||||||
* @param stack1
|
* @param stack1
|
||||||
* The first item stack
|
* The first item stack
|
||||||
* @param stack2
|
* @param stack2
|
||||||
* The second item stack
|
* The second item stack
|
||||||
* @return true if the itemstacks match. (Material, durability, enchants, name)
|
* @return true if the itemstacks match. (Material, durability, enchants, name)
|
||||||
*/
|
*/
|
||||||
public static boolean matches(final ItemStack stack1, final ItemStack stack2) {
|
public static boolean matches(final ItemStack stack1, final ItemStack stack2) {
|
||||||
if (stack1 == stack2) {
|
if (stack1 == stack2) {
|
||||||
return true; // Referring to the same thing, or both are null.
|
return true; // Referring to the same thing, or both are null.
|
||||||
}
|
}
|
||||||
if (stack1 == null || stack2 == null) {
|
if (stack1 == null || stack2 == null) {
|
||||||
return false; // One of them is null (Can't be both, see above)
|
return false; // One of them is null (Can't be both, see above)
|
||||||
}
|
}
|
||||||
if (stack1.getType() != stack2.getType()) {
|
if (stack1.getType() != stack2.getType()) {
|
||||||
return false; // Not the same material
|
return false; // Not the same material
|
||||||
}
|
}
|
||||||
if (stack1.getDurability() != stack2.getDurability()) {
|
if (stack1.getDurability() != stack2.getDurability()) {
|
||||||
return false; // Not the same durability
|
return false; // Not the same durability
|
||||||
}
|
}
|
||||||
if (!stack1.getEnchantments().equals(stack2.getEnchantments())) {
|
if (!stack1.getEnchantments().equals(stack2.getEnchantments())) {
|
||||||
return false; // They have the same enchants
|
return false; // They have the same enchants
|
||||||
}
|
}
|
||||||
if (stack1.getItemMeta().hasDisplayName() || stack2.getItemMeta().hasDisplayName()) {
|
if (stack1.getItemMeta().hasDisplayName() || stack2.getItemMeta().hasDisplayName()) {
|
||||||
if (stack1.getItemMeta().hasDisplayName() && stack2.getItemMeta().hasDisplayName()) {
|
if (stack1.getItemMeta().hasDisplayName() && stack2.getItemMeta().hasDisplayName()) {
|
||||||
if (!stack1.getItemMeta().getDisplayName().equals(stack2.getItemMeta().getDisplayName())) {
|
if (!stack1.getItemMeta().getDisplayName().equals(stack2.getItemMeta().getDisplayName())) {
|
||||||
return false; // items have different display name
|
return false; // items have different display name
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false; // one of the item stacks have a display name
|
return false; // one of the item stacks have a display name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta");
|
Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta");
|
||||||
final boolean book1 = stack1.getItemMeta() instanceof EnchantmentStorageMeta;
|
final boolean book1 = stack1.getItemMeta() instanceof EnchantmentStorageMeta;
|
||||||
final boolean book2 = stack2.getItemMeta() instanceof EnchantmentStorageMeta;
|
final boolean book2 = stack2.getItemMeta() instanceof EnchantmentStorageMeta;
|
||||||
if (book1 != book2) {
|
if (book1 != book2) {
|
||||||
return false;// One has enchantment meta, the other does not.
|
return false;// One has enchantment meta, the other does not.
|
||||||
}
|
}
|
||||||
if (book1 == true) { // They are the same here (both true or both
|
if (book1 == true) { // They are the same here (both true or both
|
||||||
// false). So if one is true, the other is
|
// false). So if one is true, the other is
|
||||||
// true.
|
// true.
|
||||||
final Map<Enchantment, Integer> ench1 = ((EnchantmentStorageMeta) stack1.getItemMeta()).getStoredEnchants();
|
final Map<Enchantment, Integer> ench1 = ((EnchantmentStorageMeta) stack1.getItemMeta()).getStoredEnchants();
|
||||||
final Map<Enchantment, Integer> ench2 = ((EnchantmentStorageMeta) stack2.getItemMeta()).getStoredEnchants();
|
final Map<Enchantment, Integer> ench2 = ((EnchantmentStorageMeta) stack2.getItemMeta()).getStoredEnchants();
|
||||||
if (!ench1.equals(ench2)) {
|
if (!ench1.equals(ench2)) {
|
||||||
return false; // Enchants aren't the same.
|
return false; // Enchants aren't the same.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final ClassNotFoundException e) {
|
} catch (final ClassNotFoundException e) {
|
||||||
// Nothing. They dont have a build high enough to support this.
|
// Nothing. They dont have a build high enough to support this.
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void parseColours(final YamlConfiguration config) {
|
public static void parseColours(final YamlConfiguration config) {
|
||||||
final Set<String> keys = config.getKeys(true);
|
final Set<String> keys = config.getKeys(true);
|
||||||
for (final String key : keys) {
|
for (final String key : keys) {
|
||||||
String filtered = config.getString(key);
|
String filtered = config.getString(key);
|
||||||
if (filtered.startsWith("MemorySection")) {
|
if (filtered.startsWith("MemorySection")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
filtered = ChatColor.translateAlternateColorCodes('&', filtered);
|
filtered = ChatColor.translateAlternateColorCodes('&', filtered);
|
||||||
config.set(key, filtered);
|
config.set(key, filtered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String serialize(final ItemStack iStack) {
|
public static String serialize(final ItemStack iStack) {
|
||||||
final YamlConfiguration cfg = new YamlConfiguration();
|
final YamlConfiguration cfg = new YamlConfiguration();
|
||||||
cfg.set("item", iStack);
|
cfg.set("item", iStack);
|
||||||
return cfg.saveToString();
|
return cfg.saveToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,36 +17,36 @@ import org.maxgamer.QuickShop.Shop.ShopChunk;
|
|||||||
* Also deletes invalid items.
|
* Also deletes invalid items.
|
||||||
*/
|
*/
|
||||||
public class ItemWatcher implements Runnable {
|
public class ItemWatcher implements Runnable {
|
||||||
private QuickShop plugin;
|
private QuickShop plugin;
|
||||||
|
|
||||||
public ItemWatcher(QuickShop plugin) {
|
public ItemWatcher(QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
List<Shop> toRemove = new ArrayList<Shop>(1);
|
List<Shop> toRemove = new ArrayList<Shop>(1);
|
||||||
for (Entry<String, HashMap<ShopChunk, HashMap<Location, Shop>>> inWorld : plugin.getShopManager().getShops().entrySet()) {
|
for (Entry<String, HashMap<ShopChunk, HashMap<Location, Shop>>> inWorld : plugin.getShopManager().getShops().entrySet()) {
|
||||||
// This world
|
// This world
|
||||||
World world = Bukkit.getWorld(inWorld.getKey());
|
World world = Bukkit.getWorld(inWorld.getKey());
|
||||||
if (world == null)
|
if (world == null)
|
||||||
continue; // world not loaded.
|
continue; // world not loaded.
|
||||||
for (Entry<ShopChunk, HashMap<Location, Shop>> inChunk : inWorld.getValue().entrySet()) {
|
for (Entry<ShopChunk, HashMap<Location, Shop>> inChunk : inWorld.getValue().entrySet()) {
|
||||||
if (!world.isChunkLoaded(inChunk.getKey().getX(), inChunk.getKey().getZ())) {
|
if (!world.isChunkLoaded(inChunk.getKey().getX(), inChunk.getKey().getZ())) {
|
||||||
// If the chunk is not loaded, next chunk!
|
// If the chunk is not loaded, next chunk!
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (Shop shop : inChunk.getValue().values()) {
|
for (Shop shop : inChunk.getValue().values()) {
|
||||||
// Validate the shop.
|
// Validate the shop.
|
||||||
if (!shop.isValid()) {
|
if (!shop.isValid()) {
|
||||||
toRemove.add(shop);
|
toRemove.add(shop);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Now we can remove it.
|
// Now we can remove it.
|
||||||
for (Shop shop : toRemove) {
|
for (Shop shop : toRemove) {
|
||||||
shop.delete();
|
shop.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,43 +11,43 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
|
|
||||||
public class LogWatcher implements Runnable {
|
public class LogWatcher implements Runnable {
|
||||||
private PrintStream ps;
|
private PrintStream ps;
|
||||||
private ArrayList<String> logs = new ArrayList<String>(5);
|
private ArrayList<String> logs = new ArrayList<String>(5);
|
||||||
public BukkitTask task;
|
public BukkitTask task;
|
||||||
|
|
||||||
public LogWatcher(QuickShop plugin, File log) {
|
public LogWatcher(QuickShop plugin, File log) {
|
||||||
try {
|
try {
|
||||||
if (!log.exists()) {
|
if (!log.exists()) {
|
||||||
log.createNewFile();
|
log.createNewFile();
|
||||||
}
|
}
|
||||||
FileOutputStream fos = new FileOutputStream(log, true);
|
FileOutputStream fos = new FileOutputStream(log, true);
|
||||||
this.ps = new PrintStream(fos);
|
this.ps = new PrintStream(fos);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
plugin.getLogger().severe("日志文件未找到!");
|
plugin.getLogger().severe("日志文件未找到!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
plugin.getLogger().severe("无法创建日志文件!");
|
plugin.getLogger().severe("无法创建日志文件!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
synchronized (logs) {
|
|
||||||
for (String s : logs) {
|
|
||||||
ps.println(s);
|
|
||||||
}
|
|
||||||
logs.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(String s) {
|
@Override
|
||||||
synchronized (logs) {
|
public void run() {
|
||||||
logs.add(s);
|
synchronized (logs) {
|
||||||
}
|
for (String s : logs) {
|
||||||
}
|
ps.println(s);
|
||||||
|
}
|
||||||
|
logs.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void close() {
|
public void add(String s) {
|
||||||
this.ps.close();
|
synchronized (logs) {
|
||||||
}
|
logs.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
this.ps.close();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user