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

Release Version 1.0...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-10-05 04:19:20 +08:00
parent d870528b7f
commit ebf4d99e72
10 changed files with 122 additions and 201 deletions

View File

@ -2,12 +2,12 @@ package org.maxgamer.QuickShop.Economy;
import java.util.UUID; import java.util.UUID;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import net.milkbowl.vault.economy.Economy;
public class Economy_Vault implements EconomyCore { public class Economy_Vault implements EconomyCore {
private Economy vault; private Economy vault;
@ -15,12 +15,37 @@ public class Economy_Vault implements EconomyCore {
setupEconomy(); setupEconomy();
} }
private boolean setupEconomy() { @Override
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServicesManager().getRegistration(Economy.class); @Deprecated
if (economyProvider != null) { public boolean deposit(final String name, final double amount) {
this.vault = ((Economy) economyProvider.getProvider()); return this.vault.depositPlayer(name, amount).transactionSuccess();
}
@Override
public boolean deposit(final UUID name, final double amount) {
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
return this.vault.depositPlayer(p, amount).transactionSuccess();
}
@Override
public String format(final double balance) {
try {
return this.vault.format(balance);
} catch (final NumberFormatException e) {
} }
return this.vault != null; return "" + balance;
}
@Override
@Deprecated
public double getBalance(final String name) {
return this.vault.getBalance(name);
}
@Override
public double getBalance(final UUID name) {
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
return this.vault.getBalance(p);
} }
@Override @Override
@ -30,19 +55,7 @@ public class Economy_Vault implements EconomyCore {
@Override @Override
@Deprecated @Deprecated
public boolean deposit(String name, double amount) { public boolean transfer(final String from, final String to, final double amount) {
return this.vault.depositPlayer(name, amount).transactionSuccess();
}
@Override
@Deprecated
public boolean withdraw(String name, double amount) {
return this.vault.withdrawPlayer(name, amount).transactionSuccess();
}
@Override
@Deprecated
public boolean transfer(String from, String to, double amount) {
if (this.vault.getBalance(from) >= amount) { if (this.vault.getBalance(from) >= amount) {
if (this.vault.withdrawPlayer(from, amount).transactionSuccess()) { if (this.vault.withdrawPlayer(from, amount).transactionSuccess()) {
if (!this.vault.depositPlayer(to, amount).transactionSuccess()) { if (!this.vault.depositPlayer(to, amount).transactionSuccess()) {
@ -57,36 +70,9 @@ public class Economy_Vault implements EconomyCore {
} }
@Override @Override
@Deprecated public boolean transfer(final UUID from, final UUID to, final double amount) {
public double getBalance(String name) { final OfflinePlayer pFrom = Bukkit.getOfflinePlayer(from);
return this.vault.getBalance(name); final OfflinePlayer pTo = Bukkit.getOfflinePlayer(to);
}
@Override
public String format(double balance) {
try {
return this.vault.format(balance);
} catch (NumberFormatException e) {
}
return "$" + balance;
}
@Override
public boolean deposit(UUID name, double amount) {
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
return this.vault.depositPlayer(p, amount).transactionSuccess();
}
@Override
public boolean withdraw(UUID name, double amount) {
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
return this.vault.withdrawPlayer(p, amount).transactionSuccess();
}
@Override
public boolean transfer(UUID from, UUID to, double amount) {
OfflinePlayer pFrom = Bukkit.getOfflinePlayer(from);
OfflinePlayer pTo = Bukkit.getOfflinePlayer(to);
if (this.vault.getBalance(pFrom) >= amount) { if (this.vault.getBalance(pFrom) >= amount) {
if (this.vault.withdrawPlayer(pFrom, amount).transactionSuccess()) { if (this.vault.withdrawPlayer(pFrom, amount).transactionSuccess()) {
if (!this.vault.depositPlayer(pTo, amount).transactionSuccess()) { if (!this.vault.depositPlayer(pTo, amount).transactionSuccess()) {
@ -101,8 +87,22 @@ public class Economy_Vault implements EconomyCore {
} }
@Override @Override
public double getBalance(UUID name) { @Deprecated
OfflinePlayer p = Bukkit.getOfflinePlayer(name); public boolean withdraw(final String name, final double amount) {
return this.vault.getBalance(p); return this.vault.withdrawPlayer(name, amount).transactionSuccess();
}
@Override
public boolean withdraw(final UUID name, final double amount) {
final OfflinePlayer p = Bukkit.getOfflinePlayer(name);
return this.vault.withdrawPlayer(p, amount).transactionSuccess();
}
private boolean setupEconomy() {
final RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServicesManager().getRegistration(Economy.class);
if (economyProvider != null) {
this.vault = (economyProvider.getProvider());
}
return this.vault != null;
} }
} }

View File

@ -14,13 +14,13 @@ import org.maxgamer.QuickShop.QuickShop;
public class ChatListener implements Listener { public class ChatListener implements Listener {
QuickShop plugin; QuickShop plugin;
public ChatListener(QuickShop plugin) { public ChatListener(final QuickShop plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onChat(final AsyncPlayerChatEvent e) { public void onChat(final AsyncPlayerChatEvent e) {
if (!plugin.getShopManager().getActions().containsKey(e.getPlayer().getUniqueId())) { if (!plugin.getShopManager().getActions().containsKey(e.getPlayer().getName())) {
return; return;
} }
plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage()); plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage());

View File

@ -1,7 +1,6 @@
package org.maxgamer.QuickShop.Listeners; package org.maxgamer.QuickShop.Listeners;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -14,12 +13,14 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockIterator; import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.QuickShop;
@ -37,17 +38,6 @@ public class PlayerListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
/*
* Could be useful one day private LinkedList<String> getParents(Class<?>
* clazz){ LinkedList<String> classes = new LinkedList<String>();
*
* while(clazz != null){ classes.add("Extends " + ChatColor.GREEN +
* clazz.getCanonicalName()); for(Class<?> iface : clazz.getInterfaces()){
* classes.add("Implements " + ChatColor.RED + iface.getCanonicalName());
* classes.addAll(getParents(iface)); }
*
* clazz = clazz.getSuperclass(); } return classes; }
*/
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
/** /**
* Handles players left clicking a chest. Left click a NORMAL chest with * Handles players left clicking a chest. Left click a NORMAL chest with
@ -90,9 +80,9 @@ public class PlayerListener implements Listener {
p.sendMessage(MsgUtil.p("how-many-sell", "" + items)); p.sendMessage(MsgUtil.p("how-many-sell", "" + items));
} }
// Add the new action // Add the new action
final HashMap<UUID, Info> actions = plugin.getShopManager().getActions(); final HashMap<String, Info> actions = plugin.getShopManager().getActions();
final Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop); final Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop);
actions.put(p.getUniqueId(), info); actions.put(p.getName(), info);
return; return;
} }
// Handles creating shops // Handles creating shops
@ -127,17 +117,31 @@ public class PlayerListener implements Listener {
} }
// Send creation menu. // Send creation menu.
final Info info = new Info(b.getLocation(), ShopAction.CREATE, e.getItem(), last); final Info info = new Info(b.getLocation(), ShopAction.CREATE, e.getItem(), last);
plugin.getShopManager().getActions().put(p.getUniqueId(), info); plugin.getShopManager().getActions().put(p.getName(), info);
p.sendMessage(MsgUtil.p("how-much-to-trade-for", Util.getName(info.getItem()))); p.sendMessage(MsgUtil.p("how-much-to-trade-for", Util.getName(info.getItem())));
} }
} }
@EventHandler @EventHandler
public void onItemClick(final InventoryClickEvent e) { public void onItemClick(final InventoryClickEvent e) {
final Player p = (Player) e.getWhoClicked();
final ItemStack ci = e.getCurrentItem(); final ItemStack ci = e.getCurrentItem();
final Inventory inv = e.getInventory();
final int solt = e.getSlot();
try {
if (MarkUtil.hasMark(ci)) {
inv.setItem(solt, new ItemStack(Material.AIR));
p.chat("§c非法获取快捷商店悬浮物品 已清理...");
}
} catch (final Exception ex) {
}
}
@EventHandler
public void onItemMove(final InventoryMoveItemEvent e) {
final ItemStack ci = e.getItem();
if (MarkUtil.hasMark(ci)) { if (MarkUtil.hasMark(ci)) {
ci.setType(Material.AIR); e.setItem(new ItemStack(Material.AIR));
e.setCancelled(true);
} }
} }
@ -160,7 +164,7 @@ public class PlayerListener implements Listener {
if (e.isCancelled()) { if (e.isCancelled()) {
return; return;
} }
final Info info = plugin.getShopManager().getActions().get(e.getPlayer().getUniqueId()); final Info info = plugin.getShopManager().getActions().get(e.getPlayer().getName());
if (info != null) { if (info != null) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final Location loc1 = info.getLocation(); final Location loc1 = info.getLocation();
@ -171,7 +175,7 @@ public class PlayerListener implements Listener {
} else if (info.getAction() == ShopAction.BUY) { } else if (info.getAction() == ShopAction.BUY) {
p.sendMessage(MsgUtil.p("shop-purchase-cancelled")); p.sendMessage(MsgUtil.p("shop-purchase-cancelled"));
} }
plugin.getShopManager().getActions().remove(p.getUniqueId()); plugin.getShopManager().getActions().remove(p.getName());
return; return;
} }
} }
@ -180,13 +184,15 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onPlayerPickup(final PlayerPickupItemEvent e) { public void onPlayerPickup(final PlayerPickupItemEvent e) {
final ItemStack ci = e.getItem().getItemStack(); final ItemStack ci = e.getItem().getItemStack();
e.setCancelled(!MarkUtil.hasMark(ci)); if (MarkUtil.hasMark(ci)) {
e.setCancelled(true);
}
} }
@EventHandler @EventHandler
public void onPlayerQuit(final PlayerQuitEvent e) { public void onPlayerQuit(final PlayerQuitEvent e) {
// Remove them from the menu // Remove them from the menu
plugin.getShopManager().getActions().remove(e.getPlayer().getUniqueId()); plugin.getShopManager().getActions().remove(e.getPlayer().getName());
} }
@EventHandler @EventHandler

View File

@ -159,8 +159,8 @@ public class QuickShop extends JavaPlugin {
final EconomyCore core = new Economy_Vault(); final EconomyCore core = new Economy_Vault();
if (!core.isValid()) { if (!core.isValid()) {
// getLogger().severe("Economy is not valid!"); // getLogger().severe("Economy is not valid!");
getLogger().severe("QuickShop could not hook an economy!"); getLogger().warning("无法找到经济管理类插件...");
getLogger().severe("QuickShop CANNOT start!"); getLogger().warning("卸载插件!!!");
this.getPluginLoader().disablePlugin(this); this.getPluginLoader().disablePlugin(this);
// if(econ.equals("Vault")) // if(econ.equals("Vault"))
// getLogger().severe("(Does Vault have an Economy to hook into?!)"); // getLogger().severe("(Does Vault have an Economy to hook into?!)");
@ -283,7 +283,7 @@ public class QuickShop extends JavaPlugin {
int count = 0; // Shops count int count = 0; // Shops count
Connection con; Connection con;
try { try {
getLogger().info("从数据载入商店数据..."); getLogger().info("从数据载入商店数据...");
con = database.getConnection(); con = database.getConnection();
final PreparedStatement ps = con.prepareStatement("SELECT * FROM shops"); final PreparedStatement ps = con.prepareStatement("SELECT * FROM shops");
final ResultSet rs = ps.executeQuery(); final ResultSet rs = ps.executeQuery();

View File

@ -638,13 +638,13 @@ public class ContainerShop implements Shop {
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder( final StringBuilder sb = new StringBuilder(
"Shop " + (loc.getWorld() == null ? "unloaded world" : loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ")"); "商店 " + (loc.getWorld() == null ? "世界尚未载入" : "坐标: " + loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ")");
sb.append(" Owner: " + getOwner().toString()); sb.append(" 所有者: " + getOwner());
if (isUnlimited()) { if (isUnlimited()) {
sb.append(" Unlimited: true"); sb.append("无限模式: true");
} }
sb.append(" Price: " + getPrice()); sb.append("价格: " + getPrice());
sb.append("Item: " + getItem().toString()); sb.append("物品: " + getItem().toString());
return sb.toString(); return sb.toString();
} }
@ -660,7 +660,7 @@ public class ContainerShop implements Shop {
final int unlimited = this.isUnlimited() ? 1 : 0; final int unlimited = this.isUnlimited() ? 1 : 0;
final String q = "UPDATE shops SET owner = ?, itemConfig = ?, unlimited = ?, type = ?, price = ? WHERE x = ? AND y = ? and z = ? and world = ?"; final String q = "UPDATE shops SET owner = ?, itemConfig = ?, unlimited = ?, type = ?, price = ? WHERE x = ? AND y = ? and z = ? and world = ?";
try { try {
plugin.getDB().execute(q, this.getOwner().toString(), Util.serialize(this.getItem()), unlimited, shopType.toID(), this.getPrice(), x, y, z, world); plugin.getDB().execute(q, this.getOwner(), Util.serialize(this.getItem()), unlimited, shopType.toID(), this.getPrice(), x, y, z, world);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("Could not update shop in database! Changes will revert after a reboot!"); System.out.println("Could not update shop in database! Changes will revert after a reboot!");

View File

@ -3,7 +3,6 @@ package org.maxgamer.QuickShop.Shop;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -90,7 +89,7 @@ public class ShopManager {
} }
private final QuickShop plugin; private final QuickShop plugin;
private final HashMap<UUID, Info> actions = new HashMap<UUID, Info>(); private final HashMap<String, Info> actions = new HashMap<String, Info>();
private final HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> shops = new HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>>(); private final HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> shops = new HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>>();
@ -113,13 +112,13 @@ public class ShopManager {
int owned = 0; int owned = 0;
final Iterator<Shop> it = getShopIterator(); final Iterator<Shop> it = getShopIterator();
while (it.hasNext()) { while (it.hasNext()) {
if (it.next().getOwner().equals(p.getUniqueId())) { if (it.next().getOwner().equals(p.getName())) {
owned++; owned++;
} }
} }
final int max = plugin.getShopLimit(p); final int max = plugin.getShopLimit(p);
if (owned + 1 > max) { if (owned + 1 > max) {
p.sendMessage(ChatColor.RED + "You have already created a maximum of " + owned + "/" + max + " shops!"); p.sendMessage(ChatColor.RED + "您已经创建了 " + owned + "/" + max + " 个商店!");
return false; return false;
} }
} }
@ -171,8 +170,9 @@ public class ShopManager {
// Add it to the world // Add it to the world
addShop(loc.getWorld().getName(), shop); addShop(loc.getWorld().getName(), shop);
} catch (final Exception e) { } catch (final Exception e) {
plugin.getLogger().warning("无法保存商店到数据库! 下次重启商店将会消失!");
plugin.getLogger().warning("错误信息: " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
System.out.println("Could not create shop! Changes will revert after a reboot!");
} }
} }
@ -184,7 +184,7 @@ public class ShopManager {
* @return Returns the HashMap<Player name, shopInfo>. Info contains what * @return Returns the HashMap<Player name, shopInfo>. Info contains what
* their last question etc was. * their last question etc was.
*/ */
public HashMap<UUID, Info> getActions() { public HashMap<String, Info> getActions() {
return this.actions; return this.actions;
} }
@ -273,9 +273,9 @@ public class ShopManager {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void run() { public void run() {
final HashMap<UUID, Info> actions = getActions(); final HashMap<String, Info> actions = getActions();
// They wanted to do something. // They wanted to do something.
final Info info = actions.remove(p.getUniqueId()); final Info info = actions.remove(p.getName());
if (info == null) { if (info == null) {
return; // multithreaded means this can happen return; // multithreaded means this can happen
} }
@ -323,26 +323,25 @@ public class ShopManager {
} }
// Create the sample shop. // Create the sample shop.
final Shop shop = new ContainerShop(info.getLocation(), price, info.getItem(), p.getName()); final Shop shop = new ContainerShop(info.getLocation(), price, info.getItem(), p.getName());
shop.onLoad();
final ShopCreateEvent e = new ShopCreateEvent(shop, p);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
shop.onUnload();
return;
}
// This must be called after the event has been called. // This must be called after the event has been called.
// Else, if the event is cancelled, they won't get their // Else, if the event is cancelled, they won't get their
// money back. // money back.
if (tax != 0) { if (tax != 0) {
if (!plugin.getEcon().withdraw(p.getName(), tax)) { if (!plugin.getEcon().withdraw(p.getName(), tax)) {
p.sendMessage(MsgUtil.p("you-cant-afford-a-new-shop", format(tax))); p.sendMessage(MsgUtil.p("you-cant-afford-a-new-shop", format(tax)));
shop.onUnload();
return; return;
} }
plugin.getEcon().deposit(plugin.getConfig().getString("tax-account"), tax); plugin.getEcon().deposit(plugin.getConfig().getString("tax-account"), tax);
} }
final ShopCreateEvent e = new ShopCreateEvent(shop, p);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
return;
}
shop.onLoad();
/* The shop has hereforth been successfully created */ /* The shop has hereforth been successfully created */
createShop(shop); createShop(shop);
p.sendMessage(MsgUtil.p("success-created-shop"));
final Location loc = shop.getLocation(); final Location loc = shop.getLocation();
plugin.log(p.getName() + " created a " + shop.getDataName() + " shop at (" + loc.getWorld().getName() + " - " + loc.getX() + "," + loc.getY() + "," + loc.getZ() + ")"); plugin.log(p.getName() + " created a " + shop.getDataName() + " shop at (" + loc.getWorld().getName() + " - " + loc.getX() + "," + loc.getY() + "," + loc.getZ() + ")");
if (!plugin.getConfig().getBoolean("shop.lock")) { if (!plugin.getConfig().getBoolean("shop.lock")) {
@ -363,34 +362,6 @@ public class ShopManager {
sign.setFacingDirection(bf); sign.setFacingDirection(bf);
bs.update(true); bs.update(true);
shop.setSignText(); shop.setSignText();
/*
* Block b = shop.getLocation().getBlock();
* ItemFrame iFrame = (ItemFrame)
* b.getWorld().spawnEntity(b.getLocation(),
* EntityType.ITEM_FRAME);
*
* BlockFace[] faces = new
* BlockFace[]{BlockFace.NORTH, BlockFace.EAST,
* BlockFace.SOUTH, BlockFace.WEST}; for(BlockFace
* face : faces){ if(face == bf) continue; //This is
* the sign's location iFrame.setFacingDirection(bf,
* true); //iFrame.setItem(shop.getItem());
* ItemStack iStack = shop.getItem().clone();
* iStack.setAmount(0); iFrame.setItem(iStack); /*
* Field handleField =
* iFrame.getClass().getField("entity");
* handleField.setAccessible(true); Object handle =
* handleField.get(iFrame);
*
* ItemStack bukkitStack = shop.getItem();
*
* Field itemStackHandle =
*
* Method setItemStack =
* handle.getClass().getMethod("a", Object.class);
* setItemStack.
*/
// }
} }
if (shop instanceof ContainerShop) { if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop; final ContainerShop cs = (ContainerShop) shop;
@ -456,7 +427,7 @@ public class ShopManager {
return; // Cancelled return; // Cancelled
} }
// Money handling // Money handling
if (!p.getUniqueId().equals(shop.getOwner())) { if (!p.getName().equals(shop.getOwner())) {
// Check their balance. Works with *most* economy // Check their balance. Works with *most* economy
// plugins* // plugins*
if (plugin.getEcon().getBalance(p.getName()) < amount * shop.getPrice()) { if (plugin.getEcon().getBalance(p.getName()) < amount * shop.getPrice()) {
@ -468,7 +439,7 @@ public class ShopManager {
// Do charge an amount of tax though. // Do charge an amount of tax though.
final double tax = plugin.getConfig().getDouble("tax"); final double tax = plugin.getConfig().getDouble("tax");
final double total = amount * shop.getPrice(); final double total = amount * shop.getPrice();
if (!plugin.getEcon().withdraw(p.getUniqueId(), total)) { if (!plugin.getEcon().withdraw(p.getName(), total)) {
p.sendMessage(MsgUtil.p("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEcon().getBalance(p.getName())))); p.sendMessage(MsgUtil.p("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEcon().getBalance(p.getName()))));
return; return;
} }
@ -521,7 +492,7 @@ public class ShopManager {
return; return;
} }
// Money handling // Money handling
if (!p.getUniqueId().equals(shop.getOwner())) { if (!p.getName().equals(shop.getOwner())) {
// Don't tax them if they're purchasing from // Don't tax them if they're purchasing from
// themselves. // themselves.
// Do charge an amount of tax though. // Do charge an amount of tax though.

View File

@ -4,17 +4,13 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop; import org.maxgamer.QuickShop.Shop.Shop;
@ -35,7 +31,7 @@ public class MsgUtil {
* on space. * on space.
*/ */
public static void clean() { public static void clean() {
System.out.println("Cleaning purchase messages from database that are over a week old..."); System.out.println("清理超过 一周 的 商店交易记录...");
// 604800,000 msec = 1 week. // 604800,000 msec = 1 week.
final long weekAgo = System.currentTimeMillis() - 604800000; final long weekAgo = System.currentTimeMillis() - 604800000;
plugin.getDB().execute("DELETE FROM messages WHERE time < ?", weekAgo); plugin.getDB().execute("DELETE FROM messages WHERE time < ?", weekAgo);
@ -139,38 +135,8 @@ public class MsgUtil {
public static void sendPurchaseSuccess(final Player p, final Shop shop, final int amount) { public static void sendPurchaseSuccess(final Player p, final Shop shop, final int amount) {
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.successful-purchase")); p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.successful-purchase"));
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item-name-and-price", "" + amount, shop.getDataName(), Util.format((amount * shop.getPrice())))); final FancyMessage fm = new FancyMessage();
Map<Enchantment, Integer> enchs = shop.getItem().getItemMeta().getEnchants(); fm.text(ChatColor.DARK_PURPLE + "| ").then(MsgUtil.p("menu.item-name-and-price", "" + amount, shop.getDataName(), Util.format((amount * shop.getPrice())))).itemTooltip(shop.getItem()).send(p);
if (enchs != null && !enchs.isEmpty()) {
p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.p("menu.enchants") + "-----------------------+");
for (final Entry<Enchantment, Integer> entries : enchs.entrySet()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey().getName() + " " + entries.getValue());
}
}
enchs = shop.getItem().getItemMeta().getEnchants();
if (enchs != null && !enchs.isEmpty()) {
p.sendMessage(ChatColor.DARK_PURPLE + "+-----------------" + MsgUtil.p("menu.stored-enchants") + "--------------------+");
for (final Entry<Enchantment, Integer> entries : enchs.entrySet()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey().getName() + " " + entries.getValue());
}
}
try {
Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta");
if (shop.getItem().getItemMeta() instanceof EnchantmentStorageMeta) {
final EnchantmentStorageMeta stor = (EnchantmentStorageMeta) shop.getItem().getItemMeta();
stor.getStoredEnchants();
enchs = stor.getStoredEnchants();
if (enchs != null && !enchs.isEmpty()) {
p.sendMessage(ChatColor.DARK_PURPLE + "+-----------------" + MsgUtil.p("menu.stored-enchants") + "--------------------+");
for (final Entry<Enchantment, Integer> entries : enchs.entrySet()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey().getName() + " " + entries.getValue());
}
}
}
} catch (final ClassNotFoundException e) {
// They don't have an up to date enough build of CB to do this.
// TODO: Remove this when it becomes redundant
}
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
} }
@ -189,30 +155,6 @@ public class MsgUtil {
} }
} }
} }
Map<Enchantment, Integer> enchs = shop.getItem().getItemMeta().getEnchants();
if (enchs != null && !enchs.isEmpty()) {
p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.p("menu.enchants") + "-----------------------+");
for (final Entry<Enchantment, Integer> entries : enchs.entrySet()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey().getName() + " " + entries.getValue());
}
}
try {
Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta");
if (shop.getItem().getItemMeta() instanceof EnchantmentStorageMeta) {
final EnchantmentStorageMeta stor = (EnchantmentStorageMeta) shop.getItem().getItemMeta();
stor.getStoredEnchants();
enchs = stor.getStoredEnchants();
if (enchs != null && !enchs.isEmpty()) {
p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.p("menu.stored-enchants") + "-----------------------+");
for (final Entry<Enchantment, Integer> entries : enchs.entrySet()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey().getName() + " " + entries.getValue());
}
}
}
} catch (final ClassNotFoundException e) {
// They don't have an up to date enough build of CB to do this.
// TODO: Remove this when it becomes redundant
}
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
} }

View File

@ -127,7 +127,7 @@ public class Util {
try { try {
return plugin.getEcon().format(n); return plugin.getEcon().format(n);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
return "$" + n; return "" + n;
} }
} }

View File

@ -1,4 +1,5 @@
version: 1.2 Version: 1.0
AIR_-1: 爪子 AIR_-1: 爪子
AIR: 爪子 AIR: 爪子
STONE: 石头 STONE: 石头

View File

@ -1,6 +1,7 @@
# Colors: # Colors:
# &0-9, &a-f # &0-9, &a-f
# {0}, {1}, {2}, etc are variables. You can swap them around, but adding a new variable won't work. Removing them will work # {0}, {1}, {2}, etc are variables. You can swap them around, but adding a new variable won't work. Removing them will work
Version: 1.0
not-looking-at-shop: "&c没找到快捷商店. 你必须看着那个箱子." not-looking-at-shop: "&c没找到快捷商店. 你必须看着那个箱子."
no-permission: "&4你没有此命令的权限." no-permission: "&4你没有此命令的权限."
@ -43,14 +44,14 @@ empty-success: "&a库存清理成功"
menu: menu:
successful-purchase: "&a商品购买成功:" successful-purchase: "&a商品购买成功:"
successfully-sold: "&a商品出售成功:" successfully-sold: "&a商品出售成功:"
item-name-and-price: "&a花费&e{2} &a获得 &e{0} &a件 &e{1} &a商品" item-name-and-price: "&a花费&e{2} &a获得 &e{0} &a件 &e{1}&b(查看详情) &a商品"
shop-information: "&a商店信息:" shop-information: "&a商店信息:"
owner: "&a所有者: {0}" owner: "&a所有者: {0}"
item: "&a物品: &e{0}" item: "&a物品: &e{0} &b(查看详情)"
space: "&aSpace: &e{0}" space: "&aSpace: &e{0}"
stock: "&a库存 &e{0}" stock: "&a库存: &e{0}"
price-per: "&a每件 &e{0} 的价格 &a为 &e{1}" price-per: "&a单价: &e{1}元"
total-value-of-chest: "&a所有存货总价格: &c{0}元" total-value-of-chest: "&a所有存货总价格: &c{0}元"
damage-percent-remaining: "&a耐久剩余: &e{0}% ." damage-percent-remaining: "&a耐久剩余: &e{0}% ."
this-shop-is-buying: "&a此商店只 &d购买&a 物品." this-shop-is-buying: "&a此商店只 &d购买&a 物品."