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

Signed-off-by: 502647092 <admin@yumc.pw>
pull/3/HEAD
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>
<groupId>org.maxgamer</groupId>
<artifactId>QuickShop</artifactId>
<version>1.9.5</version>
<version>2.0</version>
<description>快捷商店重置版本...</description>
<build>
<finalName>${project.name}</finalName>
@ -71,6 +71,10 @@
<id>yumc-repo</id>
<url>http://repo.yumc.pw/content/groups/public/</url>
</repository>
<repository>
<id>dmulloy</id>
<url>http://repo.dmulloy2.net/content/groups/public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
@ -80,23 +84,11 @@
</repository>
</distributionManagement>
<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>
<groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId>
<type>jar</type>
<version>1.1</version>
<version>1.5</version>
</dependency>
<dependency>
<groupId>io.github.Cnly.WowSuchCleaner</groupId>
@ -110,12 +102,5 @@
<scope>system</scope>
<systemPath>${project.basedir}/lib/WorldEdit.jar</systemPath>
</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>
</project>

View File

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

View File

@ -1,17 +1,18 @@
package org.maxgamer.QuickShop.Config;
import java.util.*;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Item.FakeItem_17_18;
import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_110;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.tellraw.Tellraw;
import java.util.*;
public class ConfigManager {
private boolean enableMagicLib = false;
/** Whether debug info should be shown in the console */
@ -91,7 +92,7 @@ public class ConfigManager {
plugin.getLogger().info("虚拟悬浮物功能测试正常(1.8-1.10.2)...");
fakeItem = true;
} catch (final Throwable e) {
Log.debug(e);
Log.d(e);
try {
FakeItem_17_18.register(plugin);
plugin.getLogger().info("虚拟悬浮物功能测试正常(1.7)...");
@ -100,7 +101,7 @@ public class ConfigManager {
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);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
rs.getString(column); // Throws an exception if it can't find
// that column
rs.getString(column); // Throws an exception if it can't find that column
return true;
}
} catch (SQLException e) {
@ -149,7 +148,7 @@ public class Database {
*/
public void copyTo(Database db) throws SQLException {
ResultSet rs = getConnection().getMetaData().getTables(null, null, "%", null);
List<String> tables = new LinkedList<String>();
List<String> tables = new LinkedList<>();
while (rs.next()) {
tables.add(rs.getString("TABLE_NAME"));
}

View File

@ -3,11 +3,11 @@ package org.maxgamer.QuickShop.Database;
import java.sql.Connection;
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.
*/
public static void checkColumns(Database db) {
PreparedStatement ps = null;
PreparedStatement ps;
try {
// V3.4.2
ps = db.getConnection().prepareStatement("ALTER TABLE shops MODIFY COLUMN price double(32,2) NOT NULL AFTER owner");
ps.execute();
ps.close();
} catch (SQLException e) {
} catch (SQLException ignored) {
}
try {
// V3.4.3
ps = db.getConnection().prepareStatement("ALTER TABLE messages MODIFY COLUMN time BIGINT(32) NOT NULL AFTER message");
ps.execute();
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.. */
private Properties info;
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) {
info = new Properties();
@ -59,7 +59,7 @@ public class MySQLCore implements DatabaseCore {
while (con == null) {
try {
Thread.sleep(15);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
// Try again
this.getConnection();
@ -69,7 +69,6 @@ public class MySQLCore implements DatabaseCore {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
return;
}
}

View File

@ -12,7 +12,7 @@ public class SQLiteCore implements DatabaseCore {
private Connection connection;
private final File dbFile;
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) {
this.dbFile = dbFile;
@ -25,7 +25,7 @@ public class SQLiteCore implements DatabaseCore {
@Override
public void flush() {
while (queue.isEmpty() == false) {
while (!queue.isEmpty()) {
BufferStatement bs;
synchronized (queue) {
bs = queue.removeFirst();
@ -51,9 +51,7 @@ public class SQLiteCore implements DatabaseCore {
public Connection getConnection() {
try {
// If we have a current connection, fetch it
if (this.connection != null && !this.connection.isClosed()) {
return this.connection;
}
if (this.connection != null && !this.connection.isClosed()) { return this.connection; }
} catch (final SQLException e) {
e.printStackTrace();
}
@ -63,10 +61,7 @@ public class SQLiteCore implements DatabaseCore {
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbFile);
return this.connection;
} catch (final ClassNotFoundException e) {
e.printStackTrace();
return null;
} catch (final SQLException e) {
} catch (final ClassNotFoundException | SQLException e) {
e.printStackTrace();
return null;
}
@ -100,7 +95,7 @@ public class SQLiteCore implements DatabaseCore {
public void run() {
try {
Thread.sleep(30000);
} catch (final InterruptedException e) {
} catch (final InterruptedException ignored) {
}
flush();
}

View File

@ -36,7 +36,7 @@ public class Economy_Vault implements EconomyCore {
public String format(final double balance) {
try {
return this.vault.format(balance);
} catch (final NumberFormatException e) {
} catch (final NumberFormatException ignored) {
}
return "" + balance;
}
@ -109,7 +109,7 @@ public class Economy_Vault implements EconomyCore {
if (economyProvider != null) {
vault = (economyProvider.getProvider());
}
} catch (final Exception e) {
} catch (final Exception ignored) {
}
return vault != null;
}

View File

@ -1,20 +1,12 @@
package org.maxgamer.QuickShop;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -26,22 +18,11 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.maxgamer.QuickShop.Command.QuickShopCommands;
import org.maxgamer.QuickShop.Config.ConfigManager;
import org.maxgamer.QuickShop.Database.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.Database.*;
import org.maxgamer.QuickShop.Economy.Economy;
import org.maxgamer.QuickShop.Economy.EconomyCore;
import org.maxgamer.QuickShop.Economy.Economy_Vault;
import org.maxgamer.QuickShop.Listeners.BlockListener;
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.Listeners.*;
import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopManager;
@ -177,7 +158,7 @@ public class QuickShop extends JavaPlugin {
final double price = rs.getDouble("price");
final Location loc = new Location(world, x, y, z);
/* 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 + ". 删除...");
database.execute("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?", x, y, z, worldName);
continue;
@ -248,7 +229,7 @@ public class QuickShop extends JavaPlugin {
database.close();
try {
database.getConnection().close();
} catch (final SQLException e) {
} catch (final SQLException ignored) {
}
}
if (configManager != null) {
@ -258,7 +239,7 @@ public class QuickShop extends JavaPlugin {
@Override
public void onEnable() {
if (loadEcon() == false) {
if (!loadEcon()) {
return;
}
configManager = new ConfigManager(this);

View File

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

View File

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

View File

@ -1,10 +1,7 @@
package org.maxgamer.QuickShop.Shop.Item;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
@ -76,14 +73,8 @@ public abstract class FakeItem extends DisplayItem {
final int chunkX = packet.getIntegers().read(0);
final int chunkZ = packet.getIntegers().read(1);
final List<FakeItem> fakesInChunk = fakes.get(getChunkIdentifyString(p.getWorld().getChunkAt(chunkX, chunkZ)));
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());
}
}
} catch (final Exception e) {
sendChunkPacket(p, fakesInChunk);
} catch (final Exception ignored) {
}
}
};
@ -97,16 +88,9 @@ public abstract class FakeItem extends DisplayItem {
final int[] chunksZ = packet.getIntegerArrays().read(1);
for (int i = 0; i < chunksX.length; i++) {
final List<FakeItem> fakesInChunk = fakes.get(getChunkIdentifyString(p.getWorld().getChunkAt(chunksX[i], chunksZ[i])));
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());
}
}
sendChunkPacket(p, fakesInChunk);
}
} catch (final Exception e) {
} catch (final Exception ignored) {
}
}
};
@ -115,6 +99,17 @@ public abstract class FakeItem extends DisplayItem {
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) {
return chunk.getWorld().getName() + "@@" + chunk.getX() + "@@" + chunk.getZ();
}

View File

@ -55,9 +55,7 @@ public class NormalItem extends DisplayItem {
*/
@Override
public void remove() {
if (this.item == null) {
return;
}
if (this.item == null) { return; }
this.item.remove();
}
@ -67,9 +65,7 @@ public class NormalItem extends DisplayItem {
*/
@Override
public boolean removeDupe() {
if (shop.getLocation().getWorld() == null) {
return false;
}
if (shop.getLocation().getWorld() == null) { return false; }
final Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation();
boolean removed = false;
final Chunk c = displayLoc.getChunk();
@ -103,15 +99,13 @@ public class NormalItem extends DisplayItem {
*/
@Override
public void spawn() {
if (shop.getLocation().getWorld() == null) {
return;
}
if (shop.getLocation().getWorld() == null) { return; }
final Location dispLoc = this.getDisplayLocation();
try {
this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack);
this.item.setVelocity(new Vector(0, 0.1, 0));
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.inventory.ItemStack;
public abstract interface Shop {
public abstract void add(ItemStack paramItemStack, int paramInt);
public interface Shop {
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 {
BUY(),
CREATE(),
CANCELLED();
CANCELLED()
}

View File

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

View File

@ -88,12 +88,8 @@ public class MsgUtil {
public static String p(final String loc, final Object... args) {
String raw = messages.getString(loc);
if (raw == null || raw.isEmpty()) {
return ChatColor.RED + "语言文件词条丢失: " + loc;
}
if (args == null) {
return raw;
}
if (raw == null || raw.isEmpty()) { return ChatColor.RED + "语言文件词条丢失: " + loc; }
if (args == null) { return raw; }
for (int i = 0; i < args.length; i++) {
raw = raw.replace("{" + i + "}", args[i] == null ? "null" : args[i].toString());
}
@ -127,7 +123,7 @@ public class MsgUtil {
}
msgs.add(message);
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 {
p.getPlayer().sendMessage(message);
}
@ -186,10 +182,8 @@ public class MsgUtil {
p.sendMessage("");
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information"));
p.sendMessage(ChatColor.DARK_PURPLE
+ "| "
+ MsgUtil.p("menu.owner",
Bukkit.getOfflinePlayer(shop.getOwner()).getName() == null ? (shop.isUnlimited() ? "系统商店" : "未知") : Bukkit.getOfflinePlayer(shop.getOwner()).getName()));
p.sendMessage(ChatColor.DARK_PURPLE + "| " + 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());
sendItemMessage(p, shop.getItem(), msg);
if (Util.isTool(item.getType())) {