mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Upload code
This commit is contained in:
1 parent
150f67f706
commit
f1f96f3abc
16 files changed
+3993
-4021
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1,29 +1,30 @@
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Netherfoam
|
||||
*
|
||||
*/
|
||||
public class ChatListener implements Listener {
|
||||
QuickShop plugin;
|
||||
|
||||
public ChatListener(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChat(final AsyncPlayerChatEvent e) {
|
||||
if (!plugin.getShopManager().getActions().containsKey(e.getPlayer().getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Netherfoam
|
||||
*
|
||||
*/
|
||||
public class ChatListener implements Listener {
|
||||
QuickShop plugin;
|
||||
|
||||
public ChatListener(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChat(final AsyncPlayerChatEvent e) {
|
||||
if (!plugin.getShopManager().getActions().containsKey(e.getPlayer().getUniqueId())) {
|
||||
plugin.log(plugin.getShopManager().getActions().toString());
|
||||
return;
|
||||
}
|
||||
plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
|
||||
import com.dthielke.herochat.ChannelChatEvent;
|
||||
import com.dthielke.herochat.Chatter.Result;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Netherfoam
|
||||
*
|
||||
*/
|
||||
public class HeroChatListener implements Listener {
|
||||
QuickShop plugin;
|
||||
|
||||
public HeroChatListener(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onHeroChat(ChannelChatEvent e) {
|
||||
if (!plugin.getShopManager().getActions().containsKey(e.getSender().getPlayer().getUniqueId()))
|
||||
return;
|
||||
plugin.getShopManager().handleChat(e.getSender().getPlayer(), e.getMessage());
|
||||
e.setResult(Result.FAIL);
|
||||
}
|
||||
}
|
||||
@@ -1,228 +1,228 @@
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
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;
|
||||
import org.maxgamer.quickshop.Shop.Info;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Shop.ShopAction;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private QuickShop plugin;
|
||||
|
||||
public PlayerListener(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Could be useful one day private LinkedList<String> getParents(Class<?>
|
||||
* clazz){ LinkedList<String> classes = new LinkedList<String>();
|
||||
*
|
||||
* while(clazz != null){ classes.add("Extends " + ChatColor.GREEN +
|
||||
* clazz.getCanonicalName()); for(Class<?> iface : clazz.getInterfaces()){
|
||||
* classes.add("Implements " + ChatColor.RED + iface.getCanonicalName());
|
||||
* classes.addAll(getParents(iface)); }
|
||||
*
|
||||
* clazz = clazz.getSuperclass(); } return classes; }
|
||||
*/
|
||||
/**
|
||||
* 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)
|
||||
public void onClick(PlayerInteractEvent e) {
|
||||
if (e.getAction() != Action.LEFT_CLICK_BLOCK)
|
||||
return;
|
||||
Block b = e.getClickedBlock();
|
||||
if (!Util.canBeShop(b) && b.getType() != Material.WALL_SIGN)
|
||||
return;
|
||||
Player p = e.getPlayer();
|
||||
if (plugin.sneak && !p.isSneaking()) {
|
||||
// Sneak only
|
||||
return;
|
||||
}
|
||||
Location loc = b.getLocation();
|
||||
ItemStack item = e.getItem();
|
||||
// Get the shop
|
||||
Shop shop = plugin.getShopManager().getShop(loc);
|
||||
// If that wasn't a shop, search nearby shops
|
||||
if (shop == null) {
|
||||
Block attached = null;
|
||||
|
||||
if (b.getType() == Material.WALL_SIGN) {
|
||||
attached = Util.getAttached(b);
|
||||
if (attached != null) {
|
||||
shop = plugin.getShopManager().getShop(attached.getLocation());
|
||||
}
|
||||
} else if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
|
||||
attached = Util.getSecondHalf(b);
|
||||
if (attached != null) {
|
||||
Shop secondHalfShop = plugin.getShopManager().getShop(attached.getLocation());
|
||||
if (secondHalfShop != null && !p.getUniqueId().equals(secondHalfShop.getOwner())) {
|
||||
// If player not the owner of the shop, make him select the second half of the shop
|
||||
// Otherwise owner will be able to create new double chest shop
|
||||
shop = secondHalfShop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Purchase handling
|
||||
if (shop != null && p.hasPermission("quickshop.use") && (plugin.sneakTrade == false || p.isSneaking())) {
|
||||
shop.onClick();
|
||||
// Text menu
|
||||
MsgUtil.sendShopInfo(p, shop);
|
||||
if (shop.isSelling()) {
|
||||
p.sendMessage(MsgUtil.getMessage("how-many-buy"));
|
||||
} else {
|
||||
int items = Util.countItems(p.getInventory(), shop.getItem());
|
||||
p.sendMessage(MsgUtil.getMessage("how-many-sell", "" + items));
|
||||
}
|
||||
// Add the new action
|
||||
HashMap<UUID, Info> actions = plugin.getShopManager().getActions();
|
||||
Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop);
|
||||
actions.put(p.getUniqueId(), info);
|
||||
return;
|
||||
}
|
||||
// Handles creating shops
|
||||
else if (!e.isCancelled() && shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE && (plugin.sneakCreate == false || p.isSneaking())) {
|
||||
if (!plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
|
||||
// As of the new checking system, most plugins will tell the
|
||||
// player why they can't create a shop there.
|
||||
// So telling them a message would cause spam etc.
|
||||
return;
|
||||
}
|
||||
if (Util.getSecondHalf(b) != null && !p.hasPermission("quickshop.create.double")) {
|
||||
p.sendMessage(MsgUtil.getMessage("no-double-chests"));
|
||||
return;
|
||||
}
|
||||
if (Util.isBlacklisted(item.getType()) && !p.hasPermission("quickshop.bypass." + item.getTypeId())) {
|
||||
p.sendMessage(MsgUtil.getMessage("blacklisted-item"));
|
||||
return;
|
||||
}
|
||||
// Finds out where the sign should be placed for the shop
|
||||
Block last = null;
|
||||
Location from = p.getLocation().clone();
|
||||
from.setY(b.getY());
|
||||
from.setPitch(0);
|
||||
BlockIterator bIt = new BlockIterator(from, 0, 7);
|
||||
while (bIt.hasNext()) {
|
||||
Block n = bIt.next();
|
||||
if (n.equals(b))
|
||||
break;
|
||||
last = n;
|
||||
}
|
||||
// Send creation menu.
|
||||
Info info = new Info(b.getLocation(), ShopAction.CREATE, e.getItem(), last);
|
||||
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
|
||||
p.sendMessage(MsgUtil.getMessage("how-much-to-trade-for", Util.getName(info.getItem())));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
/**
|
||||
* Waits for a player to move too far from a shop, then cancels the menu.
|
||||
*/
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
if (e.isCancelled())
|
||||
return;
|
||||
Info info = plugin.getShopManager().getActions().get(e.getPlayer().getUniqueId());
|
||||
if (info != null) {
|
||||
Player p = e.getPlayer();
|
||||
Location loc1 = info.getLocation();
|
||||
Location loc2 = p.getLocation();
|
||||
if (loc1.getWorld() != loc2.getWorld() || loc1.distanceSquared(loc2) > 25) {
|
||||
if (info.getAction() == ShopAction.CREATE) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-creation-cancelled"));
|
||||
} else if (info.getAction() == ShopAction.BUY) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-purchase-cancelled"));
|
||||
}
|
||||
plugin.getShopManager().getActions().remove(p.getUniqueId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
PlayerMoveEvent me = new PlayerMoveEvent(e.getPlayer(), e.getFrom(), e.getTo());
|
||||
onMove(me);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(final PlayerJoinEvent e) {
|
||||
// Notify the player any messages they were sent
|
||||
Bukkit.getScheduler().runTaskLater(QuickShop.instance, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MsgUtil.flush(e.getPlayer());
|
||||
}
|
||||
}, 60);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
// Remove them from the menu
|
||||
plugin.getShopManager().getActions().remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickup(PlayerPickupItemEvent e) {
|
||||
ItemStack stack = e.getItem().getItemStack();
|
||||
try {
|
||||
if (stack.getItemMeta().getDisplayName().startsWith(ChatColor.RED + "QuickShop ")) {
|
||||
e.setCancelled(true);
|
||||
// You shouldn't be able to pick up that...
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
} // if meta/displayname/stack is null. We don't really care in that case.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
try {
|
||||
final Inventory inventory = e.getInventory();
|
||||
if (inventory == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Location location = inventory.getLocation();
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Shop shop = plugin.getShopManager().getShop(location);
|
||||
if (shop == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
shop.setSignText();
|
||||
} catch (Throwable t) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
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;
|
||||
import org.maxgamer.quickshop.Shop.Info;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Shop.ShopAction;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private QuickShop plugin;
|
||||
|
||||
public PlayerListener(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Could be useful one day private LinkedList<String> getParents(Class<?>
|
||||
* clazz){ LinkedList<String> classes = new LinkedList<String>();
|
||||
*
|
||||
* while(clazz != null){ classes.add("Extends " + ChatColor.GREEN +
|
||||
* clazz.getCanonicalName()); for(Class<?> iface : clazz.getInterfaces()){
|
||||
* classes.add("Implements " + ChatColor.RED + iface.getCanonicalName());
|
||||
* classes.addAll(getParents(iface)); }
|
||||
*
|
||||
* clazz = clazz.getSuperclass(); } return classes; }
|
||||
*/
|
||||
/**
|
||||
* 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)
|
||||
public void onClick(PlayerInteractEvent e) {
|
||||
if (e.getAction() != Action.LEFT_CLICK_BLOCK)
|
||||
return;
|
||||
Block b = e.getClickedBlock();
|
||||
if (!Util.canBeShop(b) && b.getType() != Material.WALL_SIGN)
|
||||
return;
|
||||
Player p = e.getPlayer();
|
||||
if (plugin.sneak && !p.isSneaking()) {
|
||||
// Sneak only
|
||||
return;
|
||||
}
|
||||
Location loc = b.getLocation();
|
||||
ItemStack item = e.getItem();
|
||||
// Get the shop
|
||||
Shop shop = plugin.getShopManager().getShop(loc);
|
||||
// If that wasn't a shop, search nearby shops
|
||||
if (shop == null) {
|
||||
Block attached = null;
|
||||
|
||||
if (b.getType() == Material.WALL_SIGN) {
|
||||
attached = Util.getAttached(b);
|
||||
if (attached != null) {
|
||||
shop = plugin.getShopManager().getShop(attached.getLocation());
|
||||
}
|
||||
} else if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
|
||||
attached = Util.getSecondHalf(b);
|
||||
if (attached != null) {
|
||||
Shop secondHalfShop = plugin.getShopManager().getShop(attached.getLocation());
|
||||
if (secondHalfShop != null && !p.getUniqueId().equals(secondHalfShop.getOwner())) {
|
||||
// If player not the owner of the shop, make him select the second half of the shop
|
||||
// Otherwise owner will be able to create new double chest shop
|
||||
shop = secondHalfShop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Purchase handling
|
||||
if (shop != null && p.hasPermission("quickshop.use") && (plugin.sneakTrade == false || p.isSneaking())) {
|
||||
shop.onClick();
|
||||
// Text menu
|
||||
MsgUtil.sendShopInfo(p, shop);
|
||||
if (shop.isSelling()) {
|
||||
p.sendMessage(MsgUtil.getMessage("how-many-buy"));
|
||||
} else {
|
||||
int items = Util.countItems(p.getInventory(), shop.getItem());
|
||||
p.sendMessage(MsgUtil.getMessage("how-many-sell", "" + items));
|
||||
}
|
||||
// Add the new action
|
||||
HashMap<UUID, Info> actions = plugin.getShopManager().getActions();
|
||||
Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop);
|
||||
actions.put(p.getUniqueId(), info);
|
||||
return;
|
||||
}
|
||||
// Handles creating shops
|
||||
else if (!e.isCancelled() && shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE && (plugin.sneakCreate == false || p.isSneaking())) {
|
||||
if (!plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
|
||||
// As of the new checking system, most plugins will tell the
|
||||
// player why they can't create a shop there.
|
||||
// So telling them a message would cause spam etc.
|
||||
return;
|
||||
}
|
||||
if (Util.getSecondHalf(b) != null && !p.hasPermission("quickshop.create.double")) {
|
||||
p.sendMessage(MsgUtil.getMessage("no-double-chests"));
|
||||
return;
|
||||
}
|
||||
if (Util.isBlacklisted(item.getType()) && !p.hasPermission("quickshop.bypass." + item.getType().name())) {
|
||||
p.sendMessage(MsgUtil.getMessage("blacklisted-item"));
|
||||
return;
|
||||
}
|
||||
// Finds out where the sign should be placed for the shop
|
||||
Block last = null;
|
||||
Location from = p.getLocation().clone();
|
||||
from.setY(b.getY());
|
||||
from.setPitch(0);
|
||||
BlockIterator bIt = new BlockIterator(from, 0, 7);
|
||||
while (bIt.hasNext()) {
|
||||
Block n = bIt.next();
|
||||
if (n.equals(b))
|
||||
break;
|
||||
last = n;
|
||||
}
|
||||
// Send creation menu.
|
||||
Info info = new Info(b.getLocation(), ShopAction.CREATE, e.getItem(), last);
|
||||
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
|
||||
p.sendMessage(MsgUtil.getMessage("how-much-to-trade-for", Util.getName(info.getItem())));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
/**
|
||||
* Waits for a player to move too far from a shop, then cancels the menu.
|
||||
*/
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
if (e.isCancelled())
|
||||
return;
|
||||
Info info = plugin.getShopManager().getActions().get(e.getPlayer().getUniqueId());
|
||||
if (info != null) {
|
||||
Player p = e.getPlayer();
|
||||
Location loc1 = info.getLocation();
|
||||
Location loc2 = p.getLocation();
|
||||
if (loc1.getWorld() != loc2.getWorld() || loc1.distanceSquared(loc2) > 25) {
|
||||
if (info.getAction() == ShopAction.CREATE) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-creation-cancelled"));
|
||||
} else if (info.getAction() == ShopAction.BUY) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-purchase-cancelled"));
|
||||
}
|
||||
plugin.getShopManager().getActions().remove(p.getUniqueId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
PlayerMoveEvent me = new PlayerMoveEvent(e.getPlayer(), e.getFrom(), e.getTo());
|
||||
onMove(me);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(final PlayerJoinEvent e) {
|
||||
// Notify the player any messages they were sent
|
||||
Bukkit.getScheduler().runTaskLater(QuickShop.instance, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MsgUtil.flush(e.getPlayer());
|
||||
}
|
||||
}, 60);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
// Remove them from the menu
|
||||
plugin.getShopManager().getActions().remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickup(PlayerPickupItemEvent e) {
|
||||
ItemStack stack = e.getItem().getItemStack();
|
||||
try {
|
||||
if (stack.getItemMeta().getDisplayName().startsWith(ChatColor.RED + "QuickShop ")) {
|
||||
e.setCancelled(true);
|
||||
// You shouldn't be able to pick up that...
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
} // if meta/displayname/stack is null. We don't really care in that case.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
try {
|
||||
final Inventory inventory = e.getInventory();
|
||||
if (inventory == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Location location = inventory.getLocation();
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Shop shop = plugin.getShopManager().getShop(location);
|
||||
if (shop == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
shop.setSignText();
|
||||
} catch (Throwable t) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,636 +1,214 @@
|
||||
package org.maxgamer.quickshop.Util;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.Potion.Tier;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Util.CustomPotionsName.GenericPotionData;
|
||||
import org.maxgamer.quickshop.Util.CustomPotionsName.GenericPotionData.Category;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class NMS {
|
||||
private static ArrayList<NMSDependent> nmsDependencies = new ArrayList<NMSDependent>();
|
||||
private static int nextId = 0;
|
||||
private static NMSDependent nms;
|
||||
|
||||
static {
|
||||
nmsDependencies.add(new NMSDependent("v1_7") {
|
||||
@Override
|
||||
public void safeGuard(Item item) {
|
||||
if(QuickShop.debug)System.out.println("safeGuard");
|
||||
org.bukkit.inventory.ItemStack iStack = item.getItemStack();
|
||||
net.minecraft.server.v1_7_R3.ItemStack nmsI = org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
nmsI.count = 0;
|
||||
iStack = org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack.asBukkitCopy(nmsI);
|
||||
item.setItemStack(iStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
|
||||
if(QuickShop.debug)System.out.println("getNBTBytes");
|
||||
net.minecraft.server.v1_7_R3.ItemStack is = org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
net.minecraft.server.v1_7_R3.NBTTagCompound itemCompound = new net.minecraft.server.v1_7_R3.NBTTagCompound();
|
||||
itemCompound = is.save(itemCompound);
|
||||
return net.minecraft.server.v1_7_R3.NBTCompressedStreamTools.a(itemCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
|
||||
if(QuickShop.debug)System.out.println("getItemStack");
|
||||
net.minecraft.server.v1_7_R3.NBTTagCompound c = net.minecraft.server.v1_7_R3.NBTCompressedStreamTools.a(bytes, null);
|
||||
net.minecraft.server.v1_7_R3.ItemStack is = net.minecraft.server.v1_7_R3.ItemStack.createStack(c);
|
||||
return org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack.asBukkitCopy(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericPotionData getPotionData(ItemStack potionItemStack) {
|
||||
if (potionItemStack.getDurability()==0) {
|
||||
return new GenericPotionData(PotionType.WATER, Collections.emptyList(), Category.NORMAL, false, 0, 0);
|
||||
}
|
||||
|
||||
Potion potion = Potion.fromItemStack(potionItemStack);
|
||||
if (potion==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Category category;
|
||||
if (potion.isSplash()) {
|
||||
category = Category.SPLASH;
|
||||
} else {
|
||||
category = Category.NORMAL;
|
||||
}
|
||||
|
||||
return new GenericPotionData(potion.getType(), potion.getEffects(), category, potion.getType()==PotionType.WATER && !potion.getEffects().isEmpty(), potion.hasExtendedDuration() ? -1 : 0, potion.getTier()==Tier.TWO ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPotion(Material material) {
|
||||
return material==Material.POTION;
|
||||
}
|
||||
});
|
||||
|
||||
nmsDependencies.add(new NMSDependent("v1_8") {
|
||||
@Override
|
||||
public void safeGuard(Item item) {
|
||||
if(QuickShop.debug)System.out.println("safeGuard");
|
||||
org.bukkit.inventory.ItemStack iStack = item.getItemStack();
|
||||
net.minecraft.server.v1_8_R3.ItemStack nmsI = org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
nmsI.count = 0;
|
||||
iStack = org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack.asBukkitCopy(nmsI);
|
||||
item.setItemStack(iStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getNBTBytes");
|
||||
net.minecraft.server.v1_8_R3.ItemStack is = org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
net.minecraft.server.v1_8_R3.NBTTagCompound itemCompound = new net.minecraft.server.v1_8_R3.NBTTagCompound();
|
||||
itemCompound = is.save(itemCompound);
|
||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataoutputstream = new DataOutputStream(new GZIPOutputStream(bytearrayoutputstream));
|
||||
try {
|
||||
net.minecraft.server.v1_8_R3.NBTCompressedStreamTools.a(itemCompound, (DataOutput) dataoutputstream);
|
||||
} finally {
|
||||
dataoutputstream.close();
|
||||
}
|
||||
return bytearrayoutputstream.toByteArray();
|
||||
}catch(Exception e){
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getItemStack");
|
||||
DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes))));
|
||||
net.minecraft.server.v1_8_R3.NBTTagCompound nbttagcompound;
|
||||
try {
|
||||
nbttagcompound = net.minecraft.server.v1_8_R3.NBTCompressedStreamTools.a((DataInput) datainputstream, null);
|
||||
} finally {
|
||||
datainputstream.close();
|
||||
}
|
||||
net.minecraft.server.v1_8_R3.ItemStack is = net.minecraft.server.v1_8_R3.ItemStack.createStack(nbttagcompound);
|
||||
return org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack.asBukkitCopy(is);
|
||||
}catch(Exception e){
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericPotionData getPotionData(ItemStack potionItemStack) {
|
||||
if (potionItemStack.getDurability()==0) {
|
||||
return new GenericPotionData(PotionType.WATER, Collections.emptyList(), Category.NORMAL, false, 0, 0);
|
||||
}
|
||||
|
||||
Potion potion = Potion.fromItemStack(potionItemStack);
|
||||
if (potion==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Category category;
|
||||
if (potion.isSplash()) {
|
||||
category = Category.SPLASH;
|
||||
} else {
|
||||
category = Category.NORMAL;
|
||||
}
|
||||
|
||||
return new GenericPotionData(potion.getType(), potion.getEffects(), category, potion.getType()==PotionType.WATER && !potion.getEffects().isEmpty(), potion.hasExtendedDuration() ? -1 : 0, potion.getTier()==Tier.TWO ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPotion(Material material) {
|
||||
return material==Material.POTION;
|
||||
}
|
||||
});
|
||||
|
||||
nmsDependencies.add(new NMSDependent("v1_9") {
|
||||
@Override
|
||||
public void safeGuard(Item item) {
|
||||
if(QuickShop.debug)System.out.println("safeGuard");
|
||||
org.bukkit.inventory.ItemStack iStack = item.getItemStack();
|
||||
net.minecraft.server.v1_9_R2.ItemStack nmsI = org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
nmsI.count = 0;
|
||||
iStack = org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack.asBukkitCopy(nmsI);
|
||||
item.setItemStack(iStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getNBTBytes");
|
||||
net.minecraft.server.v1_9_R2.ItemStack is = org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
net.minecraft.server.v1_9_R2.NBTTagCompound itemCompound = new net.minecraft.server.v1_9_R2.NBTTagCompound();
|
||||
itemCompound = is.save(itemCompound);
|
||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataoutputstream = new DataOutputStream(new GZIPOutputStream(bytearrayoutputstream));
|
||||
try {
|
||||
net.minecraft.server.v1_9_R2.NBTCompressedStreamTools.a(itemCompound, (DataOutput) dataoutputstream);
|
||||
} finally {
|
||||
dataoutputstream.close();
|
||||
}
|
||||
return bytearrayoutputstream.toByteArray();
|
||||
}catch(Exception e){
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getItemStack");
|
||||
DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes))));
|
||||
net.minecraft.server.v1_9_R2.NBTTagCompound nbttagcompound;
|
||||
try {
|
||||
nbttagcompound = net.minecraft.server.v1_9_R2.NBTCompressedStreamTools.a((DataInput) datainputstream, null);
|
||||
} finally {
|
||||
datainputstream.close();
|
||||
}
|
||||
net.minecraft.server.v1_9_R2.ItemStack is = net.minecraft.server.v1_9_R2.ItemStack.createStack(nbttagcompound);
|
||||
return org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack.asBukkitCopy(is);
|
||||
}catch(Exception e){
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericPotionData getPotionData(ItemStack potionItemStack) {
|
||||
PotionMeta potionMeta = (PotionMeta) potionItemStack.getItemMeta();
|
||||
|
||||
Category category;
|
||||
switch(potionItemStack.getType()) {
|
||||
case POTION:
|
||||
category = Category.NORMAL;
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
category = Category.SPLASH;
|
||||
break;
|
||||
case LINGERING_POTION:
|
||||
category = Category.LINGERING;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
List<PotionEffect> effects = new ArrayList<PotionEffect>(potionMeta.getCustomEffects().size()+1);
|
||||
|
||||
if (potionMeta.hasCustomEffects()) {
|
||||
effects.addAll(potionMeta.getCustomEffects());
|
||||
}
|
||||
|
||||
PotionType potionType = potionMeta.getBasePotionData().getType();
|
||||
|
||||
return new GenericPotionData(potionType, effects, category, (potionType==PotionType.WATER || potionType==PotionType.MUNDANE || potionType==PotionType.UNCRAFTABLE || potionType==PotionType.THICK || potionType==PotionType.AWKWARD) && !effects.isEmpty(), potionMeta.getBasePotionData().isExtended() ? -1 : 0, potionMeta.getBasePotionData().isUpgraded() ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPotion(Material material) {
|
||||
switch(material) {
|
||||
case POTION:
|
||||
case SPLASH_POTION:
|
||||
case LINGERING_POTION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nmsDependencies.add(new NMSDependent("v1_10") {
|
||||
@Override
|
||||
public void safeGuard(Item item) {
|
||||
if(QuickShop.debug)System.out.println("safeGuard");
|
||||
org.bukkit.inventory.ItemStack iStack = item.getItemStack();
|
||||
net.minecraft.server.v1_10_R1.ItemStack nmsI = org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
nmsI.count = 0;
|
||||
iStack = org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack.asBukkitCopy(nmsI);
|
||||
item.setItemStack(iStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getNBTBytes");
|
||||
net.minecraft.server.v1_10_R1.ItemStack is = org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
net.minecraft.server.v1_10_R1.NBTTagCompound itemCompound = new net.minecraft.server.v1_10_R1.NBTTagCompound();
|
||||
itemCompound = is.save(itemCompound);
|
||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataoutputstream = new DataOutputStream(new GZIPOutputStream(bytearrayoutputstream));
|
||||
try {
|
||||
net.minecraft.server.v1_10_R1.NBTCompressedStreamTools.a(itemCompound, (DataOutput) dataoutputstream);
|
||||
} finally {
|
||||
dataoutputstream.close();
|
||||
}
|
||||
return bytearrayoutputstream.toByteArray();
|
||||
}catch(Exception e){
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getItemStack");
|
||||
DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes))));
|
||||
net.minecraft.server.v1_10_R1.NBTTagCompound nbttagcompound;
|
||||
try {
|
||||
nbttagcompound = net.minecraft.server.v1_10_R1.NBTCompressedStreamTools.a((DataInput) datainputstream, null);
|
||||
} finally {
|
||||
datainputstream.close();
|
||||
}
|
||||
net.minecraft.server.v1_10_R1.ItemStack is = net.minecraft.server.v1_10_R1.ItemStack.createStack(nbttagcompound);
|
||||
return org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack.asBukkitCopy(is);
|
||||
}catch(Exception e){
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericPotionData getPotionData(ItemStack potionItemStack) {
|
||||
PotionMeta potionMeta = (PotionMeta) potionItemStack.getItemMeta();
|
||||
|
||||
Category category;
|
||||
switch(potionItemStack.getType()) {
|
||||
case POTION:
|
||||
category = Category.NORMAL;
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
category = Category.SPLASH;
|
||||
break;
|
||||
case LINGERING_POTION:
|
||||
category = Category.LINGERING;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
List<PotionEffect> effects = new ArrayList<PotionEffect>(potionMeta.getCustomEffects().size()+1);
|
||||
|
||||
if (potionMeta.hasCustomEffects()) {
|
||||
effects.addAll(potionMeta.getCustomEffects());
|
||||
}
|
||||
|
||||
PotionType potionType = potionMeta.getBasePotionData().getType();
|
||||
|
||||
return new GenericPotionData(potionType, effects, category, (potionType==PotionType.WATER || potionType==PotionType.MUNDANE || potionType==PotionType.UNCRAFTABLE || potionType==PotionType.THICK || potionType==PotionType.AWKWARD) && !effects.isEmpty(), potionMeta.getBasePotionData().isExtended() ? -1 : 0, potionMeta.getBasePotionData().isUpgraded() ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPotion(Material material) {
|
||||
switch(material) {
|
||||
case POTION:
|
||||
case SPLASH_POTION:
|
||||
case LINGERING_POTION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nmsDependencies.add(new NMSDependent("v1_11") {
|
||||
@Override
|
||||
public void safeGuard(Item item) {
|
||||
if(QuickShop.debug)System.out.println("safeGuard");
|
||||
org.bukkit.inventory.ItemStack iStack = item.getItemStack();
|
||||
net.minecraft.server.v1_11_R1.ItemStack nmsI = org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
nmsI.setCount(0);
|
||||
iStack = org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack.asBukkitCopy(nmsI);
|
||||
item.setItemStack(iStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getNBTBytes");
|
||||
net.minecraft.server.v1_11_R1.ItemStack is = org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
net.minecraft.server.v1_11_R1.NBTTagCompound itemCompound = new net.minecraft.server.v1_11_R1.NBTTagCompound();
|
||||
itemCompound = is.save(itemCompound);
|
||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataoutputstream = new DataOutputStream(new GZIPOutputStream(bytearrayoutputstream));
|
||||
try {
|
||||
net.minecraft.server.v1_11_R1.NBTCompressedStreamTools.a(itemCompound, (DataOutput) dataoutputstream);
|
||||
} finally {
|
||||
dataoutputstream.close();
|
||||
}
|
||||
return bytearrayoutputstream.toByteArray();
|
||||
}catch(Exception e){
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getItemStack");
|
||||
DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes))));
|
||||
net.minecraft.server.v1_11_R1.NBTTagCompound nbttagcompound;
|
||||
try {
|
||||
nbttagcompound = net.minecraft.server.v1_11_R1.NBTCompressedStreamTools.a((DataInput) datainputstream, null);
|
||||
} finally {
|
||||
datainputstream.close();
|
||||
}
|
||||
net.minecraft.server.v1_11_R1.ItemStack is = new net.minecraft.server.v1_11_R1.ItemStack(nbttagcompound);
|
||||
return org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack.asBukkitCopy(is);
|
||||
}catch(Exception e){
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericPotionData getPotionData(ItemStack potionItemStack) {
|
||||
PotionMeta potionMeta = (PotionMeta) potionItemStack.getItemMeta();
|
||||
|
||||
Category category;
|
||||
switch(potionItemStack.getType()) {
|
||||
case POTION:
|
||||
category = Category.NORMAL;
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
category = Category.SPLASH;
|
||||
break;
|
||||
case LINGERING_POTION:
|
||||
category = Category.LINGERING;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
List<PotionEffect> effects = new ArrayList<PotionEffect>(potionMeta.getCustomEffects().size()+1);
|
||||
|
||||
if (potionMeta.hasCustomEffects()) {
|
||||
effects.addAll(potionMeta.getCustomEffects());
|
||||
}
|
||||
|
||||
PotionType potionType = potionMeta.getBasePotionData().getType();
|
||||
|
||||
return new GenericPotionData(potionType, effects, category, (potionType==PotionType.WATER || potionType==PotionType.MUNDANE || potionType==PotionType.UNCRAFTABLE || potionType==PotionType.THICK || potionType==PotionType.AWKWARD) && !effects.isEmpty(), potionMeta.getBasePotionData().isExtended() ? -1 : 0, potionMeta.getBasePotionData().isUpgraded() ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPotion(Material material) {
|
||||
switch(material) {
|
||||
case POTION:
|
||||
case SPLASH_POTION:
|
||||
case LINGERING_POTION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nmsDependencies.add(new NMSDependent("v1_12") {
|
||||
@Override
|
||||
public void safeGuard(Item item) {
|
||||
if(QuickShop.debug)System.out.println("safeGuard");
|
||||
org.bukkit.inventory.ItemStack iStack = item.getItemStack();
|
||||
net.minecraft.server.v1_12_R1.ItemStack nmsI = org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
nmsI.setCount(0);
|
||||
iStack = org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack.asBukkitCopy(nmsI);
|
||||
item.setItemStack(iStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getNBTBytes");
|
||||
net.minecraft.server.v1_12_R1.ItemStack is = org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
net.minecraft.server.v1_12_R1.NBTTagCompound itemCompound = new net.minecraft.server.v1_12_R1.NBTTagCompound();
|
||||
itemCompound = is.save(itemCompound);
|
||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataoutputstream = new DataOutputStream(new GZIPOutputStream(bytearrayoutputstream));
|
||||
try {
|
||||
net.minecraft.server.v1_12_R1.NBTCompressedStreamTools.a(itemCompound, (DataOutput) dataoutputstream);
|
||||
} finally {
|
||||
dataoutputstream.close();
|
||||
}
|
||||
return bytearrayoutputstream.toByteArray();
|
||||
}catch(Exception e){
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getItemStack(byte[] bytes) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getItemStack");
|
||||
DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes))));
|
||||
net.minecraft.server.v1_12_R1.NBTTagCompound nbttagcompound;
|
||||
try {
|
||||
nbttagcompound = net.minecraft.server.v1_12_R1.NBTCompressedStreamTools.a((DataInput) datainputstream, null);
|
||||
} finally {
|
||||
datainputstream.close();
|
||||
}
|
||||
net.minecraft.server.v1_12_R1.ItemStack is = new net.minecraft.server.v1_12_R1.ItemStack(nbttagcompound);
|
||||
return org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack.asBukkitCopy(is);
|
||||
}catch(Exception e){
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericPotionData getPotionData(ItemStack potionItemStack) {
|
||||
PotionMeta potionMeta = (PotionMeta) potionItemStack.getItemMeta();
|
||||
|
||||
Category category;
|
||||
switch(potionItemStack.getType()) {
|
||||
case POTION:
|
||||
category = Category.NORMAL;
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
category = Category.SPLASH;
|
||||
break;
|
||||
case LINGERING_POTION:
|
||||
category = Category.LINGERING;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
List<PotionEffect> effects = new ArrayList<PotionEffect>(potionMeta.getCustomEffects().size()+1);
|
||||
|
||||
if (potionMeta.hasCustomEffects()) {
|
||||
effects.addAll(potionMeta.getCustomEffects());
|
||||
}
|
||||
|
||||
PotionType potionType = potionMeta.getBasePotionData().getType();
|
||||
|
||||
return new GenericPotionData(potionType, effects, category, (potionType==PotionType.WATER || potionType==PotionType.MUNDANE || potionType==PotionType.UNCRAFTABLE || potionType==PotionType.THICK || potionType==PotionType.AWKWARD) && !effects.isEmpty(), potionMeta.getBasePotionData().isExtended() ? -1 : 0, potionMeta.getBasePotionData().isUpgraded() ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPotion(Material material) {
|
||||
switch(material) {
|
||||
case POTION:
|
||||
case SPLASH_POTION:
|
||||
case LINGERING_POTION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void safeGuard(Item item) throws ClassNotFoundException {
|
||||
if(QuickShop.debug)System.out.println("Renaming");
|
||||
rename(item.getItemStack());
|
||||
//if(QuickShop.debug)System.out.println("Protecting");
|
||||
//protect(item);
|
||||
if(QuickShop.debug)System.out.println("Seting pickup delay");
|
||||
item.setPickupDelay(2147483647);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
packageName = packageName.substring(packageName.lastIndexOf(".") + 1);
|
||||
//System.out.println("Package: " + packageName);
|
||||
for (NMSDependent dep : nmsDependencies) {
|
||||
if ((packageName.startsWith(dep.getVersion())) || ((dep.getVersion().isEmpty()) && ((packageName.equals("bukkit")) || (packageName.equals("craftbukkit"))))) {
|
||||
nms = dep;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new UnsupportedClassVersionError("This version of QuickShop is incompatible. Internal version: "+packageName);
|
||||
}
|
||||
|
||||
private static void rename(ItemStack iStack) {
|
||||
ItemMeta meta = iStack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.RED + "QuickShop " + Util.getName(iStack) + " " + nextId++);
|
||||
iStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public static byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) throws ClassNotFoundException {
|
||||
return nms.getNBTBytes(iStack);
|
||||
}
|
||||
|
||||
public static ItemStack getItemStack(byte[] bytes) throws ClassNotFoundException {
|
||||
return nms.getItemStack(bytes);
|
||||
}
|
||||
|
||||
public static boolean isPotion(Material material) {
|
||||
return nms.isPotion(material);
|
||||
}
|
||||
|
||||
public static GenericPotionData getPotionData(ItemStack potion) {
|
||||
return nms.getPotionData(potion);
|
||||
}
|
||||
|
||||
/*private static void protect(Item item) {
|
||||
try {
|
||||
Field itemField = item.getClass().getDeclaredField("item");
|
||||
itemField.setAccessible(true);
|
||||
Object nmsEntityItem = itemField.get(item);
|
||||
Method getItemStack;
|
||||
try {
|
||||
getItemStack = nmsEntityItem.getClass().getMethod("getItemStack", new Class[0]);
|
||||
} catch (NoSuchMethodException e) {
|
||||
try {
|
||||
getItemStack = nmsEntityItem.getClass().getMethod("d", new Class[0]);
|
||||
} catch (NoSuchMethodException e2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Object itemStack = getItemStack.invoke(nmsEntityItem, new Object[0]);
|
||||
Field countField;
|
||||
try {
|
||||
countField = itemStack.getClass().getDeclaredField("count");
|
||||
} catch (NoSuchFieldException e) {
|
||||
countField = itemStack.getClass().getDeclaredField("a");
|
||||
}
|
||||
countField.setAccessible(true);
|
||||
countField.set(itemStack, Integer.valueOf(0));
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("[QuickShop] Could not protect item from pickup properly! Dupes are now possible.");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Other error");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
private static abstract class NMSDependent {
|
||||
private String version;
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public NMSDependent(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public abstract boolean isPotion(Material material);
|
||||
|
||||
public abstract GenericPotionData getPotionData(ItemStack potionItemStack);
|
||||
|
||||
public abstract void safeGuard(Item paramItem);
|
||||
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack paramItemStack) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public org.bukkit.inventory.ItemStack getItemStack(byte[] paramArrayOfByte) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.maxgamer.quickshop.Util;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Util.CustomPotionsName.GenericPotionData;
|
||||
import org.maxgamer.quickshop.Util.CustomPotionsName.GenericPotionData.Category;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class NMS {
|
||||
private static ArrayList<NMSDependent> nmsDependencies = new ArrayList<NMSDependent>();
|
||||
private static int nextId = 0;
|
||||
private static NMSDependent nms;
|
||||
|
||||
static {
|
||||
nmsDependencies.add(new NMSDependent("v1_13") {
|
||||
@Override
|
||||
public void safeGuard(Item item) {
|
||||
if(QuickShop.debug)System.out.println("safeGuard");
|
||||
org.bukkit.inventory.ItemStack iStack = item.getItemStack();
|
||||
net.minecraft.server.v1_13_R1.ItemStack nmsI = org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
nmsI.setCount(0);
|
||||
iStack = org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack.asBukkitCopy(nmsI);
|
||||
item.setItemStack(iStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) {
|
||||
try{
|
||||
if(QuickShop.debug)System.out.println("getNBTBytes");
|
||||
net.minecraft.server.v1_13_R1.ItemStack is = org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack.asNMSCopy(iStack);
|
||||
net.minecraft.server.v1_13_R1.NBTTagCompound itemCompound = new net.minecraft.server.v1_13_R1.NBTTagCompound();
|
||||
itemCompound = is.save(itemCompound);
|
||||
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataoutputstream = new DataOutputStream(new GZIPOutputStream(bytearrayoutputstream));
|
||||
try {
|
||||
net.minecraft.server.v1_13_R1.NBTCompressedStreamTools.a(itemCompound, (DataOutput) dataoutputstream);
|
||||
} finally {
|
||||
dataoutputstream.close();
|
||||
}
|
||||
return bytearrayoutputstream.toByteArray();
|
||||
}catch(Exception e){
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GenericPotionData getPotionData(ItemStack potionItemStack) {
|
||||
PotionMeta potionMeta = (PotionMeta) potionItemStack.getItemMeta();
|
||||
|
||||
Category category;
|
||||
switch(potionItemStack.getType()) {
|
||||
case POTION:
|
||||
category = Category.NORMAL;
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
category = Category.SPLASH;
|
||||
break;
|
||||
case LINGERING_POTION:
|
||||
category = Category.LINGERING;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
List<PotionEffect> effects = new ArrayList<PotionEffect>(potionMeta.getCustomEffects().size()+1);
|
||||
|
||||
if (potionMeta.hasCustomEffects()) {
|
||||
effects.addAll(potionMeta.getCustomEffects());
|
||||
}
|
||||
|
||||
PotionType potionType = potionMeta.getBasePotionData().getType();
|
||||
|
||||
return new GenericPotionData(potionType, effects, category, (potionType==PotionType.WATER || potionType==PotionType.MUNDANE || potionType==PotionType.UNCRAFTABLE || potionType==PotionType.THICK || potionType==PotionType.AWKWARD) && !effects.isEmpty(), potionMeta.getBasePotionData().isExtended() ? -1 : 0, potionMeta.getBasePotionData().isUpgraded() ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPotion(Material material) {
|
||||
switch(material) {
|
||||
case POTION:
|
||||
case SPLASH_POTION:
|
||||
case LINGERING_POTION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void safeGuard(Item item) throws ClassNotFoundException {
|
||||
if(QuickShop.debug)System.out.println("Renaming");
|
||||
rename(item.getItemStack());
|
||||
//if(QuickShop.debug)System.out.println("Protecting");
|
||||
//protect(item);
|
||||
if(QuickShop.debug)System.out.println("Seting pickup delay");
|
||||
item.setPickupDelay(2147483647);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
packageName = packageName.substring(packageName.lastIndexOf(".") + 1);
|
||||
//System.out.println("Package: " + packageName);
|
||||
for (NMSDependent dep : nmsDependencies) {
|
||||
if ((packageName.startsWith(dep.getVersion())) || ((dep.getVersion().isEmpty()) && ((packageName.equals("bukkit")) || (packageName.equals("craftbukkit"))))) {
|
||||
nms = dep;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new UnsupportedClassVersionError("This version of QuickShop is incompatible. Internal version: "+packageName);
|
||||
}
|
||||
|
||||
private static void rename(ItemStack iStack) {
|
||||
ItemMeta meta = iStack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.RED + "QuickShop " + Util.getName(iStack) + " " + nextId++);
|
||||
iStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public static byte[] getNBTBytes(org.bukkit.inventory.ItemStack iStack) throws ClassNotFoundException {
|
||||
return nms.getNBTBytes(iStack);
|
||||
}
|
||||
|
||||
public static ItemStack getItemStack(byte[] bytes) throws ClassNotFoundException {
|
||||
return nms.getItemStack(bytes);
|
||||
}
|
||||
|
||||
public static boolean isPotion(Material material) {
|
||||
return nms.isPotion(material);
|
||||
}
|
||||
|
||||
public static GenericPotionData getPotionData(ItemStack potion) {
|
||||
return nms.getPotionData(potion);
|
||||
}
|
||||
|
||||
/*private static void protect(Item item) {
|
||||
try {
|
||||
Field itemField = item.getClass().getDeclaredField("item");
|
||||
itemField.setAccessible(true);
|
||||
Object nmsEntityItem = itemField.get(item);
|
||||
Method getItemStack;
|
||||
try {
|
||||
getItemStack = nmsEntityItem.getClass().getMethod("getItemStack", new Class[0]);
|
||||
} catch (NoSuchMethodException e) {
|
||||
try {
|
||||
getItemStack = nmsEntityItem.getClass().getMethod("d", new Class[0]);
|
||||
} catch (NoSuchMethodException e2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Object itemStack = getItemStack.invoke(nmsEntityItem, new Object[0]);
|
||||
Field countField;
|
||||
try {
|
||||
countField = itemStack.getClass().getDeclaredField("count");
|
||||
} catch (NoSuchFieldException e) {
|
||||
countField = itemStack.getClass().getDeclaredField("a");
|
||||
}
|
||||
countField.setAccessible(true);
|
||||
countField.set(itemStack, Integer.valueOf(0));
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("[QuickShop] Could not protect item from pickup properly! Dupes are now possible.");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Other error");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
private static abstract class NMSDependent {
|
||||
private String version;
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public NMSDependent(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public abstract boolean isPotion(Material material);
|
||||
|
||||
public abstract GenericPotionData getPotionData(ItemStack potionItemStack);
|
||||
|
||||
public abstract void safeGuard(Item paramItem);
|
||||
|
||||
public byte[] getNBTBytes(org.bukkit.inventory.ItemStack paramItemStack) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public org.bukkit.inventory.ItemStack getItemStack(byte[] paramArrayOfByte) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user