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:
parent
a545a62ef0
commit
b4623befa9
@ -162,23 +162,31 @@ public class PlayerListener implements Listener {
|
|||||||
final Block attached = Util.getAttached(b);
|
final Block attached = Util.getAttached(b);
|
||||||
final Shop shop = attached == null ? null : plugin.getShopManager().getShop(attached.getLocation());
|
final Shop shop = attached == null ? null : plugin.getShopManager().getShop(attached.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
|
final Location loc = shop.getLocation();
|
||||||
|
String shopmode = "";
|
||||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
if (p.hasPermission("quickshop.unlimited")) {
|
if (p.hasPermission("quickshop.unlimited")) {
|
||||||
shop.setUnlimited(!shop.isUnlimited());
|
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;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (shop.getShopType() == ShopType.BUYING && p.hasPermission("quickshop.create.sell")) {
|
if (shop.getShopType() == ShopType.BUYING && p.hasPermission("quickshop.create.sell")) {
|
||||||
shop.setShopType(ShopType.SELLING);
|
shop.setShopType(ShopType.SELLING);
|
||||||
p.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
|
p.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
|
||||||
|
shopmode = "出售模式";
|
||||||
return;
|
return;
|
||||||
} else if (shop.getShopType() == ShopType.SELLING && p.hasPermission("quickshop.create.buy")) {
|
} else if (shop.getShopType() == ShopType.SELLING && p.hasPermission("quickshop.create.buy")) {
|
||||||
shop.setShopType(ShopType.BUYING);
|
shop.setShopType(ShopType.BUYING);
|
||||||
p.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
|
p.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
|
||||||
|
shopmode = "收购模式";
|
||||||
return;
|
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.setSignText();
|
||||||
shop.update();
|
shop.update();
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,16 @@ public class ShopManager {
|
|||||||
try {
|
try {
|
||||||
// Write it to the database
|
// Write it to the database
|
||||||
final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
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(),
|
plugin.getDB().execute(q,
|
||||||
(shop.isUnlimited() ? 1 : 0), shop.getShopType().toID());
|
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
|
// Add it to the world
|
||||||
addShop(loc.getWorld().getName(), shop);
|
addShop(loc.getWorld().getName(), shop);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
@ -279,7 +287,7 @@ public class ShopManager {
|
|||||||
createShop(shop);
|
createShop(shop);
|
||||||
p.sendMessage(MsgUtil.p("success-created-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(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")) {
|
if (!plugin.getConfig().getBoolean("shop.lock")) {
|
||||||
// Warn them if they haven't been warned since
|
// Warn them if they haven't been warned since
|
||||||
// reboot
|
// reboot
|
||||||
@ -390,14 +398,20 @@ public class ShopManager {
|
|||||||
if (plugin.getConfigManager().isShowTax()) {
|
if (plugin.getConfigManager().isShowTax()) {
|
||||||
String msg = MsgUtil.p("player-bought-from-your-store-tax", p.getName(), "" + amount, shop.getDataName(), Util.format((tax * total)));
|
String msg = MsgUtil.p("player-bought-from-your-store-tax", p.getName(), "" + amount, shop.getDataName(), Util.format((tax * total)));
|
||||||
if (stock == amount) {
|
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());
|
shop.getDataName());
|
||||||
}
|
}
|
||||||
MsgUtil.send(shop.getOwner(), msg);
|
MsgUtil.send(shop.getOwner(), msg);
|
||||||
} else {
|
} else {
|
||||||
String msg = MsgUtil.p("player-bought-from-your-store", p.getName(), "" + amount, shop.getDataName());
|
String msg = MsgUtil.p("player-bought-from-your-store", p.getName(), "" + amount, shop.getDataName());
|
||||||
if (stock == amount) {
|
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());
|
shop.getDataName());
|
||||||
}
|
}
|
||||||
MsgUtil.send(shop.getOwner(), msg);
|
MsgUtil.send(shop.getOwner(), msg);
|
||||||
@ -406,7 +420,7 @@ public class ShopManager {
|
|||||||
// Transfers the item from A to B
|
// Transfers the item from A to B
|
||||||
shop.sell(p, amount);
|
shop.sell(p, amount);
|
||||||
MsgUtil.sendPurchaseSuccess(p, shop, 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()) {
|
} else if (shop.isBuying()) {
|
||||||
final int space = shop.getRemainingSpace();
|
final int space = shop.getRemainingSpace();
|
||||||
if (space < amount) {
|
if (space < amount) {
|
||||||
@ -462,7 +476,7 @@ public class ShopManager {
|
|||||||
}
|
}
|
||||||
shop.buy(p, amount);
|
shop.buy(p, amount);
|
||||||
MsgUtil.sendSellSuccess(p, shop, 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
|
shop.setSignText(); // Update the signs count
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package org.maxgamer.QuickShop.Util;
|
package org.maxgamer.QuickShop.Util;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -10,43 +7,9 @@ public class NMS {
|
|||||||
|
|
||||||
public static void safeGuard(final Item item) throws ClassNotFoundException {
|
public static void safeGuard(final Item item) throws ClassNotFoundException {
|
||||||
rename(item.getItemStack());
|
rename(item.getItemStack());
|
||||||
protect(item);
|
|
||||||
item.setPickupDelay(2147483647);
|
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) {
|
private static void rename(final ItemStack iStack) {
|
||||||
MarkUtil.addMark(iStack);
|
MarkUtil.addMark(iStack);
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,10 @@ public class LogWatcher implements Runnable {
|
|||||||
this.ps = new PrintStream(fos);
|
this.ps = new PrintStream(fos);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
plugin.getLogger().severe("Log file not found!");
|
plugin.getLogger().severe("日志文件未找到!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
plugin.getLogger().severe("Could not create log file!");
|
plugin.getLogger().severe("无法创建日志文件!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user