From 389427d2ae9519186dba2e73ae531f593f70c692 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Wed, 7 Apr 2021 14:08:43 +0800 Subject: [PATCH 01/36] Little tweak --- .../quickshop/listener/PlayerListener.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java index 60d993980..fe6aa9a32 100644 --- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java +++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java @@ -67,31 +67,32 @@ public class PlayerListener extends QSListener { if (e.getHand() != EquipmentSlot.HAND) { return; } - if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && e.getClickedBlock() != null) { - if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && Util.isWallSign(e.getClickedBlock().getType())) { + final Block b = e.getClickedBlock(); + final Player p = e.getPlayer(); + if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) { + if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && Util.isWallSign(b.getType())) { final Block block; - if (Util.isWallSign(e.getClickedBlock().getType())) { - block = Util.getAttached(e.getClickedBlock()); + if (Util.isWallSign(b.getType())) { + block = Util.getAttached(b); } else { block = e.getClickedBlock(); } Shop controlPanelShop = plugin.getShopManager().getShop(Objects.requireNonNull(block).getLocation()); - if (controlPanelShop != null && (controlPanelShop.getOwner().equals(e.getPlayer().getUniqueId()) || QuickShop.getPermissionManager().hasPermission(e.getPlayer(), "quickshop.other.control"))) { - MsgUtil.sendControlPanelInfo(e.getPlayer(), Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation()))); + if (controlPanelShop != null && (controlPanelShop.getOwner().equals(p.getUniqueId()) || QuickShop.getPermissionManager().hasPermission(p, "quickshop.other.control"))) { + MsgUtil.sendControlPanelInfo(p, Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation()))); this.playClickSound(e.getPlayer()); Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())).setSignText(); } } return; } - final Block b = e.getClickedBlock(); if (b == null) { return; } if (!Util.canBeShop(b) && !Util.isWallSign(b.getType())) { return; } - final Player p = e.getPlayer(); + final Location loc = b.getLocation(); final ItemStack item = e.getItem(); // Get the shop From 306ef44ffa4567ea8afb8c04e4ca937a7ce4bf2c Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Wed, 7 Apr 2021 14:14:08 +0800 Subject: [PATCH 02/36] Closed #877 --- .../command/subcommand/SubCommand_Create.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Create.java b/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Create.java index 37a887ff5..1b000ad93 100644 --- a/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Create.java +++ b/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Create.java @@ -100,7 +100,16 @@ public class SubCommand_Create implements CommandProcesser { MsgUtil.sendMessage(sender, MsgUtil.getMessage("item-not-exist", sender, cmdArg[1])); return; } - item = new ItemStack(material, 1); + if (cmdArg.length > 2 && QuickShop.getPermissionManager().hasPermission(sender, "quicshop.create.stack") && plugin.isAllowStack()) { + try { + int amount = Integer.parseInt(cmdArg[2]); + item = new ItemStack(material, amount); + } catch (NumberFormatException e) { + item = new ItemStack(material, 1); + } + } else { + item = new ItemStack(material, 1); + } } Util.debugLog("Pending task for material: " + item.toString()); @@ -169,6 +178,9 @@ public class SubCommand_Create implements CommandProcesser { if (cmdArg.length == 2) { return Collections.singletonList(MsgUtil.getMessage("tabcomplete.item", sender)); } + if (cmdArg.length == 3) { + return Collections.singletonList(MsgUtil.getMessage("tabcomplete.amount", sender)); + } return Collections.emptyList(); } From 1d03026badf6a89a71129aa95fb29f6b4ed35484 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 14:29:31 +0800 Subject: [PATCH 03/36] Update status about Reserve and TNE --- src/main/java/org/maxgamer/quickshop/QuickShop.java | 4 ++-- .../java/org/maxgamer/quickshop/economy/Economy_Reserve.java | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index f68641bdb..a26dc6e47 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -416,7 +416,7 @@ public class QuickShop extends JavaPlugin { } } break; - case RESERVE: //TODO: Remove Reserve supporting + case RESERVE: core = new Economy_Reserve(this); Util.debugLog("Now using the Reserve economy system."); break; @@ -425,7 +425,7 @@ public class QuickShop extends JavaPlugin { Util.debugLog("Now using the GemsEconomy economy system."); break; case TNE: - core = new Economy_TNE(this); //TODO: Unstable + core = new Economy_TNE(this); Util.debugLog("Now using the TNE economy system."); break; // case MIXED: diff --git a/src/main/java/org/maxgamer/quickshop/economy/Economy_Reserve.java b/src/main/java/org/maxgamer/quickshop/economy/Economy_Reserve.java index 7163fa3fc..acb4614d7 100644 --- a/src/main/java/org/maxgamer/quickshop/economy/Economy_Reserve.java +++ b/src/main/java/org/maxgamer/quickshop/economy/Economy_Reserve.java @@ -39,9 +39,7 @@ import java.util.logging.Level; /** * @author creatorfromhell - * @deprecated Reserve no-longer active after Minecraft 1.14. */ -@Deprecated public class Economy_Reserve implements EconomyCore { private static final String errorMsg = From 7a74cf9c567b1156cded500f443287251d7537a7 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 14:37:52 +0800 Subject: [PATCH 04/36] Use weakValue for cache not WeakReference --- pom.xml | 2 +- .../java/org/maxgamer/quickshop/Cache.java | 20 ++++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index fb3735720..bda08438d 100644 --- a/pom.xml +++ b/pom.xml @@ -543,7 +543,7 @@ org.spigotmc spigot-api - 1.16.4-R0.1-SNAPSHOT + 1.16.5-R0.1-SNAPSHOT provided diff --git a/src/main/java/org/maxgamer/quickshop/Cache.java b/src/main/java/org/maxgamer/quickshop/Cache.java index 3ce69bdc8..df121778f 100644 --- a/src/main/java/org/maxgamer/quickshop/Cache.java +++ b/src/main/java/org/maxgamer/quickshop/Cache.java @@ -27,16 +27,16 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.shop.Shop; -import java.lang.ref.WeakReference; import java.util.concurrent.TimeUnit; public class Cache { private final QuickShop plugin; - private final com.github.benmanes.caffeine.cache.Cache> accessCaching = Caffeine + private final com.github.benmanes.caffeine.cache.Cache accessCaching = Caffeine .newBuilder() .initialCapacity(10000) .expireAfterAccess(120, TimeUnit.MINUTES) .recordStats() + .weakValues() .build(); public Cache(QuickShop plugin) { @@ -57,7 +57,7 @@ public class Cache { */ @Nullable public Shop getCaching(@NotNull Location location, boolean includeAttached) { - WeakReference result = accessCaching.get(location, update -> { + Shop result = accessCaching.get(location, update -> { Shop shop; //Because we need the data from Caffeine, so we cannot direct return WeakReference directly //Cause we will see 100% load success data :( if (includeAttached) { @@ -65,17 +65,9 @@ public class Cache { } else { shop = plugin.getShopManager().getShop(update); } - if (shop == null) { - return null; - } else { - return new WeakReference<>(shop); - } + return shop; }); - if (result == null) { - return null; - } else { - return result.get(); - } + return result; } /** @@ -89,6 +81,6 @@ public class Cache { accessCaching.invalidate(location); return; } - accessCaching.put(location, new WeakReference<>(shop)); + accessCaching.put(location, shop); } } From 59f447b4a1fc883a24b12df5b3c54090b0857d6a Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 15:11:41 +0800 Subject: [PATCH 05/36] Cleanup and remove Adventure support since BungeeChat lib fixed --- pom.xml | 50 ++-- .../quickshop/chat/QuickChatType.java | 19 +- .../platform/minedown/AdventureQuickChat.java | 255 +++++++++--------- .../quickshop/shop/ShopControlPanelImpl.java | 2 + src/main/resources/config.yml | 5 +- 5 files changed, 171 insertions(+), 160 deletions(-) diff --git a/pom.xml b/pom.xml index bda08438d..46e0e255b 100644 --- a/pom.xml +++ b/pom.xml @@ -757,24 +757,6 @@ system ${project.basedir}/lib/BlocksHub-3.1.1.jar - - net.kyori - adventure-platform-bukkit - 4.0.0-SNAPSHOT - compile - - - net.kyori - adventure-text-serializer-gson - 4.2.0 - compile - - - com.google.code.gson - gson - - - com.rollbar [1.0,) @@ -872,5 +854,37 @@ 1.0.6 compile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/maxgamer/quickshop/chat/QuickChatType.java b/src/main/java/org/maxgamer/quickshop/chat/QuickChatType.java index 9eacf83c1..bcebec8ca 100644 --- a/src/main/java/org/maxgamer/quickshop/chat/QuickChatType.java +++ b/src/main/java/org/maxgamer/quickshop/chat/QuickChatType.java @@ -20,7 +20,6 @@ package org.maxgamer.quickshop.chat; import org.jetbrains.annotations.NotNull; -import org.maxgamer.quickshop.chat.platform.minedown.AdventureQuickChat; import org.maxgamer.quickshop.chat.platform.minedown.BungeeQuickChat; public enum QuickChatType { @@ -28,8 +27,8 @@ public enum QuickChatType { * BUNGEECHAT = Use the chat lib that Spigot offered. * ADVENTURE = Use the chat lib Adventure, it can resolve player disconnected issue but have no message output bug. */ - BUNGEECHAT(0), - ADVENTURE(1); + BUNGEECHAT(0); + //ADVENTURE(1); private final int id; @@ -51,17 +50,17 @@ public enum QuickChatType { } public static QuickChat createById(int id) { - QuickChatType type = fromID(id); - if (type == QuickChatType.ADVENTURE) { - return new AdventureQuickChat(); - } +// QuickChatType type = fromID(id); +// if (type == QuickChatType.ADVENTURE) { +// return new AdventureQuickChat(); +// } return new BungeeQuickChat(); } public static QuickChat createByType(QuickChatType type) { - if (type == QuickChatType.ADVENTURE) { - return new AdventureQuickChat(); - } +// if (type == QuickChatType.ADVENTURE) { +// return new AdventureQuickChat(); +// } return new BungeeQuickChat(); } diff --git a/src/main/java/org/maxgamer/quickshop/chat/platform/minedown/AdventureQuickChat.java b/src/main/java/org/maxgamer/quickshop/chat/platform/minedown/AdventureQuickChat.java index e1fa7f34c..a2d9a60a9 100644 --- a/src/main/java/org/maxgamer/quickshop/chat/platform/minedown/AdventureQuickChat.java +++ b/src/main/java/org/maxgamer/quickshop/chat/platform/minedown/AdventureQuickChat.java @@ -1,128 +1,127 @@ -/* - * This file is a part of project QuickShop, the name is AdventureQuickChat.java - * Copyright (C) PotatoCraft Studio and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.maxgamer.quickshop.chat.platform.minedown; - -import net.kyori.adventure.identity.Identity; -import net.kyori.adventure.key.Key; -import net.kyori.adventure.nbt.api.BinaryTagHolder; -import net.kyori.adventure.platform.bukkit.BukkitAudiences; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.ComponentLike; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.apache.commons.lang.StringUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.maxgamer.quickshop.QuickShop; -import org.maxgamer.quickshop.chat.QuickChat; -import org.maxgamer.quickshop.chat.QuickComponent; -import org.maxgamer.quickshop.chat.QuickComponentImpl; -import org.maxgamer.quickshop.shop.Shop; -import org.maxgamer.quickshop.util.ItemNMS; -import org.maxgamer.quickshop.util.MsgUtil; -import org.maxgamer.quickshop.util.Util; - -import java.util.logging.Level; - -public class AdventureQuickChat implements QuickChat { - private final QuickShop plugin = QuickShop.getInstance(); - private final BukkitAudiences audiences = BukkitAudiences.create(QuickShop.getInstance()); - - @Override - public void send(@NotNull CommandSender receiver, @Nullable String message) { - if (StringUtils.isEmpty(message)) { - return; - } - audiences.sender(receiver).sendMessage(LegacyComponentSerializer.legacySection().deserialize(message)); - } - - @Override - public void send(@NotNull CommandSender receiver, @Nullable QuickComponent component) { - if (component == null) { - return; - } - if ((component.get() instanceof ComponentLike)) { - audiences.sender(receiver).sendMessage(Identity.nil(), (ComponentLike) component.get()); - return; - } - Util.debugLog("Illegal component " + component.get().getClass().getName() + " sending to " + this.getClass().getName() + " processor, rejected."); - - } - - @Override - public void sendItemHologramChat(@NotNull Player player, @NotNull String left, @NotNull ItemStack itemStack, @NotNull String right) { - audiences.player(player).sendMessage((Component) getItemTextComponent(itemStack, player, left + Util.getItemStackName(itemStack) + right).get()); - } - - @Override - public @NotNull QuickComponent getItemHologramChat(@NotNull Shop shop, @NotNull ItemStack itemStack, @NotNull Player player, @NotNull String message) { - Component component = (Component) getItemTextComponent(itemStack, player, message).get(); - if (QuickShop.getPermissionManager().hasPermission(player, "quickshop.preview")) { - component = component.clickEvent(ClickEvent.runCommand(MsgUtil.fillArgs( - "/qs silentpreview {0}", - shop.getRuntimeRandomUniqueId().toString()))); - } - return new QuickComponentImpl(component); - } - - @Override - public @NotNull QuickComponent getItemTextComponent(@NotNull ItemStack itemStack, @NotNull Player player, @NotNull String normalText) { - TextComponent errorComponent = Component.text(MsgUtil.getMessage("menu.item-holochat-error", player)); - try { - String json = ItemNMS.saveJsonfromNMS(itemStack); - if (json != null) { - return new QuickComponentImpl(Component - .text(normalText + " " + MsgUtil.getMessage("menu.preview", player)) - .hoverEvent(HoverEvent.showItem(Key.key(itemStack.getType().getKey().toString()) - , itemStack.getAmount(), BinaryTagHolder.of(json)))); - } - } catch (Throwable throwable) { - plugin.getLogger().log(Level.SEVERE, "Failed to saving item to json for holochat", throwable); - } - return new QuickComponentImpl(errorComponent); - - } - - @Override - public void sendExecutableChat(@NotNull CommandSender receiver, @NotNull String message, @NotNull String hoverText, @NotNull String command) { - TextComponent component = Component.text(MsgUtil.getMessage("tableformat.left_begin", receiver) + message) - .color(NamedTextColor.DARK_PURPLE) - .clickEvent(ClickEvent.runCommand(command)) - .hoverEvent(HoverEvent.showText(Component.text(hoverText))); - - audiences.sender(receiver).sendMessage(component); - } - - @Override - public void sendSuggestedChat(@NotNull CommandSender receiver, @NotNull String message, @NotNull String hoverText, @NotNull String command) { - TextComponent component = Component.text(MsgUtil.getMessage("tableformat.left_begin", receiver) + message) - .color(NamedTextColor.DARK_PURPLE) - .clickEvent(ClickEvent.suggestCommand(command)) - .hoverEvent(HoverEvent.showText(Component.text(hoverText))); - audiences.sender(receiver).sendMessage(component); - } - -} +///* +// * This file is a part of project QuickShop, the name is AdventureQuickChat.java +// * Copyright (C) PotatoCraft Studio and contributors +// * +// * This program is free software: you can redistribute it and/or modify it +// * under the terms of the GNU General Public License as published by the +// * Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, but WITHOUT +// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// * for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see . +// * +// */ +// +//package org.maxgamer.quickshop.chat.platform.minedown; +// +//import net.kyori.adventure.identity.Identity; +//import net.kyori.adventure.key.Key; +//import net.kyori.adventure.nbt.api.BinaryTagHolder; +//import net.kyori.adventure.text.Component; +//import net.kyori.adventure.text.ComponentLike; +//import net.kyori.adventure.text.TextComponent; +//import net.kyori.adventure.text.event.ClickEvent; +//import net.kyori.adventure.text.event.HoverEvent; +//import net.kyori.adventure.text.format.NamedTextColor; +//import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +//import org.apache.commons.lang.StringUtils; +//import org.bukkit.command.CommandSender; +//import org.bukkit.entity.Player; +//import org.bukkit.inventory.ItemStack; +//import org.jetbrains.annotations.NotNull; +//import org.jetbrains.annotations.Nullable; +//import org.maxgamer.quickshop.QuickShop; +//import org.maxgamer.quickshop.chat.QuickChat; +//import org.maxgamer.quickshop.chat.QuickComponent; +//import org.maxgamer.quickshop.chat.QuickComponentImpl; +//import org.maxgamer.quickshop.shop.Shop; +//import org.maxgamer.quickshop.util.ItemNMS; +//import org.maxgamer.quickshop.util.MsgUtil; +//import org.maxgamer.quickshop.util.Util; +// +//import java.util.logging.Level; +// +//public class AdventureQuickChat implements QuickChat { +// private final QuickShop plugin = QuickShop.getInstance(); +// private final BukkitAudiences audiences = BukkitAudiences.create(QuickShop.getInstance()); +// +// @Override +// public void send(@NotNull CommandSender receiver, @Nullable String message) { +// if (StringUtils.isEmpty(message)) { +// return; +// } +// audiences.sender(receiver).sendMessage(LegacyComponentSerializer.legacySection().deserialize(message)); +// } +// +// @Override +// public void send(@NotNull CommandSender receiver, @Nullable QuickComponent component) { +// if (component == null) { +// return; +// } +// if ((component.get() instanceof ComponentLike)) { +// audiences.sender(receiver).sendMessage(Identity.nil(), (ComponentLike) component.get()); +// return; +// } +// Util.debugLog("Illegal component " + component.get().getClass().getName() + " sending to " + this.getClass().getName() + " processor, rejected."); +// +// } +// +// @Override +// public void sendItemHologramChat(@NotNull Player player, @NotNull String left, @NotNull ItemStack itemStack, @NotNull String right) { +// audiences.player(player).sendMessage((Component) getItemTextComponent(itemStack, player, left + Util.getItemStackName(itemStack) + right).get()); +// } +// +// @Override +// public @NotNull QuickComponent getItemHologramChat(@NotNull Shop shop, @NotNull ItemStack itemStack, @NotNull Player player, @NotNull String message) { +// Component component = (Component) getItemTextComponent(itemStack, player, message).get(); +// if (QuickShop.getPermissionManager().hasPermission(player, "quickshop.preview")) { +// component = component.clickEvent(ClickEvent.runCommand(MsgUtil.fillArgs( +// "/qs silentpreview {0}", +// shop.getRuntimeRandomUniqueId().toString()))); +// } +// return new QuickComponentImpl(component); +// } +// +// @Override +// public @NotNull QuickComponent getItemTextComponent(@NotNull ItemStack itemStack, @NotNull Player player, @NotNull String normalText) { +// TextComponent errorComponent = Component.text(MsgUtil.getMessage("menu.item-holochat-error", player)); +// try { +// String json = ItemNMS.saveJsonfromNMS(itemStack); +// if (json != null) { +// return new QuickComponentImpl(Component +// .text(normalText + " " + MsgUtil.getMessage("menu.preview", player)) +// .hoverEvent(HoverEvent.showItem(Key.key(itemStack.getType().getKey().toString()) +// , itemStack.getAmount(), BinaryTagHolder.of(json)))); +// } +// } catch (Throwable throwable) { +// plugin.getLogger().log(Level.SEVERE, "Failed to saving item to json for holochat", throwable); +// } +// return new QuickComponentImpl(errorComponent); +// +// } +// +// @Override +// public void sendExecutableChat(@NotNull CommandSender receiver, @NotNull String message, @NotNull String hoverText, @NotNull String command) { +// TextComponent component = Component.text(MsgUtil.getMessage("tableformat.left_begin", receiver) + message) +// .color(NamedTextColor.DARK_PURPLE) +// .clickEvent(ClickEvent.runCommand(command)) +// .hoverEvent(HoverEvent.showText(Component.text(hoverText))); +// +// audiences.sender(receiver).sendMessage(component); +// } +// +// @Override +// public void sendSuggestedChat(@NotNull CommandSender receiver, @NotNull String message, @NotNull String hoverText, @NotNull String command) { +// TextComponent component = Component.text(MsgUtil.getMessage("tableformat.left_begin", receiver) + message) +// .color(NamedTextColor.DARK_PURPLE) +// .clickEvent(ClickEvent.suggestCommand(command)) +// .hoverEvent(HoverEvent.showText(Component.text(hoverText))); +// audiences.sender(receiver).sendMessage(component); +// } +// +//} diff --git a/src/main/java/org/maxgamer/quickshop/shop/ShopControlPanelImpl.java b/src/main/java/org/maxgamer/quickshop/shop/ShopControlPanelImpl.java index 3d7333058..578652ec5 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ShopControlPanelImpl.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ShopControlPanelImpl.java @@ -27,4 +27,6 @@ public class ShopControlPanelImpl { public ShopControlPanelImpl(QuickShop plugin) { this.plugin = plugin; } + + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fea8e75ce..f7c0e81e3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -135,7 +135,7 @@ use-caching: true #Control which one chat system QuickShop should to use. #0=BungeeChat (Spigot Defaults) -#1=Adventure +#1=Adventure (Removed In Current Version) chat-type: 0 #MySQL database settings. @@ -248,7 +248,6 @@ shop: display-check-time: 40 #Allow display show stacks effect when stack creation turned on - #!WIP, DON'T TURN ON IT BEFORE WE FINISH IT! display-allow-stacks: false #Use enhance display protect @@ -417,8 +416,6 @@ shop: remove-protection-trigger: true #Allow quickshop selling/buying multi items in once transaction. allow-stacks: false - #Disallow player put items into shop container if that item not the shop item. WIP - #deny-non-shop-items-to-shop-container: false #List of items that can't be sold in shops. Anyone with quickshop.bypass. can bypass it blacklist: - Bedrock From 0cce6a972ef8cf9686d7f8db989ad733f1c5c7a5 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 15:13:03 +0800 Subject: [PATCH 06/36] fix package name issue --- .../FabledIntegration.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) rename src/main/java/org/maxgamer/quickshop/integration/{FabledSkyblock => fabledskyblock}/FabledIntegration.java (78%) diff --git a/src/main/java/org/maxgamer/quickshop/integration/FabledSkyblock/FabledIntegration.java b/src/main/java/org/maxgamer/quickshop/integration/fabledskyblock/FabledIntegration.java similarity index 78% rename from src/main/java/org/maxgamer/quickshop/integration/FabledSkyblock/FabledIntegration.java rename to src/main/java/org/maxgamer/quickshop/integration/fabledskyblock/FabledIntegration.java index bbf6e3388..b6a0274e2 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/FabledSkyblock/FabledIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/fabledskyblock/FabledIntegration.java @@ -1,4 +1,23 @@ -package org.maxgamer.quickshop.integration.Fabledskyblock; +/* + * This file is a part of project QuickShop, the name is FabledIntegration.java + * Copyright (C) PotatoCraft Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.maxgamer.quickshop.integration.fabledskyblock; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.island.Island; From f661b50831ec74ce71e8fa3b637f3ee9163c328d Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:01:46 +0800 Subject: [PATCH 07/36] Impl SuperiorSkyblock2Integration, Solved #890 --- pom.xml | 9 + .../org/maxgamer/quickshop/QuickShop.java | 7 +- .../integration/IntegrationHelper.java | 4 +- .../SuperiorSkyblock2Integration.java | 159 ++++++++++++++++++ src/main/resources/config.yml | 9 +- 5 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java diff --git a/pom.xml b/pom.xml index 46e0e255b..fe78e3bc0 100644 --- a/pom.xml +++ b/pom.xml @@ -353,6 +353,10 @@ papermc https://papermc.io/repo/repository/maven-public/ + + bg-repo + https://repo.bg-software.com/repository/api/ + @@ -854,6 +858,11 @@ 1.0.6 compile + + com.bgsoftware + SuperiorSkyblockAPI + latest + diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index a26dc6e47..c862c1d4f 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1723,7 +1723,12 @@ public class QuickShop extends JavaPlugin { getConfig().set("plugin.BKCommonLib", true); getConfig().set("config-version", ++selectedVersion); } - + if (selectedVersion == 125) { + getConfig().set("integration.superiorskyblock.enable", false); + getConfig().set("integration.superiorskyblock.owner-create-only", false); + getConfig().set("integration.superiorskyblock.delete-shop-on-member-leave", true); + getConfig().set("config-version", ++selectedVersion); + } if (getConfig().getInt("matcher.work-type") != 0 && GameVersion.get(ReflectFactory.getServerVersion()).name().contains("1_16")) { getLogger().warning("You are not using QS Matcher, it may meeting item comparing issue mentioned there: https://hub.spigotmc.org/jira/browse/SPIGOT-5063"); diff --git a/src/main/java/org/maxgamer/quickshop/integration/IntegrationHelper.java b/src/main/java/org/maxgamer/quickshop/integration/IntegrationHelper.java index 6b7694da6..4972b1bb0 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/IntegrationHelper.java +++ b/src/main/java/org/maxgamer/quickshop/integration/IntegrationHelper.java @@ -25,12 +25,13 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.NotNull; import org.maxgamer.quickshop.QuickShop; -import org.maxgamer.quickshop.integration.Fabledskyblock.FabledIntegration; +import org.maxgamer.quickshop.integration.fabledskyblock.FabledIntegration; import org.maxgamer.quickshop.integration.factionsuuid.FactionsUUIDIntegration; import org.maxgamer.quickshop.integration.griefprevention.GriefPreventionIntegration; import org.maxgamer.quickshop.integration.lands.LandsIntegration; import org.maxgamer.quickshop.integration.plotsquared.PlotSquaredIntegrationProxy; import org.maxgamer.quickshop.integration.residence.ResidenceIntegration; +import org.maxgamer.quickshop.integration.superiorskyblock.SuperiorSkyblock2Integration; import org.maxgamer.quickshop.integration.towny.TownyIntegration; import org.maxgamer.quickshop.integration.worldguard.WorldGuardIntegration; import org.maxgamer.quickshop.util.Util; @@ -54,6 +55,7 @@ public class IntegrationHelper extends QuickShopInstanceHolder { integratedPluginNameMap.put("Towny", TownyIntegration.class); integratedPluginNameMap.put("WorldGuard", WorldGuardIntegration.class); integratedPluginNameMap.put("FabledSkyblock", FabledIntegration.class); + integratedPluginNameMap.put("SuperiorSkyblock", SuperiorSkyblock2Integration.class); } private final Map integrations = new HashMap<>(7); diff --git a/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java b/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java new file mode 100644 index 000000000..6008ff2d7 --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java @@ -0,0 +1,159 @@ +/* + * This file is a part of project QuickShop, the name is SuperiorSkyblock2Integration.java + * Copyright (C) PotatoCraft Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.maxgamer.quickshop.integration.superiorskyblock; + +import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI; +import com.bgsoftware.superiorskyblock.api.island.Island; +import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; +import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.integration.IntegrateStage; +import org.maxgamer.quickshop.integration.IntegrationStage; +import org.maxgamer.quickshop.integration.QSIntegratedPlugin; +import org.maxgamer.quickshop.shop.Shop; + +import java.util.Map; + +@IntegrationStage(loadStage = IntegrateStage.onEnableAfter) +public class SuperiorSkyblock2Integration extends QSIntegratedPlugin implements Listener { + private final boolean onlyOwnerCanCreateShop; + private final boolean deleteShopOnMemberLeave; + + public SuperiorSkyblock2Integration(QuickShop plugin) { + super(plugin); + onlyOwnerCanCreateShop = plugin.getConfig().getBoolean("integration.superiorskyblock.owner-create-only"); + deleteShopOnMemberLeave = plugin.getConfig().getBoolean("integration.superiorskyblock.delete-shop-on-member-leave"); + if (plugin.getConfig().getBoolean("integration.superiorskyblock.delete-shop-on-member-leave")) { + Bukkit.getPluginManager().registerEvents(this, plugin); + } + } + + /** + * Return the integrated plugin name. + * For example, Residence + * + * @return integrated plugin + */ + @Override + public @NotNull String getName() { + return "SuperiorSkyblock"; + } + + /** + * Check if a player can create shop here + * + * @param player the player want to create shop + * @param location shop location + * @return If you can create shop here + */ + @Override + public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { + Island island = SuperiorSkyblockAPI.getIslandAt(location); + SuperiorPlayer superiorPlayer = SuperiorSkyblockAPI.getPlayer(player); + if (island == null) { + return false; + } + if (onlyOwnerCanCreateShop) { + return island.getOwner().equals(superiorPlayer); + } else { + if (island.getOwner().equals(superiorPlayer)) + return true; + return island.isMember(superiorPlayer); + } + } + + /** + * Check if a player can trade with shop here + * + * @param player the player want to trade with shop + * @param location shop location + * @return If you can trade with shop here + */ + @Override + public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) { + return true; + } + + /** + * Loading logic + * Execute Stage defined by IntegrationStage + */ + @Override + public void load() { + + } + + /** + * Unloding logic + * Will execute when Quickshop unloading + */ + @Override + public void unload() { + + } + + @EventHandler + public void deleteShops(com.bgsoftware.superiorskyblock.api.events.IslandQuitEvent event) { + event.getIsland().getAllChunks().forEach((chunk) -> { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null && !shops.isEmpty()) { + shops.forEach((location, shop) -> { + if (shop.getOwner().equals(event.getPlayer().getUniqueId())) { + plugin.log("[SuperiorSkyBlock2 Integration]Shop " + shop + " deleted caused by ShopOwnerQuitFromIsland"); + shop.delete(); + } + }); + } + }); + } + + @EventHandler + public void deleteShops(com.bgsoftware.superiorskyblock.api.events.IslandKickEvent event) { + event.getIsland().getAllChunks().forEach((chunk) -> { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null && !shops.isEmpty()) { + shops.forEach((location, shop) -> { + if (shop.getOwner().equals(event.getTarget().getUniqueId())) { + plugin.log("[SuperiorSkyBlock2 Integration]Shop " + shop + " deleted caused by ShopOwnerKickedFromIsland"); + shop.delete(); + } + }); + } + }); + + } + + @EventHandler + public void deleteShops(com.bgsoftware.superiorskyblock.api.events.IslandChunkResetEvent event) { + Map shops = plugin.getShopManager().getShops(event.getWorld().getName(), event.getChunkX(), event.getChunkZ()); + if (shops != null && !shops.isEmpty()) { + shops.forEach((location, shop) -> { + plugin.log("[SuperiorSkyBlock2 Integration]Shop " + shop + " deleted caused by IslandChunkReset."); + shop.delete(); + }); + } + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f7c0e81e3..faacfa666 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,7 +4,7 @@ #Do not touch if you not clear know about this -config-version: 125 +config-version: 126 #Select the language you want to use, (e.g de), use only supported language codes from the list below. #If you use a not exist/not support language, plugin will move to use en_US to keep everything working. @@ -660,6 +660,13 @@ integration: warzone: false #Player must have flags in the faction: flags: [ ] + #Superior Skyblock Integration + superiorskyblock: + enable: false + #Does only island owner can create shops on island? + owner-create-only: false + #Delete shop when the shop owner kicked/quited from island + delete-shop-on-member-leave: true #the protection that shop should check protect: explode: true From 1b11c8b488570f065f80f275d16389fd48d315e6 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:08:23 +0800 Subject: [PATCH 08/36] Remove Adventure code from ContainerShop --- src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java index fd2a412ec..ef7b78e12 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java @@ -22,8 +22,6 @@ package org.maxgamer.quickshop.shop; import com.lishid.openinv.OpenInv; import io.papermc.lib.PaperLib; import lombok.EqualsAndHashCode; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -146,8 +144,7 @@ public class ContainerShop implements Shop { Util.debugLog("Shop item display is: " + meta.getDisplayName()); //https://hub.spigotmc.org/jira/browse/SPIGOT-5964 if (meta.getDisplayName().matches("\\{.*\\}")) { - meta.setDisplayName(LegacyComponentSerializer.legacySection().serialize( - GsonComponentSerializer.gson().deserialize(meta.getDisplayName()))); + meta.setDisplayName(meta.getDisplayName()); //Correct both items item.setItemMeta(meta); this.item.setItemMeta(meta); From a6ce18431b8cb02ffade1ec746c41420a44e28e0 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:15:48 +0800 Subject: [PATCH 09/36] Fix typo --- .../maxgamer/quickshop/permission/BukkitPermsProvider.java | 4 ++-- ...onContainer.java => PermissionInformationContainer.java} | 4 ++-- .../maxgamer/quickshop/permission/PermissionManager.java | 2 +- .../maxgamer/quickshop/permission/PermissionProvider.java | 2 +- .../quickshop/permission/VaultPermissionProvider.java | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) rename src/main/java/org/maxgamer/quickshop/permission/{PermissionInfomationContainer.java => PermissionInformationContainer.java} (94%) diff --git a/src/main/java/org/maxgamer/quickshop/permission/BukkitPermsProvider.java b/src/main/java/org/maxgamer/quickshop/permission/BukkitPermsProvider.java index 61226bdd2..224b89931 100644 --- a/src/main/java/org/maxgamer/quickshop/permission/BukkitPermsProvider.java +++ b/src/main/java/org/maxgamer/quickshop/permission/BukkitPermsProvider.java @@ -42,9 +42,9 @@ public class BukkitPermsProvider implements PermissionProvider { * @return Debug Infos */ @Override - public @NotNull PermissionInfomationContainer getDebugInfo( + public @NotNull PermissionInformationContainer getDebugInfo( @NotNull CommandSender sender, @NotNull String permission) { - return new PermissionInfomationContainer(sender, permission, null, null); + return new PermissionInformationContainer(sender, permission, null, null); } } diff --git a/src/main/java/org/maxgamer/quickshop/permission/PermissionInfomationContainer.java b/src/main/java/org/maxgamer/quickshop/permission/PermissionInformationContainer.java similarity index 94% rename from src/main/java/org/maxgamer/quickshop/permission/PermissionInfomationContainer.java rename to src/main/java/org/maxgamer/quickshop/permission/PermissionInformationContainer.java index 794f4150b..1744baba9 100644 --- a/src/main/java/org/maxgamer/quickshop/permission/PermissionInfomationContainer.java +++ b/src/main/java/org/maxgamer/quickshop/permission/PermissionInformationContainer.java @@ -1,5 +1,5 @@ /* - * This file is a part of project QuickShop, the name is PermissionInfomationContainer.java + * This file is a part of project QuickShop, the name is PermissionInformationContainer.java * Copyright (C) PotatoCraft Studio and contributors * * This program is free software: you can redistribute it and/or modify it @@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable; @Data @AllArgsConstructor -public class PermissionInfomationContainer { +public class PermissionInformationContainer { @NotNull private CommandSender sender; diff --git a/src/main/java/org/maxgamer/quickshop/permission/PermissionManager.java b/src/main/java/org/maxgamer/quickshop/permission/PermissionManager.java index 5ec9caaca..bc339bc42 100644 --- a/src/main/java/org/maxgamer/quickshop/permission/PermissionManager.java +++ b/src/main/java/org/maxgamer/quickshop/permission/PermissionManager.java @@ -57,7 +57,7 @@ public class PermissionManager { boolean result = provider.hasPermission(sender, permission); if (Util.isDevMode()) { try { - PermissionInfomationContainer container = provider.getDebugInfo(sender, permission); + PermissionInformationContainer container = provider.getDebugInfo(sender, permission); Util.debugLog("Permission Node: " + container.getPermission() + "; Result: " + result + "; Sender: " + container.getSender().getName()); // Util.debugLog("Result: " + result); // Util.debugLog("Sender: " + container.getSender().getName()); diff --git a/src/main/java/org/maxgamer/quickshop/permission/PermissionProvider.java b/src/main/java/org/maxgamer/quickshop/permission/PermissionProvider.java index aa47389eb..100a36a7d 100644 --- a/src/main/java/org/maxgamer/quickshop/permission/PermissionProvider.java +++ b/src/main/java/org/maxgamer/quickshop/permission/PermissionProvider.java @@ -48,7 +48,7 @@ public interface PermissionProvider { * @return Debug Infos */ @NotNull - PermissionInfomationContainer getDebugInfo( + PermissionInformationContainer getDebugInfo( @NotNull CommandSender sender, @NotNull String permission); } diff --git a/src/main/java/org/maxgamer/quickshop/permission/VaultPermissionProvider.java b/src/main/java/org/maxgamer/quickshop/permission/VaultPermissionProvider.java index 633d8853b..4d037af3e 100644 --- a/src/main/java/org/maxgamer/quickshop/permission/VaultPermissionProvider.java +++ b/src/main/java/org/maxgamer/quickshop/permission/VaultPermissionProvider.java @@ -71,13 +71,13 @@ public class VaultPermissionProvider implements PermissionProvider { * @return Debug Infos */ @Override - public @NotNull PermissionInfomationContainer getDebugInfo( + public @NotNull PermissionInformationContainer getDebugInfo( @NotNull CommandSender sender, @NotNull String permission) { if (sender instanceof Server) { - return new PermissionInfomationContainer(sender, permission, null, "User is Console"); + return new PermissionInformationContainer(sender, permission, null, "User is Console"); } OfflinePlayer offlinePlayer = (OfflinePlayer) sender; - return new PermissionInfomationContainer( + return new PermissionInformationContainer( sender, permission, api.getPrimaryGroup(null, offlinePlayer), null); } From e62821a5874987205b2988ffec684508f036f3f4 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:16:54 +0800 Subject: [PATCH 10/36] Remove ArmorStandDisplayItem since we stop to use them --- .../quickshop/shop/ArmorStandDisplayItem.java | 664 +++++++++--------- .../maxgamer/quickshop/shop/DisplayType.java | 8 +- 2 files changed, 336 insertions(+), 336 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java index d53b703da..a2c68cc1f 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java @@ -1,335 +1,335 @@ -/* - * This file is a part of project QuickShop, the name is ArmorStandDisplayItem.java - * Copyright (C) PotatoCraft Studio and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.maxgamer.quickshop.shop; - -import lombok.ToString; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Directional; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.util.EulerAngle; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.maxgamer.quickshop.event.ShopDisplayItemDespawnEvent; -import org.maxgamer.quickshop.event.ShopDisplayItemSpawnEvent; -import org.maxgamer.quickshop.util.GameVersion; -import org.maxgamer.quickshop.util.MsgUtil; -import org.maxgamer.quickshop.util.ReflectFactory; -import org.maxgamer.quickshop.util.Util; - -import java.util.Objects; - -@ToString -@Deprecated - -public class ArmorStandDisplayItem extends DisplayItem { - - @Nullable - private volatile ArmorStand armorStand; - - /** - * @deprecated This display type pending for removal in future - */ - ArmorStandDisplayItem(@NotNull Shop shop) { - super(shop); - } - - private static boolean isTool(Material material) { - String nlc = material.name().toLowerCase(); - return nlc.contains("sword") || nlc.contains("shovel") || nlc.contains("axe"); //TODO: Needs a better impl. Maybe NamespacedKey - } - - @Override - public boolean checkDisplayIsMoved() { - if (this.armorStand == null) { - return false; - } - return !this.armorStand.getLocation().equals(getDisplayLocation()); - } - - public Location getCenter(Location loc) { - // This is always '+' instead of '-' even in negative pos - return new Location( - loc.getWorld(), loc.getBlockX() + .5, loc.getBlockY() + .5, loc.getBlockZ() + .5); - } - - @Override - public boolean checkDisplayNeedRegen() { - if (this.armorStand == null) { - return false; - } - return !this.armorStand.isValid() || this.armorStand.isDead(); - } - - @Override - public boolean checkIsShopEntity(@NotNull Entity entity) { - if (!(entity instanceof ArmorStand)) { - return false; - } - return DisplayItem.checkIsGuardItemStack(((ArmorStand) entity).getItemInHand()); //FIXME: Update this when drop 1.13 supports - } - - @Override - public void fixDisplayMoved() { - Location location = this.getDisplayLocation(); - //if (this.armorStand != null) { - if (location != null) { - this.armorStand.teleport(location); - } else { - fixDisplayMovedOld(); - } +///* +// * This file is a part of project QuickShop, the name is ArmorStandDisplayItem.java +// * Copyright (C) PotatoCraft Studio and contributors +// * +// * This program is free software: you can redistribute it and/or modify it +// * under the terms of the GNU General Public License as published by the +// * Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, but WITHOUT +// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// * for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see . +// * +// */ +// +//package org.maxgamer.quickshop.shop; +// +//import lombok.ToString; +//import org.bukkit.Location; +//import org.bukkit.Material; +//import org.bukkit.NamespacedKey; +//import org.bukkit.block.BlockFace; +//import org.bukkit.block.data.Directional; +//import org.bukkit.entity.ArmorStand; +//import org.bukkit.entity.Entity; +//import org.bukkit.entity.EntityType; +//import org.bukkit.util.EulerAngle; +//import org.jetbrains.annotations.NotNull; +//import org.jetbrains.annotations.Nullable; +//import org.maxgamer.quickshop.event.ShopDisplayItemDespawnEvent; +//import org.maxgamer.quickshop.event.ShopDisplayItemSpawnEvent; +//import org.maxgamer.quickshop.util.GameVersion; +//import org.maxgamer.quickshop.util.MsgUtil; +//import org.maxgamer.quickshop.util.ReflectFactory; +//import org.maxgamer.quickshop.util.Util; +// +//import java.util.Objects; +// +//@ToString +//@Deprecated +// +//public class ArmorStandDisplayItem extends DisplayItem { +// +// @Nullable +// private volatile ArmorStand armorStand; +// +// /** +// * @deprecated This display type pending for removal in future +// */ +// ArmorStandDisplayItem(@NotNull Shop shop) { +// super(shop); +// } +// +// private static boolean isTool(Material material) { +// String nlc = material.name().toLowerCase(); +// return nlc.contains("sword") || nlc.contains("shovel") || nlc.contains("axe"); //TODO: Needs a better impl. Maybe NamespacedKey +// } +// +// @Override +// public boolean checkDisplayIsMoved() { +// if (this.armorStand == null) { +// return false; +// } +// return !this.armorStand.getLocation().equals(getDisplayLocation()); +// } +// +// public Location getCenter(Location loc) { +// // This is always '+' instead of '-' even in negative pos +// return new Location( +// loc.getWorld(), loc.getBlockX() + .5, loc.getBlockY() + .5, loc.getBlockZ() + .5); +// } +// +// @Override +// public boolean checkDisplayNeedRegen() { +// if (this.armorStand == null) { +// return false; +// } +// return !this.armorStand.isValid() || this.armorStand.isDead(); +// } +// +// @Override +// public boolean checkIsShopEntity(@NotNull Entity entity) { +// if (!(entity instanceof ArmorStand)) { +// return false; +// } +// return DisplayItem.checkIsGuardItemStack(((ArmorStand) entity).getItemInHand()); //FIXME: Update this when drop 1.13 supports +// } +// +// @Override +// public void fixDisplayMoved() { +// Location location = this.getDisplayLocation(); +// //if (this.armorStand != null) { +// if (location != null) { +// this.armorStand.teleport(location); // } else { // fixDisplayMovedOld(); // } - } - - public void fixDisplayMovedOld() { - for (Entity entity : Objects.requireNonNull(this.shop.getLocation().getWorld()).getEntities()) { - if (!(entity instanceof ArmorStand)) { - continue; - } - ArmorStand eArmorStand = (ArmorStand) entity; - if (eArmorStand.getUniqueId().equals(Objects.requireNonNull(this.armorStand).getUniqueId())) { - Util.debugLog( - "Fixing moved ArmorStand displayItem " - + eArmorStand.getUniqueId() - + " at " - + eArmorStand.getLocation()); - eArmorStand.teleport(getDisplayLocation()); - return; - } - } - } - - @Override - public void fixDisplayNeedRegen() { - respawn(); - } - - @Override - public void remove() { - if (this.armorStand == null) { - Util.debugLog("Ignore the armorStand removing because the armorStand not spawned."); - return; - } - this.armorStand.remove(); - this.armorStand = null; - this.guardedIstack = null; - ShopDisplayItemDespawnEvent shopDisplayItemDespawnEvent = - new ShopDisplayItemDespawnEvent(this.shop, this.originalItemStack, DisplayType.ARMORSTAND); - plugin.getServer().getPluginManager().callEvent(shopDisplayItemDespawnEvent); - } - - @Override - public boolean removeDupe() { - if (this.armorStand == null) { - Util.debugLog("Warning: Trying to removeDupe for a null display shop."); - return false; - } - boolean removed = false; - for (Entity entity : armorStand.getNearbyEntities(1.5, 1.5, 1.5)) { - if (entity.getType() != EntityType.ARMOR_STAND) { - continue; - } - ArmorStand eArmorStand = (ArmorStand) entity; - - if (!eArmorStand.getUniqueId().equals(this.armorStand.getUniqueId()) && DisplayItem.checkIsTargetShopDisplay(eArmorStand.getItemInHand(), this.shop)) {//FIXME: Update this when drop 1.13 supports - Util.debugLog("Removing dupes ArmorEntity " + eArmorStand.getUniqueId() + " at " + eArmorStand.getLocation()); - entity.remove(); - removed = true; - } - } - return removed; - } - - @Override - public void respawn() { - remove(); - spawn(); - } - - @Override - public void safeGuard(@NotNull Entity entity) { - if (!(entity instanceof ArmorStand)) { - Util.debugLog( - "Failed to safeGuard " + entity.getLocation() + ", cause target not a ArmorStand"); - return; - } - ArmorStand armorStand = (ArmorStand) entity; - // Set item protect in the armorstand's hand - this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop); - Objects.requireNonNull(armorStand.getEquipment()).setHelmet(guardedIstack); - if (GameVersion.get(ReflectFactory.getServerVersion()).isPersistentStorageApiSupports()) { - armorStand - .getPersistentDataContainer() - .set( - new NamespacedKey(plugin, "displayMark"), - DisplayItemPersistentDataType.INSTANCE, - DisplayItem.createShopProtectionFlag(this.originalItemStack, shop)); - - } - } - - @Override - public void spawn() { - if (shop.isDeleted() || !shop.isLoaded()) { - return; - } - if (shop.getLocation().getWorld() == null) { - Util.debugLog("Canceled the displayItem spawning because the location in the world is null."); - return; - } - - if (originalItemStack == null) { - Util.debugLog("Canceled the displayItem spawning because the ItemStack is null."); - return; - } - - if (armorStand != null && armorStand.isValid() && !armorStand.isDead()) { - Util.debugLog( - "Warning: Spawning the armorStand for DisplayItem when there is already an existing armorStand may cause a duplicated armorStand!"); - MsgUtil.debugStackTrace(Thread.currentThread().getStackTrace()); - - ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = - new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.ARMORSTAND); - plugin.getServer().getPluginManager().callEvent(shopDisplayItemSpawnEvent); - if (shopDisplayItemSpawnEvent.isCancelled()) { - Util.debugLog( - "Canceled the displayItem from spawning because a plugin setCancelled the spawning event, usually it is a QuickShop Add on"); - return; - } - - Location location = getDisplayLocation(); - this.armorStand = - this.shop - .getLocation() - .getWorld() - .spawn( - location, - ArmorStand.class, - armorStand -> { - // Set basic armorstand datas. - armorStand.setGravity(false); - armorStand.setVisible(false); - armorStand.setMarker(true); - armorStand.setCollidable(false); - armorStand.setSmall(true); - armorStand.setArms(false); - armorStand.setBasePlate(false); - armorStand.setSilent(true); - armorStand.setAI(false); - armorStand.setCanPickupItems(false); - // Set pose (this is for hand while we use helmet) - // setPoseForArmorStand(); - }); - // Set safeGuard - Util.debugLog( - "Spawned armor stand @ " - + this.armorStand.getLocation() - + " with UUID " - + this.armorStand.getUniqueId()); - safeGuard(this.armorStand); // Helmet must be set after spawning - } - } - - @Override - public @Nullable Entity getDisplay() { - return this.armorStand; - } - - @Override - public Location getDisplayLocation() { - BlockFace containerBlockFace = BlockFace.NORTH; // Set default vaule - if (this.shop.getLocation().getBlock().getBlockData() instanceof Directional) { - containerBlockFace = - ((Directional) this.shop.getLocation().getBlock().getBlockData()) - .getFacing(); // Replace by container face. - } - // Fix specific block facing - Material type = this.shop.getLocation().getBlock().getType(); - if (type.name().contains("ANVIL") - || type.name().contains("FENCE") - || type.name().contains("WALL")) { - switch (containerBlockFace) { - case SOUTH: - containerBlockFace = BlockFace.WEST; - break; - case NORTH: - containerBlockFace = BlockFace.EAST; - case EAST: - containerBlockFace = BlockFace.NORTH; - case WEST: - containerBlockFace = BlockFace.SOUTH; - default: - break; - } - } - - Location asloc = getCenter(this.shop.getLocation()); - Util.debugLog("containerBlockFace " + containerBlockFace); - if (this.originalItemStack.getType().isBlock()) { - asloc.add(0, 0.5, 0); - } - switch (containerBlockFace) { - case SOUTH: - asloc.add(0, -0.5, 0); - asloc.setYaw(0); - Util.debugLog("Block face as SOUTH"); - break; - case WEST: - asloc.add(0, -0.5, 0); - asloc.setYaw(90); - Util.debugLog("Block face as WEST"); - break; - case EAST: - asloc.add(0, -0.5, 0); - asloc.setYaw(-90); - Util.debugLog("Block face as EAST"); - break; - case NORTH: - asloc.add(0, -0.5, 0); - asloc.setYaw(180); - Util.debugLog("Block face as NORTH"); - break; - default: - break; - } - return asloc; - } - - @Override - public synchronized boolean isSpawned() { - return this.armorStand != null && this.armorStand.isValid(); - } - - @Deprecated // no use, will be removed soon - private void setPoseForArmorStand() { - if (this.originalItemStack.getType().isBlock()) { - Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-0.2, 0, 0)); - } else { - Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-89.5, 0, 0)); - } - } - -} +//// } else { +//// fixDisplayMovedOld(); +//// } +// } +// +// public void fixDisplayMovedOld() { +// for (Entity entity : Objects.requireNonNull(this.shop.getLocation().getWorld()).getEntities()) { +// if (!(entity instanceof ArmorStand)) { +// continue; +// } +// ArmorStand eArmorStand = (ArmorStand) entity; +// if (eArmorStand.getUniqueId().equals(Objects.requireNonNull(this.armorStand).getUniqueId())) { +// Util.debugLog( +// "Fixing moved ArmorStand displayItem " +// + eArmorStand.getUniqueId() +// + " at " +// + eArmorStand.getLocation()); +// eArmorStand.teleport(getDisplayLocation()); +// return; +// } +// } +// } +// +// @Override +// public void fixDisplayNeedRegen() { +// respawn(); +// } +// +// @Override +// public void remove() { +// if (this.armorStand == null) { +// Util.debugLog("Ignore the armorStand removing because the armorStand not spawned."); +// return; +// } +// this.armorStand.remove(); +// this.armorStand = null; +// this.guardedIstack = null; +// ShopDisplayItemDespawnEvent shopDisplayItemDespawnEvent = +// new ShopDisplayItemDespawnEvent(this.shop, this.originalItemStack, DisplayType.ARMORSTAND); +// plugin.getServer().getPluginManager().callEvent(shopDisplayItemDespawnEvent); +// } +// +// @Override +// public boolean removeDupe() { +// if (this.armorStand == null) { +// Util.debugLog("Warning: Trying to removeDupe for a null display shop."); +// return false; +// } +// boolean removed = false; +// for (Entity entity : armorStand.getNearbyEntities(1.5, 1.5, 1.5)) { +// if (entity.getType() != EntityType.ARMOR_STAND) { +// continue; +// } +// ArmorStand eArmorStand = (ArmorStand) entity; +// +// if (!eArmorStand.getUniqueId().equals(this.armorStand.getUniqueId()) && DisplayItem.checkIsTargetShopDisplay(eArmorStand.getItemInHand(), this.shop)) {//FIXME: Update this when drop 1.13 supports +// Util.debugLog("Removing dupes ArmorEntity " + eArmorStand.getUniqueId() + " at " + eArmorStand.getLocation()); +// entity.remove(); +// removed = true; +// } +// } +// return removed; +// } +// +// @Override +// public void respawn() { +// remove(); +// spawn(); +// } +// +// @Override +// public void safeGuard(@NotNull Entity entity) { +// if (!(entity instanceof ArmorStand)) { +// Util.debugLog( +// "Failed to safeGuard " + entity.getLocation() + ", cause target not a ArmorStand"); +// return; +// } +// ArmorStand armorStand = (ArmorStand) entity; +// // Set item protect in the armorstand's hand +// this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop); +// Objects.requireNonNull(armorStand.getEquipment()).setHelmet(guardedIstack); +// if (GameVersion.get(ReflectFactory.getServerVersion()).isPersistentStorageApiSupports()) { +// armorStand +// .getPersistentDataContainer() +// .set( +// new NamespacedKey(plugin, "displayMark"), +// DisplayItemPersistentDataType.INSTANCE, +// DisplayItem.createShopProtectionFlag(this.originalItemStack, shop)); +// +// } +// } +// +// @Override +// public void spawn() { +// if (shop.isDeleted() || !shop.isLoaded()) { +// return; +// } +// if (shop.getLocation().getWorld() == null) { +// Util.debugLog("Canceled the displayItem spawning because the location in the world is null."); +// return; +// } +// +// if (originalItemStack == null) { +// Util.debugLog("Canceled the displayItem spawning because the ItemStack is null."); +// return; +// } +// +// if (armorStand != null && armorStand.isValid() && !armorStand.isDead()) { +// Util.debugLog( +// "Warning: Spawning the armorStand for DisplayItem when there is already an existing armorStand may cause a duplicated armorStand!"); +// MsgUtil.debugStackTrace(Thread.currentThread().getStackTrace()); +// +// ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = +// new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.ARMORSTAND); +// plugin.getServer().getPluginManager().callEvent(shopDisplayItemSpawnEvent); +// if (shopDisplayItemSpawnEvent.isCancelled()) { +// Util.debugLog( +// "Canceled the displayItem from spawning because a plugin setCancelled the spawning event, usually it is a QuickShop Add on"); +// return; +// } +// +// Location location = getDisplayLocation(); +// this.armorStand = +// this.shop +// .getLocation() +// .getWorld() +// .spawn( +// location, +// ArmorStand.class, +// armorStand -> { +// // Set basic armorstand datas. +// armorStand.setGravity(false); +// armorStand.setVisible(false); +// armorStand.setMarker(true); +// armorStand.setCollidable(false); +// armorStand.setSmall(true); +// armorStand.setArms(false); +// armorStand.setBasePlate(false); +// armorStand.setSilent(true); +// armorStand.setAI(false); +// armorStand.setCanPickupItems(false); +// // Set pose (this is for hand while we use helmet) +// // setPoseForArmorStand(); +// }); +// // Set safeGuard +// Util.debugLog( +// "Spawned armor stand @ " +// + this.armorStand.getLocation() +// + " with UUID " +// + this.armorStand.getUniqueId()); +// safeGuard(this.armorStand); // Helmet must be set after spawning +// } +// } +// +// @Override +// public @Nullable Entity getDisplay() { +// return this.armorStand; +// } +// +// @Override +// public Location getDisplayLocation() { +// BlockFace containerBlockFace = BlockFace.NORTH; // Set default vaule +// if (this.shop.getLocation().getBlock().getBlockData() instanceof Directional) { +// containerBlockFace = +// ((Directional) this.shop.getLocation().getBlock().getBlockData()) +// .getFacing(); // Replace by container face. +// } +// // Fix specific block facing +// Material type = this.shop.getLocation().getBlock().getType(); +// if (type.name().contains("ANVIL") +// || type.name().contains("FENCE") +// || type.name().contains("WALL")) { +// switch (containerBlockFace) { +// case SOUTH: +// containerBlockFace = BlockFace.WEST; +// break; +// case NORTH: +// containerBlockFace = BlockFace.EAST; +// case EAST: +// containerBlockFace = BlockFace.NORTH; +// case WEST: +// containerBlockFace = BlockFace.SOUTH; +// default: +// break; +// } +// } +// +// Location asloc = getCenter(this.shop.getLocation()); +// Util.debugLog("containerBlockFace " + containerBlockFace); +// if (this.originalItemStack.getType().isBlock()) { +// asloc.add(0, 0.5, 0); +// } +// switch (containerBlockFace) { +// case SOUTH: +// asloc.add(0, -0.5, 0); +// asloc.setYaw(0); +// Util.debugLog("Block face as SOUTH"); +// break; +// case WEST: +// asloc.add(0, -0.5, 0); +// asloc.setYaw(90); +// Util.debugLog("Block face as WEST"); +// break; +// case EAST: +// asloc.add(0, -0.5, 0); +// asloc.setYaw(-90); +// Util.debugLog("Block face as EAST"); +// break; +// case NORTH: +// asloc.add(0, -0.5, 0); +// asloc.setYaw(180); +// Util.debugLog("Block face as NORTH"); +// break; +// default: +// break; +// } +// return asloc; +// } +// +// @Override +// public synchronized boolean isSpawned() { +// return this.armorStand != null && this.armorStand.isValid(); +// } +// +// @Deprecated // no use, will be removed soon +// private void setPoseForArmorStand() { +// if (this.originalItemStack.getType().isBlock()) { +// Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-0.2, 0, 0)); +// } else { +// Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-89.5, 0, 0)); +// } +// } +// +//} diff --git a/src/main/java/org/maxgamer/quickshop/shop/DisplayType.java b/src/main/java/org/maxgamer/quickshop/shop/DisplayType.java index 92d7271db..e21e72f73 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/DisplayType.java +++ b/src/main/java/org/maxgamer/quickshop/shop/DisplayType.java @@ -31,7 +31,7 @@ public enum DisplayType { * */ UNKNOWN(-1), REALITEM(0), - ARMORSTAND(1), + // ARMORSTAND(1), VIRTUALITEM(2); private final int id; @@ -57,9 +57,9 @@ public enum DisplayType { if (displayItem instanceof RealDisplayItem) { return REALITEM; } - if (displayItem instanceof ArmorStandDisplayItem) { - return ARMORSTAND; - } +// if (displayItem instanceof ArmorStandDisplayItem) { +// return ARMORSTAND; +// } if (displayItem instanceof VirtualDisplayItem) { return VIRTUALITEM; } From d4ba2aa54af2c11eb8a52843389a0fa9b608e5d2 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:33:18 +0800 Subject: [PATCH 11/36] Stop using portlek files and migrate to JsonConfiguration --- .../fileportlek/old/FileEnvelope.java | 530 +++++++++--------- .../quickshop/fileportlek/old/IFile.java | 448 +++++++-------- .../quickshop/fileportlek/old/JSONFile.java | 128 ++--- .../quickshop/fileportlek/old/YAMLFile.java | 110 ++-- .../org/maxgamer/quickshop/util/MsgUtil.java | 71 ++- 5 files changed, 652 insertions(+), 635 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/fileportlek/old/FileEnvelope.java b/src/main/java/org/maxgamer/quickshop/fileportlek/old/FileEnvelope.java index 0a4bafa81..568408b29 100644 --- a/src/main/java/org/maxgamer/quickshop/fileportlek/old/FileEnvelope.java +++ b/src/main/java/org/maxgamer/quickshop/fileportlek/old/FileEnvelope.java @@ -1,265 +1,265 @@ -/* - * This file is a part of project QuickShop, the name is FileEnvelope.java - * Copyright (C) PotatoCraft Studio and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.maxgamer.quickshop.fileportlek.old; - -import lombok.ToString; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.maxgamer.quickshop.mock.MckFileConfiguration; -import org.maxgamer.quickshop.util.Copied; -import org.maxgamer.quickshop.util.Util; -import org.maxgamer.quickshop.util.location.LocationOf; -import org.maxgamer.quickshop.util.location.StringOf; - -import java.io.File; -import java.io.InputStream; -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -@ToString -public abstract class FileEnvelope implements IFile { - - @NotNull - protected final File file; - - protected final boolean loadDefault; - - @NotNull - protected final Plugin plugin; - @NotNull - protected final String resourcePath; - @NotNull - private final Copied copied; - @NotNull - protected FileConfiguration fileConfiguration = new MckFileConfiguration(); - - public FileEnvelope(@NotNull Plugin plugin, @NotNull File file, @NotNull String resourcePath, boolean loadDefault) { - this.plugin = plugin; - this.file = file; - this.copied = new Copied(file); - this.resourcePath = resourcePath; - this.loadDefault = loadDefault; - } - - @Override - public void create() { - if (file.exists()) { - reload(); - return; - } - - try { - final File parent = file.getParentFile(); - - if (parent != null) { - parent.mkdirs(); - } - - file.createNewFile(); - } catch (Exception exception) { - throw new RuntimeException(exception); - } - - if (loadDefault) { - copied.accept(getInputStream()); - } - - reload(); - } - - @NotNull - @Override - public InputStream getInputStream() { - return Objects.requireNonNull(plugin.getResource(resourcePath)); - } - - @Override - public void save() { - try { - if (fileConfiguration instanceof MckFileConfiguration) { - reload(); - } - fileConfiguration.save(file); - } catch (Exception exception) { - throw new IllegalStateException(exception); - } - } - - @NotNull - @Override - public String saveToString() { - return fileConfiguration.saveToString(); - } - - @Override - public void loadFromString(@NotNull String data) throws InvalidConfigurationException { - fileConfiguration.loadFromString(data); - } - - @Nullable - @Override - public Object get(@NotNull String path) { - return fileConfiguration.get(path); - } - - @Nullable - @Override - public Object get(@NotNull String path, @Nullable Object fallback) { - final Object object = fileConfiguration.get(path, fallback); - - if (object == null) { - return fallback; - } - - return object; - } - - @NotNull - @Override - @SuppressWarnings("unchecked") - public T getOrSet(@NotNull String path, @NotNull T fallback) { - final T object = (T) fileConfiguration.get(path, null); - - if (object != null) { - return object; - } - - set(path, fallback); - - return fallback; - } - - @NotNull - @Override - public Location getLocation(@NotNull String path) { - return new LocationOf(getString(path).orElse("")).value(); - } - - @Override - public void setLocation(@NotNull String path, @NotNull Location location) { - set(path, new StringOf(location).asString()); - } - - @NotNull - @Override - public ItemStack getCustomItemStack(@NotNull String path) { - try { - ItemStack deserialize = Util.deserialize(path); - if (deserialize != null) { - return deserialize; - } - return new ItemStack(Material.AIR); - } catch (Exception exception) { - return new ItemStack(Material.AIR); - } - } - - @Override - public void setCustomItemStack(@NotNull String path, @NotNull ItemStack itemStack) { - fileConfiguration.set(path, Util.serialize(itemStack)); - } - - @NotNull - @Override - public Optional getString(@NotNull String path) { - return Optional.ofNullable(fileConfiguration.getString(path)); - } - - @Override - public void set(@NotNull String path, @Nullable Object object) { - fileConfiguration.set(path, object); - save(); - } - - @NotNull - @Override - public List getStringList(@NotNull String path) { - return fileConfiguration.getStringList(path); - } - - @Override - public int getInt(@NotNull String path) { - return fileConfiguration.getInt(path); - } - - @Override - public double getDouble(@NotNull String path) { - return fileConfiguration.getDouble(path); - } - - @Override - public long getLong(@NotNull String path) { - return fileConfiguration.getLong(path); - } - - @Override - public byte getByte(@NotNull String path) { - return (byte) fileConfiguration.getInt(path); - } - - @Override - public short getShort(@NotNull String path) { - return (short) fileConfiguration.getInt(path); - } - - @Override - public boolean getBoolean(@NotNull String path) { - return fileConfiguration.getBoolean(path); - } - - @NotNull - @Override - public ConfigurationSection createSection(@NotNull String path) { - final ConfigurationSection configurationSection = fileConfiguration.createSection(path); - - save(); - - return configurationSection; - } - - @NotNull - @Override - public ConfigurationSection getSection(@NotNull String path) { - final ConfigurationSection configurationSection = fileConfiguration.getConfigurationSection(path); - - return configurationSection == null ? new MckFileConfiguration() : configurationSection; - } - - @NotNull - @Override - public ConfigurationSection getOrCreateSection(@NotNull String path) { - ConfigurationSection section = getSection(path); - - if (section instanceof MckFileConfiguration) { - section = createSection(path); - } - - return section; - } - -} +///* +// * This file is a part of project QuickShop, the name is FileEnvelope.java +// * Copyright (C) PotatoCraft Studio and contributors +// * +// * This program is free software: you can redistribute it and/or modify it +// * under the terms of the GNU General Public License as published by the +// * Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, but WITHOUT +// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// * for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see . +// * +// */ +// +//package org.maxgamer.quickshop.fileportlek.old; +// +//import lombok.ToString; +//import org.bukkit.Location; +//import org.bukkit.Material; +//import org.bukkit.configuration.ConfigurationSection; +//import org.bukkit.configuration.InvalidConfigurationException; +//import org.bukkit.configuration.file.FileConfiguration; +//import org.bukkit.inventory.ItemStack; +//import org.bukkit.plugin.Plugin; +//import org.jetbrains.annotations.NotNull; +//import org.jetbrains.annotations.Nullable; +//import org.maxgamer.quickshop.mock.MckFileConfiguration; +//import org.maxgamer.quickshop.util.Copied; +//import org.maxgamer.quickshop.util.Util; +//import org.maxgamer.quickshop.util.location.LocationOf; +//import org.maxgamer.quickshop.util.location.StringOf; +// +//import java.io.File; +//import java.io.InputStream; +//import java.util.List; +//import java.util.Objects; +//import java.util.Optional; +// +//@ToString +//public abstract class FileEnvelope implements IFile { +// +// @NotNull +// protected final File file; +// +// protected final boolean loadDefault; +// +// @NotNull +// protected final Plugin plugin; +// @NotNull +// protected final String resourcePath; +// @NotNull +// private final Copied copied; +// @NotNull +// protected FileConfiguration fileConfiguration = new MckFileConfiguration(); +// +// public FileEnvelope(@NotNull Plugin plugin, @NotNull File file, @NotNull String resourcePath, boolean loadDefault) { +// this.plugin = plugin; +// this.file = file; +// this.copied = new Copied(file); +// this.resourcePath = resourcePath; +// this.loadDefault = loadDefault; +// } +// +// @Override +// public void create() { +// if (file.exists()) { +// reload(); +// return; +// } +// +// try { +// final File parent = file.getParentFile(); +// +// if (parent != null) { +// parent.mkdirs(); +// } +// +// file.createNewFile(); +// } catch (Exception exception) { +// throw new RuntimeException(exception); +// } +// +// if (loadDefault) { +// copied.accept(getInputStream()); +// } +// +// reload(); +// } +// +// @NotNull +// @Override +// public InputStream getInputStream() { +// return Objects.requireNonNull(plugin.getResource(resourcePath)); +// } +// +// @Override +// public void save() { +// try { +// if (fileConfiguration instanceof MckFileConfiguration) { +// reload(); +// } +// fileConfiguration.save(file); +// } catch (Exception exception) { +// throw new IllegalStateException(exception); +// } +// } +// +// @NotNull +// @Override +// public String saveToString() { +// return fileConfiguration.saveToString(); +// } +// +// @Override +// public void loadFromString(@NotNull String data) throws InvalidConfigurationException { +// fileConfiguration.loadFromString(data); +// } +// +// @Nullable +// @Override +// public Object get(@NotNull String path) { +// return fileConfiguration.get(path); +// } +// +// @Nullable +// @Override +// public Object get(@NotNull String path, @Nullable Object fallback) { +// final Object object = fileConfiguration.get(path, fallback); +// +// if (object == null) { +// return fallback; +// } +// +// return object; +// } +// +// @NotNull +// @Override +// @SuppressWarnings("unchecked") +// public T getOrSet(@NotNull String path, @NotNull T fallback) { +// final T object = (T) fileConfiguration.get(path, null); +// +// if (object != null) { +// return object; +// } +// +// set(path, fallback); +// +// return fallback; +// } +// +// @NotNull +// @Override +// public Location getLocation(@NotNull String path) { +// return new LocationOf(getString(path).orElse("")).value(); +// } +// +// @Override +// public void setLocation(@NotNull String path, @NotNull Location location) { +// set(path, new StringOf(location).asString()); +// } +// +// @NotNull +// @Override +// public ItemStack getCustomItemStack(@NotNull String path) { +// try { +// ItemStack deserialize = Util.deserialize(path); +// if (deserialize != null) { +// return deserialize; +// } +// return new ItemStack(Material.AIR); +// } catch (Exception exception) { +// return new ItemStack(Material.AIR); +// } +// } +// +// @Override +// public void setCustomItemStack(@NotNull String path, @NotNull ItemStack itemStack) { +// fileConfiguration.set(path, Util.serialize(itemStack)); +// } +// +// @NotNull +// @Override +// public Optional getString(@NotNull String path) { +// return Optional.ofNullable(fileConfiguration.getString(path)); +// } +// +// @Override +// public void set(@NotNull String path, @Nullable Object object) { +// fileConfiguration.set(path, object); +// save(); +// } +// +// @NotNull +// @Override +// public List getStringList(@NotNull String path) { +// return fileConfiguration.getStringList(path); +// } +// +// @Override +// public int getInt(@NotNull String path) { +// return fileConfiguration.getInt(path); +// } +// +// @Override +// public double getDouble(@NotNull String path) { +// return fileConfiguration.getDouble(path); +// } +// +// @Override +// public long getLong(@NotNull String path) { +// return fileConfiguration.getLong(path); +// } +// +// @Override +// public byte getByte(@NotNull String path) { +// return (byte) fileConfiguration.getInt(path); +// } +// +// @Override +// public short getShort(@NotNull String path) { +// return (short) fileConfiguration.getInt(path); +// } +// +// @Override +// public boolean getBoolean(@NotNull String path) { +// return fileConfiguration.getBoolean(path); +// } +// +// @NotNull +// @Override +// public ConfigurationSection createSection(@NotNull String path) { +// final ConfigurationSection configurationSection = fileConfiguration.createSection(path); +// +// save(); +// +// return configurationSection; +// } +// +// @NotNull +// @Override +// public ConfigurationSection getSection(@NotNull String path) { +// final ConfigurationSection configurationSection = fileConfiguration.getConfigurationSection(path); +// +// return configurationSection == null ? new MckFileConfiguration() : configurationSection; +// } +// +// @NotNull +// @Override +// public ConfigurationSection getOrCreateSection(@NotNull String path) { +// ConfigurationSection section = getSection(path); +// +// if (section instanceof MckFileConfiguration) { +// section = createSection(path); +// } +// +// return section; +// } +// +//} diff --git a/src/main/java/org/maxgamer/quickshop/fileportlek/old/IFile.java b/src/main/java/org/maxgamer/quickshop/fileportlek/old/IFile.java index b60a3eeb1..a3192b805 100644 --- a/src/main/java/org/maxgamer/quickshop/fileportlek/old/IFile.java +++ b/src/main/java/org/maxgamer/quickshop/fileportlek/old/IFile.java @@ -1,224 +1,224 @@ -/* - * This file is a part of project QuickShop, the name is IFile.java - * Copyright (C) PotatoCraft Studio and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.maxgamer.quickshop.fileportlek.old; - -import org.bukkit.Location; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.maxgamer.quickshop.mock.MckFileConfiguration; - -import java.io.InputStream; -import java.util.List; -import java.util.Optional; - -public interface IFile { - - /** - * Creates yml file on the path - */ - void create(); - - @NotNull InputStream getInputStream(); - - /** - * Reloads file - */ - void reload(); - - /** - * Saves file - */ - void save(); - - /** - * @return the string of the file - */ - @NotNull String saveToString(); - - /** - * Loads from the data - * - * @param data the data - * @throws InvalidConfigurationException if config is invalid - */ - void loadFromString(@NotNull String data) throws InvalidConfigurationException; - - /** - * Gets the object - * - * @param path object path to get - * @return if path does not exist returns null - */ - @Nullable Object get(@NotNull String path); - - /** - * Gets the object with fallback - * - * @param path object path to get - * @param fallback fallback object to get if path does not exist - * @return if path does not exist returns fallback object - */ - @Nullable Object get(@NotNull String path, @Nullable Object fallback); - - /** - * Gets or sets the object - * - * @param path object path to get - * @param fallback fallback object to get if path does not exist - * @param object type - * @return if path does not exist returns and set the path with fallback object - */ - @NotNull T getOrSet(@NotNull String path, @NotNull T fallback); - - /** - * Gets location - * - * @param path location path to get - * @return {@link Location} - */ - @NotNull Location getLocation(@NotNull String path); - - /** - * Sets location into the path - * - * @param path location path to set - * @param location {@link Location} - */ - void setLocation(@NotNull String path, @NotNull Location location); - - /** - * Pattern: - * - *

path: (material): 'DIAMOND' [amount]: 1 [data]: 0 [display-name]: 'Diamond Sword' - * [enchants]: DAMAGE_ALL: 10 FIRE_ASPECT: 2 [lore]: - 'Lore 1' - 'Lore 2' - * - * @param path itemstack path to get - * @return {@link ItemStack} - */ - @NotNull ItemStack getCustomItemStack(@NotNull String path); - - /** - * Sets custom itemstack to path - * - * @param path itemstack path to set - * @param itemStack {@link ItemStack} - */ - void setCustomItemStack(@NotNull String path, @NotNull ItemStack itemStack); - - /** - * Gets string - * - * @param path string path to get - * @return {@link String} - */ - @NotNull Optional getString(@NotNull String path); - - /** - * Sets object to path - * - * @param path object path to set - * @param object {@link Object} - */ - void set(@NotNull String path, @Nullable Object object); - - /** - * Gets string list - * - * @param path string list path to get - * @return string list - */ - @NotNull List getStringList(@NotNull String path); - - /** - * Gets int - * - * @param path integer path to get - * @return {@link Integer} - */ - int getInt(@NotNull String path); - - /** - * Gets double - * - * @param path double path to get - * @return {@link Double} - */ - double getDouble(@NotNull String path); - - /** - * Gets long - * - * @param path long path to get - * @return {@link Integer} - */ - long getLong(@NotNull String path); - - /** - * Gets byte - * - * @param path byte path to get - * @return {@link Byte} - */ - byte getByte(@NotNull String path); - - /** - * Gets short - * - * @param path short path to get - * @return {@link Short} - */ - short getShort(@NotNull String path); - - /** - * Gets boolean - * - * @param path boolean path to get - * @return {@link Boolean} - */ - boolean getBoolean(@NotNull String path); - - /** - * Creates configuration section into path - * - * @param path configuration section path to create - * @return {@link ConfigurationSection} - */ - @NotNull ConfigurationSection createSection(@NotNull String path); - - /** - * Gets configuration section from path - * - * @param path configurations section path to get - * @return if there isn't section returns {@link MckFileConfiguration} - */ - @NotNull ConfigurationSection getSection(@NotNull String path); - - /** - * Gets configuration section from path if there is no section It will create - * - * @param path configurations section path to get - * @return {@link ConfigurationSection} - */ - @NotNull ConfigurationSection getOrCreateSection(@NotNull String path); - -} +///* +// * This file is a part of project QuickShop, the name is IFile.java +// * Copyright (C) PotatoCraft Studio and contributors +// * +// * This program is free software: you can redistribute it and/or modify it +// * under the terms of the GNU General Public License as published by the +// * Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, but WITHOUT +// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// * for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see . +// * +// */ +// +//package org.maxgamer.quickshop.fileportlek.old; +// +//import org.bukkit.Location; +//import org.bukkit.configuration.ConfigurationSection; +//import org.bukkit.configuration.InvalidConfigurationException; +//import org.bukkit.inventory.ItemStack; +//import org.jetbrains.annotations.NotNull; +//import org.jetbrains.annotations.Nullable; +//import org.maxgamer.quickshop.mock.MckFileConfiguration; +// +//import java.io.InputStream; +//import java.util.List; +//import java.util.Optional; +// +//public interface IFile { +// +// /** +// * Creates yml file on the path +// */ +// void create(); +// +// @NotNull InputStream getInputStream(); +// +// /** +// * Reloads file +// */ +// void reload(); +// +// /** +// * Saves file +// */ +// void save(); +// +// /** +// * @return the string of the file +// */ +// @NotNull String saveToString(); +// +// /** +// * Loads from the data +// * +// * @param data the data +// * @throws InvalidConfigurationException if config is invalid +// */ +// void loadFromString(@NotNull String data) throws InvalidConfigurationException; +// +// /** +// * Gets the object +// * +// * @param path object path to get +// * @return if path does not exist returns null +// */ +// @Nullable Object get(@NotNull String path); +// +// /** +// * Gets the object with fallback +// * +// * @param path object path to get +// * @param fallback fallback object to get if path does not exist +// * @return if path does not exist returns fallback object +// */ +// @Nullable Object get(@NotNull String path, @Nullable Object fallback); +// +// /** +// * Gets or sets the object +// * +// * @param path object path to get +// * @param fallback fallback object to get if path does not exist +// * @param object type +// * @return if path does not exist returns and set the path with fallback object +// */ +// @NotNull T getOrSet(@NotNull String path, @NotNull T fallback); +// +// /** +// * Gets location +// * +// * @param path location path to get +// * @return {@link Location} +// */ +// @NotNull Location getLocation(@NotNull String path); +// +// /** +// * Sets location into the path +// * +// * @param path location path to set +// * @param location {@link Location} +// */ +// void setLocation(@NotNull String path, @NotNull Location location); +// +// /** +// * Pattern: +// * +// *

path: (material): 'DIAMOND' [amount]: 1 [data]: 0 [display-name]: 'Diamond Sword' +// * [enchants]: DAMAGE_ALL: 10 FIRE_ASPECT: 2 [lore]: - 'Lore 1' - 'Lore 2' +// * +// * @param path itemstack path to get +// * @return {@link ItemStack} +// */ +// @NotNull ItemStack getCustomItemStack(@NotNull String path); +// +// /** +// * Sets custom itemstack to path +// * +// * @param path itemstack path to set +// * @param itemStack {@link ItemStack} +// */ +// void setCustomItemStack(@NotNull String path, @NotNull ItemStack itemStack); +// +// /** +// * Gets string +// * +// * @param path string path to get +// * @return {@link String} +// */ +// @NotNull Optional getString(@NotNull String path); +// +// /** +// * Sets object to path +// * +// * @param path object path to set +// * @param object {@link Object} +// */ +// void set(@NotNull String path, @Nullable Object object); +// +// /** +// * Gets string list +// * +// * @param path string list path to get +// * @return string list +// */ +// @NotNull List getStringList(@NotNull String path); +// +// /** +// * Gets int +// * +// * @param path integer path to get +// * @return {@link Integer} +// */ +// int getInt(@NotNull String path); +// +// /** +// * Gets double +// * +// * @param path double path to get +// * @return {@link Double} +// */ +// double getDouble(@NotNull String path); +// +// /** +// * Gets long +// * +// * @param path long path to get +// * @return {@link Integer} +// */ +// long getLong(@NotNull String path); +// +// /** +// * Gets byte +// * +// * @param path byte path to get +// * @return {@link Byte} +// */ +// byte getByte(@NotNull String path); +// +// /** +// * Gets short +// * +// * @param path short path to get +// * @return {@link Short} +// */ +// short getShort(@NotNull String path); +// +// /** +// * Gets boolean +// * +// * @param path boolean path to get +// * @return {@link Boolean} +// */ +// boolean getBoolean(@NotNull String path); +// +// /** +// * Creates configuration section into path +// * +// * @param path configuration section path to create +// * @return {@link ConfigurationSection} +// */ +// @NotNull ConfigurationSection createSection(@NotNull String path); +// +// /** +// * Gets configuration section from path +// * +// * @param path configurations section path to get +// * @return if there isn't section returns {@link MckFileConfiguration} +// */ +// @NotNull ConfigurationSection getSection(@NotNull String path); +// +// /** +// * Gets configuration section from path if there is no section It will create +// * +// * @param path configurations section path to get +// * @return {@link ConfigurationSection} +// */ +// @NotNull ConfigurationSection getOrCreateSection(@NotNull String path); +// +//} diff --git a/src/main/java/org/maxgamer/quickshop/fileportlek/old/JSONFile.java b/src/main/java/org/maxgamer/quickshop/fileportlek/old/JSONFile.java index 0f3a0c2fb..e777e315a 100644 --- a/src/main/java/org/maxgamer/quickshop/fileportlek/old/JSONFile.java +++ b/src/main/java/org/maxgamer/quickshop/fileportlek/old/JSONFile.java @@ -1,64 +1,64 @@ -/* - * This file is a part of project QuickShop, the name is JSONFile.java - * Copyright (C) PotatoCraft Studio and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.maxgamer.quickshop.fileportlek.old; - -import com.dumptruckman.bukkit.configuration.json.JsonConfiguration; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.logging.Level; - -public class JSONFile extends FileEnvelope { - - public JSONFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath, boolean loadDefault) { - super(plugin, file, resourcePath.endsWith(".json") ? resourcePath : resourcePath + ".json", loadDefault); - } - - public JSONFile(@NotNull final Plugin plugin, @NotNull final String fileName) { - this(plugin, "", fileName); - } - - public JSONFile(@NotNull final Plugin plugin, @NotNull final String resourcePath, @NotNull final String fileName) { - this(plugin, new File(plugin.getDataFolder().getAbsolutePath() + (resourcePath.startsWith(File.separator) ? resourcePath : File.separator + resourcePath), fileName.endsWith(".json") ? fileName : fileName + ".json"), resourcePath.isEmpty() ? fileName : resourcePath.endsWith(File.separator) ? resourcePath + fileName : resourcePath + File.separator + fileName); - } - - public JSONFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath) { - super(plugin, file, resourcePath.endsWith(".json") ? resourcePath : resourcePath + ".json", true); - } - - @Override - public void reload() { - fileConfiguration = HumanReadableJsonConfiguration.loadConfiguration(file); - if (loadDefault) { - try { - JsonConfiguration defaultConfig = new HumanReadableJsonConfiguration(); - defaultConfig.load(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8)); - fileConfiguration.setDefaults(defaultConfig); - } catch (IOException | InvalidConfigurationException e) { - plugin.getLogger().log(Level.SEVERE, "Could not load json file " + resourcePath, e); - } - } - } -} +///* +// * This file is a part of project QuickShop, the name is JSONFile.java +// * Copyright (C) PotatoCraft Studio and contributors +// * +// * This program is free software: you can redistribute it and/or modify it +// * under the terms of the GNU General Public License as published by the +// * Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, but WITHOUT +// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// * for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see . +// * +// */ +// +//package org.maxgamer.quickshop.fileportlek.old; +// +//import com.dumptruckman.bukkit.configuration.json.JsonConfiguration; +//import org.bukkit.configuration.InvalidConfigurationException; +//import org.bukkit.plugin.Plugin; +//import org.jetbrains.annotations.NotNull; +// +//import java.io.File; +//import java.io.IOException; +//import java.io.InputStreamReader; +//import java.nio.charset.StandardCharsets; +//import java.util.logging.Level; +// +//public class JSONFile extends FileEnvelope { +// +// public JSONFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath, boolean loadDefault) { +// super(plugin, file, resourcePath.endsWith(".json") ? resourcePath : resourcePath + ".json", loadDefault); +// } +// +// public JSONFile(@NotNull final Plugin plugin, @NotNull final String fileName) { +// this(plugin, "", fileName); +// } +// +// public JSONFile(@NotNull final Plugin plugin, @NotNull final String resourcePath, @NotNull final String fileName) { +// this(plugin, new File(plugin.getDataFolder().getAbsolutePath() + (resourcePath.startsWith(File.separator) ? resourcePath : File.separator + resourcePath), fileName.endsWith(".json") ? fileName : fileName + ".json"), resourcePath.isEmpty() ? fileName : resourcePath.endsWith(File.separator) ? resourcePath + fileName : resourcePath + File.separator + fileName); +// } +// +// public JSONFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath) { +// super(plugin, file, resourcePath.endsWith(".json") ? resourcePath : resourcePath + ".json", true); +// } +// +// @Override +// public void reload() { +// fileConfiguration = HumanReadableJsonConfiguration.loadConfiguration(file); +// if (loadDefault) { +// try { +// JsonConfiguration defaultConfig = new HumanReadableJsonConfiguration(); +// defaultConfig.load(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8)); +// fileConfiguration.setDefaults(defaultConfig); +// } catch (IOException | InvalidConfigurationException e) { +// plugin.getLogger().log(Level.SEVERE, "Could not load json file " + resourcePath, e); +// } +// } +// } +//} diff --git a/src/main/java/org/maxgamer/quickshop/fileportlek/old/YAMLFile.java b/src/main/java/org/maxgamer/quickshop/fileportlek/old/YAMLFile.java index 37b76ff6c..30a1fe0f1 100644 --- a/src/main/java/org/maxgamer/quickshop/fileportlek/old/YAMLFile.java +++ b/src/main/java/org/maxgamer/quickshop/fileportlek/old/YAMLFile.java @@ -1,55 +1,55 @@ -/* - * This file is a part of project QuickShop, the name is YAMLFile.java - * Copyright (C) PotatoCraft Studio and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.maxgamer.quickshop.fileportlek.old; - -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.InputStreamReader; - -public class YAMLFile extends FileEnvelope { - - public YAMLFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath, boolean loadDefault) { - super(plugin, file, resourcePath.endsWith(".yml") ? resourcePath : resourcePath + ".yml", loadDefault); - } - - public YAMLFile(@NotNull final Plugin plugin, @NotNull final String fileName) { - this(plugin, "", fileName); - } - - public YAMLFile(@NotNull final Plugin plugin, @NotNull final String resourcePath, @NotNull final String fileName) { - this(plugin, new File(plugin.getDataFolder().getAbsolutePath() + (resourcePath.startsWith(File.separator) ? resourcePath : File.separator + resourcePath), fileName.endsWith(".yml") ? fileName : fileName + ".yml"), resourcePath.isEmpty() ? fileName : resourcePath.endsWith(File.separator) ? resourcePath + fileName : resourcePath + File.separator + fileName); - } - - public YAMLFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath) { - super(plugin, file, resourcePath.endsWith(".yml") ? resourcePath : resourcePath + ".yml", true); - } - - @Override - public void reload() { - fileConfiguration = YamlConfiguration.loadConfiguration(file); - if (loadDefault) { - fileConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(getInputStream()))); - } - } - -} +///* +// * This file is a part of project QuickShop, the name is YAMLFile.java +// * Copyright (C) PotatoCraft Studio and contributors +// * +// * This program is free software: you can redistribute it and/or modify it +// * under the terms of the GNU General Public License as published by the +// * Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, but WITHOUT +// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// * for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see . +// * +// */ +// +//package org.maxgamer.quickshop.fileportlek.old; +// +//import org.bukkit.configuration.file.YamlConfiguration; +//import org.bukkit.plugin.Plugin; +//import org.jetbrains.annotations.NotNull; +// +//import java.io.File; +//import java.io.InputStreamReader; +// +//public class YAMLFile extends FileEnvelope { +// +// public YAMLFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath, boolean loadDefault) { +// super(plugin, file, resourcePath.endsWith(".yml") ? resourcePath : resourcePath + ".yml", loadDefault); +// } +// +// public YAMLFile(@NotNull final Plugin plugin, @NotNull final String fileName) { +// this(plugin, "", fileName); +// } +// +// public YAMLFile(@NotNull final Plugin plugin, @NotNull final String resourcePath, @NotNull final String fileName) { +// this(plugin, new File(plugin.getDataFolder().getAbsolutePath() + (resourcePath.startsWith(File.separator) ? resourcePath : File.separator + resourcePath), fileName.endsWith(".yml") ? fileName : fileName + ".yml"), resourcePath.isEmpty() ? fileName : resourcePath.endsWith(File.separator) ? resourcePath + fileName : resourcePath + File.separator + fileName); +// } +// +// public YAMLFile(@NotNull final Plugin plugin, @NotNull final File file, @NotNull final String resourcePath) { +// super(plugin, file, resourcePath.endsWith(".yml") ? resourcePath : resourcePath + ".yml", true); +// } +// +// @Override +// public void reload() { +// fileConfiguration = YamlConfiguration.loadConfiguration(file); +// if (loadDefault) { +// fileConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(getInputStream()))); +// } +// } +// +//} diff --git a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java index a4b18451c..cf0eebc3a 100644 --- a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java @@ -19,6 +19,7 @@ package org.maxgamer.quickshop.util; +import com.dumptruckman.bukkit.configuration.json.JsonConfiguration; import com.google.common.collect.Maps; import lombok.Getter; import lombok.SneakyThrows; @@ -45,8 +46,7 @@ import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.ServiceInjector; import org.maxgamer.quickshop.database.WarpedResultSet; import org.maxgamer.quickshop.event.ShopControlPanelOpenEvent; -import org.maxgamer.quickshop.fileportlek.old.IFile; -import org.maxgamer.quickshop.fileportlek.old.JSONFile; +import org.maxgamer.quickshop.fileportlek.old.HumanReadableJsonConfiguration; import org.maxgamer.quickshop.shop.Shop; import org.maxgamer.quickshop.util.language.game.GameLanguage; import org.maxgamer.quickshop.util.language.game.MojangGameLanguageImpl; @@ -75,10 +75,10 @@ public class MsgUtil { private static boolean inited; @Getter private static YamlConfiguration itemi18n; - private static IFile messagei18n; + private static JsonConfiguration messagei18n; @Getter private static YamlConfiguration potioni18n; - private static IFile builtInLang; + private static JsonConfiguration builtInLang; private static DecimalFormat processFormat() { try { @@ -172,11 +172,11 @@ public class MsgUtil { public static String getMessageOfflinePlayer( @NotNull String loc, @Nullable OfflinePlayer player, @NotNull String... args) { try { - Optional raw = messagei18n.getString(loc); - if (!raw.isPresent()) { + String raw = messagei18n.getString(loc); + if (raw == null) { return invaildMsg + ": " + loc; } - String filled = fillArgs(raw.get(), args); + String filled = fillArgs(raw, args); if (player != null) { if (plugin.getConfig().getBoolean("plugin.PlaceHolderAPI") && plugin.getPlaceHolderAPI() != null && plugin.getPlaceHolderAPI().isEnabled()) { filled = PlaceholderAPI.setPlaceholders(player, filled); @@ -228,16 +228,21 @@ public class MsgUtil { String languageCode = plugin.getConfig().getString("language", "en-US").replace("_", "-"); // Init message file instance - IFile messageFile; + JsonConfiguration messageFile; File extractedMessageFile = new File(plugin.getDataFolder(), "messages.json"); String buildInMessageFilePath = "lang/" + languageCode + "/messages.json"; if (plugin.getResource(buildInMessageFilePath) == null) { //Use default buildInMessageFilePath = "lang-original/messages.json"; } - messageFile = new JSONFile(plugin, extractedMessageFile, buildInMessageFilePath, true); - messageFile.create(); - + if (!extractedMessageFile.exists()) { + try { + Files.copy(Objects.requireNonNull(plugin.getResource(buildInMessageFilePath)), extractedMessageFile.toPath()); + } catch (IOException ioException) { + plugin.getLogger().log(Level.WARNING, "Cannot extract the messages.json file", ioException); + } + } + messageFile = HumanReadableJsonConfiguration.loadConfiguration(extractedMessageFile); //Handle old message file and load it up File oldMsgFile = new File(plugin.getDataFolder(), "messages.yml"); if (oldMsgFile.exists()) { @@ -248,7 +253,11 @@ public class MsgUtil { for (String key : oldMsgI18n.getKeys(true)) { messageFile.set(key, oldMsgI18n.get(key)); } - messageFile.save(); + try { + messageFile.save(extractedMessageFile); + } catch (IOException ioException) { + ioException.printStackTrace(); + } try { Files.move( oldMsgFile.toPath(), new File(plugin.getDataFolder(), "messages.yml.bak").toPath()); @@ -269,16 +278,20 @@ public class MsgUtil { } //Init global instance + File buildInLangFile = new File(Util.getCacheFolder(), "bulitin-messages.json"); messagei18n = messageFile; - builtInLang = new JSONFile(plugin, buildInMessageFilePath); - - + try { + Files.copy(Objects.requireNonNull(plugin.getResource(buildInMessageFilePath)), buildInLangFile.toPath()); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + builtInLang = HumanReadableJsonConfiguration.loadConfiguration(buildInLangFile); //Check the i18n language name and backup - if (!messagei18n.getString("language-name").isPresent()) { + if (StringUtils.isEmpty(messagei18n.getString("language-name"))) { setAndUpdate("language-name"); } - String messageCodeInFile = messagei18n.getString("language-name").get(); - if (!messageCodeInFile.equals(languageCode)) { + String messageCodeInFile = messagei18n.getString("language-name"); + if (!Objects.equals(messageCodeInFile, languageCode)) { String backupFileName = "messages-bak-" + UUID.randomUUID().toString() + ".json"; Util.debugLog("Language name " + messageCodeInFile + " not matched with " + languageCode + ", replacing with build-in files and renaming current file to " + backupFileName); plugin.getLogger().warning("Language name " + messageCodeInFile + " not matched with " + languageCode + ", replacing with build-in files and renaming current file to " + backupFileName); @@ -296,10 +309,10 @@ public class MsgUtil { /* Set default language vesion and update messages.yml */ int ver = 0; - Optional strVer = messagei18n.getString("language-version"); - if (strVer.isPresent()) { + String strVer = messagei18n.getString("language-version"); + if (StringUtils.isNumeric(strVer)) { try { - ver = Integer.parseInt(strVer.get()); + ver = Integer.parseInt(strVer); } catch (NumberFormatException ignore) { } } @@ -323,7 +336,11 @@ public class MsgUtil { } /* Save the upgraded messages.yml */ - messagei18n.save(); + try { + messagei18n.save(extractedMessageFile); + } catch (IOException ioException) { + ioException.printStackTrace(); + } plugin.getLogger().info("Completed to load plugin translations files."); } @@ -708,13 +725,13 @@ public class MsgUtil { public static String getMessage( @NotNull String loc, @Nullable CommandSender player, @NotNull String... args) { try { - final Optional raw = messagei18n.getString(loc); - if (!raw.isPresent()) { + final String raw = messagei18n.getString(loc); + if (raw == null) { Util.debugLog("ERR: MsgUtil cannot find the the phrase at " + loc + ", printing the all readed datas: " + messagei18n); return invaildMsg + ": " + loc; } - String filled = fillArgs(raw.get(), args); + String filled = fillArgs(raw, args); if (player instanceof OfflinePlayer) { if (plugin.getPlaceHolderAPI() != null && plugin.getPlaceHolderAPI().isEnabled() && plugin.getConfig().getBoolean("plugin.PlaceHolderAPI")) { try { @@ -972,7 +989,7 @@ public class MsgUtil { return Util.prettifyText(potionString); } - public static IFile getI18nFile() { + public static JsonConfiguration getI18nFile() { return messagei18n; } @@ -1451,7 +1468,7 @@ public class MsgUtil { } for (String msg : messages) { try { - if (msg == null || msg.isEmpty()) { + if (StringUtils.isEmpty(msg)) { continue; } plugin.getQuickChat().send(sender, chatColor + msg); From a69142d96be0fea1cd73b9066ca981079015db19 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:35:09 +0800 Subject: [PATCH 12/36] Fix build error --- .../quickshop/shop/ArmorStandDisplayItem.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java index a2c68cc1f..e175aa0d8 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java @@ -1,23 +1,22 @@ -///* -// * This file is a part of project QuickShop, the name is ArmorStandDisplayItem.java -// * Copyright (C) PotatoCraft Studio and contributors -// * -// * This program is free software: you can redistribute it and/or modify it -// * under the terms of the GNU General Public License as published by the -// * Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, but WITHOUT -// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// * for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see . -// * -// */ -// -//package org.maxgamer.quickshop.shop; +/* + * This file is a part of project QuickShop, the name is ArmorStandDisplayItem.java + * Copyright (C) PotatoCraft Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package org.maxgamer.quickshop.shop; // //import lombok.ToString; //import org.bukkit.Location; From 9619a2d426249893cbeb95b70328a6d75cc5d8d4 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:36:35 +0800 Subject: [PATCH 13/36] Fix build error --- .../quickshop/shop/ArmorStandDisplayItem.java | 334 ------------------ 1 file changed, 334 deletions(-) delete mode 100644 src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java diff --git a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java deleted file mode 100644 index e175aa0d8..000000000 --- a/src/main/java/org/maxgamer/quickshop/shop/ArmorStandDisplayItem.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * This file is a part of project QuickShop, the name is ArmorStandDisplayItem.java - * Copyright (C) PotatoCraft Studio and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package org.maxgamer.quickshop.shop; -// -//import lombok.ToString; -//import org.bukkit.Location; -//import org.bukkit.Material; -//import org.bukkit.NamespacedKey; -//import org.bukkit.block.BlockFace; -//import org.bukkit.block.data.Directional; -//import org.bukkit.entity.ArmorStand; -//import org.bukkit.entity.Entity; -//import org.bukkit.entity.EntityType; -//import org.bukkit.util.EulerAngle; -//import org.jetbrains.annotations.NotNull; -//import org.jetbrains.annotations.Nullable; -//import org.maxgamer.quickshop.event.ShopDisplayItemDespawnEvent; -//import org.maxgamer.quickshop.event.ShopDisplayItemSpawnEvent; -//import org.maxgamer.quickshop.util.GameVersion; -//import org.maxgamer.quickshop.util.MsgUtil; -//import org.maxgamer.quickshop.util.ReflectFactory; -//import org.maxgamer.quickshop.util.Util; -// -//import java.util.Objects; -// -//@ToString -//@Deprecated -// -//public class ArmorStandDisplayItem extends DisplayItem { -// -// @Nullable -// private volatile ArmorStand armorStand; -// -// /** -// * @deprecated This display type pending for removal in future -// */ -// ArmorStandDisplayItem(@NotNull Shop shop) { -// super(shop); -// } -// -// private static boolean isTool(Material material) { -// String nlc = material.name().toLowerCase(); -// return nlc.contains("sword") || nlc.contains("shovel") || nlc.contains("axe"); //TODO: Needs a better impl. Maybe NamespacedKey -// } -// -// @Override -// public boolean checkDisplayIsMoved() { -// if (this.armorStand == null) { -// return false; -// } -// return !this.armorStand.getLocation().equals(getDisplayLocation()); -// } -// -// public Location getCenter(Location loc) { -// // This is always '+' instead of '-' even in negative pos -// return new Location( -// loc.getWorld(), loc.getBlockX() + .5, loc.getBlockY() + .5, loc.getBlockZ() + .5); -// } -// -// @Override -// public boolean checkDisplayNeedRegen() { -// if (this.armorStand == null) { -// return false; -// } -// return !this.armorStand.isValid() || this.armorStand.isDead(); -// } -// -// @Override -// public boolean checkIsShopEntity(@NotNull Entity entity) { -// if (!(entity instanceof ArmorStand)) { -// return false; -// } -// return DisplayItem.checkIsGuardItemStack(((ArmorStand) entity).getItemInHand()); //FIXME: Update this when drop 1.13 supports -// } -// -// @Override -// public void fixDisplayMoved() { -// Location location = this.getDisplayLocation(); -// //if (this.armorStand != null) { -// if (location != null) { -// this.armorStand.teleport(location); -// } else { -// fixDisplayMovedOld(); -// } -//// } else { -//// fixDisplayMovedOld(); -//// } -// } -// -// public void fixDisplayMovedOld() { -// for (Entity entity : Objects.requireNonNull(this.shop.getLocation().getWorld()).getEntities()) { -// if (!(entity instanceof ArmorStand)) { -// continue; -// } -// ArmorStand eArmorStand = (ArmorStand) entity; -// if (eArmorStand.getUniqueId().equals(Objects.requireNonNull(this.armorStand).getUniqueId())) { -// Util.debugLog( -// "Fixing moved ArmorStand displayItem " -// + eArmorStand.getUniqueId() -// + " at " -// + eArmorStand.getLocation()); -// eArmorStand.teleport(getDisplayLocation()); -// return; -// } -// } -// } -// -// @Override -// public void fixDisplayNeedRegen() { -// respawn(); -// } -// -// @Override -// public void remove() { -// if (this.armorStand == null) { -// Util.debugLog("Ignore the armorStand removing because the armorStand not spawned."); -// return; -// } -// this.armorStand.remove(); -// this.armorStand = null; -// this.guardedIstack = null; -// ShopDisplayItemDespawnEvent shopDisplayItemDespawnEvent = -// new ShopDisplayItemDespawnEvent(this.shop, this.originalItemStack, DisplayType.ARMORSTAND); -// plugin.getServer().getPluginManager().callEvent(shopDisplayItemDespawnEvent); -// } -// -// @Override -// public boolean removeDupe() { -// if (this.armorStand == null) { -// Util.debugLog("Warning: Trying to removeDupe for a null display shop."); -// return false; -// } -// boolean removed = false; -// for (Entity entity : armorStand.getNearbyEntities(1.5, 1.5, 1.5)) { -// if (entity.getType() != EntityType.ARMOR_STAND) { -// continue; -// } -// ArmorStand eArmorStand = (ArmorStand) entity; -// -// if (!eArmorStand.getUniqueId().equals(this.armorStand.getUniqueId()) && DisplayItem.checkIsTargetShopDisplay(eArmorStand.getItemInHand(), this.shop)) {//FIXME: Update this when drop 1.13 supports -// Util.debugLog("Removing dupes ArmorEntity " + eArmorStand.getUniqueId() + " at " + eArmorStand.getLocation()); -// entity.remove(); -// removed = true; -// } -// } -// return removed; -// } -// -// @Override -// public void respawn() { -// remove(); -// spawn(); -// } -// -// @Override -// public void safeGuard(@NotNull Entity entity) { -// if (!(entity instanceof ArmorStand)) { -// Util.debugLog( -// "Failed to safeGuard " + entity.getLocation() + ", cause target not a ArmorStand"); -// return; -// } -// ArmorStand armorStand = (ArmorStand) entity; -// // Set item protect in the armorstand's hand -// this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop); -// Objects.requireNonNull(armorStand.getEquipment()).setHelmet(guardedIstack); -// if (GameVersion.get(ReflectFactory.getServerVersion()).isPersistentStorageApiSupports()) { -// armorStand -// .getPersistentDataContainer() -// .set( -// new NamespacedKey(plugin, "displayMark"), -// DisplayItemPersistentDataType.INSTANCE, -// DisplayItem.createShopProtectionFlag(this.originalItemStack, shop)); -// -// } -// } -// -// @Override -// public void spawn() { -// if (shop.isDeleted() || !shop.isLoaded()) { -// return; -// } -// if (shop.getLocation().getWorld() == null) { -// Util.debugLog("Canceled the displayItem spawning because the location in the world is null."); -// return; -// } -// -// if (originalItemStack == null) { -// Util.debugLog("Canceled the displayItem spawning because the ItemStack is null."); -// return; -// } -// -// if (armorStand != null && armorStand.isValid() && !armorStand.isDead()) { -// Util.debugLog( -// "Warning: Spawning the armorStand for DisplayItem when there is already an existing armorStand may cause a duplicated armorStand!"); -// MsgUtil.debugStackTrace(Thread.currentThread().getStackTrace()); -// -// ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = -// new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.ARMORSTAND); -// plugin.getServer().getPluginManager().callEvent(shopDisplayItemSpawnEvent); -// if (shopDisplayItemSpawnEvent.isCancelled()) { -// Util.debugLog( -// "Canceled the displayItem from spawning because a plugin setCancelled the spawning event, usually it is a QuickShop Add on"); -// return; -// } -// -// Location location = getDisplayLocation(); -// this.armorStand = -// this.shop -// .getLocation() -// .getWorld() -// .spawn( -// location, -// ArmorStand.class, -// armorStand -> { -// // Set basic armorstand datas. -// armorStand.setGravity(false); -// armorStand.setVisible(false); -// armorStand.setMarker(true); -// armorStand.setCollidable(false); -// armorStand.setSmall(true); -// armorStand.setArms(false); -// armorStand.setBasePlate(false); -// armorStand.setSilent(true); -// armorStand.setAI(false); -// armorStand.setCanPickupItems(false); -// // Set pose (this is for hand while we use helmet) -// // setPoseForArmorStand(); -// }); -// // Set safeGuard -// Util.debugLog( -// "Spawned armor stand @ " -// + this.armorStand.getLocation() -// + " with UUID " -// + this.armorStand.getUniqueId()); -// safeGuard(this.armorStand); // Helmet must be set after spawning -// } -// } -// -// @Override -// public @Nullable Entity getDisplay() { -// return this.armorStand; -// } -// -// @Override -// public Location getDisplayLocation() { -// BlockFace containerBlockFace = BlockFace.NORTH; // Set default vaule -// if (this.shop.getLocation().getBlock().getBlockData() instanceof Directional) { -// containerBlockFace = -// ((Directional) this.shop.getLocation().getBlock().getBlockData()) -// .getFacing(); // Replace by container face. -// } -// // Fix specific block facing -// Material type = this.shop.getLocation().getBlock().getType(); -// if (type.name().contains("ANVIL") -// || type.name().contains("FENCE") -// || type.name().contains("WALL")) { -// switch (containerBlockFace) { -// case SOUTH: -// containerBlockFace = BlockFace.WEST; -// break; -// case NORTH: -// containerBlockFace = BlockFace.EAST; -// case EAST: -// containerBlockFace = BlockFace.NORTH; -// case WEST: -// containerBlockFace = BlockFace.SOUTH; -// default: -// break; -// } -// } -// -// Location asloc = getCenter(this.shop.getLocation()); -// Util.debugLog("containerBlockFace " + containerBlockFace); -// if (this.originalItemStack.getType().isBlock()) { -// asloc.add(0, 0.5, 0); -// } -// switch (containerBlockFace) { -// case SOUTH: -// asloc.add(0, -0.5, 0); -// asloc.setYaw(0); -// Util.debugLog("Block face as SOUTH"); -// break; -// case WEST: -// asloc.add(0, -0.5, 0); -// asloc.setYaw(90); -// Util.debugLog("Block face as WEST"); -// break; -// case EAST: -// asloc.add(0, -0.5, 0); -// asloc.setYaw(-90); -// Util.debugLog("Block face as EAST"); -// break; -// case NORTH: -// asloc.add(0, -0.5, 0); -// asloc.setYaw(180); -// Util.debugLog("Block face as NORTH"); -// break; -// default: -// break; -// } -// return asloc; -// } -// -// @Override -// public synchronized boolean isSpawned() { -// return this.armorStand != null && this.armorStand.isValid(); -// } -// -// @Deprecated // no use, will be removed soon -// private void setPoseForArmorStand() { -// if (this.originalItemStack.getType().isBlock()) { -// Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-0.2, 0, 0)); -// } else { -// Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-89.5, 0, 0)); -// } -// } -// -//} From 1167c4632b4a532df85dfdb855f167aaac33bc4d Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:42:13 +0800 Subject: [PATCH 14/36] Fix build error --- .../org/maxgamer/quickshop/QuickShop.java | 2 +- .../listener/DisplayBugFixListener.java | 63 --------------- .../listener/DisplayProtectionListener.java | 30 ++++--- .../EnhanceDisplayProtectionListener.java | 78 +++++++++---------- .../quickshop/shop/ContainerShop.java | 12 +-- 5 files changed, 58 insertions(+), 127 deletions(-) delete mode 100644 src/main/java/org/maxgamer/quickshop/listener/DisplayBugFixListener.java diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index c862c1d4f..73304111a 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -808,7 +808,7 @@ public class QuickShop extends JavaPlugin { Bukkit.getPluginManager().registerEvents(internalListener, this); if (isDisplay() && DisplayItem.getNowUsing() != DisplayType.VIRTUALITEM) { displayWatcher = new DisplayWatcher(this); - new DisplayBugFixListener(this).register(); +// new DisplayBugFixListener(this).register(); new DisplayProtectionListener(this, this.shopCache).register(); if (Bukkit.getPluginManager().getPlugin("ClearLag") != null) { new ClearLaggListener(this).register(); diff --git a/src/main/java/org/maxgamer/quickshop/listener/DisplayBugFixListener.java b/src/main/java/org/maxgamer/quickshop/listener/DisplayBugFixListener.java deleted file mode 100644 index 1172ff918..000000000 --- a/src/main/java/org/maxgamer/quickshop/listener/DisplayBugFixListener.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is a part of project QuickShop, the name is DisplayBugFixListener.java - * Copyright (C) PotatoCraft Studio and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.maxgamer.quickshop.listener; - -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.BlockCanBuildEvent; -import org.maxgamer.quickshop.QuickShop; -import org.maxgamer.quickshop.shop.DisplayItem; -import org.maxgamer.quickshop.shop.DisplayType; -import org.maxgamer.quickshop.util.Util; - -import java.util.Collection; - - -public class DisplayBugFixListener extends QSListener { - public DisplayBugFixListener(QuickShop plugin) { - super(plugin); - } - - @EventHandler(ignoreCancelled = true) - public void canBuild(BlockCanBuildEvent e) { - if (!plugin.isDisplay() - || DisplayItem.getNowUsing() != DisplayType.ARMORSTAND - || e.isBuildable()) { - return; - } - - final Collection entities = - e.getBlock().getWorld().getNearbyEntities(e.getBlock().getLocation(), 1.0, 1, 1.0); - - for (final Entity entity : entities) { - if (!(entity instanceof ArmorStand) - || !DisplayItem.checkIsGuardItemStack(((ArmorStand) entity).getItemInHand())) { //FIXME: Update this when drop 1.13 supports - continue; - } - - e.setBuildable(true); - Util.debugLog( - "Re-set the allowed build flag here because it found the cause of the display-item blocking it before."); - return; - } - } - -} diff --git a/src/main/java/org/maxgamer/quickshop/listener/DisplayProtectionListener.java b/src/main/java/org/maxgamer/quickshop/listener/DisplayProtectionListener.java index ec4fd64c2..955fec10b 100644 --- a/src/main/java/org/maxgamer/quickshop/listener/DisplayProtectionListener.java +++ b/src/main/java/org/maxgamer/quickshop/listener/DisplayProtectionListener.java @@ -20,12 +20,10 @@ package org.maxgamer.quickshop.listener; import org.bukkit.Location; -import org.bukkit.entity.ArmorStand; import org.bukkit.entity.EntityType; import org.bukkit.entity.Item; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityPortalEvent; import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.event.inventory.InventoryOpenEvent; @@ -81,20 +79,20 @@ public class DisplayProtectionListener extends ProtectionListenerBase { + " , QuickShop already cancel it."); } } - - @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void entity(EntityDamageEvent event) { - if (!(event.getEntity() instanceof ArmorStand)) { - return; - } - if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) { - return; - } - if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports - return; - } - event.setCancelled(true); - } +// +// @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) +// public void entity(EntityDamageEvent event) { +// if (!(event.getEntity() instanceof ArmorStand)) { +// return; +// } +// if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) { +// return; +// } +// if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports +// return; +// } +// event.setCancelled(true); +// } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) diff --git a/src/main/java/org/maxgamer/quickshop/listener/EnhanceDisplayProtectionListener.java b/src/main/java/org/maxgamer/quickshop/listener/EnhanceDisplayProtectionListener.java index 6e22c509e..6f02fa1cd 100644 --- a/src/main/java/org/maxgamer/quickshop/listener/EnhanceDisplayProtectionListener.java +++ b/src/main/java/org/maxgamer/quickshop/listener/EnhanceDisplayProtectionListener.java @@ -25,7 +25,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Furnace; -import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; @@ -34,8 +33,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.inventory.*; import org.bukkit.event.player.PlayerBucketEmptyEvent; @@ -46,7 +43,6 @@ import org.jetbrains.annotations.NotNull; import org.maxgamer.quickshop.Cache; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.shop.DisplayItem; -import org.maxgamer.quickshop.shop.DisplayType; import org.maxgamer.quickshop.shop.Shop; import org.maxgamer.quickshop.util.MsgUtil; import org.maxgamer.quickshop.util.Util; @@ -251,44 +247,44 @@ public class EnhanceDisplayProtectionListener extends ProtectionListenerBase imp } } - @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void entity(EntityDeathEvent event) { - if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) { - return; - } - if (!(event.getEntity() instanceof ArmorStand)) { - return; - } - if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports - return; - } - event.setDroppedExp(0); - event.getDrops().clear(); - } +// @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) +// public void entity(EntityDeathEvent event) { +// if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) { +// return; +// } +// if (!(event.getEntity() instanceof ArmorStand)) { +// return; +// } +// if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports +// return; +// } +// event.setDroppedExp(0); +// event.getDrops().clear(); +// } - @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void entity(EntityInteractEvent event) { - if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) { - return; - } - if (!(event.getEntity() instanceof ArmorStand)) { - return; - } - if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports - return; - } - event.setCancelled(true); - final Entity entity = event.getEntity(); - if (entity instanceof InventoryHolder) { - Util.inventoryCheck(((InventoryHolder) entity).getInventory()); - } - sendAlert( - "[DisplayGuard] Entity " - + event.getEntityType().name() - + " # " - + event.getEntity().getLocation() - + " trying interact the hold displayItem's entity."); - } +// @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) +// public void entity(EntityInteractEvent event) { +// if (DisplayItem.getNowUsing() != DisplayType.ARMORSTAND) { +// return; +// } +// if (!(event.getEntity() instanceof ArmorStand)) { +// return; +// } +// if (!DisplayItem.checkIsGuardItemStack(((ArmorStand) event.getEntity()).getItemInHand())) { //FIXME: Update this when drop 1.13 supports +// return; +// } +// event.setCancelled(true); +// final Entity entity = event.getEntity(); +// if (entity instanceof InventoryHolder) { +// Util.inventoryCheck(((InventoryHolder) entity).getInventory()); +// } +// sendAlert( +// "[DisplayGuard] Entity " +// + event.getEntityType().name() +// + " # " +// + event.getEntity().getLocation() +// + " trying interact the hold displayItem's entity."); +// } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void inventory(InventoryClickEvent event) { diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java index ef7b78e12..4bbce7d17 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java @@ -178,21 +178,21 @@ public class ContainerShop implements Shop { switch (DisplayItem.getNowUsing()) { case UNKNOWN: Util.debugLog( - "Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem"); + "Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem"); this.displayItem = new RealDisplayItem(this); break; case REALITEM: this.displayItem = new RealDisplayItem(this); break; - case ARMORSTAND: - this.displayItem = new ArmorStandDisplayItem(this); - break; +// case ARMORSTAND: +// this.displayItem = new ArmorStandDisplayItem(this); +// break; case VIRTUALITEM: try { if (!GameVersion.get(ReflectFactory.getServerVersion()) - .isVirtualDisplaySupports()) { + .isVirtualDisplaySupports()) { throw new IllegalStateException( - "Version not supports Virtual DisplayItem."); + "Version not supports Virtual DisplayItem."); } this.displayItem = new VirtualDisplayItem(this); From 1025fa4d5a8f012a0158a31e3e70da3a1aacd3dd Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:46:34 +0800 Subject: [PATCH 15/36] Fix javadoc in ShopTaxEvent --- src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java b/src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java index a086d1282..d90dade15 100644 --- a/src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java +++ b/src/main/java/org/maxgamer/quickshop/event/ShopTaxEvent.java @@ -75,7 +75,7 @@ public class ShopTaxEvent extends QSEvent { /** * Sets the new tax in purchase * - * @return new tax + * @param tax New tax */ public void setTax(double tax) { this.tax = tax; From cd304e128dd0af7bd7677a77fdfc1eb240324544 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 16:51:34 +0800 Subject: [PATCH 16/36] Remove Adventure flag --- .../org/maxgamer/quickshop/QuickShop.java | 8 +++---- src/main/resources/config.yml | 22 ++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 73304111a..a5ea72acb 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -524,10 +524,10 @@ public class QuickShop extends JavaPlugin { //noinspection ResultOfMethodCallIgnored getDataFolder().mkdirs(); // replaceLogger(); - if (getConfig().getBoolean("debug.adventure", false)) { - System.setProperty("net.kyori.adventure.debug", "true"); - getLogger().warning("Adventure debug flag was set! You can disable this anytime in config by set `debug.adventure` to false."); - } +// if (getConfig().getBoolean("debug.adventure", false)) { +// System.setProperty("net.kyori.adventure.debug", "true"); +// getLogger().warning("Adventure debug flag was set! You can disable this anytime in config by set `debug.adventure` to false."); +// } this.bootError = null; getLogger().info("Loading up integration modules."); this.integrationHelper = new IntegrationHelper(this); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index faacfa666..114c9f8a3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,7 +1,25 @@ #This is example config, don't direct modify this file, all changes will revert when you reload the plugin. #This is example config, don't direct modify this file, all changes will revert when you reload the plugin. #This is example config, don't direct modify this file, all changes will revert when you reload the plugin. - +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +#This is example config, don't direct modify this file, all changes will revert when you reload the plugin. +# READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE READ ABOVE +# IF YOU WANT EDIT CONFIGURATION, THE FILE "config.yml" IS THE CORRECT FILE #Do not touch if you not clear know about this config-version: 126 @@ -688,8 +706,6 @@ debug: disable-debuglogger: false #logging stacktrace when deleting shop shop-deletion: false - #Enable adventure debug flag - adventure: false From c914911449d880bb7ed14d6c41665f34c287f85e Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:11:19 +0800 Subject: [PATCH 17/36] Start async handler correctly --- .../maxgamer/quickshop/shop/VirtualDisplayItem.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index e5e192804..249e20b55 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -21,6 +21,7 @@ package org.maxgamer.quickshop.shop; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; +import com.comphenix.protocol.async.AsyncListenerHandler; import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; @@ -85,6 +86,8 @@ public class VirtualDisplayItem extends DisplayItem { @Nullable private BukkitTask asyncSendingTask; + private AsyncListenerHandler handler; + public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException { super(shop); @@ -249,7 +252,9 @@ public class VirtualDisplayItem extends DisplayItem { private void unload() { packetSenders.clear(); if (packetAdapter != null) { - protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter); + handler.stop(); + protocolManager.getAsynchronousManager().unregisterAsyncHandler(handler); + //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter); } if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) { asyncSendingTask.cancel(); @@ -383,7 +388,8 @@ public class VirtualDisplayItem extends DisplayItem { } }; } - protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance + AsyncListenerHandler handler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance + handler.start(); asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> { Runnable runnable = asyncPacketSendQueue.poll(); while (runnable != null) { From 94bbc787255f00456d1c1284e902869f988c11e9 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:11:38 +0800 Subject: [PATCH 18/36] Fix file not exist exception --- src/main/java/org/maxgamer/quickshop/util/MsgUtil.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java index cf0eebc3a..4c97dae4c 100644 --- a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java @@ -281,9 +281,12 @@ public class MsgUtil { File buildInLangFile = new File(Util.getCacheFolder(), "bulitin-messages.json"); messagei18n = messageFile; try { + if (buildInLangFile.exists()) { + buildInLangFile.delete(); + } Files.copy(Objects.requireNonNull(plugin.getResource(buildInMessageFilePath)), buildInLangFile.toPath()); } catch (IOException ioException) { - ioException.printStackTrace(); + Util.debugLog("Cannow load default built-in language file: " + ioException.getMessage()); } builtInLang = HumanReadableJsonConfiguration.loadConfiguration(buildInLangFile); //Check the i18n language name and backup From b5c81da37132115e1ff1d375cbb3a8ce3b28dc98 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:11:53 +0800 Subject: [PATCH 19/36] fix typo --- src/main/java/org/maxgamer/quickshop/util/MsgUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java index 4c97dae4c..d83a0a31c 100644 --- a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java @@ -286,7 +286,7 @@ public class MsgUtil { } Files.copy(Objects.requireNonNull(plugin.getResource(buildInMessageFilePath)), buildInLangFile.toPath()); } catch (IOException ioException) { - Util.debugLog("Cannow load default built-in language file: " + ioException.getMessage()); + Util.debugLog("Cannot load default built-in language file: " + ioException.getMessage()); } builtInLang = HumanReadableJsonConfiguration.loadConfiguration(buildInLangFile); //Check the i18n language name and backup From 532200cb15e7d10a2882283c362f3f6cbf03c0bd Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:14:52 +0800 Subject: [PATCH 20/36] Fix wrong args passed into ProtocolLib --- .../maxgamer/quickshop/shop/VirtualDisplayItem.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index 249e20b55..70549c590 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -86,7 +86,7 @@ public class VirtualDisplayItem extends DisplayItem { @Nullable private BukkitTask asyncSendingTask; - private AsyncListenerHandler handler; + private AsyncListenerHandler asyncHandler; public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException { @@ -252,8 +252,8 @@ public class VirtualDisplayItem extends DisplayItem { private void unload() { packetSenders.clear(); if (packetAdapter != null) { - handler.stop(); - protocolManager.getAsynchronousManager().unregisterAsyncHandler(handler); + asyncHandler.stop(); + protocolManager.getAsynchronousManager().unregisterAsyncHandler(asyncHandler); //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter); } if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) { @@ -388,8 +388,8 @@ public class VirtualDisplayItem extends DisplayItem { } }; } - AsyncListenerHandler handler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance - handler.start(); + asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance + asyncHandler.start(); asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> { Runnable runnable = asyncPacketSendQueue.poll(); while (runnable != null) { From a70589d5ce112a9309359385f0ce47aaea93ec74 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:20:11 +0800 Subject: [PATCH 21/36] Optimize logic about sending VDI to players --- .../quickshop/shop/VirtualDisplayItem.java | 71 +++++++++---------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index 70549c590..3427de27c 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -43,7 +43,6 @@ import org.maxgamer.quickshop.util.Util; import java.lang.reflect.InvocationTargetException; import java.util.*; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; @@ -64,7 +63,7 @@ public class VirtualDisplayItem extends DisplayItem { //The List which store packet sender private final Set packetSenders = new ConcurrentSkipListSet<>(); - private final Queue asyncPacketSendQueue = new ConcurrentLinkedQueue<>(); + // private final Queue asyncPacketSendQueue = new ConcurrentLinkedQueue<>(); private volatile boolean isDisplay; @@ -335,6 +334,10 @@ public class VirtualDisplayItem extends DisplayItem { } } } + + asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance + asyncHandler.start(); + if (packetAdapter == null) { packetAdapter = new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.MAP_CHUNK) { @Override @@ -348,32 +351,29 @@ public class VirtualDisplayItem extends DisplayItem { int x = event.getPacket().getIntegers().read(0); //chunk z int z = event.getPacket().getIntegers().read(1); - asyncPacketSendQueue.offer(() -> { - //lazy initialize - if (chunkLocation == null) { - World world = shop.getLocation().getWorld(); - Chunk chunk = null; - try { - //sync getting chunk - chunk = plugin.getServer().getScheduler().callSyncMethod(plugin, () -> shop.getLocation().getChunk()).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException("An error occurred when getting chunk from the world", e); - } - chunkLocation = new ShopChunk(world.getName(), chunk.getX(), chunk.getZ()); + + if (chunkLocation == null) { + World world = shop.getLocation().getWorld(); + Chunk chunk; + try { + //sync getting chunk + chunk = plugin.getServer().getScheduler().callSyncMethod(plugin, () -> shop.getLocation().getChunk()).get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException("An error occurred when getting chunk from the world", e); } - Player player = event.getPlayer(); - if (player instanceof TemporaryPlayer) { - return; - } - if (player == null || !player.isOnline()) { - Util.debugLog("Cancelled packet sending cause player logged out when sending packets."); - return; - } - if (chunkLocation.isSame(player.getWorld().getName(), x, z)) { - packetSenders.add(player.getUniqueId()); - sendFakeItem(player); - } - }); + chunkLocation = new ShopChunk(world.getName(), chunk.getX(), chunk.getZ()); + } + Player player = event.getPlayer(); + if (player instanceof TemporaryPlayer) { + return; + } + if (player == null || !player.isOnline()) { + return; + } + if (chunkLocation.isSame(player.getWorld().getName(), x, z)) { + packetSenders.add(player.getUniqueId()); + sendFakeItem(player); + } // Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { // if (chunkLocation == null) { // World world = shop.getLocation().getWorld(); @@ -388,15 +388,14 @@ public class VirtualDisplayItem extends DisplayItem { } }; } - asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance - asyncHandler.start(); - asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> { - Runnable runnable = asyncPacketSendQueue.poll(); - while (runnable != null) { - runnable.run(); - runnable = asyncPacketSendQueue.poll(); - } - }, 0, 1); + +// asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> { +// Runnable runnable = asyncPacketSendQueue.poll(); +// while (runnable != null) { +// runnable.run(); +// runnable = asyncPacketSendQueue.poll(); +// } +// }, 0, 1); } public void sendFakeItem(@NotNull Player player) { From 1d5b65cb31ec8b4c229a86d20374f223b2b2eda5 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:21:35 +0800 Subject: [PATCH 22/36] Optimize VDI CPU time cost --- .../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index 3427de27c..87b356bd8 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -27,6 +27,7 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.injector.server.TemporaryPlayer; +import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedDataWatcher; import org.bukkit.Chunk; @@ -344,13 +345,14 @@ public class VirtualDisplayItem extends DisplayItem { public void onPacketSending(@NotNull PacketEvent event) { //is really full chunk data boolean isFull = event.getPacket().getBooleans().read(0); - if (!shop.isLoaded() || !isDisplay || !isFull || !Util.isLoaded(shop.getLocation()) || shop.isLeftShop()) { + if (!shop.isLoaded() || !isDisplay || !isFull || shop.isLeftShop()) { return; } + StructureModifier integerStructureModifier = event.getPacket().getIntegers(); //chunk x - int x = event.getPacket().getIntegers().read(0); + int x = integerStructureModifier.read(0); //chunk z - int z = event.getPacket().getIntegers().read(1); + int z = integerStructureModifier.read(1); if (chunkLocation == null) { World world = shop.getLocation().getWorld(); From 10ad07c45206c75da75db37c8e9e0d66d7d072d2 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:22:41 +0800 Subject: [PATCH 23/36] Optimize VDI CPU time cost --- .../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index 87b356bd8..d1f6a2e80 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -124,9 +124,10 @@ public class VirtualDisplayItem extends DisplayItem { switch (version) { case "v1_13_R1": case "v1_13_R2": - fakeItemPacket.getIntegers().write(6, 2); - //int data to mark - fakeItemPacket.getIntegers().write(7, 1); + fakeItemPacket.getIntegers() + .write(6, 2) + //int data to mark + .write(7, 1); break; //int data to mark default: From d2f59c9d621e226e3a2fb96f32ceb2e1693af9bb Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:30:02 +0800 Subject: [PATCH 24/36] Fix listener not be null exception --- .../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index d1f6a2e80..052b43f2f 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -337,8 +337,7 @@ public class VirtualDisplayItem extends DisplayItem { } } - asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance - asyncHandler.start(); + if (packetAdapter == null) { packetAdapter = new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.MAP_CHUNK) { @@ -391,7 +390,8 @@ public class VirtualDisplayItem extends DisplayItem { } }; } - + asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance + asyncHandler.start(); // asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> { // Runnable runnable = asyncPacketSendQueue.poll(); // while (runnable != null) { From 32509c8f896f28c9b0edae82b3aeb1707986c75c Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:36:40 +0800 Subject: [PATCH 25/36] unregister before stop --- .../quickshop/shop/VirtualDisplayItem.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index 052b43f2f..d0bf75899 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -250,17 +250,6 @@ public class VirtualDisplayItem extends DisplayItem { } } - private void unload() { - packetSenders.clear(); - if (packetAdapter != null) { - asyncHandler.stop(); - protocolManager.getAsynchronousManager().unregisterAsyncHandler(asyncHandler); - //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter); - } - if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) { - asyncSendingTask.cancel(); - } - } private void sendPacket(@NotNull Player player, @NotNull PacketContainer packet) { try { @@ -401,6 +390,20 @@ public class VirtualDisplayItem extends DisplayItem { // }, 0, 1); } + private void unload() { + packetSenders.clear(); + if (packetAdapter != null) { + protocolManager.getAsynchronousManager().unregisterAsyncHandler(asyncHandler); + asyncHandler.stop(); + + //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter); + } + if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) { + asyncSendingTask.cancel(); + } + } + + public void sendFakeItem(@NotNull Player player) { sendPacket(player, fakeItemPacket); sendPacket(player, fakeItemMetaPacket); From 3c8a764e950b75a26f64250ac2128a880e6b4c3e Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:43:20 +0800 Subject: [PATCH 26/36] Revert "Update dependency manually, avoid CVE-2021-27568" This reverts commit ff311875 --- pom.xml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pom.xml b/pom.xml index fe78e3bc0..debcbe4f1 100644 --- a/pom.xml +++ b/pom.xml @@ -411,21 +411,6 @@ com.dumptruckman.minecraft JsonConfiguration 1.1 - - - - - net.minidev - json-smart - - - - - - - net.minidev - json-smart - 1.3.2 com.github.MilkBowl From 74b353e065ea40996ded02e89166694482f60af4 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:46:39 +0800 Subject: [PATCH 27/36] Revert "Fix display conflict with PacketListenerAPI" --- .../maxgamer/quickshop/shop/VirtualDisplayItem.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index d0bf75899..f85314865 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -326,8 +326,6 @@ public class VirtualDisplayItem extends DisplayItem { } } - - if (packetAdapter == null) { packetAdapter = new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.MAP_CHUNK) { @Override @@ -379,8 +377,7 @@ public class VirtualDisplayItem extends DisplayItem { } }; } - asyncHandler = protocolManager.getAsynchronousManager().registerAsyncHandler(packetAdapter); //TODO: This may affects performance - asyncHandler.start(); + protocolManager.addPacketListener(packetAdapter); //TODO: This may affects performance // asyncSendingTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> { // Runnable runnable = asyncPacketSendQueue.poll(); // while (runnable != null) { @@ -393,10 +390,7 @@ public class VirtualDisplayItem extends DisplayItem { private void unload() { packetSenders.clear(); if (packetAdapter != null) { - protocolManager.getAsynchronousManager().unregisterAsyncHandler(asyncHandler); - asyncHandler.stop(); - - //protocolManager.getAsynchronousManager().unregisterAsyncHandler(packetAdapter); + protocolManager.removePacketListener(packetAdapter); } if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) { asyncSendingTask.cancel(); From b738c61366081a052213d554f02954621ba0c3d9 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 17:55:54 +0800 Subject: [PATCH 28/36] Fix dead lock --- .../org/maxgamer/quickshop/listener/PlayerListener.java | 4 ++++ .../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 9 +-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java index fe6aa9a32..4e422f9d8 100644 --- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java +++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java @@ -52,6 +52,8 @@ import java.util.UUID; public class PlayerListener extends QSListener { + boolean actionSwapping = false; + public PlayerListener(QuickShop plugin) { super(plugin); } @@ -69,6 +71,8 @@ public class PlayerListener extends QSListener { } final Block b = e.getClickedBlock(); final Player p = e.getPlayer(); + + if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) { if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && Util.isWallSign(b.getType())) { final Block block; diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index f85314865..69baf0c68 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -45,7 +45,6 @@ import org.maxgamer.quickshop.util.Util; import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.concurrent.ConcurrentSkipListSet; -import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; public class VirtualDisplayItem extends DisplayItem { @@ -343,13 +342,7 @@ public class VirtualDisplayItem extends DisplayItem { if (chunkLocation == null) { World world = shop.getLocation().getWorld(); - Chunk chunk; - try { - //sync getting chunk - chunk = plugin.getServer().getScheduler().callSyncMethod(plugin, () -> shop.getLocation().getChunk()).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException("An error occurred when getting chunk from the world", e); - } + Chunk chunk = shop.getLocation().getChunk(); chunkLocation = new ShopChunk(world.getName(), chunk.getX(), chunk.getZ()); } Player player = event.getPlayer(); From 5ef66da294e6de8f7191c8beab20963617d0d184 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 18:10:56 +0800 Subject: [PATCH 29/36] Add adventure mode debug --- .../org/maxgamer/quickshop/QuickShop.java | 1 + .../quickshop/listener/PlayerListener.java | 78 ++++++++++++------- src/main/resources/config.yml | 2 + 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index a5ea72acb..75f1e8c9e 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1727,6 +1727,7 @@ public class QuickShop extends JavaPlugin { getConfig().set("integration.superiorskyblock.enable", false); getConfig().set("integration.superiorskyblock.owner-create-only", false); getConfig().set("integration.superiorskyblock.delete-shop-on-member-leave", true); + getConfig().set("shop.interact.swap-click-behavior", false); getConfig().set("config-version", ++selectedVersion); } diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java index 4e422f9d8..8e9b817ac 100644 --- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java +++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java @@ -27,7 +27,7 @@ import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.entity.Player; -import org.bukkit.event.Event.Result; +import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; @@ -52,10 +52,34 @@ import java.util.UUID; public class PlayerListener extends QSListener { - boolean actionSwapping = false; + + boolean swapBehavior = false; public PlayerListener(QuickShop plugin) { super(plugin); + swapBehavior = plugin.getConfig().getBoolean("shop.interact.swap-click-behavior"); + } + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onClick(PlayerInteractEvent e) { + if (e.getPlayer().getGameMode() == GameMode.ADVENTURE) { + plugin.getLogger().info(e.getHand().name()); + plugin.getLogger().info(e.getAction().name()); + plugin.getLogger().info(e.getClickedBlock().toString()); + } + if (e.getHand() != EquipmentSlot.HAND) { + return; + } + final Block b = e.getClickedBlock(); + + if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) { + if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { + postControlPanel(e); + return; + } + } + + postTrade(e); } private void playClickSound(@NotNull Player player) { @@ -64,32 +88,29 @@ public class PlayerListener extends QSListener { } } - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onClick(PlayerInteractEvent e) { - if (e.getHand() != EquipmentSlot.HAND) { - return; - } + private void postControlPanel(PlayerInteractEvent e) { final Block b = e.getClickedBlock(); final Player p = e.getPlayer(); - - - if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) { - if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && Util.isWallSign(b.getType())) { - final Block block; - if (Util.isWallSign(b.getType())) { - block = Util.getAttached(b); - } else { - block = e.getClickedBlock(); - } - Shop controlPanelShop = plugin.getShopManager().getShop(Objects.requireNonNull(block).getLocation()); - if (controlPanelShop != null && (controlPanelShop.getOwner().equals(p.getUniqueId()) || QuickShop.getPermissionManager().hasPermission(p, "quickshop.other.control"))) { - MsgUtil.sendControlPanelInfo(p, Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation()))); - this.playClickSound(e.getPlayer()); - Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())).setSignText(); - } + if (Util.isWallSign(b.getType())) { + final Block block; + if (Util.isWallSign(b.getType())) { + block = Util.getAttached(b); + } else { + block = e.getClickedBlock(); + } + Shop controlPanelShop = plugin.getShopManager().getShop(Objects.requireNonNull(block).getLocation()); + if (controlPanelShop != null && (controlPanelShop.getOwner().equals(p.getUniqueId()) || QuickShop.getPermissionManager().hasPermission(p, "quickshop.other.control"))) { + MsgUtil.sendControlPanelInfo(p, Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation()))); + this.playClickSound(e.getPlayer()); + Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())).setSignText(); } - return; } + return; + } + + private void postTrade(PlayerInteractEvent e) { + final Block b = e.getClickedBlock(); + final Player p = e.getPlayer(); if (b == null) { return; } @@ -182,13 +203,13 @@ public class PlayerListener extends QSListener { actions.put(p.getUniqueId(), info); } // Handles creating shops - else if (e.useInteractedBlock() == Result.ALLOW + else if (e.useInteractedBlock() == Event.Result.ALLOW && shop == null && item != null && item.getType() != Material.AIR && QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.sell") && p.getGameMode() != GameMode.CREATIVE) { - if (e.useInteractedBlock() == Result.DENY + if (e.useInteractedBlock() == Event.Result.DENY || !InteractUtil.check(InteractUtil.Action.CREATE, p.isSneaking()) || plugin.getConfig().getBoolean("shop.disable-quick-create") || !plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) { @@ -242,6 +263,11 @@ public class PlayerListener extends QSListener { } } + enum InteractAction { + TRADE, + CONTROL_PANEL + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryClose(InventoryCloseEvent e) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 114c9f8a3..4ef6a3db6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -239,6 +239,8 @@ shop: sneak-to-create: false sneak-to-trade: false sneak-to-control: false + #Swap left and right click behavior + swap-click-behavior: false #Should we automatically create the sign for the chest? auto-sign: true From 162223c45340efedcffd4e4befa33d980c224ea0 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 18:28:08 +0800 Subject: [PATCH 30/36] beta: adventure mode click --- .../quickshop/listener/PlayerListener.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java index 8e9b817ac..d7e159493 100644 --- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java +++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java @@ -62,24 +62,48 @@ public class PlayerListener extends QSListener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onClick(PlayerInteractEvent e) { - if (e.getPlayer().getGameMode() == GameMode.ADVENTURE) { - plugin.getLogger().info(e.getHand().name()); - plugin.getLogger().info(e.getAction().name()); - plugin.getLogger().info(e.getClickedBlock().toString()); - } if (e.getHand() != EquipmentSlot.HAND) { return; } final Block b = e.getClickedBlock(); - + plugin.getLogger().info("CLICK"); if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) { if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { - postControlPanel(e); + if (!swapBehavior) { + postControlPanel(e); + } else { + postTrade(e); + } return; } } + if (!swapBehavior) { + postTrade(e); + } else { + postControlPanel(e); + } + } + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onAdventureClick(PlayerAnimationEvent event) { + if (event.getPlayer().getGameMode() != GameMode.ADVENTURE) { + return; + } + plugin.getLogger().info("ANIMATION"); + Block focused = event.getPlayer().getTargetBlock(null, 5); + PlayerInteractEvent interactEvent + = new PlayerInteractEvent(event.getPlayer(), + focused.getType() == Material.AIR ? Action.LEFT_CLICK_AIR : Action.LEFT_CLICK_BLOCK, + event.getPlayer().getInventory().getItemInMainHand(), + focused, + event.getPlayer().getFacing().getOppositeFace()); + + if (!swapBehavior) { + postTrade(interactEvent); + } else { + postControlPanel(interactEvent); + } - postTrade(e); } private void playClickSound(@NotNull Player player) { From 40d17585fb4bf3f8da650461fd2cf8104bf9f5fb Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 18:39:30 +0800 Subject: [PATCH 31/36] Adventure mode dupe bug workaround --- .../quickshop/listener/PlayerListener.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java index d7e159493..a08228458 100644 --- a/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java +++ b/src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java @@ -19,6 +19,8 @@ package org.maxgamer.quickshop.listener; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; import io.papermc.lib.PaperLib; import org.bukkit.GameMode; import org.bukkit.Location; @@ -49,11 +51,16 @@ import org.maxgamer.quickshop.util.Util; import java.util.Map; import java.util.Objects; import java.util.UUID; +import java.util.concurrent.TimeUnit; public class PlayerListener extends QSListener { - - - boolean swapBehavior = false; + private final Cache dupeClickPrevent = Caffeine + .newBuilder() + .initialCapacity(10) + .expireAfterAccess(1, TimeUnit.SECONDS) + .weakKeys() + .build(); + private boolean swapBehavior = false; public PlayerListener(QuickShop plugin) { super(plugin); @@ -66,7 +73,12 @@ public class PlayerListener extends QSListener { return; } final Block b = e.getClickedBlock(); - plugin.getLogger().info("CLICK"); + + // ----Adventure dupe click workaround start---- + if (e.getPlayer().getGameMode() == GameMode.ADVENTURE) { + dupeClickPrevent.put(e.getPlayer(), System.currentTimeMillis()); + } + // ----Adventure dupe click workaround end---- if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b != null) { if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if (!swapBehavior) { @@ -82,6 +94,7 @@ public class PlayerListener extends QSListener { } else { postControlPanel(e); } + } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @@ -89,7 +102,14 @@ public class PlayerListener extends QSListener { if (event.getPlayer().getGameMode() != GameMode.ADVENTURE) { return; } - plugin.getLogger().info("ANIMATION"); + // ----Adventure dupe click workaround start---- + Long dupeTime = dupeClickPrevent.getIfPresent(event.getPlayer()); + if (dupeTime != null && dupeTime > System.currentTimeMillis() - 1000) { + return; + } else if (dupeTime != null) { + dupeClickPrevent.invalidate(event.getPlayer()); + } + // ----Adventure dupe click workaround end---- Block focused = event.getPlayer().getTargetBlock(null, 5); PlayerInteractEvent interactEvent = new PlayerInteractEvent(event.getPlayer(), From b3462ea88d4e2ada108ef78249277a6993ca514b Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 19:41:31 +0800 Subject: [PATCH 32/36] 4.0.7.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index debcbe4f1..160f46f20 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 4.0.0 org.maxgamer QuickShop - 4.0.7.6 + 4.0.7.8 From 71330089529c6f12b56f0476f4485ceec7f696c2 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 20:10:53 +0800 Subject: [PATCH 33/36] add PacketListenerAPI check --- .../quickshop/util/envcheck/EnvironmentChecker.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/maxgamer/quickshop/util/envcheck/EnvironmentChecker.java b/src/main/java/org/maxgamer/quickshop/util/envcheck/EnvironmentChecker.java index b198e0a2d..5031418d2 100644 --- a/src/main/java/org/maxgamer/quickshop/util/envcheck/EnvironmentChecker.java +++ b/src/main/java/org/maxgamer/quickshop/util/envcheck/EnvironmentChecker.java @@ -20,6 +20,7 @@ package org.maxgamer.quickshop.util.envcheck; import lombok.SneakyThrows; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.event.HandlerList; import org.bukkit.event.block.BlockPlaceEvent; @@ -27,6 +28,8 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredListener; import org.jetbrains.annotations.NotNull; import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.shop.DisplayItem; +import org.maxgamer.quickshop.shop.DisplayType; import org.maxgamer.quickshop.util.GameVersion; import org.maxgamer.quickshop.util.JsonUtil; import org.maxgamer.quickshop.util.ReflectFactory; @@ -404,4 +407,12 @@ public class EnvironmentChecker { } return new ResultContainer(CheckResult.PASSED, "Passed checks"); } + + @EnvCheckEntry(name = "PacketListenerAPI conflict Test", priority = 9) + public ResultContainer plapiConflictTest() { + if (plugin.isDisplay() && DisplayItem.getNowUsing() == DisplayType.VIRTUALITEM && Bukkit.getPluginManager().isPluginEnabled("ProtocolLib") && Bukkit.getPluginManager().isPluginEnabled("PacketListenerAPI")) { + return new ResultContainer(CheckResult.WARNING, "Virtual DisplayItem may stop working on your server. We already know plugin [PacketListenerAPI] conflict with plugin [ProtocolLib] (that we required to sending fake items). If you display not showing, please uninstall [PacketListenerAPI]. And it's fine to keep them if nothing wrong."); + } + return new ResultContainer(CheckResult.PASSED, "Passed checks"); + } } From a9120ac2f9b64a78ce7f78f0a3556ea6da4bb2b3 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 21:28:11 +0800 Subject: [PATCH 34/36] Remove useless field --- .../org/maxgamer/quickshop/shop/VirtualDisplayItem.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index 69baf0c68..bb7232bde 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -21,7 +21,6 @@ package org.maxgamer.quickshop.shop; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; -import com.comphenix.protocol.async.AsyncListenerHandler; import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; @@ -36,7 +35,6 @@ import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.event.ShopDisplayItemSpawnEvent; @@ -82,10 +80,6 @@ public class VirtualDisplayItem extends DisplayItem { //cache chunk x and z private ShopChunk chunkLocation; - @Nullable - private BukkitTask asyncSendingTask; - - private AsyncListenerHandler asyncHandler; public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException { @@ -385,9 +379,6 @@ public class VirtualDisplayItem extends DisplayItem { if (packetAdapter != null) { protocolManager.removePacketListener(packetAdapter); } - if (asyncSendingTask != null && !asyncSendingTask.isCancelled()) { - asyncSendingTask.cancel(); - } } From 3e9800987dff7815df63906420f4d9c4bf39aadc Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 21:30:44 +0800 Subject: [PATCH 35/36] Register & unregister events --- .../SuperiorSkyblock2Integration.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java b/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java index 6008ff2d7..245f9caaf 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/superiorskyblock/SuperiorSkyblock2Integration.java @@ -20,6 +20,9 @@ package org.maxgamer.quickshop.integration.superiorskyblock; import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI; +import com.bgsoftware.superiorskyblock.api.events.IslandChunkResetEvent; +import com.bgsoftware.superiorskyblock.api.events.IslandKickEvent; +import com.bgsoftware.superiorskyblock.api.events.IslandQuitEvent; import com.bgsoftware.superiorskyblock.api.island.Island; import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer; import org.bukkit.Bukkit; @@ -45,9 +48,7 @@ public class SuperiorSkyblock2Integration extends QSIntegratedPlugin implements super(plugin); onlyOwnerCanCreateShop = plugin.getConfig().getBoolean("integration.superiorskyblock.owner-create-only"); deleteShopOnMemberLeave = plugin.getConfig().getBoolean("integration.superiorskyblock.delete-shop-on-member-leave"); - if (plugin.getConfig().getBoolean("integration.superiorskyblock.delete-shop-on-member-leave")) { - Bukkit.getPluginManager().registerEvents(this, plugin); - } + } /** @@ -102,7 +103,9 @@ public class SuperiorSkyblock2Integration extends QSIntegratedPlugin implements */ @Override public void load() { - + if (plugin.getConfig().getBoolean("integration.superiorskyblock.delete-shop-on-member-leave")) { + Bukkit.getPluginManager().registerEvents(this, plugin); + } } /** @@ -111,7 +114,9 @@ public class SuperiorSkyblock2Integration extends QSIntegratedPlugin implements */ @Override public void unload() { - + IslandQuitEvent.getHandlerList().unregister(this); + IslandKickEvent.getHandlerList().unregister(this); + IslandChunkResetEvent.getHandlerList().unregister(this); } @EventHandler From 36ef5b5be3588ed5d1d6605dec8dac873412acfa Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 8 Apr 2021 23:35:59 +0800 Subject: [PATCH 36/36] Hot fix for display issue --- pom.xml | 2 +- src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 160f46f20..5b9bc693f 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 4.0.0 org.maxgamer QuickShop - 4.0.7.8 + 4.0.7.9 diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java index 4bbce7d17..57f572460 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java @@ -813,7 +813,7 @@ public class ContainerShop implements Shop { checkDisplay(); - if (!isLeftShop) { + if (!isLeftShop && plugin.isDisplay()) { initDisplayItem(); displayItem.spawn(); }