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

View File

@ -39,9 +39,7 @@ public class BlockListener implements Listener {
// If the shop was a chest
if (b.getState() instanceof InventoryHolder) {
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) {
return;
}
if (shop == null) { return; }
// If they're either survival or the owner, they can break it
final ItemStack pinh = p.getItemInHand();
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 {
e.setCancelled(true);
p.sendMessage(MsgUtil.p("no-creative-break"));
return;
}
} else if (b.getType() == Material.WALL_SIGN) {
final Shop shop = getShopNextTo(b.getLocation());
if (shop == null) {
return;
}
if (shop == null) { return; }
e.setCancelled(true);
}
}
@ -71,30 +66,29 @@ public class BlockListener implements Listener {
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onExplode(final EntityExplodeEvent e) {
if (e.isCancelled()) {
return;
}
if (e.isCancelled()) { return; }
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());
if (shop != null) {
shop.delete();
}
}
}
}
/**
* Listens for chest placement, so a doublechest shop can't be created.
*/
@EventHandler(ignoreCancelled = true)
public void onPlace(final BlockPlaceEvent e) {
if (e.isCancelled()) {
return;
}
if (e.isCancelled()) { return; }
final BlockState bs = e.getBlock().getState();
if (bs instanceof DoubleChest == false) {
return;
}
if (!(bs instanceof DoubleChest)) { return; }
final Block b = e.getBlock();
final Player p = e.getPlayer();
final Block chest = Util.getSecondHalf(b);
@ -114,9 +108,7 @@ public class BlockListener implements Listener {
private Shop getShopNextTo(final Location loc) {
final Block b = Util.getAttached(loc.getBlock());
// Util.getAttached(b)
if (b == null) {
return null;
}
if (b == null) { return null; }
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.Util;
import java.util.ArrayList;
import java.util.List;
public class LockListener implements Listener {
private final QuickShop plugin;
@ -33,24 +36,18 @@ public class LockListener implements Listener {
// If the chest was a chest
if (Util.canBeShop(b)) {
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) {
return; // Wasn't a shop
if (shop == null) { return; // Wasn't a shop
}
// If they owned it or have bypass perms, they can destroy it
if (!shop.getOwner().equals(p.getName()) && !p.hasPermission("quickshop.other.destroy")) {
e.setCancelled(true);
p.sendMessage(MsgUtil.p("no-permission"));
return;
}
} else if (b.getType() == Material.WALL_SIGN) {
b = Util.getAttached(b);
if (b == null) {
return;
}
if (b == null) { return; }
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) {
return;
}
if (shop == null) { return; }
e.setCancelled(true);
}
}
@ -59,24 +56,13 @@ public class LockListener implements Listener {
public void onClick(final PlayerInteractEvent e) {
Block b = e.getClickedBlock();
final Player p = e.getPlayer();
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
return; // Didn't right click it, we dont care.
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) { return; // Didn't right click it, we dont care.
}
if (!Util.canBeShop(b)) {
return; // Interacted with air
if (!Util.canBeShop(b)) { return; // Interacted with air
}
Shop shop = plugin.getShopManager().getShop(b.getLocation());
// Make sure they're not using the non-shop half of a double chest.
if (shop == null) {
b = Util.getSecondHalf(b);
if (b == null) {
return;
}
shop = plugin.getShopManager().getShop(b.getLocation());
if (shop == null) {
return;
}
}
if (!hasSecondHalf(shop, b)) { return; }
if (!shop.getOwner().equals(p.getName())) {
if (p.hasPermission("quickshop.other.open")) {
p.sendMessage(MsgUtil.p("bypassing-lock"));
@ -84,28 +70,62 @@ public class LockListener implements Listener {
}
p.sendMessage(MsgUtil.p("that-is-locked"));
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
*/
@EventHandler(priority = EventPriority.LOW)
public void onExplode(final EntityExplodeEvent e) {
if (e.isCancelled()) {
return;
}
if (e.isCancelled()) { return; }
List<Block> removed = new ArrayList<>();
for (int i = 0; i < e.blockList().size(); i++) {
final Block b = e.blockList().get(i);
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
Block b = e.blockList().get(i);
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);
removed.add(b);
} else if (b.getType() == Material.WALL_SIGN) {
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
@ -114,36 +134,22 @@ public class LockListener implements Listener {
public void onPlace(final BlockPlaceEvent e) {
final Block b = e.getBlock();
try {
if (b.getType() != Material.HOPPER) {
return;
}
if (b.getType() != Material.HOPPER) { return; }
} catch (final NoSuchFieldError er) {
return; // Your server doesn't have hoppers
}
Block c = e.getBlockAgainst();
if (Util.canBeShop(c) == false) {
return;
}
if (!Util.canBeShop(c)) { return; }
final Player p = e.getPlayer();
Shop shop = plugin.getShopManager().getShop(c.getLocation());
if (shop == null) {
c = Util.getSecondHalf(c);
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 (!hasSecondHalf(shop, b)) { return; }
if (!p.getName().equals(shop.getOwner())) {
if (p.hasPermission("quickshop.other.open")) {
p.sendMessage(MsgUtil.p("bypassing-lock"));
return;
}
p.sendMessage(MsgUtil.p("that-is-locked"));
e.setCancelled(true);
return;
}
}
}

View File

@ -1,7 +1,5 @@
package org.maxgamer.QuickShop.Listeners;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
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.Util;
import java.util.HashMap;
public class PlayerListener implements Listener {
private final QuickShop plugin;
@ -34,11 +34,12 @@ public class PlayerListener implements Listener {
this.plugin = plugin;
}
@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, ignoreCancelled = true)
public void onClick(final PlayerInteractEvent e) {
final Block b = e.getClickedBlock();
@ -71,7 +72,6 @@ public class PlayerListener implements Listener {
final HashMap<String, Info> actions = plugin.getShopManager().getActions();
final Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop);
actions.put(p.getName(), info);
return;
}
// 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
@ -138,7 +138,6 @@ public class PlayerListener implements Listener {
p.sendMessage(MsgUtil.p("shop-purchase-cancelled"));
}
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 meshop = getShop(me);
final Shop desshop = getShop(des);
if ((srcshop != null && meshop == null) || (meshop != null && desshop == null)
|| (srcshop != null && desshop != null && srcshop.getOwner() != null && !srcshop.getOwner().equalsIgnoreCase(desshop.getOwner()))) {
if (srcshop != null && meshop == null || meshop != null && desshop == null || srcshop != null && srcshop.getOwner() != null && !srcshop.getOwner().equalsIgnoreCase(desshop.getOwner())) {
e.setCancelled(true);
}
}
@ -97,7 +96,7 @@ public class ProtectListener implements Listener {
sendWarning(p, ci, "§d§l获取");
p.closeInventory();
}
} catch (final Exception ex) {
} catch (final Exception ignored) {
}
}

View File

@ -1,8 +1,5 @@
package org.maxgamer.QuickShop.Listeners;
import java.util.HashMap;
import java.util.Map.Entry;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
@ -14,6 +11,9 @@ import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopChunk;
import java.util.HashMap;
import java.util.Map.Entry;
public class WorldListener implements Listener {
QuickShop plugin;
@ -32,16 +32,14 @@ public class WorldListener implements Listener {
*/
final World world = e.getWorld();
// 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
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
// update.
if (oldInWorld == null) {
return;
}
if (oldInWorld == null) { return; }
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
inWorld.put(oldInChunk.getKey(), inChunk);
for (final Entry<Location, Shop> entry : oldInChunk.getValue().entrySet()) {

View File

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

View File

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