mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Holy shit, a fucking huge SignGUI System
Former-commit-id: dfcdc7be0c12530dc542ef0895e733e9ef8cc08b [formerly d6d8443502872624f55041e845f7c22c2bc81dac] Former-commit-id: e715b001faaf80a7bd6a7fd729734a5583eacbd2
This commit is contained in:
1 parent
6ae9a4eecf
commit
96942d5b40
8 files changed
+337
-9
No files matched your search
@@ -1,9 +1,12 @@
|
||||
package org.maxgamer.quickshop.Command;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -40,11 +43,13 @@ import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
public class QS implements CommandExecutor {
|
||||
QuickShop plugin;
|
||||
|
||||
public static HashMap<UUID,ArrayList<Object>> signPlayerCache = new HashMap<>();
|
||||
public QS(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void signGUIApi(ArrayList<Object> data, String arg) {
|
||||
|
||||
}
|
||||
private void setUnlimited(CommandSender sender) {
|
||||
if (sender instanceof Player && sender.hasPermission("quickshop.unlimited")) {
|
||||
BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
||||
@@ -66,7 +71,34 @@ public class QS implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void sign(CommandSender sender, String[] args) {
|
||||
if(!(sender instanceof Player))
|
||||
return;
|
||||
if(args.length<10) //sign world x y z type line1 line2 line3 line4
|
||||
return;
|
||||
ShopManager manager = new ShopManager(plugin);
|
||||
Shop shop = manager.getShop(new Location(Bukkit.getWorld(args[1]), Integer.valueOf(args[2]), Integer.valueOf(args[3]), Integer.valueOf(args[4])));
|
||||
if(shop==null)
|
||||
return;
|
||||
String[] texts = new String[3];
|
||||
String type = args[5];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String string = args[i];
|
||||
if(i<6)
|
||||
return;
|
||||
texts[i-6]=string;
|
||||
}
|
||||
try {
|
||||
ArrayList<Object> data = new ArrayList<>();
|
||||
data.add(shop);
|
||||
data.add(type);
|
||||
signPlayerCache.put(((Player)sender).getUniqueId(),data);
|
||||
Util.sendSignEditForGUI((Player)sender, texts);
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void remove(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player == false) {
|
||||
sender.sendMessage(ChatColor.RED + "Only players may use that command.");
|
||||
@@ -558,6 +590,9 @@ public class QS implements CommandExecutor {
|
||||
} else if (subArg.startsWith("amount")) {
|
||||
amount(sender, args);
|
||||
return true;
|
||||
} else if (subArg.startsWith("sign")) {
|
||||
sign(sender, args);
|
||||
return true;
|
||||
} else if (subArg.startsWith("buy")) {
|
||||
setBuy(sender);
|
||||
return true;
|
||||
|
||||
@@ -141,16 +141,18 @@ public class PlayerListener implements Listener {
|
||||
p.sendMessage(
|
||||
MsgUtil.getMessage("how-much-to-trade-for", MsgUtil.getItemi18n(Util.getName(info.getItem()))));
|
||||
}
|
||||
} else if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)&&e.getClickedBlock().getType()==Material.WALL_SIGN) {
|
||||
} else if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
|
||||
&& e.getClickedBlock().getType() == Material.WALL_SIGN) {
|
||||
/** @TODO: ControlPanel **/
|
||||
Block block;
|
||||
if(e.getClickedBlock().getType()==Material.WALL_SIGN) {
|
||||
if (e.getClickedBlock().getType() == Material.WALL_SIGN) {
|
||||
block = Util.getAttached(e.getClickedBlock());
|
||||
}else {
|
||||
} else {
|
||||
block = e.getClickedBlock();
|
||||
}
|
||||
if (plugin.getShopManager().getShop(block.getLocation()) != null) {
|
||||
MsgUtil.sendControlPanelInfo((CommandSender)e.getPlayer(), plugin.getShopManager().getShop(block.getLocation()));
|
||||
MsgUtil.sendControlPanelInfo((CommandSender) e.getPlayer(),
|
||||
plugin.getShopManager().getShop(block.getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package org.maxgamer.quickshop;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -30,6 +33,7 @@ import org.maxgamer.quickshop.Util.Util;
|
||||
import org.maxgamer.quickshop.Watcher.ItemWatcher;
|
||||
import org.maxgamer.quickshop.Watcher.LogWatcher;
|
||||
import org.maxgamer.quickshop.Watcher.UpdateWatcher;
|
||||
import org.maxgamer.quickshop.wrapper.WrapperPlayClientUpdateSign;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -93,7 +97,7 @@ public class QuickShop extends JavaPlugin {
|
||||
/** Use SpoutPlugin to get item / block names */
|
||||
public boolean useSpout = false;
|
||||
// private Metrics metrics;
|
||||
|
||||
QS commandExecutor =null;
|
||||
MultiverseCore mPlugin = null;
|
||||
private int displayItemCheckTicks;
|
||||
private boolean noopDisable;
|
||||
@@ -165,6 +169,15 @@ public class QuickShop extends JavaPlugin {
|
||||
}
|
||||
protocolLibPlugin = (ProtocolLib) Bukkit.getPluginManager().getPlugin("ProtocolLib");
|
||||
if (protocolLibPlugin != null) {
|
||||
getProtocolLib().addPacketListener(new PacketAdapter(this, PacketType.Play.Client.UPDATE_SIGN) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
WrapperPlayClientUpdateSign wrapper = new WrapperPlayClientUpdateSign(event.getPacket());
|
||||
//BlockPosition blockPos = wrapper.getLocation();
|
||||
ArrayList<Object> data = QS.signPlayerCache.get(event.getPlayer().getUniqueId());
|
||||
QuickShop.instance.commandExecutor.signGUIApi(data,wrapper.getLines()[0]);
|
||||
}
|
||||
});
|
||||
getLogger().info("Successfully loaded ProtocolLib support!");
|
||||
}
|
||||
if(getConfig().getInt("config-version")==0)
|
||||
@@ -542,7 +555,7 @@ public class QuickShop extends JavaPlugin {
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().registerEvents(worldListener, this);
|
||||
// Command handlers
|
||||
QS commandExecutor = new QS(this);
|
||||
commandExecutor = new QS(this);
|
||||
getCommand("qs").setExecutor(commandExecutor);
|
||||
if (getConfig().getInt("shop.find-distance") > 100) {
|
||||
getLogger().severe("Shop.find-distance is too high! It may cause lag! Pick a number under 100!");
|
||||
|
||||
@@ -36,6 +36,7 @@ public class ShopManager {
|
||||
private HashMap<UUID, Info> actions = new HashMap<UUID, Info>();
|
||||
private HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> shops = new HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>>();
|
||||
final private static ItemStack AIR = new ItemStack(Material.AIR);
|
||||
|
||||
|
||||
public ShopManager(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
@@ -126,6 +126,92 @@ public class MsgUtil {
|
||||
loadCfgMessages(true);
|
||||
}
|
||||
|
||||
public static void sendNormalControlPanelInfo(CommandSender sender, Shop shop) {
|
||||
if (!sender.hasPermission("quickshop.use")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getConfig().getBoolean("sneak-to-control"))
|
||||
if (sender instanceof Player)
|
||||
if (!((Player) sender).isSneaking())
|
||||
return;
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||
sender.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("controlpanel.infomation"));
|
||||
// Owner
|
||||
if (!sender.hasPermission("quickshop.setowner")) {
|
||||
sender.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.owner", shop.ownerName()));
|
||||
} else {
|
||||
String Text = MsgUtil.getMessage("controlpanel.setowner",shop.ownerName());
|
||||
String hoverText = MsgUtil.getMessage("controlpanel.setowner-hover");
|
||||
String clickCommand = "/qs setowner [Player]";
|
||||
TextComponent message = new TextComponent(ChatColor.DARK_PURPLE + "| " + Text);
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, clickCommand));
|
||||
message.setHoverEvent(
|
||||
new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hoverText).create()));
|
||||
sender.spigot().sendMessage(message);
|
||||
}
|
||||
// Unlimited
|
||||
if (sender.hasPermission("quickshop.unlimited")) {
|
||||
String Text = MsgUtil.getMessage("controlpanel.unlimited", bool2String(shop.isUnlimited()));
|
||||
String hoverText = MsgUtil.getMessage("controlpanel.unlimited-hover");
|
||||
String clickCommand = "/qs unlimited";
|
||||
MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand);
|
||||
}
|
||||
// Buying/Selling Mode
|
||||
if (sender.hasPermission("quickshop.create.buy") && sender.hasPermission("quickshop.create.sell")) {
|
||||
if (shop.isSelling()) {
|
||||
String Text = MsgUtil.getMessage("controlpanel.mode-selling");
|
||||
String hoverText = MsgUtil.getMessage("controlpanel.mode-selling-hover");
|
||||
String clickCommand = "/qs buy";
|
||||
MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand);
|
||||
} else if (shop.isBuying()) {
|
||||
String Text = MsgUtil.getMessage("controlpanel.mode-buying");
|
||||
String hoverText = MsgUtil.getMessage("controlpanel.mode-buying-hover");
|
||||
String clickCommand = "/qs sell";
|
||||
MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand);
|
||||
}
|
||||
}
|
||||
// Set Price
|
||||
if (sender.hasPermission("quickshop.other.price")) {
|
||||
String Text = MsgUtil.getMessage("controlpanel.price", String.valueOf(shop.getPrice()));
|
||||
String hoverText = MsgUtil.getMessage("controlpanel.mode-buying-hover");
|
||||
String clickCommand = "/qs price [New Price]";
|
||||
TextComponent message = new TextComponent(ChatColor.DARK_PURPLE + "| " + Text);
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, clickCommand));
|
||||
message.setHoverEvent(
|
||||
new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hoverText).create()));
|
||||
sender.spigot().sendMessage(message);
|
||||
}
|
||||
// Refill
|
||||
if (sender.hasPermission("quickshop.refill")) {
|
||||
String Text = MsgUtil.getMessage("controlpanel.refill", String.valueOf(shop.getPrice()));
|
||||
String hoverText = MsgUtil.getMessage("controlpanel.refill-hover");
|
||||
String clickCommand = "/qs refill [Amount]";
|
||||
TextComponent message = new TextComponent(ChatColor.DARK_PURPLE + "| " + Text);
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, clickCommand));
|
||||
message.setHoverEvent(
|
||||
new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hoverText).create()));
|
||||
sender.spigot().sendMessage(message);
|
||||
}
|
||||
// Refill
|
||||
if (sender.hasPermission("quickshop.empty")) {
|
||||
String Text = MsgUtil.getMessage("controlpanel.empty", String.valueOf(shop.getPrice()));
|
||||
String hoverText = MsgUtil.getMessage("controlpanel.empty-hover");
|
||||
String clickCommand = "/qs empty";
|
||||
MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand);
|
||||
}
|
||||
// Remove
|
||||
if (sender.hasPermission("quickshop.other.destroy") || shop.getOwner().equals(((Player)sender).getUniqueId())) {
|
||||
String Text = MsgUtil.getMessage("controlpanel.remove", String.valueOf(shop.getPrice()));
|
||||
String hoverText = MsgUtil.getMessage("controlpanel.remove-hover");
|
||||
String clickCommand = "/qs remove "+shop.getLocation().getBlockX()+" "+shop.getLocation().getBlockY()+" "+shop.getLocation().getBlockZ();
|
||||
MsgUtil.sendPanelMessage(sender, Text, hoverText, clickCommand);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||
}
|
||||
public static void sendControlPanelInfo(CommandSender sender, Shop shop) {
|
||||
if (!sender.hasPermission("quickshop.use")) {
|
||||
return;
|
||||
|
||||
@@ -26,7 +26,14 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.DisplayItem;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
@@ -178,6 +185,33 @@ public class Util {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void sendSignEditForGUI(Player player, String[] texts) throws InvocationTargetException {
|
||||
ProtocolManager manager = plugin.getProtocolLib();
|
||||
BlockPosition position = new BlockPosition(player.getLocation().getBlockX(), 255,
|
||||
player.getLocation().getBlockZ());
|
||||
|
||||
PacketContainer blockPacket = manager.createPacket(PacketType.Play.Server.BLOCK_CHANGE);
|
||||
blockPacket.getBlockPositionModifier().write(0, position);
|
||||
blockPacket.getBlockData().write(0, WrappedBlockData.createData(Material.WALL_SIGN));
|
||||
|
||||
PacketContainer dataPacket = manager.createPacket(PacketType.Play.Server.TILE_ENTITY_DATA);
|
||||
dataPacket.getBlockPositionModifier().write(0, position);
|
||||
dataPacket.getIntegers().write(0, 9);
|
||||
|
||||
NbtCompound compound = (NbtCompound) dataPacket.getNbtModifier().read(0);
|
||||
for (int index = 0; index < 4; index++) {
|
||||
compound.put("Text" + (index + 1), "{\"extra\":[{\"text\":\"" + texts[index] + "\"}],\"text\":\"\"}");
|
||||
}
|
||||
dataPacket.getNbtModifier().write(0, compound);
|
||||
|
||||
PacketContainer editorPacket = manager.createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR);
|
||||
editorPacket.getBlockPositionModifier().write(0, position);
|
||||
|
||||
manager.sendServerPacket(player, blockPacket);
|
||||
manager.sendServerPacket(player, dataPacket);
|
||||
manager.sendServerPacket(player, editorPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether someone else's shop is within reach of a hopper being placed by a player.
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package org.maxgamer.quickshop.wrapper;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
public abstract class AbstractPacket {
|
||||
// The packet we will be modifying
|
||||
protected PacketContainer handle;
|
||||
|
||||
/**
|
||||
* Constructs a new strongly typed wrapper for the given packet.
|
||||
*
|
||||
* @param handle - handle to the raw packet data.
|
||||
* @param type - the packet type.
|
||||
*/
|
||||
protected AbstractPacket(PacketContainer handle, PacketType type) {
|
||||
// Make sure we're given a valid packet
|
||||
if (handle == null)
|
||||
throw new IllegalArgumentException("Packet handle cannot be NULL.");
|
||||
if (!Objects.equal(handle.getType(), type))
|
||||
throw new IllegalArgumentException(handle.getHandle()
|
||||
+ " is not a packet of type " + type);
|
||||
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a handle to the raw packet data.
|
||||
*
|
||||
* @return Raw packet data.
|
||||
*/
|
||||
public PacketContainer getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current packet to the given receiver.
|
||||
*
|
||||
* @param receiver - the receiver.
|
||||
* @throws RuntimeException If the packet cannot be sent.
|
||||
*/
|
||||
public void sendPacket(Player receiver) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
|
||||
getHandle());
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException("Cannot send packet.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current packet to all online players.
|
||||
*/
|
||||
public void broadcastPacket() {
|
||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate receiving the current packet from the given sender.
|
||||
*
|
||||
* @param sender - the sender.
|
||||
* @throws RuntimeException If the packet cannot be received.
|
||||
* @deprecated Misspelled. recieve to receive
|
||||
* @see #receivePacket(Player)
|
||||
*/
|
||||
@Deprecated
|
||||
public void recievePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
|
||||
getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot recieve packet.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate receiving the current packet from the given sender.
|
||||
*
|
||||
* @param sender - the sender.
|
||||
* @throws RuntimeException if the packet cannot be received.
|
||||
*/
|
||||
public void receivePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
|
||||
getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot receive packet.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.maxgamer.quickshop.wrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
|
||||
public class WrapperPlayClientUpdateSign extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Client.UPDATE_SIGN;
|
||||
|
||||
public WrapperPlayClientUpdateSign() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayClientUpdateSign(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Location.
|
||||
* <p>
|
||||
* Notes: block Coordinates
|
||||
*
|
||||
* @return The current Location
|
||||
*/
|
||||
public BlockPosition getLocation() {
|
||||
return handle.getBlockPositionModifier().read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Location.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setLocation(BlockPosition value) {
|
||||
handle.getBlockPositionModifier().write(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve this sign's lines of text.
|
||||
*
|
||||
* @return The current lines
|
||||
*/
|
||||
public String[] getLines() {
|
||||
return handle.getStringArrays().read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this sign's lines of text.
|
||||
*
|
||||
* @param value - Lines, must be 4 elements long
|
||||
*/
|
||||
public void setLines(String[] value) {
|
||||
if (value == null)
|
||||
throw new IllegalArgumentException("value cannot be null!");
|
||||
if (value.length != 4)
|
||||
throw new IllegalArgumentException("value must have 4 elements!");
|
||||
|
||||
handle.getStringArrays().write(0, value);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user