mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-11-22 01:58:54 +00:00
add protect holder and update version to 1.4.4...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
7d908ff59a
commit
5b6abc1c07
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.maxgamer</groupId>
|
||||
<artifactId>QuickShop</artifactId>
|
||||
<version>1.4.3</version>
|
||||
<version>1.4.4</version>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
<resources>
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
import org.maxgamer.QuickShop.QuickShop;
|
||||
@ -62,6 +63,11 @@ public class PlayerListener implements Listener {
|
||||
shop.onClick();
|
||||
// Text menu
|
||||
MsgUtil.sendShopInfo(p, shop);
|
||||
if (!plugin.getConfigManager().isEnableMagicLib() && !shop.getOwner().equalsIgnoreCase(p.getName()) && b.getType() == Material.WALL_SIGN) {
|
||||
final Inventory in = Bukkit.createInventory(null, 9, plugin.getConfigManager().getGuiTitle());
|
||||
in.setItem(4, shop.getItem());
|
||||
p.openInventory(in);
|
||||
}
|
||||
if (shop.isSelling()) {
|
||||
p.sendMessage(MsgUtil.p("how-many-buy"));
|
||||
} else {
|
||||
|
@ -2,11 +2,12 @@ package org.maxgamer.QuickShop.Listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ItemDespawnEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||
@ -14,8 +15,10 @@ import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.maxgamer.QuickShop.QuickShop;
|
||||
import org.maxgamer.QuickShop.Shop.Shop;
|
||||
import org.maxgamer.QuickShop.Util.MarkUtil;
|
||||
|
||||
public class ProtectListener implements Listener {
|
||||
@ -26,18 +29,41 @@ public class ProtectListener implements Listener {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Shop getShop(final Inventory inv) {
|
||||
if (inv == null) {
|
||||
return null;
|
||||
}
|
||||
InventoryHolder holder = inv.getHolder();
|
||||
if (holder instanceof DoubleChest) {
|
||||
holder = ((DoubleChest) holder).getLeftSide();
|
||||
}
|
||||
|
||||
if (holder instanceof BlockState) {
|
||||
final Block block = ((BlockState) holder).getBlock();
|
||||
final Shop sp = plugin.getShopManager().getShop(block.getLocation());
|
||||
if (sp != null) {
|
||||
return sp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvMove(final InventoryMoveItemEvent e) {
|
||||
final ItemStack ci = e.getItem();
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
e.setCancelled(true);
|
||||
final ItemStack[] items = e.getSource().getContents();
|
||||
for (final ItemStack itemStack : items) {
|
||||
if (MarkUtil.hasMark(itemStack)) {
|
||||
itemStack.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
e.getSource().setContents(items);
|
||||
}
|
||||
|
||||
final Inventory src = e.getSource();
|
||||
final Inventory me = e.getInitiator();
|
||||
final Inventory des = e.getDestination();
|
||||
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().equalsIgnoreCase(desshop.getOwner()))) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,14 +101,6 @@ public class ProtectListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onItemDespawn(final ItemDespawnEvent e) {
|
||||
final ItemStack ci = e.getEntity().getItemStack();
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerHandlerItem(final PlayerItemHeldEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.maxgamer.QuickShop.QuickShop;
|
||||
import org.maxgamer.QuickShop.Shop.Shop;
|
||||
@ -193,10 +192,5 @@ public class MsgUtil {
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-selling"));
|
||||
}
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||
if (!plugin.getConfigManager().isEnableMagicLib() && !shop.getOwner().equalsIgnoreCase(p.getName())) {
|
||||
final Inventory in = Bukkit.createInventory(null, 9, plugin.getConfigManager().getGuiTitle());
|
||||
in.setItem(4, items);
|
||||
p.openInventory(in);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user