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

add log create and change shop type...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-10-28 10:49:00 +08:00
parent a545a62ef0
commit b4623befa9
4 changed files with 33 additions and 48 deletions

View File

@ -162,23 +162,31 @@ public class PlayerListener implements Listener {
final Block attached = Util.getAttached(b);
final Shop shop = attached == null ? null : plugin.getShopManager().getShop(attached.getLocation());
if (shop != null) {
final Location loc = shop.getLocation();
String shopmode = "";
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (p.hasPermission("quickshop.unlimited")) {
shop.setUnlimited(!shop.isUnlimited());
p.sendMessage(MsgUtil.p("command.toggle-unlimited", (shop.isUnlimited() ? "§e无限模式" : "§c有限模式")));
shopmode = shop.isUnlimited() ? "§e无限模式" : "§c有限模式";
p.sendMessage(MsgUtil.p("command.toggle-unlimited", shopmode));
return;
}
} else {
if (shop.getShopType() == ShopType.BUYING && p.hasPermission("quickshop.create.sell")) {
shop.setShopType(ShopType.SELLING);
p.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
shopmode = "出售模式";
return;
} else if (shop.getShopType() == ShopType.SELLING && p.hasPermission("quickshop.create.buy")) {
shop.setShopType(ShopType.BUYING);
p.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
shopmode = "收购模式";
return;
}
}
if (!shopmode.isEmpty()) {
plugin.log(String.format("玩家: %s 将 %s(%s,%s,%s) 的商店切换为 %s !", p.getName(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), shopmode));
}
shop.setSignText();
shop.update();
}

View File

@ -101,8 +101,16 @@ public class ShopManager {
try {
// Write it to the database
final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
plugin.getDB().execute(q, shop.getOwner().toString(), shop.getPrice(), Util.serialize(item), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getWorld().getName(),
(shop.isUnlimited() ? 1 : 0), shop.getShopType().toID());
plugin.getDB().execute(q,
shop.getOwner().toString(),
shop.getPrice(),
Util.serialize(item),
loc.getBlockX(),
loc.getBlockY(),
loc.getBlockZ(),
loc.getWorld().getName(),
(shop.isUnlimited() ? 1 : 0),
shop.getShopType().toID());
// Add it to the world
addShop(loc.getWorld().getName(), shop);
} catch (final Exception e) {
@ -279,7 +287,7 @@ public class ShopManager {
createShop(shop);
p.sendMessage(MsgUtil.p("success-created-shop"));
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(String.format("玩家: %s 创建了一个 %s 商店 在 (%s - %s,%s,%s)", p.getName(), shop.getDataName(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ()));
if (!plugin.getConfig().getBoolean("shop.lock")) {
// Warn them if they haven't been warned since
// reboot
@ -390,14 +398,20 @@ public class ShopManager {
if (plugin.getConfigManager().isShowTax()) {
String msg = MsgUtil.p("player-bought-from-your-store-tax", p.getName(), "" + amount, shop.getDataName(), Util.format((tax * total)));
if (stock == amount) {
msg += "\n" + MsgUtil.p("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(),
msg += "\n" + MsgUtil.p("shop-out-of-stock",
"" + shop.getLocation().getBlockX(),
"" + shop.getLocation().getBlockY(),
"" + shop.getLocation().getBlockZ(),
shop.getDataName());
}
MsgUtil.send(shop.getOwner(), msg);
} else {
String msg = MsgUtil.p("player-bought-from-your-store", p.getName(), "" + amount, shop.getDataName());
if (stock == amount) {
msg += "\n" + MsgUtil.p("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(),
msg += "\n" + MsgUtil.p("shop-out-of-stock",
"" + shop.getLocation().getBlockX(),
"" + shop.getLocation().getBlockY(),
"" + shop.getLocation().getBlockZ(),
shop.getDataName());
}
MsgUtil.send(shop.getOwner(), msg);
@ -406,7 +420,7 @@ public class ShopManager {
// Transfers the item from A to B
shop.sell(p, amount);
MsgUtil.sendPurchaseSuccess(p, shop, amount);
plugin.log(String.format("%s 从 %s 购买了 %s 件商品 花费 %s", p.getName(), shop.toString(), amount, shop.getPrice() * amount));
plugin.log(String.format("玩家: %s 从 %s 购买了 %s 件商品 花费 %s", p.getName(), shop.toString(), amount, shop.getPrice() * amount));
} else if (shop.isBuying()) {
final int space = shop.getRemainingSpace();
if (space < amount) {
@ -462,7 +476,7 @@ public class ShopManager {
}
shop.buy(p, amount);
MsgUtil.sendSellSuccess(p, shop, amount);
plugin.log(String.format("%s 出售了 %s 件商品 到 %s 获得 %s", p.getName(), amount, shop.toString(), shop.getPrice() * amount));
plugin.log(String.format("玩家: %s 出售了 %s 件商品 到 %s 获得 %s", p.getName(), amount, shop.toString(), shop.getPrice() * amount));
}
shop.setSignText(); // Update the signs count
}

View File

@ -1,8 +1,5 @@
package org.maxgamer.QuickShop.Util;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
@ -10,43 +7,9 @@ public class NMS {
public static void safeGuard(final Item item) throws ClassNotFoundException {
rename(item.getItemStack());
protect(item);
item.setPickupDelay(2147483647);
}
private static void protect(final Item item) {
try {
final Field itemField = item.getClass().getDeclaredField("item");
itemField.setAccessible(true);
final Object nmsEntityItem = itemField.get(item);
Method getItemStack;
try {
getItemStack = nmsEntityItem.getClass().getMethod("getItemStack", new Class[0]);
} catch (final NoSuchMethodException e) {
try {
getItemStack = nmsEntityItem.getClass().getMethod("d", new Class[0]);
} catch (final NoSuchMethodException e2) {
return;
}
}
final Object itemStack = getItemStack.invoke(nmsEntityItem, new Object[0]);
Field countField;
try {
countField = itemStack.getClass().getDeclaredField("count");
} catch (final NoSuchFieldException e) {
countField = itemStack.getClass().getDeclaredField("a");
}
countField.setAccessible(true);
countField.set(itemStack, Integer.valueOf(1));
} catch (final NoSuchFieldException e) {
e.printStackTrace();
System.out.println("[QuickShop] Could not protect item from pickup properly! Dupes are now possible.");
} catch (final Exception e) {
System.out.println("Other error");
e.printStackTrace();
}
}
private static void rename(final ItemStack iStack) {
MarkUtil.addMark(iStack);
}

View File

@ -24,13 +24,13 @@ public class LogWatcher implements Runnable {
this.ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
plugin.getLogger().severe("Log file not found!");
plugin.getLogger().severe("日志文件未找到!");
} catch (IOException e) {
e.printStackTrace();
plugin.getLogger().severe("Could not create log file!");
plugin.getLogger().severe("无法创建日志文件!");
}
}
@Override
public void run() {
synchronized (logs) {