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

remove UUID and remove QS Item...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-10-05 02:09:41 +08:00
parent f3dafd6b5e
commit bc5e6a6c0b
10 changed files with 1101 additions and 1664 deletions

View File

@ -14,7 +14,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.util.BlockIterator;
@ -31,407 +30,55 @@ import org.maxgamer.QuickShop.Util.MsgUtil;
public class QS implements CommandExecutor {
QuickShop plugin;
public QS(QuickShop plugin) {
public QS(final QuickShop plugin) {
this.plugin = plugin;
}
private void setUnlimited(CommandSender sender) {
if (sender instanceof Player && sender.hasPermission("quickshop.unlimited")) {
BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
Block b = bIt.next();
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.setUnlimited(!shop.isUnlimited());
shop.update();
sender.sendMessage(MsgUtil.p("command.toggle-unlimited", (shop.isUnlimited() ? "unlimited" : "limited")));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
/**
* Returns loc with modified pitch/yaw angles so it faces lookat
*
* @param loc
* The location a players head is
* @param lookat
* The location they should be looking
* @return The location the player should be facing to have their crosshairs
* on the location lookAt Kudos to bergerkiller for most of this
* function
*/
public Location lookAt(Location loc, final Location lookat) {
// Clone the loc to prevent applied changes to the input loc
loc = loc.clone();
// Values of change in distance (make it relative)
final double dx = lookat.getX() - loc.getX();
final double dy = lookat.getY() - loc.getY();
final double dz = lookat.getZ() - loc.getZ();
// Set yaw
if (dx != 0) {
// Set yaw start value based on dx
if (dx < 0) {
loc.setYaw((float) (1.5 * Math.PI));
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
private void remove(CommandSender sender, String[] args) {
if (sender instanceof Player == false) {
sender.sendMessage(ChatColor.RED + "Only players may use that command.");
return;
}
if (!sender.hasPermission("quickshop.delete")) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command. Try break the shop instead?");
return;
}
Player p = (Player) sender;
BlockIterator bIt = new BlockIterator(p, 10);
while (bIt.hasNext()) {
Block b = bIt.next();
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if (shop.getOwner().equals(p.getUniqueId())) {
shop.delete();
sender.sendMessage(ChatColor.GREEN + "Success. Deleted shop.");
} else {
p.sendMessage(ChatColor.RED + "That's not your shop!");
}
return;
}
}
p.sendMessage(ChatColor.RED + "No shop found!");
}
private void export(CommandSender sender, String[] args) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: /qs export mysql|sqlite");
return;
}
String type = args[1].toLowerCase();
if (type.startsWith("mysql")) {
if (plugin.getDB().getCore() instanceof MySQLCore) {
sender.sendMessage(ChatColor.RED + "Database is already MySQL");
return;
}
ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("database");
String host = cfg.getString("host");
String port = cfg.getString("port");
String user = cfg.getString("user");
String pass = cfg.getString("password");
String name = cfg.getString("database");
MySQLCore core = new MySQLCore(host, user, pass, name, port);
Database target;
try {
target = new Database(core);
QuickShop.instance.getDB().copyTo(target);
sender.sendMessage(ChatColor.GREEN + "Success - Exported to MySQL " + user + "@" + host + "." + name);
} catch (Exception e) {
e.printStackTrace();
sender.sendMessage(ChatColor.RED + "Failed to export to MySQL " + user + "@" + host + "." + name + ChatColor.DARK_RED + " Reason: " + e.getMessage());
}
return;
}
if (type.startsWith("sql") || type.contains("file")) {
if (plugin.getDB().getCore() instanceof SQLiteCore) {
sender.sendMessage(ChatColor.RED + "Database is already SQLite");
return;
}
File file = new File(plugin.getDataFolder(), "shops.db");
if (file.exists()) {
if (file.delete() == false) {
sender.sendMessage(ChatColor.RED + "Warning: Failed to delete old shops.db file. This may cause errors.");
}
}
SQLiteCore core = new SQLiteCore(file);
try {
Database target = new Database(core);
QuickShop.instance.getDB().copyTo(target);
sender.sendMessage(ChatColor.GREEN + "Success - Exported to SQLite: " + file.toString());
} catch (Exception e) {
e.printStackTrace();
sender.sendMessage(ChatColor.RED + "Failed to export to SQLite: " + file.toString() + " Reason: " + e.getMessage());
}
return;
}
sender.sendMessage(ChatColor.RED + "No target given. Usage: /qs export mysql|sqlite");
}
private void setOwner(CommandSender sender, String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.setowner")) {
if (args.length < 2) {
sender.sendMessage(MsgUtil.p("command.no-owner-given"));
return;
}
BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
Block b = bIt.next();
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
@SuppressWarnings("deprecation")
OfflinePlayer p = this.plugin.getServer().getOfflinePlayer(args[1]);
shop.setOwner(p.getUniqueId());
shop.update();
sender.sendMessage(MsgUtil.p("command.new-owner", this.plugin.getServer().getOfflinePlayer(shop.getOwner()).getName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
private void refill(CommandSender sender, String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.refill")) {
if (args.length < 2) {
sender.sendMessage(MsgUtil.p("command.no-amount-given"));
return;
}
int add;
try {
add = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
return;
}
BlockIterator bIt = new BlockIterator((LivingEntity) (Player) sender, 10);
while (bIt.hasNext()) {
Block b = bIt.next();
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.add(shop.getItem(), add);
sender.sendMessage(MsgUtil.p("refill-success"));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
private void empty(CommandSender sender, String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.refill")) {
BlockIterator bIt = new BlockIterator((LivingEntity) (Player) sender, 10);
while (bIt.hasNext()) {
Block b = bIt.next();
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if (shop instanceof ContainerShop) {
ContainerShop cs = (ContainerShop) shop;
cs.getInventory().clear();
sender.sendMessage(MsgUtil.p("empty-success"));
return;
} else {
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
private void find(CommandSender sender, String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.find")) {
if (args.length < 2) {
sender.sendMessage(MsgUtil.p("command.no-type-given"));
return;
}
StringBuilder sb = new StringBuilder(args[1]);
for (int i = 2; i < args.length; i++) {
sb.append(" " + args[i]);
}
String lookFor = sb.toString();
lookFor = lookFor.toLowerCase();
Player p = (Player) sender;
Location loc = p.getEyeLocation().clone();
double minDistance = plugin.getConfig().getInt("shop.find-distance");
double minDistanceSquared = minDistance * minDistance;
int chunkRadius = (int) minDistance / 16 + 1;
Shop closest = null;
Chunk c = loc.getChunk();
for (int x = -chunkRadius + c.getX(); x < chunkRadius + c.getX(); x++) {
for (int z = -chunkRadius + c.getZ(); z < chunkRadius + c.getZ(); z++) {
Chunk d = c.getWorld().getChunkAt(x, z);
HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(d);
if (inChunk == null)
continue;
for (Shop shop : inChunk.values()) {
if (shop.getDataName().toLowerCase().contains(lookFor) && shop.getLocation().distanceSquared(loc) < minDistanceSquared) {
closest = shop;
minDistanceSquared = shop.getLocation().distanceSquared(loc);
}
}
}
}
if (closest == null) {
sender.sendMessage(MsgUtil.p("no-nearby-shop", args[1]));
return;
}
Location lookat = closest.getLocation().clone().add(0.5, 0.5, 0.5);
// Hack fix to make /qs find not used by /back
p.teleport(this.lookAt(loc, lookat).add(0, -1.62, 0), TeleportCause.UNKNOWN);
p.sendMessage(MsgUtil.p("nearby-shop-this-way", "" + (int) Math.floor(Math.sqrt(minDistanceSquared))));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
private void setBuy(CommandSender sender) {
if (sender instanceof Player && sender.hasPermission("quickshop.create.buy")) {
BlockIterator bIt = new BlockIterator((LivingEntity) (Player) sender, 10);
while (bIt.hasNext()) {
Block b = bIt.next();
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null && shop.getOwner().equals(((Player) sender).getUniqueId())) {
shop.setShopType(ShopType.BUYING);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
private void setSell(CommandSender sender) {
if (sender instanceof Player && sender.hasPermission("quickshop.create.sell")) {
BlockIterator bIt = new BlockIterator((LivingEntity) (Player) sender, 10);
while (bIt.hasNext()) {
Block b = bIt.next();
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null && shop.getOwner().equals(((Player) sender).getUniqueId())) {
shop.setShopType(ShopType.SELLING);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
@SuppressWarnings("deprecation")
private void setPrice(CommandSender sender, String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.create.changeprice")) {
Player p = (Player) sender;
if (args.length < 2) {
sender.sendMessage(MsgUtil.p("no-price-given"));
return;
}
double price;
try {
price = Double.parseDouble(args[1]);
} catch (NumberFormatException e) {
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
return;
}
if (price < 0.01) {
sender.sendMessage(MsgUtil.p("price-too-cheap"));
return;
}
double fee = 0;
if (plugin.priceChangeRequiresFee) {
fee = plugin.getConfig().getDouble("shop.fee-for-price-change");
if (fee > 0 && plugin.getEcon().getBalance(p.getUniqueId()) < fee) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
}
BlockIterator bIt = new BlockIterator(p, 10);
// Loop through every block they're looking at upto 10 blocks away
while (bIt.hasNext()) {
Block b = bIt.next();
Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null && (shop.getOwner().equals(((Player) sender).getUniqueId()) || sender.hasPermission("quickshop.other.price"))) {
if (shop.getPrice() == price) {
// Stop here if there isn't a price change
sender.sendMessage(MsgUtil.p("no-price-change"));
return;
}
if (fee > 0) {
if (!plugin.getEcon().withdraw(p.getUniqueId(), fee)) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
sender.sendMessage(MsgUtil.p("fee-charged-for-price-change", plugin.getEcon().format(fee)));
plugin.getEcon().deposit(plugin.getConfig().getString("tax-account"), fee);
}
// Update the shop
shop.setPrice(price);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("price-is-now", plugin.getEcon().format(shop.getPrice())));
// Chest shops can be double shops.
if (shop instanceof ContainerShop) {
ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
Shop nextTo = cs.getAttachedShop();
if (cs.isSelling()) {
if (cs.getPrice() < nextTo.getPrice()) {
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
} else {
// Buying
if (cs.getPrice() > nextTo.getPrice()) {
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
}
}
}
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
private void clean(CommandSender sender) {
if (sender.hasPermission("quickshop.clean")) {
sender.sendMessage(MsgUtil.p("command.cleaning"));
Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
int i = 0;
while (shIt.hasNext()) {
Shop shop = shIt.next();
try {
if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) {
ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop())
continue;
shIt.remove(); // Is selling, but has no stock, and is a chest shop, but is not a double shop. Can be deleted safely.
i++;
}
} catch (IllegalStateException e) {
shIt.remove(); // The shop is not there anymore, remove it
}
}
MsgUtil.clean();
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
private void reload(CommandSender sender) {
if (sender.hasPermission("quickshop.reload")) {
sender.sendMessage(MsgUtil.p("command.reloading"));
Bukkit.getPluginManager().disablePlugin(plugin);
Bukkit.getPluginManager().enablePlugin(plugin);
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
loc.setYaw((float) (0.5 * Math.PI));
}
loc.setYaw(loc.getYaw() - (float) Math.atan(dz / dx));
} else if (dz < 0) {
loc.setYaw((float) Math.PI);
}
// Get the distance from dx/dz
final double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));
final float pitch = (float) -Math.atan(dy / dxz);
// Set values, convert to degrees
// Minecraft yaw (vertical) angles are inverted (negative)
loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI + 360);
// But pitch angles are normal
loc.setPitch(pitch * 180f / (float) Math.PI);
return loc;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
if (args.length > 0) {
String subArg = args[0].toLowerCase();
final String subArg = args[0].toLowerCase();
if (subArg.equals("unlimited")) {
setUnlimited(sender);
return true;
@ -472,11 +119,11 @@ public class QS implements CommandExecutor {
int buying, selling, doubles, chunks, worlds;
buying = selling = doubles = chunks = worlds = 0;
int nostock = 0;
for (HashMap<ShopChunk, HashMap<Location, Shop>> inWorld : plugin.getShopManager().getShops().values()) {
for (final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld : plugin.getShopManager().getShops().values()) {
worlds++;
for (HashMap<Location, Shop> inChunk : inWorld.values()) {
for (final HashMap<Location, Shop> inChunk : inWorld.values()) {
chunks++;
for (Shop shop : inChunk.values()) {
for (final Shop shop : inChunk.values()) {
if (shop.isBuying()) {
buying++;
} else if (shop.isSelling()) {
@ -509,68 +156,432 @@ public class QS implements CommandExecutor {
return true;
}
/**
* Returns loc with modified pitch/yaw angles so it faces lookat
*
* @param loc
* The location a players head is
* @param lookat
* The location they should be looking
* @return The location the player should be facing to have their crosshairs
* on the location lookAt Kudos to bergerkiller for most of this
* function
*/
public Location lookAt(Location loc, Location lookat) {
// Clone the loc to prevent applied changes to the input loc
loc = loc.clone();
// Values of change in distance (make it relative)
double dx = lookat.getX() - loc.getX();
double dy = lookat.getY() - loc.getY();
double dz = lookat.getZ() - loc.getZ();
// Set yaw
if (dx != 0) {
// Set yaw start value based on dx
if (dx < 0) {
loc.setYaw((float) (1.5 * Math.PI));
} else {
loc.setYaw((float) (0.5 * Math.PI));
}
loc.setYaw((float) loc.getYaw() - (float) Math.atan(dz / dx));
} else if (dz < 0) {
loc.setYaw((float) Math.PI);
}
// Get the distance from dx/dz
double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));
float pitch = (float) -Math.atan(dy / dxz);
// Set values, convert to degrees
// Minecraft yaw (vertical) angles are inverted (negative)
loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI + 360);
// But pitch angles are normal
loc.setPitch(pitch * 180f / (float) Math.PI);
return loc;
}
public void sendHelp(CommandSender s) {
public void sendHelp(final CommandSender s) {
s.sendMessage(MsgUtil.p("command.description.title"));
if (s.hasPermission("quickshop.unlimited"))
if (s.hasPermission("quickshop.unlimited")) {
s.sendMessage(ChatColor.GREEN + "/qs unlimited" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.unlimited"));
if (s.hasPermission("quickshop.setowner"))
}
if (s.hasPermission("quickshop.setowner")) {
s.sendMessage(ChatColor.GREEN + "/qs setowner <player>" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.setowner"));
if (s.hasPermission("quickshop.create.buy"))
}
if (s.hasPermission("quickshop.create.buy")) {
s.sendMessage(ChatColor.GREEN + "/qs buy" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.buy"));
if (s.hasPermission("quickshop.create.sell"))
}
if (s.hasPermission("quickshop.create.sell")) {
s.sendMessage(ChatColor.GREEN + "/qs sell" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.sell"));
if (s.hasPermission("quickshop.create.changeprice"))
}
if (s.hasPermission("quickshop.create.changeprice")) {
s.sendMessage(ChatColor.GREEN + "/qs price" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.price"));
if (s.hasPermission("quickshop.clean"))
}
if (s.hasPermission("quickshop.clean")) {
s.sendMessage(ChatColor.GREEN + "/qs clean" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.clean"));
if (s.hasPermission("quickshop.find"))
}
if (s.hasPermission("quickshop.find")) {
s.sendMessage(ChatColor.GREEN + "/qs find <item>" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.find"));
if (s.hasPermission("quickshop.refill"))
}
if (s.hasPermission("quickshop.refill")) {
s.sendMessage(ChatColor.GREEN + "/qs refill <amount>" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.refill"));
if (s.hasPermission("quickshop.empty"))
}
if (s.hasPermission("quickshop.empty")) {
s.sendMessage(ChatColor.GREEN + "/qs empty" + ChatColor.YELLOW + " - " + MsgUtil.p("command.description.empty"));
if (s.hasPermission("quickshop.export"))
}
if (s.hasPermission("quickshop.export")) {
s.sendMessage(ChatColor.GREEN + "/qs export mysql|sqlite" + ChatColor.YELLOW + " - Exports the database to SQLite or MySQL");
}
}
private void clean(final CommandSender sender) {
if (sender.hasPermission("quickshop.clean")) {
sender.sendMessage(MsgUtil.p("command.cleaning"));
final Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
int i = 0;
while (shIt.hasNext()) {
final Shop shop = shIt.next();
try {
if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
continue;
}
shIt.remove(); // Is selling, but has no stock, and is a chest shop, but is not a double shop. Can be deleted safely.
i++;
}
} catch (final IllegalStateException e) {
shIt.remove(); // The shop is not there anymore, remove it
}
}
MsgUtil.clean();
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
private void empty(final CommandSender sender, final String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.refill")) {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
cs.getInventory().clear();
sender.sendMessage(MsgUtil.p("empty-success"));
return;
} else {
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
private void export(final CommandSender sender, final String[] args) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: /qs export mysql|sqlite");
return;
}
final String type = args[1].toLowerCase();
if (type.startsWith("mysql")) {
if (plugin.getDB().getCore() instanceof MySQLCore) {
sender.sendMessage(ChatColor.RED + "Database is already MySQL");
return;
}
final ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("database");
final String host = cfg.getString("host");
final String port = cfg.getString("port");
final String user = cfg.getString("user");
final String pass = cfg.getString("password");
final String name = cfg.getString("database");
final MySQLCore core = new MySQLCore(host, user, pass, name, port);
Database target;
try {
target = new Database(core);
QuickShop.instance.getDB().copyTo(target);
sender.sendMessage(ChatColor.GREEN + "Success - Exported to MySQL " + user + "@" + host + "." + name);
} catch (final Exception e) {
e.printStackTrace();
sender.sendMessage(ChatColor.RED + "Failed to export to MySQL " + user + "@" + host + "." + name + ChatColor.DARK_RED + " Reason: " + e.getMessage());
}
return;
}
if (type.startsWith("sql") || type.contains("file")) {
if (plugin.getDB().getCore() instanceof SQLiteCore) {
sender.sendMessage(ChatColor.RED + "Database is already SQLite");
return;
}
final File file = new File(plugin.getDataFolder(), "shops.db");
if (file.exists()) {
if (file.delete() == false) {
sender.sendMessage(ChatColor.RED + "Warning: Failed to delete old shops.db file. This may cause errors.");
}
}
final SQLiteCore core = new SQLiteCore(file);
try {
final Database target = new Database(core);
QuickShop.instance.getDB().copyTo(target);
sender.sendMessage(ChatColor.GREEN + "Success - Exported to SQLite: " + file.toString());
} catch (final Exception e) {
e.printStackTrace();
sender.sendMessage(ChatColor.RED + "Failed to export to SQLite: " + file.toString() + " Reason: " + e.getMessage());
}
return;
}
sender.sendMessage(ChatColor.RED + "No target given. Usage: /qs export mysql|sqlite");
}
private void find(final CommandSender sender, final String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.find")) {
if (args.length < 2) {
sender.sendMessage(MsgUtil.p("command.no-type-given"));
return;
}
final StringBuilder sb = new StringBuilder(args[1]);
for (int i = 2; i < args.length; i++) {
sb.append(" " + args[i]);
}
String lookFor = sb.toString();
lookFor = lookFor.toLowerCase();
final Player p = (Player) sender;
final Location loc = p.getEyeLocation().clone();
final double minDistance = plugin.getConfig().getInt("shop.find-distance");
double minDistanceSquared = minDistance * minDistance;
final int chunkRadius = (int) minDistance / 16 + 1;
Shop closest = null;
final Chunk c = loc.getChunk();
for (int x = -chunkRadius + c.getX(); x < chunkRadius + c.getX(); x++) {
for (int z = -chunkRadius + c.getZ(); z < chunkRadius + c.getZ(); z++) {
final Chunk d = c.getWorld().getChunkAt(x, z);
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(d);
if (inChunk == null) {
continue;
}
for (final Shop shop : inChunk.values()) {
if (shop.getDataName().toLowerCase().contains(lookFor) && shop.getLocation().distanceSquared(loc) < minDistanceSquared) {
closest = shop;
minDistanceSquared = shop.getLocation().distanceSquared(loc);
}
}
}
}
if (closest == null) {
sender.sendMessage(MsgUtil.p("no-nearby-shop", args[1]));
return;
}
final Location lookat = closest.getLocation().clone().add(0.5, 0.5, 0.5);
// Hack fix to make /qs find not used by /back
p.teleport(this.lookAt(loc, lookat).add(0, -1.62, 0), TeleportCause.UNKNOWN);
p.sendMessage(MsgUtil.p("nearby-shop-this-way", "" + (int) Math.floor(Math.sqrt(minDistanceSquared))));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
private void refill(final CommandSender sender, final String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.refill")) {
if (args.length < 2) {
sender.sendMessage(MsgUtil.p("command.no-amount-given"));
return;
}
int add;
try {
add = Integer.parseInt(args[1]);
} catch (final NumberFormatException e) {
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
return;
}
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.add(shop.getItem(), add);
sender.sendMessage(MsgUtil.p("refill-success"));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
private void reload(final CommandSender sender) {
if (sender.hasPermission("quickshop.reload")) {
sender.sendMessage(MsgUtil.p("command.reloading"));
Bukkit.getPluginManager().disablePlugin(plugin);
Bukkit.getPluginManager().enablePlugin(plugin);
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
private void remove(final CommandSender sender, final String[] args) {
if (sender instanceof Player == false) {
sender.sendMessage(ChatColor.RED + "Only players may use that command.");
return;
}
if (!sender.hasPermission("quickshop.delete")) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command. Try break the shop instead?");
return;
}
final Player p = (Player) sender;
final BlockIterator bIt = new BlockIterator(p, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if (shop.getOwner().equals(p.getUniqueId())) {
shop.delete();
sender.sendMessage(ChatColor.GREEN + "Success. Deleted shop.");
} else {
p.sendMessage(ChatColor.RED + "That's not your shop!");
}
return;
}
}
p.sendMessage(ChatColor.RED + "No shop found!");
}
private void setBuy(final CommandSender sender) {
if (sender instanceof Player && sender.hasPermission("quickshop.create.buy")) {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null && shop.getOwner().equals(((Player) sender).getUniqueId())) {
shop.setShopType(ShopType.BUYING);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
@SuppressWarnings("deprecation")
private void setOwner(final CommandSender sender, final String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.setowner")) {
if (args.length < 2) {
sender.sendMessage(MsgUtil.p("command.no-owner-given"));
return;
}
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
final OfflinePlayer p = this.plugin.getServer().getOfflinePlayer(args[1]);
shop.setOwner(p.getName());
shop.update();
sender.sendMessage(MsgUtil.p("command.new-owner", this.plugin.getServer().getOfflinePlayer(shop.getOwner()).getName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
@SuppressWarnings("deprecation")
private void setPrice(final CommandSender sender, final String[] args) {
if (sender instanceof Player && sender.hasPermission("quickshop.create.changeprice")) {
final Player p = (Player) sender;
if (args.length < 2) {
sender.sendMessage(MsgUtil.p("no-price-given"));
return;
}
double price;
try {
price = Double.parseDouble(args[1]);
} catch (final NumberFormatException e) {
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
return;
}
if (price < 0.01) {
sender.sendMessage(MsgUtil.p("price-too-cheap"));
return;
}
double fee = 0;
if (plugin.priceChangeRequiresFee) {
fee = plugin.getConfig().getDouble("shop.fee-for-price-change");
if (fee > 0 && plugin.getEcon().getBalance(p.getUniqueId()) < fee) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
}
final BlockIterator bIt = new BlockIterator(p, 10);
// Loop through every block they're looking at upto 10 blocks away
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null && (shop.getOwner().equals(((Player) sender).getUniqueId()) || sender.hasPermission("quickshop.other.price"))) {
if (shop.getPrice() == price) {
// Stop here if there isn't a price change
sender.sendMessage(MsgUtil.p("no-price-change"));
return;
}
if (fee > 0) {
if (!plugin.getEcon().withdraw(p.getUniqueId(), fee)) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
sender.sendMessage(MsgUtil.p("fee-charged-for-price-change", plugin.getEcon().format(fee)));
plugin.getEcon().deposit(plugin.getConfig().getString("tax-account"), fee);
}
// Update the shop
shop.setPrice(price);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("price-is-now", plugin.getEcon().format(shop.getPrice())));
// Chest shops can be double shops.
if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
final Shop nextTo = cs.getAttachedShop();
if (cs.isSelling()) {
if (cs.getPrice() < nextTo.getPrice()) {
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
} else {
// Buying
if (cs.getPrice() > nextTo.getPrice()) {
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
}
}
}
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
private void setSell(final CommandSender sender) {
if (sender instanceof Player && sender.hasPermission("quickshop.create.sell")) {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null && shop.getOwner().equals(((Player) sender).getUniqueId())) {
shop.setShopType(ShopType.SELLING);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
private void setUnlimited(final CommandSender sender) {
if (sender instanceof Player && sender.hasPermission("quickshop.unlimited")) {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.setUnlimited(!shop.isUnlimited());
shop.update();
sender.sendMessage(MsgUtil.p("command.toggle-unlimited", (shop.isUnlimited() ? "unlimited" : "limited")));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
} else {
sender.sendMessage(MsgUtil.p("no-permission"));
return;
}
}
}

View File

@ -4,7 +4,6 @@ import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
@ -14,6 +13,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
@ -26,6 +26,7 @@ import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Info;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopAction;
import org.maxgamer.QuickShop.Util.MarkUtil;
import org.maxgamer.QuickShop.Util.MsgUtil;
import org.maxgamer.QuickShop.Util.Util;
@ -47,11 +48,11 @@ public class PlayerListener implements Listener {
*
* clazz = clazz.getSuperclass(); } return classes; }
*/
@SuppressWarnings("deprecation")
/**
* Handles players left clicking a chest. Left click a NORMAL chest with
* item : Send creation menu Left click a SHOP chest : Send purchase menu
*/
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR)
public void onClick(final PlayerInteractEvent e) {
if (e.getAction() != Action.LEFT_CLICK_BLOCK) {
@ -131,6 +132,15 @@ public class PlayerListener implements Listener {
}
}
@EventHandler
public void onItemClick(final InventoryClickEvent e) {
final ItemStack ci = e.getCurrentItem();
if (MarkUtil.hasMark(ci)) {
ci.setType(Material.AIR);
e.setCancelled(true);
}
}
@EventHandler
public void onJoin(final PlayerJoinEvent e) {
// Notify the player any messages they were sent
@ -169,15 +179,8 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerPickup(final PlayerPickupItemEvent e) {
final ItemStack stack = e.getItem().getItemStack();
try {
if (stack.getItemMeta().getDisplayName().startsWith(ChatColor.RED + "QuickShop ")) {
e.setCancelled(true);
// You shouldn't be able to pick up that...
}
} catch (final NullPointerException ex) {
} // if meta/displayname/stack is null. We don't really care in that
// case.
final ItemStack ci = e.getItem().getItemStack();
e.setCancelled(!MarkUtil.hasMark(ci));
}
@EventHandler

View File

@ -12,7 +12,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -27,7 +26,6 @@ import org.bukkit.scheduler.BukkitTask;
import org.maxgamer.QuickShop.Command.QS;
import org.maxgamer.QuickShop.Config.ItemConfig;
import org.maxgamer.QuickShop.Database.Database;
import org.maxgamer.QuickShop.Database.Database.ConnectionException;
import org.maxgamer.QuickShop.Database.DatabaseCore;
import org.maxgamer.QuickShop.Database.DatabaseHelper;
import org.maxgamer.QuickShop.Database.MySQLCore;
@ -45,7 +43,6 @@ import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopManager;
import org.maxgamer.QuickShop.Shop.ShopType;
import org.maxgamer.QuickShop.Util.Converter;
import org.maxgamer.QuickShop.Util.MsgUtil;
import org.maxgamer.QuickShop.Util.Util;
import org.maxgamer.QuickShop.Watcher.ItemWatcher;
@ -59,7 +56,7 @@ public class QuickShop extends JavaPlugin {
public static QuickShop instance;
// private Metrics metrics;
/** Whether debug info should be shown in the console */
public static boolean debug = true;
public static boolean debug = false;
/** The economy we hook into for transactions */
private Economy economy;
/** The Shop Manager used to store shops */
@ -233,7 +230,7 @@ public class QuickShop extends JavaPlugin {
this.shopManager = new ShopManager(this);
if (this.display) {
// Display item handler thread
getLogger().info("Starting item scheduler");
getLogger().info("开启悬浮物品刷新线程...");
final ItemWatcher itemWatcher = new ItemWatcher(this);
itemWatcherTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 600, 600);
}
@ -248,7 +245,7 @@ public class QuickShop extends JavaPlugin {
}
ConfigurationSection limitCfg = this.getConfig().getConfigurationSection("limits");
if (limitCfg != null) {
getLogger().info("Limit cfg found...");
getLogger().info("发现物品限制配置...");
this.limit = limitCfg.getBoolean("use", false);
getLogger().info("Limits.use: " + limit);
limitCfg = limitCfg.getConfigurationSection("ranks");
@ -261,6 +258,7 @@ public class QuickShop extends JavaPlugin {
final ConfigurationSection dbCfg = getConfig().getConfigurationSection("database");
DatabaseCore dbCore;
if (dbCfg.getBoolean("mysql")) {
getLogger().info("启用MySQL 开始连接数据库...");
// MySQL database - Required database be created first.
final String user = dbCfg.getString("user");
final String pass = dbCfg.getString("password");
@ -275,14 +273,11 @@ public class QuickShop extends JavaPlugin {
this.database = new Database(dbCore);
// Make the database up to date
DatabaseHelper.setup(getDB());
} catch (final ConnectionException e) {
} catch (final Exception e) {
getLogger().warning("数据库连接错误或配置错误...");
getLogger().warning("错误信息: " + e.getMessage());
e.printStackTrace();
getLogger().severe("Error connecting to database. Aborting plugin load.");
getServer().getPluginManager().disablePlugin(this);
return;
} catch (final SQLException e) {
e.printStackTrace();
getLogger().severe("Error setting up database. Aborting plugin load.");
getLogger().warning("关闭插件!!!");
getServer().getPluginManager().disablePlugin(this);
return;
}
@ -290,15 +285,7 @@ public class QuickShop extends JavaPlugin {
int count = 0; // Shops count
Connection con;
try {
getLogger().info("Loading shops from database...");
final int res = Converter.convert();
if (res < 0) {
System.out.println("Could not convert shops. Exitting.");
return;
}
if (res > 0) {
System.out.println("Conversion success. Continuing...");
}
getLogger().info("从数据看载入商店数据...");
con = database.getConnection();
final PreparedStatement ps = con.prepareStatement("SELECT * FROM shops");
final ResultSet rs = ps.executeQuery();
@ -320,7 +307,7 @@ public class QuickShop extends JavaPlugin {
final Location loc = new Location(world, x, y, z);
/* Skip invalid shops, if we know of any */
if (world != null && (loc.getBlock().getState() instanceof InventoryHolder) == false) {
getLogger().info("Shop is not an InventoryHolder in " + rs.getString("world") + " at: " + x + ", " + y + ", " + z + ". Deleting.");
getLogger().info("商店不是一个可存储的方块 坐标 " + rs.getString("world") + " at: " + x + ", " + y + ", " + z + ". 删除...");
final PreparedStatement delps = getDB().getConnection().prepareStatement("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?");
delps.setInt(1, x);
delps.setInt(2, y);
@ -330,7 +317,7 @@ public class QuickShop extends JavaPlugin {
continue;
}
final int type = rs.getInt("type");
final Shop shop = new ContainerShop(loc, price, item, UUID.fromString(owner));
final Shop shop = new ContainerShop(loc, price, item, owner);
shop.setUnlimited(rs.getBoolean("unlimited"));
shop.setShopType(ShopType.fromID(type));
shopManager.loadShop(rs.getString("world"), shop);
@ -341,9 +328,9 @@ public class QuickShop extends JavaPlugin {
} catch (final Exception e) {
errors++;
e.printStackTrace();
getLogger().severe("Error loading a shop! Coords: " + worldName + " (" + x + ", " + y + ", " + z + ")...");
getLogger().warning("载入商店数据时发生错误! 商店位置: " + worldName + " (" + x + ", " + y + ", " + z + ")...");
if (errors < 3) {
getLogger().info("Deleting the shop...");
getLogger().warning("删除错误的商店数据...");
final PreparedStatement delps = getDB().getConnection().prepareStatement("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?");
delps.setInt(1, x);
delps.setInt(2, y);
@ -351,21 +338,22 @@ public class QuickShop extends JavaPlugin {
delps.setString(4, worldName);
delps.execute();
} else {
getLogger().severe("Multiple errors in shops - Something seems to be wrong with your shops database! Please check it out immediately!");
getLogger().warning("过多的错误数据 可能您的数据库文件已损坏! 请检查数据库文件!");
e.printStackTrace();
}
}
}
} catch (final SQLException e) {
getLogger().warning("无法载入商店数据...");
getLogger().warning("错误信息: " + e.getMessage());
e.printStackTrace();
getLogger().severe("Could not load shops.");
}
getLogger().info("Loaded " + count + " shops.");
getLogger().info("已载入 " + count + " 个商店...");
MsgUtil.loadTransactionMessages();
MsgUtil.clean();
// Register events
getLogger().info("Registering Listeners");
getLogger().info("注册监听器...");
Bukkit.getServer().getPluginManager().registerEvents(blockListener, this);
Bukkit.getServer().getPluginManager().registerEvents(playerListener, this);
if (this.display) {
@ -374,8 +362,6 @@ public class QuickShop extends JavaPlugin {
Bukkit.getServer().getPluginManager().registerEvents(worldListener, this);
if (this.getConfig().getBoolean("force-bukkit-chat-handler", false) && Bukkit.getPluginManager().getPlugin("Herochat") != null) {
this.getLogger().info("Found Herochat... Hooking!");
// this.heroChatListener = new HeroChatListener(this);
// Bukkit.getServer().getPluginManager().registerEvents(heroChatListener, this);
} else {
this.chatListener = new ChatListener(this);
Bukkit.getServer().getPluginManager().registerEvents(chatListener, this);
@ -384,7 +370,7 @@ public class QuickShop extends JavaPlugin {
final QS commandExecutor = new QS(this);
getCommand("qs").setExecutor(commandExecutor);
if (getConfig().getInt("shop.find-distance") > 100) {
getLogger().severe("Shop.find-distance is too high! Pick a number under 100!");
getLogger().warning("商店查找半径过大 可能导致服务器Lag! 推荐使用低于 100 的配置!");
}
new VersionChecker(this);
try {

View File

@ -3,7 +3,6 @@ package org.maxgamer.QuickShop.Shop;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
@ -26,7 +25,7 @@ import org.maxgamer.QuickShop.Util.Util;
public class ContainerShop implements Shop {
private final Location loc;
private double price;
private UUID owner;
private String owner;
private final ItemStack item;
private DisplayItem displayItem;
private boolean unlimited;
@ -46,7 +45,7 @@ public class ContainerShop implements Shop {
* @param owner
* The player who owns this shop.
*/
public ContainerShop(final Location loc, final double price, final ItemStack item, final UUID owner) {
public ContainerShop(final Location loc, final double price, final ItemStack item, final String owner) {
this.loc = loc;
this.price = price;
this.owner = owner;
@ -185,6 +184,7 @@ public class ContainerShop implements Shop {
* True if you are *NOT* iterating over this currently, *false if
* you are iterating*
*/
@SuppressWarnings("deprecation")
@Override
public void delete(final boolean fromMemory) {
// Delete the display item
@ -301,7 +301,7 @@ public class ContainerShop implements Shop {
* @return The name of the player who owns the shop.
*/
@Override
public UUID getOwner() {
public String getOwner() {
return this.owner;
}
@ -562,7 +562,7 @@ public class ContainerShop implements Shop {
* it after a reboot.
*/
@Override
public void setOwner(final UUID owner) {
public void setOwner(final String owner) {
this.owner = owner;
}

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +0,0 @@
package org.maxgamer.QuickShop.Util;
public class Converter {
/**
* Attempts to convert the quickshop database, if necessary.
*
* @return -1 for failure, 0 for no changes, 1 for success converting.
*/
public static int convert() {
return 0;
}
}

View File

@ -24,7 +24,7 @@ import mkremins.fanciful.FancyMessage;
public class MsgUtil {
private static QuickShop plugin;
private static FileConfig messages;
private static HashMap<UUID, LinkedList<String>> player_messages = new HashMap<UUID, LinkedList<String>>();
private static HashMap<String, LinkedList<String>> player_messages = new HashMap<String, LinkedList<String>>();
static {
plugin = QuickShop.instance;
@ -82,7 +82,7 @@ public class MsgUtil {
try {
final ResultSet rs = plugin.getDB().getConnection().prepareStatement("SELECT * FROM messages").executeQuery();
while (rs.next()) {
final UUID owner = UUID.fromString(rs.getString("owner"));
final String owner = rs.getString("owner");
final String message = rs.getString("message");
LinkedList<String> msgs = player_messages.get(owner);
if (msgs == null) {
@ -119,7 +119,8 @@ public class MsgUtil {
* they're online. Else, if they're not online, queues it for
* them in the database.
*/
public static void send(final UUID player, final String message) { // TODO Converted to UUID
public static void send(final String player, final String message) { // TODO Converted to UUID
@SuppressWarnings("deprecation")
final OfflinePlayer p = Bukkit.getOfflinePlayer(player);
if (p == null || !p.isOnline()) {
LinkedList<String> msgs = player_messages.get(player);
@ -219,6 +220,7 @@ public class MsgUtil {
sendShopInfo(p, shop, shop.getRemainingStock());
}
@SuppressWarnings("deprecation")
public static void sendShopInfo(final Player p, final Shop shop, final int stock) {
// Potentially faster with an array?
final ItemStack items = shop.getItem();

View File

@ -3,156 +3,11 @@ package org.maxgamer.QuickShop.Util;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.ChatColor;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.maxgamer.QuickShop.QuickShop;
public class NMS {
// private static ArrayList<NMSDependent> dependents = new ArrayList<NMSDependent>();
private static int nextId = 0;
// private static NMSDependent nms;
// static {
// NMSDependent dep;
// dep = new NMSDependent("v1_6_R3") {
// @Override
// public void safeGuard(Item item) {
// org.bukkit.inventory.ItemStack iStack = item.getItemStack();
// net.minecraft.server.v1_6_R3.ItemStack nmsI = org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack.asNMSCopy(iStack);
// nmsI.count = 0;
// iStack = org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack.asBukkitCopy(nmsI);
// item.setItemStack(iStack);
// }
//
// @Override
// public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
// net.minecraft.server.v1_6_R3.ItemStack is = org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack.asNMSCopy(iStack);
// net.minecraft.server.v1_6_R3.NBTTagCompound itemCompound = new net.minecraft.server.v1_6_R3.NBTTagCompound();
// itemCompound = is.save(itemCompound);
// return net.minecraft.server.v1_6_R3.NBTCompressedStreamTools.a(itemCompound);
// }
//
// @Override
// public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
// net.minecraft.server.v1_6_R3.NBTTagCompound c = net.minecraft.server.v1_6_R3.NBTCompressedStreamTools.a(bytes);
// net.minecraft.server.v1_6_R3.ItemStack is = net.minecraft.server.v1_6_R3.ItemStack.createStack(c);
// return org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack.asBukkitCopy(is);
// }
// };
// dependents.add(dep);
// dep = new NMSDependent("v1_7_R1") {
// @Override
// public void safeGuard(Item item) {
// if(QuickShop.debug)System.out.println("safeGuard");
// org.bukkit.inventory.ItemStack iStack = item.getItemStack();
// net.minecraft.server.v1_7_R1.ItemStack nmsI = org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack.asNMSCopy(iStack);
// nmsI.count = 0;
// iStack = org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack.asBukkitCopy(nmsI);
// item.setItemStack(iStack);
// }
//
// @Override
// public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
// if(QuickShop.debug)System.out.println("getNBTBytes");
// net.minecraft.server.v1_7_R1.ItemStack is = org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack.asNMSCopy(iStack);
// net.minecraft.server.v1_7_R1.NBTTagCompound itemCompound = new net.minecraft.server.v1_7_R1.NBTTagCompound();
// itemCompound = is.save(itemCompound);
// return net.minecraft.server.v1_7_R1.NBTCompressedStreamTools.a(itemCompound);
// }
//
// @Override
// public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
// if(QuickShop.debug)System.out.println("getItemStack");
// net.minecraft.server.v1_7_R1.NBTTagCompound c = net.minecraft.server.v1_7_R1.NBTCompressedStreamTools.a(bytes);
// net.minecraft.server.v1_7_R1.ItemStack is = net.minecraft.server.v1_7_R1.ItemStack.createStack(c);
// return org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack.asBukkitCopy(is);
// }
// };
// dependents.add(dep);
// dep = new NMSDependent("v1_7_R3") {
// @Override
// public void safeGuard(Item item) {
// if(QuickShop.debug)System.out.println("safeGuard");
// org.bukkit.inventory.ItemStack iStack = item.getItemStack();
// net.minecraft.server.v1_7_R3.ItemStack nmsI = org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack.asNMSCopy(iStack);
// nmsI.count = 0;
// iStack = org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack.asBukkitCopy(nmsI);
// item.setItemStack(iStack);
// }
//
// @Override
// public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
// if(QuickShop.debug)System.out.println("getNBTBytes");
// net.minecraft.server.v1_7_R3.ItemStack is = org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack.asNMSCopy(iStack);
// net.minecraft.server.v1_7_R3.NBTTagCompound itemCompound = new net.minecraft.server.v1_7_R3.NBTTagCompound();
// itemCompound = is.save(itemCompound);
// return net.minecraft.server.v1_7_R3.NBTCompressedStreamTools.a(itemCompound);
// }
//
// @Override
// public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
// if(QuickShop.debug)System.out.println("getItemStack");
// net.minecraft.server.v1_7_R3.NBTTagCompound c = net.minecraft.server.v1_7_R3.NBTCompressedStreamTools.a(bytes, null);
// net.minecraft.server.v1_7_R3.ItemStack is = net.minecraft.server.v1_7_R3.ItemStack.createStack(c);
// return org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack.asBukkitCopy(is);
// }
// };
// dependents.add(dep);
// dep = new NMSDependent("v1_8") {
// @Override
// public void safeGuard(Item item) {
// if(QuickShop.debug)System.out.println("safeGuard");
// org.bukkit.inventory.ItemStack iStack = item.getItemStack();
// net.minecraft.server.v1_8_R1.ItemStack nmsI = org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack.asNMSCopy(iStack);
// nmsI.count = 0;
// iStack = org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack.asBukkitCopy(nmsI);
// item.setItemStack(iStack);
// }
//
// @Override
// public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
// try{
// if(QuickShop.debug)System.out.println("getNBTBytes");
// net.minecraft.server.v1_8_R1.ItemStack is = org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack.asNMSCopy(iStack);
// net.minecraft.server.v1_8_R1.NBTTagCompound itemCompound = new net.minecraft.server.v1_8_R1.NBTTagCompound();
// itemCompound = is.save(itemCompound);
// ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
// DataOutputStream dataoutputstream = new DataOutputStream(new GZIPOutputStream(bytearrayoutputstream));
// try {
// net.minecraft.server.v1_8_R1.NBTCompressedStreamTools.a(itemCompound, (DataOutput) dataoutputstream);
// } finally {
// dataoutputstream.close();
// }
// return bytearrayoutputstream.toByteArray();
// }catch(Exception e){
// return new byte[0];
// }
// //return net.minecraft.server.v1_8_R1.NBTCompressedStreamTools.a(itemCompound);
// }
//
// @Override
// public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
// try{
// if(QuickShop.debug)System.out.println("getItemStack");
// DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes))));
// net.minecraft.server.v1_8_R1.NBTTagCompound nbttagcompound;
// try {
// nbttagcompound = net.minecraft.server.v1_8_R1.NBTCompressedStreamTools.a((DataInput) datainputstream, null);
// } finally {
// datainputstream.close();
// }
// //net.minecraft.server.v1_8_R1.NBTTagCompound c = net.minecraft.server.v1_8_R1.NBTCompressedStreamTools.a(bytes, null);
// net.minecraft.server.v1_8_R1.ItemStack is = net.minecraft.server.v1_8_R1.ItemStack.createStack(nbttagcompound);
// return org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack.asBukkitCopy(is);
// }catch(Exception e){
// return new ItemStack(Material.AIR);
// }
// }
// };
// dependents.add(dep);
// }
public static void safeGuard(final Item item) throws ClassNotFoundException {
if (QuickShop.debug) {
@ -202,53 +57,7 @@ public class NMS {
}
}
// public static byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) throws ClassNotFoundException {
// validate();
// return nms.getNBTBytes(iStack);
// }
//
// public static ItemStack getItemStack(byte[] bytes) throws ClassNotFoundException {
// validate();
// return nms.getItemStack(bytes);
// }
private static void rename(final ItemStack iStack) {
final ItemMeta meta = iStack.getItemMeta();
meta.setDisplayName(ChatColor.RED + "QuickShop " + Util.getName(iStack) + " " + nextId++);
iStack.setItemMeta(meta);
MarkUtil.addMark(iStack);
}
// private static void validate() throws ClassNotFoundException {
// if (nms != null) {
// return;
// }
// String packageName = Bukkit.getServer().getClass().getPackage().getName();
// packageName = packageName.substring(packageName.lastIndexOf(".") + 1);
// // System.out.println("Package: " + packageName);
// for (NMSDependent dep : dependents) {
// if ((packageName.startsWith(dep.getVersion())) || ((dep.getVersion().isEmpty()) && ((packageName.equals("bukkit")) || (packageName.equals("craftbukkit"))))) {
// nms = dep;
// return;
// }
// }
// throw new ClassNotFoundException("This version of QuickShop is incompatible.");
// }
// private static abstract class NMSDependent {
// private String version;
//
// public String getVersion() {
// return this.version;
// }
//
// public NMSDependent(String version) {
// this.version = version;
// }
//
// public abstract void safeGuard(Item paramItem);
//
// public abstract byte[] getNBTBytes(org.bukkit.inventory.ItemStack paramItemStack);
//
// public abstract org.bukkit.inventory.ItemStack getItemStack(byte[] paramArrayOfByte);
// }
}

View File

@ -22,8 +22,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.material.MaterialData;
import org.bukkit.material.Sign;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Config.ItemConfig;
@ -35,10 +33,6 @@ public class Util {
private static HashSet<Material> transparent = new HashSet<Material>();
private static QuickShop plugin;
private static final String[] ROMAN = { "X", "IX", "V", "IV", "I" };
private static final int[] DECIMAL = { 10, 9, 5, 4, 1 };
public static void addTransparentBlock(final Material m) {
if (transparent.add(m) == false) {
System.out.println("Already added as transparent: " + m.toString());
@ -579,370 +573,4 @@ public class Util {
cfg.set("item", iStack);
return cfg.saveToString();
}
/**
* Converts a given material and data value into a format similar to
* Material.<?>.toString(). Upper case, with underscores. Includes material
* name in result.
*
* @param mat
* The base material.
* @param damage
* The durability/damage of the item.
* @return A string with the name of the item.
*/
private static String getDataName(final Material mat, short damage) {
final int id = mat.getId();
switch (id) {
case 35:
switch (damage) {
case 0:
return "WHITE_WOOL";
case 1:
return "ORANGE_WOOL";
case 2:
return "MAGENTA_WOOL";
case 3:
return "LIGHT_BLUE_WOOL";
case 4:
return "YELLOW_WOOL";
case 5:
return "LIME_WOOL";
case 6:
return "PINK_WOOL";
case 7:
return "GRAY_WOOL";
case 8:
return "LIGHT_GRAY_WOOL";
case 9:
return "CYAN_WOOL";
case 10:
return "PURPLE_WOOL";
case 11:
return "BLUE_WOOL";
case 12:
return "BROWN_WOOL";
case 13:
return "GREEN_WOOL";
case 14:
return "RED_WOOL";
case 15:
return "BLACK_WOOL";
}
return mat.toString();
case 351:
switch (damage) {
case 0:
return "INK_SAC";
case 1:
return "ROSE_RED";
case 2:
return "CACTUS_GREEN";
case 3:
return "COCOA_BEANS";
case 4:
return "LAPIS_LAZULI";
case 5:
return "PURPLE_DYE";
case 6:
return "CYAN_DYE";
case 7:
return "LIGHT_GRAY_DYE";
case 8:
return "GRAY_DYE";
case 9:
return "PINK_DYE";
case 10:
return "LIME_DYE";
case 11:
return "DANDELION_YELLOW";
case 12:
return "LIGHT_BLUE_DYE";
case 13:
return "MAGENTA_DYE";
case 14:
return "ORANGE_DYE";
case 15:
return "BONE_MEAL";
}
return mat.toString();
case 98:
switch (damage) {
case 0:
return "STONE_BRICKS";
case 1:
return "MOSSY_STONE_BRICKS";
case 2:
return "CRACKED_STONE_BRICKS";
case 3:
return "CHISELED_STONE_BRICKS";
}
return mat.toString();
case 373:
// Special case,.. Why?
if (damage == 0) {
return "WATER_BOTTLE";
}
Potion pot;
try {
pot = Potion.fromDamage(damage);
} catch (final Exception e) {
return "CUSTOM_POTION";
}
String prefix = "";
String suffix = "";
if (pot.getLevel() > 0) {
suffix += "_" + pot.getLevel();
}
if (pot.hasExtendedDuration()) {
prefix += "EXTENDED_";
}
if (pot.isSplash()) {
prefix += "SPLASH_";
}
if (pot.getEffects().isEmpty()) {
switch (pot.getNameId()) {
case 0:
return prefix + "MUNDANE_POTION" + suffix;
case 7:
return prefix + "CLEAR_POTION" + suffix;
case 11:
return prefix + "DIFFUSE_POTION" + suffix;
case 13:
return prefix + "ARTLESS_POTION" + suffix;
case 15:
return prefix + "THIN_POTION" + suffix;
case 16:
return prefix + "AWKWARD_POTION" + suffix;
case 32:
return prefix + "THICK_POTION" + suffix;
}
} else {
String effects = "";
for (final PotionEffect effect : pot.getEffects()) {
effects += effect.toString().split(":")[0];
}
return prefix + effects + suffix;
}
return mat.toString();
case 6:
switch (damage) {
case 0:
return "OAK_SAPLING";
case 1:
return "PINE_SAPLING";
case 2:
return "BIRCH_SAPLING";
case 3:
return "JUNGLE_TREE_SAPLING";
}
return mat.toString();
case 5:
switch (damage) {
case 0:
return "OAK_PLANKS";
case 1:
return "PINE_PLANKS";
case 2:
return "BIRCH_PLANKS";
case 3:
return "JUNGLE_PLANKS";
}
return mat.toString();
case 17:
switch (damage) {
case 0:
return "OAK_LOG";
case 1:
return "PINE_LOG";
case 2:
return "BIRCH_LOG";
case 3:
return "JUNGLE_LOG";
}
return mat.toString();
case 18:
damage = (short) (damage % 4);
switch (damage) {
case 0:
return "OAK_LEAVES";
case 1:
return "PINE_LEAVES";
case 2:
return "BIRCH_LEAVES";
case 3:
return "JUNGLE_LEAVES";
}
case 263:
switch (damage) {
case 0:
return "COAL";
case 1:
return "CHARCOAL";
}
return mat.toString();
case 24:
switch (damage) {
case 0:
return "SANDSTONE";
case 1:
return "CHISELED_SANDSTONE";
case 2:
return "SMOOTH_SANDSTONE";
}
return mat.toString();
case 31:
switch (damage) {
case 0:
return "DEAD_SHRUB";
case 1:
return "TALL_GRASS";
case 2:
return "FERN";
}
return mat.toString();
case 44:
switch (damage) {
case 0:
return "STONE_SLAB";
case 1:
return "SANDSTONE_SLAB";
case 2:
return "WOODEN_SLAB";
case 3:
return "COBBLESTONE_SLAB";
case 4:
return "BRICK_SLAB";
case 5:
return "STONE_BRICK_SLAB";
}
return mat.toString();
case 383:
switch (damage) {
case 50:
return "CREEPER_EGG";
case 51:
return "SKELETON_EGG";
case 52:
return "SPIDER_EGG";
case 53:
return "GIANT_EGG";
case 54:
return "ZOMBIE_EGG";
case 55:
return "SLIME_EGG";
case 56:
return "GHAST_EGG";
case 57:
return "ZOMBIE_PIGMAN_EGG";
case 58:
return "ENDERMAN_EGG";
case 59:
return "CAVE_SPIDER_EGG";
case 60:
return "SILVERFISH_EGG";
case 61:
return "BLAZE_EGG";
case 62:
return "MAGMA_CUBE_EGG";
case 63:
return "ENDER_DRAGON_EGG";
case 90:
return "PIG_EGG";
case 91:
return "SHEEP_EGG";
case 92:
return "COW_EGG";
case 93:
return "CHICKEN_EGG";
case 94:
return "SQUID_EGG";
case 95:
return "WOLF_EGG";
case 96:
return "MOOSHROOM_EGG";
case 97:
return "SNOW_GOLEM_EGG";
case 98:
return "OCELOT_EGG";
case 99:
return "IRON_GOLEM_EGG";
case 120:
return "VILLAGER_EGG";
case 200:
return "ENDER_CRYSTAL_EGG";
case 14:
return "PRIMED_TNT_EGG";
case 66:
return "WITCH_EGG";
case 65:
return "BAT_EGG";
}
return mat.toString();
case 397:
switch (damage) {
case 0:
return "SKELETON_SKULL";
case 1:
return "WITHER_SKULL";
case 2:
return "ZOMBIE_HEAD";
case 3:
return "PLAYER_HEAD";
case 4:
return "CREEPER_HEAD";
}
break;
case 76:
return "REDSTONE_TORCH";
case 115:
return "NETHER_WART";
case 30:
return "COBWEB";
case 102:
return "GLASS_PANE";
case 101:
return "IRON_BARS";
case 58:
return "CRAFTING_TABLE";
case 123:
return "REDSTONE_LAMP";
case 392:
return "POTATO";
case 289:
return "GUNPOWDER";
case 391:
return "CARROT";
case 322:
switch (damage) {
case 0:
return "GOLDEN_APPLE";
case 1:
return "ENCHANTED_GOLDEN_APPLE";
}
break;
case 390:
return "FLOWER_POT";
case 145:
switch (damage) {
case 0:
return "ANVIL";
case 1:
return "SLIGHTLY_DAMAGED_ANVIL";
case 2:
return "VERY_DAMAGED:ANVIL";
}
break;
case 384:
return "BOTTLE_O'_ENCHANTING";
case 402:
return "FIREWORK_STAR";
case 385:
return "FIREWORK_CHARGE";
}
if (damage == 0 || isTool(mat)) {
return mat.toString();
}
return mat.toString() + ":" + damage;
}
}