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

fix: 修复爆炸破坏木牌的问题

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-11-11 17:44:50 +08:00
parent 16571a6035
commit b110da8f73
8 changed files with 125 additions and 143 deletions

View File

@ -24,6 +24,7 @@ import pw.yumc.YumCore.commands.CommandManager;
import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Cmd.Executor; import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
import pw.yumc.YumCore.commands.annotation.Help; import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.commands.annotation.Sort;
import pw.yumc.YumCore.commands.interfaces.CommandExecutor; import pw.yumc.YumCore.commands.interfaces.CommandExecutor;
import pw.yumc.YumCore.commands.interfaces.CommandHelpParse; import pw.yumc.YumCore.commands.interfaces.CommandHelpParse;
@ -38,12 +39,14 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
new CommandManager("qs", this).setHelpParse(this); new CommandManager("qs", this).setHelpParse(this);
} }
@Sort(1)
@Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Executor.PLAYER) @Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Executor.PLAYER)
@Help("command.description.buy") @Help("command.description.buy")
public void buy(Player player) { public void buy(Player player) {
changeShopType(player, ShopType.BUYING); changeShopType(player, ShopType.BUYING);
} }
@Sort(7)
@Cmd(aliases = "c", permission = "quickshop.clean") @Cmd(aliases = "c", permission = "quickshop.clean")
@Help("command.description.clean") @Help("command.description.clean")
public void clean(CommandSender sender) { public void clean(CommandSender sender) {
@ -69,6 +72,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i)); sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
} }
@Sort(5)
@Cmd(aliases = "e", permission = "quickshop.empty", executor = Executor.PLAYER) @Cmd(aliases = "e", permission = "quickshop.empty", executor = Executor.PLAYER)
@Help("command.description.empty") @Help("command.description.empty")
public void empty(Player player) { public void empty(Player player) {
@ -137,7 +141,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
} }
} }
@Cmd(aliases = "f", minimumArguments = 2, permission = "quickshop.find", executor = Executor.PLAYER) @Cmd(aliases = "f", minimumArguments = 1, permission = "quickshop.find", executor = Executor.PLAYER)
@Help("command.description.find") @Help("command.description.find")
public void find(Player p, String lookFor) { public void find(Player p, String lookFor) {
lookFor = lookFor.toLowerCase(); lookFor = lookFor.toLowerCase();
@ -213,6 +217,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
return MsgUtil.p(str); return MsgUtil.p(str);
} }
@Sort(4)
@Cmd(aliases = "p", minimumArguments = 1, permission = "quickshop.create.changeprice", executor = Executor.PLAYER) @Cmd(aliases = "p", minimumArguments = 1, permission = "quickshop.create.changeprice", executor = Executor.PLAYER)
@Help(value = "command.description.price", possibleArguments = "<价格>") @Help(value = "command.description.price", possibleArguments = "<价格>")
public void price(Player sender, Double price) { public void price(Player sender, Double price) {
@ -275,6 +280,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
sender.sendMessage(MsgUtil.p("not-looking-at-shop")); sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
} }
@Sort(6)
@Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Executor.PLAYER) @Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Executor.PLAYER)
@Help(value = "command.description.refill", possibleArguments = "<数量>") @Help(value = "command.description.refill", possibleArguments = "<数量>")
public void refill(Player sender, Integer add) { public void refill(Player sender, Integer add) {
@ -300,6 +306,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
Bukkit.getPluginManager().enablePlugin(plugin); Bukkit.getPluginManager().enablePlugin(plugin);
} }
@Sort(6)
@Cmd(aliases = "r", permission = "quickshop.delete", executor = Executor.PLAYER) @Cmd(aliases = "r", permission = "quickshop.delete", executor = Executor.PLAYER)
@Help("command.description.remove") @Help("command.description.remove")
public void remove(Player p) { public void remove(Player p) {
@ -320,12 +327,14 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
p.sendMessage(ChatColor.RED + "未找到商店!"); p.sendMessage(ChatColor.RED + "未找到商店!");
} }
@Sort(2)
@Cmd(aliases = "s", permission = "quickshop.create.sell", executor = Executor.PLAYER) @Cmd(aliases = "s", permission = "quickshop.create.sell", executor = Executor.PLAYER)
@Help("command.description.sell") @Help("command.description.sell")
public void sell(Player player) { public void sell(Player player) {
changeShopType(player, ShopType.SELLING); changeShopType(player, ShopType.SELLING);
} }
@Sort(3)
@Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Executor.PLAYER) @Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Executor.PLAYER)
@Help("command.description.setowner") @Help("command.description.setowner")
public void setowner(CommandSender sender, String owner) { public void setowner(CommandSender sender, String owner) {
@ -343,6 +352,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
sender.sendMessage(MsgUtil.p("not-looking-at-shop")); sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
} }
@Sort(0)
@Cmd(permission = "quickshop.unlimited", executor = Executor.PLAYER) @Cmd(permission = "quickshop.unlimited", executor = Executor.PLAYER)
@Help("command.description.unlimited") @Help("command.description.unlimited")
public void unlimited(Player sender) { public void unlimited(Player sender) {

View File

@ -39,9 +39,7 @@ public class BlockListener implements Listener {
// If the shop was a chest // If the shop was a chest
if (b.getState() instanceof InventoryHolder) { if (b.getState() instanceof InventoryHolder) {
final Shop shop = plugin.getShopManager().getShop(b.getLocation()); final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) { if (shop == null) { return; }
return;
}
// If they're either survival or the owner, they can break it // If they're either survival or the owner, they can break it
final ItemStack pinh = p.getItemInHand(); final ItemStack pinh = p.getItemInHand();
if (p.getName().equals(shop.getOwner()) || p.getGameMode() == GameMode.SURVIVAL || pinh == null || pinh.getType() == plugin.getConfigManager().getSuperItem()) { if (p.getName().equals(shop.getOwner()) || p.getGameMode() == GameMode.SURVIVAL || pinh == null || pinh.getType() == plugin.getConfigManager().getSuperItem()) {
@ -55,13 +53,10 @@ public class BlockListener implements Listener {
} else { } else {
e.setCancelled(true); e.setCancelled(true);
p.sendMessage(MsgUtil.p("no-creative-break")); p.sendMessage(MsgUtil.p("no-creative-break"));
return;
} }
} else if (b.getType() == Material.WALL_SIGN) { } else if (b.getType() == Material.WALL_SIGN) {
final Shop shop = getShopNextTo(b.getLocation()); final Shop shop = getShopNextTo(b.getLocation());
if (shop == null) { if (shop == null) { return; }
return;
}
e.setCancelled(true); e.setCancelled(true);
} }
} }
@ -71,30 +66,29 @@ public class BlockListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onExplode(final EntityExplodeEvent e) { public void onExplode(final EntityExplodeEvent e) {
if (e.isCancelled()) { if (e.isCancelled()) { return; }
return;
}
for (int i = 0; i < e.blockList().size(); i++) { for (int i = 0; i < e.blockList().size(); i++) {
final Block b = e.blockList().get(i); Block b = e.blockList().get(i);
if (b.getType() == Material.WALL_SIGN) {
b = Util.getAttached(b);
}
if (b != null) {
final Shop shop = plugin.getShopManager().getShop(b.getLocation()); final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) { if (shop != null) {
shop.delete(); shop.delete();
} }
} }
} }
}
/** /**
* Listens for chest placement, so a doublechest shop can't be created. * Listens for chest placement, so a doublechest shop can't be created.
*/ */
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlace(final BlockPlaceEvent e) { public void onPlace(final BlockPlaceEvent e) {
if (e.isCancelled()) { if (e.isCancelled()) { return; }
return;
}
final BlockState bs = e.getBlock().getState(); final BlockState bs = e.getBlock().getState();
if (bs instanceof DoubleChest == false) { if (!(bs instanceof DoubleChest)) { return; }
return;
}
final Block b = e.getBlock(); final Block b = e.getBlock();
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final Block chest = Util.getSecondHalf(b); final Block chest = Util.getSecondHalf(b);
@ -114,9 +108,7 @@ public class BlockListener implements Listener {
private Shop getShopNextTo(final Location loc) { private Shop getShopNextTo(final Location loc) {
final Block b = Util.getAttached(loc.getBlock()); final Block b = Util.getAttached(loc.getBlock());
// Util.getAttached(b) // Util.getAttached(b)
if (b == null) { if (b == null) { return null; }
return null;
}
return plugin.getShopManager().getShop(b.getLocation()); return plugin.getShopManager().getShop(b.getLocation());
} }
} }

View File

@ -16,6 +16,9 @@ import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil; import org.maxgamer.QuickShop.Util.MsgUtil;
import org.maxgamer.QuickShop.Util.Util; import org.maxgamer.QuickShop.Util.Util;
import java.util.ArrayList;
import java.util.List;
public class LockListener implements Listener { public class LockListener implements Listener {
private final QuickShop plugin; private final QuickShop plugin;
@ -33,24 +36,18 @@ public class LockListener implements Listener {
// If the chest was a chest // If the chest was a chest
if (Util.canBeShop(b)) { if (Util.canBeShop(b)) {
final Shop shop = plugin.getShopManager().getShop(b.getLocation()); final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) { if (shop == null) { return; // Wasn't a shop
return; // Wasn't a shop
} }
// If they owned it or have bypass perms, they can destroy it // If they owned it or have bypass perms, they can destroy it
if (!shop.getOwner().equals(p.getName()) && !p.hasPermission("quickshop.other.destroy")) { if (!shop.getOwner().equals(p.getName()) && !p.hasPermission("quickshop.other.destroy")) {
e.setCancelled(true); e.setCancelled(true);
p.sendMessage(MsgUtil.p("no-permission")); p.sendMessage(MsgUtil.p("no-permission"));
return;
} }
} else if (b.getType() == Material.WALL_SIGN) { } else if (b.getType() == Material.WALL_SIGN) {
b = Util.getAttached(b); b = Util.getAttached(b);
if (b == null) { if (b == null) { return; }
return;
}
final Shop shop = plugin.getShopManager().getShop(b.getLocation()); final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) { if (shop == null) { return; }
return;
}
e.setCancelled(true); e.setCancelled(true);
} }
} }
@ -59,24 +56,13 @@ public class LockListener implements Listener {
public void onClick(final PlayerInteractEvent e) { public void onClick(final PlayerInteractEvent e) {
Block b = e.getClickedBlock(); Block b = e.getClickedBlock();
final Player p = e.getPlayer(); final Player p = e.getPlayer();
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) { return; // Didn't right click it, we dont care.
return; // Didn't right click it, we dont care.
} }
if (!Util.canBeShop(b)) { if (!Util.canBeShop(b)) { return; // Interacted with air
return; // Interacted with air
} }
Shop shop = plugin.getShopManager().getShop(b.getLocation()); Shop shop = plugin.getShopManager().getShop(b.getLocation());
// Make sure they're not using the non-shop half of a double chest. // Make sure they're not using the non-shop half of a double chest.
if (shop == null) { if (!hasSecondHalf(shop, b)) { return; }
b = Util.getSecondHalf(b);
if (b == null) {
return;
}
shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) {
return;
}
}
if (!shop.getOwner().equals(p.getName())) { if (!shop.getOwner().equals(p.getName())) {
if (p.hasPermission("quickshop.other.open")) { if (p.hasPermission("quickshop.other.open")) {
p.sendMessage(MsgUtil.p("bypassing-lock")); p.sendMessage(MsgUtil.p("bypassing-lock"));
@ -84,28 +70,62 @@ public class LockListener implements Listener {
} }
p.sendMessage(MsgUtil.p("that-is-locked")); p.sendMessage(MsgUtil.p("that-is-locked"));
e.setCancelled(true); e.setCancelled(true);
return;
} }
} }
public boolean hasSecondHalf(Shop shop, Block b) {
if (shop == null) {
b = Util.getSecondHalf(b);
if (b == null) { return false; }
shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) { return false; }
}
return true;
}
/** /**
* Handles shops breaking through explosions * Handles shops breaking through explosions
*/ */
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onExplode(final EntityExplodeEvent e) { public void onExplode(final EntityExplodeEvent e) {
if (e.isCancelled()) { if (e.isCancelled()) { return; }
return; List<Block> removed = new ArrayList<>();
}
for (int i = 0; i < e.blockList().size(); i++) { for (int i = 0; i < e.blockList().size(); i++) {
final Block b = e.blockList().get(i); Block b = e.blockList().get(i);
final Shop shop = plugin.getShopManager().getShop(b.getLocation()); Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) { if (shop != null) {
// ToDo: Shouldn't I be decrementing 1 here? Concurrency and removed.add(b);
// all.. } else if (b.getType() == Material.WALL_SIGN) {
e.blockList().remove(b); Block s = Util.getAttached(b);
if (s != null) {
shop = plugin.getShopManager().getShop(s.getLocation());
if (shop != null) {
removed.add(b);
} }
} }
} }
}
e.blockList().removeAll(removed);
// for (int i = 0; i < e.blockList().size(); i++) {
// Block b = e.blockList().get(i);
// if (b.getType() == Material.WALL_SIGN) {
// Block s = Util.getAttached(b);
// if (s != null) {
// final Shop shop = plugin.getShopManager().getShop(s.getLocation());
// if (shop != null) {
// // ToDo: Shouldn't I be decrementing 1 here? Concurrency and all..
// e.blockList().remove(b);
// e.blockList().remove(s);
// }
// }
// }
// final Shop shop = plugin.getShopManager().getShop(b.getLocation());
// if (shop != null) {
// // ToDo: Shouldn't I be decrementing 1 here? Concurrency and all..
// e.blockList().remove(b);
// }
// }
}
/** /**
* Handles hopper placement * Handles hopper placement
@ -114,36 +134,22 @@ public class LockListener implements Listener {
public void onPlace(final BlockPlaceEvent e) { public void onPlace(final BlockPlaceEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
try { try {
if (b.getType() != Material.HOPPER) { if (b.getType() != Material.HOPPER) { return; }
return;
}
} catch (final NoSuchFieldError er) { } catch (final NoSuchFieldError er) {
return; // Your server doesn't have hoppers return; // Your server doesn't have hoppers
} }
Block c = e.getBlockAgainst(); Block c = e.getBlockAgainst();
if (Util.canBeShop(c) == false) { if (!Util.canBeShop(c)) { return; }
return;
}
final Player p = e.getPlayer(); final Player p = e.getPlayer();
Shop shop = plugin.getShopManager().getShop(c.getLocation()); Shop shop = plugin.getShopManager().getShop(c.getLocation());
if (shop == null) { if (!hasSecondHalf(shop, b)) { return; }
c = Util.getSecondHalf(c); if (!p.getName().equals(shop.getOwner())) {
if (c == null) {
return; // You didn't place a hopper on a shop. Meh.
}
shop = plugin.getShopManager().getShop(c.getLocation());
if (shop == null) {
return;
}
}
if (p.getName().equals(shop.getOwner()) == false) {
if (p.hasPermission("quickshop.other.open")) { if (p.hasPermission("quickshop.other.open")) {
p.sendMessage(MsgUtil.p("bypassing-lock")); p.sendMessage(MsgUtil.p("bypassing-lock"));
return; return;
} }
p.sendMessage(MsgUtil.p("that-is-locked")); p.sendMessage(MsgUtil.p("that-is-locked"));
e.setCancelled(true); e.setCancelled(true);
return;
} }
} }
} }

View File

@ -1,7 +1,5 @@
package org.maxgamer.QuickShop.Listeners; package org.maxgamer.QuickShop.Listeners;
import java.util.HashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -27,6 +25,8 @@ import org.maxgamer.QuickShop.Shop.ShopType;
import org.maxgamer.QuickShop.Util.MsgUtil; import org.maxgamer.QuickShop.Util.MsgUtil;
import org.maxgamer.QuickShop.Util.Util; import org.maxgamer.QuickShop.Util.Util;
import java.util.HashMap;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
private final QuickShop plugin; private final QuickShop plugin;
@ -34,11 +34,12 @@ public class PlayerListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
@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
* item : Send creation menu Left click a SHOP chest : Send purchase menu * item : Send creation menu Left click a SHOP chest : Send purchase menu
*/ */
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onClick(final PlayerInteractEvent e) { public void onClick(final PlayerInteractEvent e) {
final Block b = e.getClickedBlock(); final Block b = e.getClickedBlock();
@ -71,7 +72,6 @@ public class PlayerListener implements Listener {
final HashMap<String, 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.getName(), info); actions.put(p.getName(), info);
return;
} }
// Handles creating shops // Handles creating shops
else if (shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE else if (shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE
@ -138,7 +138,6 @@ public class PlayerListener implements Listener {
p.sendMessage(MsgUtil.p("shop-purchase-cancelled")); p.sendMessage(MsgUtil.p("shop-purchase-cancelled"));
} }
plugin.getShopManager().getActions().remove(p.getName()); plugin.getShopManager().getActions().remove(p.getName());
return;
} }
} }
} }

View File

@ -61,8 +61,7 @@ public class ProtectListener implements Listener {
final Shop srcshop = getShop(src); final Shop srcshop = getShop(src);
final Shop meshop = getShop(me); final Shop meshop = getShop(me);
final Shop desshop = getShop(des); final Shop desshop = getShop(des);
if ((srcshop != null && meshop == null) || (meshop != null && desshop == null) if (srcshop != null && meshop == null || meshop != null && desshop == null || srcshop != null && srcshop.getOwner() != null && !srcshop.getOwner().equalsIgnoreCase(desshop.getOwner())) {
|| (srcshop != null && desshop != null && srcshop.getOwner() != null && !srcshop.getOwner().equalsIgnoreCase(desshop.getOwner()))) {
e.setCancelled(true); e.setCancelled(true);
} }
} }
@ -97,7 +96,7 @@ public class ProtectListener implements Listener {
sendWarning(p, ci, "§d§l获取"); sendWarning(p, ci, "§d§l获取");
p.closeInventory(); p.closeInventory();
} }
} catch (final Exception ex) { } catch (final Exception ignored) {
} }
} }

View File

@ -1,8 +1,5 @@
package org.maxgamer.QuickShop.Listeners; package org.maxgamer.QuickShop.Listeners;
import java.util.HashMap;
import java.util.Map.Entry;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -14,6 +11,9 @@ import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop; import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopChunk; import org.maxgamer.QuickShop.Shop.ShopChunk;
import java.util.HashMap;
import java.util.Map.Entry;
public class WorldListener implements Listener { public class WorldListener implements Listener {
QuickShop plugin; QuickShop plugin;
@ -32,16 +32,14 @@ public class WorldListener implements Listener {
*/ */
final World world = e.getWorld(); final World world = e.getWorld();
// New world data // New world data
final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = new HashMap<ShopChunk, HashMap<Location, Shop>>(1); final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = new HashMap<>(1);
// Old world data // Old world data
final HashMap<ShopChunk, HashMap<Location, Shop>> oldInWorld = plugin.getShopManager().getShops(world.getName()); final HashMap<ShopChunk, HashMap<Location, Shop>> oldInWorld = plugin.getShopManager().getShops(world.getName());
// Nothing in the old world, therefore we don't care. No locations to // Nothing in the old world, therefore we don't care. No locations to
// update. // update.
if (oldInWorld == null) { if (oldInWorld == null) { return; }
return;
}
for (final Entry<ShopChunk, HashMap<Location, Shop>> oldInChunk : oldInWorld.entrySet()) { for (final Entry<ShopChunk, HashMap<Location, Shop>> oldInChunk : oldInWorld.entrySet()) {
final HashMap<Location, Shop> inChunk = new HashMap<Location, Shop>(1); final HashMap<Location, Shop> inChunk = new HashMap<>(1);
// Put the new chunk were the old chunk was // Put the new chunk were the old chunk was
inWorld.put(oldInChunk.getKey(), inChunk); inWorld.put(oldInChunk.getKey(), inChunk);
for (final Entry<Location, Shop> entry : oldInChunk.getValue().entrySet()) { for (final Entry<Location, Shop> entry : oldInChunk.getValue().entrySet()) {

View File

@ -1,21 +1,20 @@
package org.maxgamer.QuickShop.Listeners; package org.maxgamer.QuickShop.Listeners;
import java.util.ArrayList; import io.github.Cnly.WowSuchCleaner.WowSuchCleaner.ItemPreCleanEvent;
import java.util.List;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.maxgamer.QuickShop.Util.MarkUtil; import org.maxgamer.QuickShop.Util.MarkUtil;
import io.github.Cnly.WowSuchCleaner.WowSuchCleaner.ItemPreCleanEvent; import java.util.ArrayList;
import java.util.List;
public class WowSuchCleanerListener implements Listener { public class WowSuchCleanerListener implements Listener {
@EventHandler @EventHandler
public void onWSCClear(final ItemPreCleanEvent e) { public void onWSCClear(final ItemPreCleanEvent e) {
final List<Item> clearList = new ArrayList<Item>(); final List<Item> clearList = new ArrayList<>();
final List<ItemStack> aucList = new ArrayList<ItemStack>(); final List<ItemStack> aucList = new ArrayList<>();
final List<Item> cleanList = e.getItemsToClean(); final List<Item> cleanList = e.getItemsToClean();
final List<ItemStack> acList = e.getItemsToAuction(); final List<ItemStack> acList = e.getItemsToAuction();
if (cleanList != null) { if (cleanList != null) {

View File

@ -1,11 +1,5 @@
package org.maxgamer.QuickShop.Util; package org.maxgamer.QuickShop.Util;
import java.text.DecimalFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -22,9 +16,14 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.bukkit.material.Sign; import org.bukkit.material.Sign;
import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.QuickShop;
import pw.yumc.YumCore.global.L10N; import pw.yumc.YumCore.global.L10N;
import java.text.DecimalFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class Util { public class Util {
private static HashSet<Material> blacklist = new HashSet<>(); private static HashSet<Material> blacklist = new HashSet<>();
@ -35,7 +34,7 @@ public class Util {
private static HashSet<Material> transparent = new HashSet<>(); private static HashSet<Material> transparent = new HashSet<>();
public static void addTransparentBlock(final Material m) { public static void addTransparentBlock(final Material m) {
if (transparent.add(m) == false) { if (!transparent.add(m)) {
System.out.println("已添加透明方块: " + m.toString()); System.out.println("已添加透明方块: " + m.toString());
} }
if (!m.isBlock()) { if (!m.isBlock()) {
@ -53,10 +52,7 @@ public class Util {
public static boolean canBeShop(final Block b) { public static boolean canBeShop(final Block b) {
try { try {
final BlockState bs = b.getState(); final BlockState bs = b.getState();
if (bs instanceof InventoryHolder == false) { return bs instanceof InventoryHolder && shoppables.contains(bs.getType());
return false;
}
return shoppables.contains(bs.getType());
} catch (final Exception e) { } catch (final Exception e) {
return false; return false;
} }
@ -110,14 +106,11 @@ public class Util {
public static ItemStack deserialize(final String config) throws InvalidConfigurationException { public static ItemStack deserialize(final String config) throws InvalidConfigurationException {
final YamlConfiguration cfg = new YamlConfiguration(); final YamlConfiguration cfg = new YamlConfiguration();
cfg.loadFromString(config); cfg.loadFromString(config);
final ItemStack stack = cfg.getItemStack("item"); return cfg.getItemStack("item");
return stack;
} }
public static String firstUppercase(final String string) { public static String firstUppercase(final String string) {
if (string.length() > 1) { if (string.length() > 1) { return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase(); }
return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase();
}
return string.toUpperCase(); return string.toUpperCase();
} }
@ -138,7 +131,7 @@ public class Util {
/** /**
* Fetches the block which the given sign is attached to * Fetches the block which the given sign is attached to
* *
* @param sign * @param b
* The sign which is attached * The sign which is attached
* @return The block the sign is attached to * @return The block the sign is attached to
*/ */
@ -162,8 +155,7 @@ public class Util {
* @return The human readable item name. * @return The human readable item name.
*/ */
public static String getName(final ItemStack i) { public static String getName(final ItemStack i) {
final String vanillaName = L10N.getItemName(i); return L10N.getItemName(i);
return vanillaName;
} }
// Let's make very long names shorter for our sign // Let's make very long names shorter for our sign
@ -184,18 +176,14 @@ public class Util {
* @return the block which is also a chest and connected to b. * @return the block which is also a chest and connected to b.
*/ */
public static Block getSecondHalf(final Block b) { public static Block getSecondHalf(final Block b) {
if (b.getType().toString().contains("CHEST") == false) { if (!b.getType().toString().contains("CHEST")) { return null; }
return null;
}
final Block[] blocks = new Block[4]; final Block[] blocks = new Block[4];
blocks[0] = b.getRelative(1, 0, 0); blocks[0] = b.getRelative(1, 0, 0);
blocks[1] = b.getRelative(-1, 0, 0); blocks[1] = b.getRelative(-1, 0, 0);
blocks[2] = b.getRelative(0, 0, 1); blocks[2] = b.getRelative(0, 0, 1);
blocks[3] = b.getRelative(0, 0, -1); blocks[3] = b.getRelative(0, 0, -1);
for (final Block c : blocks) { for (final Block c : blocks) {
if (c.getType() == b.getType()) { if (c.getType() == b.getType()) { return c; }
return c;
}
} }
return null; return null;
} }
@ -224,7 +212,7 @@ public class Util {
if (mat == null) { if (mat == null) {
try { try {
mat = Material.getMaterial(Integer.parseInt(s)); mat = Material.getMaterial(Integer.parseInt(s));
} catch (final NumberFormatException e) { } catch (final NumberFormatException ignored) {
} }
} }
if (mat == null) { if (mat == null) {
@ -424,8 +412,7 @@ public class Util {
} }
public static boolean isTransparent(final Material m) { public static boolean isTransparent(final Material m) {
final boolean trans = transparent.contains(m); return transparent.contains(m);
return trans;
} }
/** /**
@ -470,25 +457,19 @@ public class Util {
* @return true if the itemstacks match. (Material, durability, enchants, name) * @return true if the itemstacks match. (Material, durability, enchants, name)
*/ */
public static boolean matches(final ItemStack stack1, final ItemStack stack2) { public static boolean matches(final ItemStack stack1, final ItemStack stack2) {
if (stack1 == stack2) { if (stack1 == stack2) { return true; // Referring to the same thing, or both are null.
return true; // Referring to the same thing, or both are null.
} }
if (stack1 == null || stack2 == null) { if (stack1 == null || stack2 == null) { return false; // One of them is null (Can't be both, see above)
return false; // One of them is null (Can't be both, see above)
} }
if (stack1.getType() != stack2.getType()) { if (stack1.getType() != stack2.getType()) { return false; // Not the same material
return false; // Not the same material
} }
if (stack1.getDurability() != stack2.getDurability()) { if (stack1.getDurability() != stack2.getDurability()) { return false; // Not the same durability
return false; // Not the same durability
} }
if (!stack1.getEnchantments().equals(stack2.getEnchantments())) { if (!stack1.getEnchantments().equals(stack2.getEnchantments())) { return false; // They have the same enchants
return false; // They have the same enchants
} }
if (stack1.getItemMeta().hasDisplayName() || stack2.getItemMeta().hasDisplayName()) { if (stack1.getItemMeta().hasDisplayName() || stack2.getItemMeta().hasDisplayName()) {
if (stack1.getItemMeta().hasDisplayName() && stack2.getItemMeta().hasDisplayName()) { if (stack1.getItemMeta().hasDisplayName() && stack2.getItemMeta().hasDisplayName()) {
if (!stack1.getItemMeta().getDisplayName().equals(stack2.getItemMeta().getDisplayName())) { if (!stack1.getItemMeta().getDisplayName().equals(stack2.getItemMeta().getDisplayName())) { return false; // items have different display name
return false; // items have different display name
} }
} else { } else {
return false; // one of the item stacks have a display name return false; // one of the item stacks have a display name
@ -498,16 +479,14 @@ public class Util {
Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta"); Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta");
final boolean book1 = stack1.getItemMeta() instanceof EnchantmentStorageMeta; final boolean book1 = stack1.getItemMeta() instanceof EnchantmentStorageMeta;
final boolean book2 = stack2.getItemMeta() instanceof EnchantmentStorageMeta; final boolean book2 = stack2.getItemMeta() instanceof EnchantmentStorageMeta;
if (book1 != book2) { if (book1 != book2) { return false;// One has enchantment meta, the other does not.
return false;// One has enchantment meta, the other does not.
} }
if (book1 == true) { // They are the same here (both true or both if (book1) { // They are the same here (both true or both
// false). So if one is true, the other is // false). So if one is true, the other is
// true. // true.
final Map<Enchantment, Integer> ench1 = ((EnchantmentStorageMeta) stack1.getItemMeta()).getStoredEnchants(); final Map<Enchantment, Integer> ench1 = ((EnchantmentStorageMeta) stack1.getItemMeta()).getStoredEnchants();
final Map<Enchantment, Integer> ench2 = ((EnchantmentStorageMeta) stack2.getItemMeta()).getStoredEnchants(); final Map<Enchantment, Integer> ench2 = ((EnchantmentStorageMeta) stack2.getItemMeta()).getStoredEnchants();
if (!ench1.equals(ench2)) { if (!ench1.equals(ench2)) { return false; // Enchants aren't the same.
return false; // Enchants aren't the same.
} }
} }
} catch (final ClassNotFoundException e) { } catch (final ClassNotFoundException e) {