1
0
mirror of https://e.coding.net/circlecloud/QuickShop.git synced 2024-11-22 01:58:54 +00:00

feat: 更新类库 代码优化 添加世界限制

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-12-13 19:07:37 +08:00
parent b110da8f73
commit 49c0b8ecd7
18 changed files with 141 additions and 235 deletions

27
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.maxgamer</groupId> <groupId>org.maxgamer</groupId>
<artifactId>QuickShop</artifactId> <artifactId>QuickShop</artifactId>
<version>1.9.5</version> <version>2.0</version>
<description>快捷商店重置版本...</description> <description>快捷商店重置版本...</description>
<build> <build>
<finalName>${project.name}</finalName> <finalName>${project.name}</finalName>
@ -71,6 +71,10 @@
<id>yumc-repo</id> <id>yumc-repo</id>
<url>http://repo.yumc.pw/content/groups/public/</url> <url>http://repo.yumc.pw/content/groups/public/</url>
</repository> </repository>
<repository>
<id>dmulloy</id>
<url>http://repo.dmulloy2.net/content/groups/public/</url>
</repository>
</repositories> </repositories>
<distributionManagement> <distributionManagement>
<repository> <repository>
@ -80,23 +84,11 @@
</repository> </repository>
</distributionManagement> </distributionManagement>
<dependencies> <dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<version>1.10.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<type>jar</type>
<version>1.5.6</version>
</dependency>
<dependency> <dependency>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId> <artifactId>YumCore</artifactId>
<type>jar</type> <type>jar</type>
<version>1.1</version> <version>1.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.github.Cnly.WowSuchCleaner</groupId> <groupId>io.github.Cnly.WowSuchCleaner</groupId>
@ -110,12 +102,5 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/WorldEdit.jar</systemPath> <systemPath>${project.basedir}/lib/WorldEdit.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ProtocolLib-4.1.jar</systemPath>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,5 +1,9 @@
package org.maxgamer.QuickShop.Command; package org.maxgamer.QuickShop.Command;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -10,37 +14,33 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.util.BlockIterator; import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Database.Database; import org.maxgamer.QuickShop.Database.Database;
import org.maxgamer.QuickShop.Database.MySQLCore; import org.maxgamer.QuickShop.Database.MySQLCore;
import org.maxgamer.QuickShop.Database.SQLiteCore; import org.maxgamer.QuickShop.Database.SQLiteCore;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.ContainerShop; import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Shop.Shop; import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopChunk; import org.maxgamer.QuickShop.Shop.ShopChunk;
import org.maxgamer.QuickShop.Shop.ShopType; import org.maxgamer.QuickShop.Shop.ShopType;
import org.maxgamer.QuickShop.Util.MsgUtil; import org.maxgamer.QuickShop.Util.MsgUtil;
import pw.yumc.YumCore.bukkit.P; import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.commands.CommandManager; import pw.yumc.YumCore.commands.CommandSub;
import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
import pw.yumc.YumCore.commands.annotation.Help; import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.commands.annotation.Sort; import pw.yumc.YumCore.commands.annotation.Sort;
import pw.yumc.YumCore.commands.interfaces.CommandExecutor; import pw.yumc.YumCore.commands.interfaces.Executor;
import pw.yumc.YumCore.commands.interfaces.CommandHelpParse; import pw.yumc.YumCore.commands.interfaces.HelpParse;
import java.io.File; public class QuickShopCommands implements Executor, HelpParse {
import java.util.HashMap;
import java.util.Iterator;
public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
QuickShop plugin = P.getPlugin(); QuickShop plugin = P.getPlugin();
public QuickShopCommands() { public QuickShopCommands() {
new CommandManager("qs", this).setHelpParse(this); new CommandSub("qs", this).setHelpParse(this);
} }
@Sort(1) @Sort(1)
@Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Executor.PLAYER) @Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Cmd.Executor.PLAYER)
@Help("command.description.buy") @Help("command.description.buy")
public void buy(Player player) { public void buy(Player player) {
changeShopType(player, ShopType.BUYING); changeShopType(player, ShopType.BUYING);
@ -73,7 +73,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
} }
@Sort(5) @Sort(5)
@Cmd(aliases = "e", permission = "quickshop.empty", executor = Executor.PLAYER) @Cmd(aliases = "e", permission = "quickshop.empty", executor = Cmd.Executor.PLAYER)
@Help("command.description.empty") @Help("command.description.empty")
public void empty(Player player) { public void empty(Player player) {
final BlockIterator bIt = new BlockIterator(player, 10); final BlockIterator bIt = new BlockIterator(player, 10);
@ -141,7 +141,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
} }
} }
@Cmd(aliases = "f", minimumArguments = 1, permission = "quickshop.find", executor = Executor.PLAYER) @Cmd(aliases = "f", minimumArguments = 1, permission = "quickshop.find", executor = Cmd.Executor.PLAYER)
@Help("command.description.find") @Help("command.description.find")
public void find(Player p, String lookFor) { public void find(Player p, String lookFor) {
lookFor = lookFor.toLowerCase(); lookFor = lookFor.toLowerCase();
@ -218,7 +218,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
} }
@Sort(4) @Sort(4)
@Cmd(aliases = "p", minimumArguments = 1, permission = "quickshop.create.changeprice", executor = Executor.PLAYER) @Cmd(aliases = "p", minimumArguments = 1, permission = "quickshop.create.changeprice", executor = Cmd.Executor.PLAYER)
@Help(value = "command.description.price", possibleArguments = "<价格>") @Help(value = "command.description.price", possibleArguments = "<价格>")
public void price(Player sender, Double price) { public void price(Player sender, Double price) {
if (price < 0.01) { if (price < 0.01) {
@ -281,7 +281,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
} }
@Sort(6) @Sort(6)
@Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Executor.PLAYER) @Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Cmd.Executor.PLAYER)
@Help(value = "command.description.refill", possibleArguments = "<数量>") @Help(value = "command.description.refill", possibleArguments = "<数量>")
public void refill(Player sender, Integer add) { public void refill(Player sender, Integer add) {
final BlockIterator bIt = new BlockIterator(sender, 10); final BlockIterator bIt = new BlockIterator(sender, 10);
@ -307,7 +307,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
} }
@Sort(6) @Sort(6)
@Cmd(aliases = "r", permission = "quickshop.delete", executor = Executor.PLAYER) @Cmd(aliases = "r", permission = "quickshop.delete", executor = Cmd.Executor.PLAYER)
@Help("command.description.remove") @Help("command.description.remove")
public void remove(Player p) { public void remove(Player p) {
final BlockIterator bIt = new BlockIterator(p, 10); final BlockIterator bIt = new BlockIterator(p, 10);
@ -328,14 +328,14 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
} }
@Sort(2) @Sort(2)
@Cmd(aliases = "s", permission = "quickshop.create.sell", executor = Executor.PLAYER) @Cmd(aliases = "s", permission = "quickshop.create.sell", executor = Cmd.Executor.PLAYER)
@Help("command.description.sell") @Help("command.description.sell")
public void sell(Player player) { public void sell(Player player) {
changeShopType(player, ShopType.SELLING); changeShopType(player, ShopType.SELLING);
} }
@Sort(3) @Sort(3)
@Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Executor.PLAYER) @Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Cmd.Executor.PLAYER)
@Help("command.description.setowner") @Help("command.description.setowner")
public void setowner(CommandSender sender, String owner) { public void setowner(CommandSender sender, String owner) {
final BlockIterator bIt = new BlockIterator((Player) sender, 10); final BlockIterator bIt = new BlockIterator((Player) sender, 10);
@ -353,7 +353,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
} }
@Sort(0) @Sort(0)
@Cmd(permission = "quickshop.unlimited", executor = Executor.PLAYER) @Cmd(permission = "quickshop.unlimited", executor = Cmd.Executor.PLAYER)
@Help("command.description.unlimited") @Help("command.description.unlimited")
public void unlimited(Player sender) { public void unlimited(Player sender) {
final BlockIterator bIt = new BlockIterator(sender, 10); final BlockIterator bIt = new BlockIterator(sender, 10);

View File

@ -1,17 +1,18 @@
package org.maxgamer.QuickShop.Config; package org.maxgamer.QuickShop.Config;
import java.util.*;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Item.FakeItem_17_18; import org.maxgamer.QuickShop.Shop.Item.FakeItem_17_18;
import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_110; import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_110;
import pw.yumc.YumCore.bukkit.Log; import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.config.FileConfig; import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.tellraw.Tellraw; import pw.yumc.YumCore.tellraw.Tellraw;
import java.util.*;
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 */
@ -91,7 +92,7 @@ public class ConfigManager {
plugin.getLogger().info("虚拟悬浮物功能测试正常(1.8-1.10.2)..."); plugin.getLogger().info("虚拟悬浮物功能测试正常(1.8-1.10.2)...");
fakeItem = true; fakeItem = true;
} catch (final Throwable e) { } catch (final Throwable e) {
Log.debug(e); Log.d(e);
try { try {
FakeItem_17_18.register(plugin); FakeItem_17_18.register(plugin);
plugin.getLogger().info("虚拟悬浮物功能测试正常(1.7)..."); plugin.getLogger().info("虚拟悬浮物功能测试正常(1.7)...");
@ -100,7 +101,7 @@ public class ConfigManager {
plugin.getLogger().warning("+========================================="); plugin.getLogger().warning("+=========================================");
plugin.getLogger().warning("| 警告: 启动虚拟物品失败 使用原版悬浮物品..."); plugin.getLogger().warning("| 警告: 启动虚拟物品失败 使用原版悬浮物品...");
plugin.getLogger().warning("+========================================="); plugin.getLogger().warning("+=========================================");
Log.debug(e2); Log.d(e2);
} }
} }
} }

View File

@ -112,8 +112,7 @@ public class Database {
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) {
@ -149,7 +148,7 @@ public class Database {
*/ */
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<>();
while (rs.next()) { while (rs.next()) {
tables.add(rs.getString("TABLE_NAME")); tables.add(rs.getString("TABLE_NAME"));
} }

View File

@ -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(); Connection getConnection();
public void queue(BufferStatement bs); void queue(BufferStatement bs);
public void flush(); void flush();
public void close(); void close();
} }

View File

@ -19,20 +19,20 @@ public class DatabaseHelper {
* 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;
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 ignored) {
} }
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 ignored) {
} }
} }

View File

@ -12,7 +12,7 @@ public class MySQLCore implements DatabaseCore {
/** 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<>();
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();
@ -59,7 +59,7 @@ public class MySQLCore implements DatabaseCore {
while (con == null) { while (con == null) {
try { try {
Thread.sleep(15); Thread.sleep(15);
} catch (InterruptedException e) { } catch (InterruptedException ignored) {
} }
// Try again // Try again
this.getConnection(); this.getConnection();
@ -69,7 +69,6 @@ public class MySQLCore implements DatabaseCore {
ps.close(); ps.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
return;
} }
} }

View File

@ -12,7 +12,7 @@ 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 final LinkedList<BufferStatement> queue = new LinkedList<BufferStatement>();
public SQLiteCore(final File dbFile) { public SQLiteCore(final File dbFile) {
this.dbFile = dbFile; this.dbFile = dbFile;
@ -25,7 +25,7 @@ public class SQLiteCore implements DatabaseCore {
@Override @Override
public void flush() { public void flush() {
while (queue.isEmpty() == false) { while (!queue.isEmpty()) {
BufferStatement bs; BufferStatement bs;
synchronized (queue) { synchronized (queue) {
bs = queue.removeFirst(); bs = queue.removeFirst();
@ -51,9 +51,7 @@ public class SQLiteCore implements DatabaseCore {
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();
} }
@ -63,10 +61,7 @@ public class SQLiteCore implements DatabaseCore {
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 | SQLException e) {
e.printStackTrace();
return null;
} catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -100,7 +95,7 @@ public class SQLiteCore implements DatabaseCore {
public void run() { public void run() {
try { try {
Thread.sleep(30000); Thread.sleep(30000);
} catch (final InterruptedException e) { } catch (final InterruptedException ignored) {
} }
flush(); flush();
} }

View File

@ -36,7 +36,7 @@ public class Economy_Vault implements EconomyCore {
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 ignored) {
} }
return "" + balance; return "" + balance;
} }
@ -109,7 +109,7 @@ public class Economy_Vault implements EconomyCore {
if (economyProvider != null) { if (economyProvider != null) {
vault = (economyProvider.getProvider()); vault = (economyProvider.getProvider());
} }
} catch (final Exception e) { } catch (final Exception ignored) {
} }
return vault != null; return vault != null;
} }

View File

@ -1,20 +1,12 @@
package org.maxgamer.QuickShop; package org.maxgamer.QuickShop;
import java.io.File; import java.io.File;
import java.sql.Connection; import java.sql.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,22 +18,11 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.maxgamer.QuickShop.Command.QuickShopCommands; import org.maxgamer.QuickShop.Command.QuickShopCommands;
import org.maxgamer.QuickShop.Config.ConfigManager; import org.maxgamer.QuickShop.Config.ConfigManager;
import org.maxgamer.QuickShop.Database.Database; import org.maxgamer.QuickShop.Database.*;
import org.maxgamer.QuickShop.Database.DatabaseCore;
import org.maxgamer.QuickShop.Database.DatabaseHelper;
import org.maxgamer.QuickShop.Database.MySQLCore;
import org.maxgamer.QuickShop.Database.SQLiteCore;
import org.maxgamer.QuickShop.Economy.Economy; import org.maxgamer.QuickShop.Economy.Economy;
import org.maxgamer.QuickShop.Economy.EconomyCore; import org.maxgamer.QuickShop.Economy.EconomyCore;
import org.maxgamer.QuickShop.Economy.Economy_Vault; import org.maxgamer.QuickShop.Economy.Economy_Vault;
import org.maxgamer.QuickShop.Listeners.BlockListener; import org.maxgamer.QuickShop.Listeners.*;
import org.maxgamer.QuickShop.Listeners.ChatListener;
import org.maxgamer.QuickShop.Listeners.ChunkListener;
import org.maxgamer.QuickShop.Listeners.LockListener;
import org.maxgamer.QuickShop.Listeners.PlayerListener;
import org.maxgamer.QuickShop.Listeners.ProtectListener;
import org.maxgamer.QuickShop.Listeners.WorldListener;
import org.maxgamer.QuickShop.Listeners.WowSuchCleanerListener;
import org.maxgamer.QuickShop.Shop.ContainerShop; import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Shop.Shop; import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopManager; import org.maxgamer.QuickShop.Shop.ShopManager;
@ -177,7 +158,7 @@ public class QuickShop extends JavaPlugin {
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)) {
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;
@ -248,7 +229,7 @@ public class QuickShop extends JavaPlugin {
database.close(); database.close();
try { try {
database.getConnection().close(); database.getConnection().close();
} catch (final SQLException e) { } catch (final SQLException ignored) {
} }
} }
if (configManager != null) { if (configManager != null) {
@ -258,7 +239,7 @@ public class QuickShop extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
if (loadEcon() == false) { if (!loadEcon()) {
return; return;
} }
configManager = new ConfigManager(this); configManager = new ConfigManager(this);

View File

@ -79,9 +79,7 @@ public class ContainerShop implements Shop {
*/ */
@Override @Override
public void add(final ItemStack item, final int amount) { public void add(final ItemStack item, final int amount) {
if (this.unlimited) { if (this.unlimited) { return; }
return;
}
final Inventory inv = this.getInventory(); final Inventory inv = this.getInventory();
int remains = amount; int remains = amount;
while (remains > 0) { while (remains > 0) {
@ -98,8 +96,6 @@ public class ContainerShop implements Shop {
* *
* @param p * @param p
* The player to buy from * The player to buy from
* @param item
* The itemStack to buy
* @param amount * @param amount
* The amount to buy * The amount to buy
*/ */
@ -217,13 +213,9 @@ public class ContainerShop implements Shop {
* null if this shop is not attached to another. * null if this shop is not attached to another.
*/ */
public ContainerShop getAttachedShop() { public ContainerShop getAttachedShop() {
if (this.getLocation() != null) { if (this.getLocation() != null) { return null; }
return null;
}
final Block c = Util.getSecondHalf(this.getLocation().getBlock()); final Block c = Util.getSecondHalf(this.getLocation().getBlock());
if (c == null) { if (c == null) { return null; }
return null;
}
final Shop shop = plugin.getShopManager().getShop(c.getLocation()); final Shop shop = plugin.getShopManager().getShop(c.getLocation());
return shop == null ? null : (ContainerShop) shop; return shop == null ? null : (ContainerShop) shop;
} }
@ -316,15 +308,11 @@ public class ContainerShop implements Shop {
/** /**
* Returns the number of free spots in the chest for the particular item. * Returns the number of free spots in the chest for the particular item.
*
* @param stackSize
* @return * @return
*/ */
@Override @Override
public int getRemainingSpace() { public int getRemainingSpace() {
if (this.unlimited) { if (this.unlimited) { return 10000; }
return 10000;
}
return Util.countSpace(this.getInventory(), item); return Util.countSpace(this.getInventory(), item);
} }
@ -335,9 +323,7 @@ public class ContainerShop implements Shop {
*/ */
@Override @Override
public int getRemainingStock() { public int getRemainingStock() {
if (this.unlimited) { if (this.unlimited) { return 10000; }
return 10000;
}
return Util.countItems(this.getInventory(), this.getItem()); return Util.countItems(this.getInventory(), this.getItem());
} }
@ -356,9 +342,7 @@ public class ContainerShop implements Shop {
@Override @Override
public List<Sign> getSigns() { public List<Sign> getSigns() {
final ArrayList<Sign> signs = new ArrayList<>(1); final ArrayList<Sign> signs = new ArrayList<>(1);
if (this.getLocation().getWorld() == null) { if (this.getLocation().getWorld() == null) { return signs; }
return signs;
}
final Block[] blocks = new Block[4]; final Block[] blocks = new Block[4];
blocks[0] = loc.getBlock().getRelative(1, 0, 0); blocks[0] = loc.getBlock().getRelative(1, 0, 0);
blocks[1] = loc.getBlock().getRelative(-1, 0, 0); blocks[1] = loc.getBlock().getRelative(-1, 0, 0);
@ -412,9 +396,7 @@ public class ContainerShop implements Shop {
*/ */
public boolean isDoubleShop() { public boolean isDoubleShop() {
final ContainerShop nextTo = this.getAttachedShop(); final ContainerShop nextTo = this.getAttachedShop();
if (nextTo == null) { if (nextTo == null) { return false; }
return false;
}
if (nextTo.matches(this.getItem())) { if (nextTo.matches(this.getItem())) {
// They're both trading the same item // They're both trading the same item
if (this.getShopType() == nextTo.getShopType()) { if (this.getShopType() == nextTo.getShopType()) {
@ -485,9 +467,7 @@ public class ContainerShop implements Shop {
*/ */
@Override @Override
public void remove(final ItemStack item, final int amount) { public void remove(final ItemStack item, final int amount) {
if (this.unlimited) { if (this.unlimited) { return; }
return;
}
final Inventory inv = this.getInventory(); final Inventory inv = this.getInventory();
int remains = amount; int remains = amount;
while (remains > 0) { while (remains > 0) {
@ -548,8 +528,8 @@ public class ContainerShop implements Shop {
// We now have to update the chests inventory manually. // We now have to update the chests inventory manually.
this.getInventory().setContents(chestContents); this.getInventory().setContents(chestContents);
} }
for (int i = 0; i < floor.size(); i++) { for (ItemStack aFloor : floor) {
p.getWorld().dropItem(p.getLocation(), floor.get(i)); p.getWorld().dropItem(p.getLocation(), aFloor);
} }
} }
@ -594,9 +574,7 @@ public class ContainerShop implements Shop {
*/ */
@Override @Override
public void setSignText() { public void setSignText() {
if (Util.isLoaded(this.getLocation()) == false) { if (!Util.isLoaded(this.getLocation())) { return; }
return;
}
final ContainerShop shop = this; final ContainerShop shop = this;
// 1.9不能异步修改木牌 // 1.9不能异步修改木牌
Bukkit.getScheduler().runTask(plugin, new Runnable() { Bukkit.getScheduler().runTask(plugin, new Runnable() {
@ -627,9 +605,7 @@ public class ContainerShop implements Shop {
*/ */
@Override @Override
public void setSignText(final String[] lines) { public void setSignText(final String[] lines) {
if (Util.isLoaded(this.getLocation()) == false) { if (!Util.isLoaded(this.getLocation())) { return; }
return;
}
final List<Sign> signs = this.getSigns(); final List<Sign> signs = this.getSigns();
// 1.9不能异步修改木牌 // 1.9不能异步修改木牌
Bukkit.getScheduler().runTask(plugin, new Runnable() { Bukkit.getScheduler().runTask(plugin, new Runnable() {
@ -652,21 +628,14 @@ public class ContainerShop implements Shop {
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder("商店 " final StringBuilder sb = new StringBuilder("商店 " + (loc.getWorld() == null ? "世界尚未载入" : "坐标: " + loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", "
+ (loc.getWorld() == null ? "世界尚未载入" : "坐标: " + loc.getWorld().getName()) + loc.getBlockZ() + ")");
+ "(" sb.append(" 所有者: ").append(getOwner());
+ loc.getBlockX()
+ ", "
+ loc.getBlockY()
+ ", "
+ loc.getBlockZ()
+ ")");
sb.append(" 所有者: " + getOwner());
if (isUnlimited()) { if (isUnlimited()) {
sb.append(" 无限模式: true"); sb.append(" 无限模式: true");
} }
sb.append(" 价格: " + getPrice()); sb.append(" 价格: ").append(getPrice());
sb.append(" 物品: " + getItem().toString()); sb.append(" 物品: ").append(getItem().toString());
return sb.toString(); return sb.toString();
} }
@ -691,11 +660,8 @@ public class ContainerShop implements Shop {
} }
private void checkDisplay() { private void checkDisplay() {
if (plugin.getConfigManager().isDisplay() == false) { if (!plugin.getConfigManager().isDisplay()) { return; }
return; if (getLocation().getWorld() == null) { return; // not loaded
}
if (getLocation().getWorld() == null) {
return; // not loaded
} }
final boolean trans = Util.isTransparent(getLocation().clone().add(0.5, 1.2, 0.5).getBlock().getType()); final boolean trans = Util.isTransparent(getLocation().clone().add(0.5, 1.2, 0.5).getBlock().getType());
if (trans && this.getDisplayItem() == null) { if (trans && this.getDisplayItem() == null) {
@ -709,14 +675,11 @@ public class ContainerShop implements Shop {
this.displayItem = null; this.displayItem = null;
return; return;
} }
if (this.getLocation().getWorld() == null) { if (this.getLocation().getWorld() == null) { return;// Ignore if world not loaded...
return;// Ignore if world not loaded...
} }
final DisplayItem disItem = this.getDisplayItem(); final DisplayItem disItem = this.getDisplayItem();
final Location dispLoc = disItem.getDisplayLocation(); final Location dispLoc = disItem.getDisplayLocation();
if (dispLoc.getWorld() == null) { if (dispLoc.getWorld() == null) { return; }
return;
}
if (dispLoc.getBlock() != null && dispLoc.getBlock().getType() == Material.WATER) { // Flowing if (dispLoc.getBlock() != null && dispLoc.getBlock().getType() == Material.WATER) { // Flowing
// water.Stationery water does not move items. // water.Stationery water does not move items.
disItem.remove(); disItem.remove();

View File

@ -21,11 +21,11 @@ public abstract class DisplayItem {
try { try {
return new FakeItem_19_110(shop, shop.getItem()); return new FakeItem_19_110(shop, shop.getItem());
} catch (final Throwable e) { } catch (final Throwable e) {
Log.debug(e); Log.d(e);
try { try {
return new FakeItem_17_18(shop, shop.getItem()); return new FakeItem_17_18(shop, shop.getItem());
} catch (final Throwable e2) { } catch (final Throwable e2) {
Log.debug(e2); Log.d(e2);
} }
} }
} }

View File

@ -1,10 +1,7 @@
package org.maxgamer.QuickShop.Shop.Item; package org.maxgamer.QuickShop.Shop.Item;
import java.util.ArrayList; import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -76,14 +73,8 @@ public abstract class FakeItem extends DisplayItem {
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) { sendChunkPacket(p, fakesInChunk);
for (final FakeItem fake : fakesInChunk) { } catch (final Exception ignored) {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket());
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket());
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket());
}
}
} catch (final Exception e) {
} }
} }
}; };
@ -97,16 +88,9 @@ public abstract class FakeItem extends DisplayItem {
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) { sendChunkPacket(p, fakesInChunk);
for (final FakeItem fake : fakesInChunk) {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket());
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket());
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket());
}
}
} }
} catch (final Exception e) { } catch (final Exception ignored) {
} }
} }
}; };
@ -115,6 +99,17 @@ public abstract class FakeItem extends DisplayItem {
registered = true; registered = true;
} }
private static void sendChunkPacket(Player p, List<FakeItem> fakesInChunk) throws InvocationTargetException {
if (fakesInChunk != null) {
for (final FakeItem fake : fakesInChunk) {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket());
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket());
ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket());
}
}
}
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();
} }

View File

@ -55,9 +55,7 @@ public class NormalItem extends DisplayItem {
*/ */
@Override @Override
public void remove() { public void remove() {
if (this.item == null) { if (this.item == null) { return; }
return;
}
this.item.remove(); this.item.remove();
} }
@ -67,9 +65,7 @@ public class NormalItem extends DisplayItem {
*/ */
@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();
@ -103,15 +99,13 @@ public class NormalItem extends DisplayItem {
*/ */
@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 ignored) {
} }
} }
} }

View File

@ -8,70 +8,70 @@ import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public abstract interface Shop { public interface Shop {
public abstract void add(ItemStack paramItemStack, int paramInt); void add(ItemStack paramItemStack, int paramInt);
public abstract void buy(Player paramPlayer, int paramInt); void buy(Player paramPlayer, int paramInt);
public abstract Shop clone(); Shop clone();
public abstract void delete(); void delete();
public abstract void delete(boolean paramBoolean); void delete(boolean paramBoolean);
public abstract String getDataName(); String getDataName();
public abstract short getDurability(); short getDurability();
public abstract ItemStack getItem(); ItemStack getItem();
public abstract Location getLocation(); Location getLocation();
public abstract String getOwner(); String getOwner();
public abstract double getPrice(); double getPrice();
public abstract int getRemainingSpace(); int getRemainingSpace();
public abstract int getRemainingStock(); int getRemainingStock();
public abstract ShopType getShopType(); ShopType getShopType();
public abstract List<Sign> getSigns(); List<Sign> getSigns();
public abstract boolean isAttached(Block paramBlock); boolean isAttached(Block paramBlock);
public abstract boolean isBuying(); boolean isBuying();
public abstract boolean isSelling(); boolean isSelling();
public abstract boolean isUnlimited(); boolean isUnlimited();
public abstract boolean isValid(); boolean isValid();
public abstract boolean matches(ItemStack paramItemStack); boolean matches(ItemStack paramItemStack);
public abstract void onClick(); void onClick();
public abstract void onLoad(); void onLoad();
public abstract void onUnload(); void onUnload();
public abstract void remove(ItemStack paramItemStack, int paramInt); void remove(ItemStack paramItemStack, int paramInt);
public abstract void sell(Player paramPlayer, int paramInt); void sell(Player paramPlayer, int paramInt);
public abstract void setOwner(String paramString); void setOwner(String paramString);
public abstract void setPrice(double paramDouble); void setPrice(double paramDouble);
public abstract void setShopType(ShopType paramShopType); void setShopType(ShopType paramShopType);
public abstract void setSignText(); void setSignText();
public abstract void setSignText(String[] paramArrayOfString); void setSignText(String[] paramArrayOfString);
public abstract void setUnlimited(boolean paramBoolean); void setUnlimited(boolean paramBoolean);
public abstract void update(); void update();
} }

View File

@ -3,5 +3,5 @@ package org.maxgamer.QuickShop.Shop;
public enum ShopAction { public enum ShopAction {
BUY(), BUY(),
CREATE(), CREATE(),
CANCELLED(); CANCELLED()
} }

View File

@ -5,7 +5,7 @@ public enum ShopType {
BUYING(1); BUYING(1);
private int id; private int id;
private ShopType(int id) { ShopType(int id) {
this.id = id; this.id = id;
} }

View File

@ -88,12 +88,8 @@ public class MsgUtil {
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) { return raw; }
}
if (args == null) {
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());
} }
@ -127,7 +123,7 @@ public class MsgUtil {
} }
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, message, System.currentTimeMillis());
} else { } else {
p.getPlayer().sendMessage(message); p.getPlayer().sendMessage(message);
} }
@ -186,10 +182,8 @@ public class MsgUtil {
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())) {