From b28d3d5ebf71de2f0376bc4a11c96d6445503622 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Sun, 4 Jul 2021 11:45:27 +0800 Subject: [PATCH] Added sign feature, solved #1155 --- .../org/maxgamer/quickshop/QuickShop.java | 6 ++ .../quickshop/listener/BlockListener.java | 1 - .../quickshop/shop/ContainerShop.java | 17 ++- .../maxgamer/quickshop/util/GameVersion.java | 100 ++++++++---------- src/main/resources/config.yml | 9 +- 5 files changed, 70 insertions(+), 63 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index b71d3bf1f..8a5ebfdb5 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1852,6 +1852,12 @@ public class QuickShop extends JavaPlugin { getConfig().set("unlimited-shop-owner-change-account", "quickshop"); getConfig().set("config-version", ++selectedVersion); } + if (selectedVersion == 132) { + getConfig().set("shop.sign-glowing", false); + getConfig().set("shop.sign-dye-color", "null"); + getConfig().set("unlimited-shop-owner-change-account", "quickshop"); + getConfig().set("config-version", ++selectedVersion); + } if (getConfig().getInt("matcher.work-type") != 0 && GameVersion.get(ReflectFactory.getServerVersion()).name().contains("1_16")) { diff --git a/src/main/java/org/maxgamer/quickshop/listener/BlockListener.java b/src/main/java/org/maxgamer/quickshop/listener/BlockListener.java index 05f998439..5f51b1d39 100644 --- a/src/main/java/org/maxgamer/quickshop/listener/BlockListener.java +++ b/src/main/java/org/maxgamer/quickshop/listener/BlockListener.java @@ -157,7 +157,6 @@ public class BlockListener extends ProtectionListenerBase { if (b == null) { return null; } - return getShopPlayer(b.getLocation(), false); } diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java index 114bf00e4..28871d884 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java @@ -22,10 +22,7 @@ package org.maxgamer.quickshop.shop; import com.lishid.openinv.OpenInv; import io.papermc.lib.PaperLib; import lombok.EqualsAndHashCode; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; @@ -679,6 +676,12 @@ public class ContainerShop implements Shop { public void setSignText(@NotNull String[] lines) { Util.ensureThread(false); List signs = this.getSigns(); + boolean signGlowing = plugin.getConfig().getBoolean("shop.sign-glowing"); + DyeColor dyeColor = null; + try { + dyeColor = DyeColor.valueOf(plugin.getConfig().getString("shop.sign-dye-color")); + } catch (IllegalArgumentException ignored) { + } for (Sign sign : signs) { if (Arrays.equals(sign.getLines(), lines)) { continue; @@ -686,6 +689,12 @@ public class ContainerShop implements Shop { for (int i = 0; i < lines.length; i++) { sign.setLine(i, lines[i]); } + if (plugin.getGameVersion().isSignTextDyeSupport()) { + sign.setColor(dyeColor); + } + if (signGlowing && plugin.getGameVersion().isSignGlowingSupport()) { + sign.setGlowingText(true); + } sign.update(true); plugin.getServer().getPluginManager().callEvent(new ShopSignUpdateEvent(this, sign)); } diff --git a/src/main/java/org/maxgamer/quickshop/util/GameVersion.java b/src/main/java/org/maxgamer/quickshop/util/GameVersion.java index 36095ff5d..717fde730 100644 --- a/src/main/java/org/maxgamer/quickshop/util/GameVersion.java +++ b/src/main/java/org/maxgamer/quickshop/util/GameVersion.java @@ -19,6 +19,8 @@ package org.maxgamer.quickshop.util; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.jetbrains.annotations.NotNull; /** @@ -26,38 +28,40 @@ import org.jetbrains.annotations.NotNull; * * @author Ghost_chu and sandtechnology */ +@AllArgsConstructor +@Getter public enum GameVersion { - v1_5_R1(false, false, false, false), - v1_5_R2(false, false, false, false), - v1_5_R3(false, false, false, false), - v1_6_R1(false, false, false, false), - v1_6_R2(false, false, false, false), - v1_6_R3(false, false, false, false), - v1_7_R1(false, false, false, false), - v1_7_R2(false, false, false, false), - v1_7_R3(false, false, false, false), - v1_7_R4(false, false, false, false), - v1_8_R1(false, false, false, false), - v1_8_R2(false, false, false, false), - v1_8_R3(false, false, false, false), - v1_9_R1(false, false, false, false), - v1_9_R2(false, false, false, false), - v1_10_R1(false, false, false, false), - v1_11_R1(false, false, false, false), - v1_12_R1(false, false, false, false), - v1_12_R2(false, false, false, false), - v1_13_R1(false, false, false, false), - v1_13_R2(true, true, false, false), - v1_14_R1(true, true, true, false), - v1_14_R2(true, true, true, false), - v1_15_R1(true, true, true, false), - v1_15_R2(true, true, true, false), - v1_16_R1(true, true, true, false), - v1_16_R2(true, true, true, false), - v1_16_R3(true, true, true, false), - v1_16_R4(true, true, true, false), - v1_17_R1(true, true, true, true), - UNKNOWN(true, true, true, true); + v1_5_R1(false, false, false, false, false, false), + v1_5_R2(false, false, false, false, false, false), + v1_5_R3(false, false, false, false, false, false), + v1_6_R1(false, false, false, false, false, false), + v1_6_R2(false, false, false, false, false, false), + v1_6_R3(false, false, false, false, false, false), + v1_7_R1(false, false, false, false, false, false), + v1_7_R2(false, false, false, false, false, false), + v1_7_R3(false, false, false, false, false, false), + v1_7_R4(false, false, false, false, false, false), + v1_8_R1(false, false, false, false, false, false), + v1_8_R2(false, false, false, false, false, false), + v1_8_R3(false, false, false, false, false, false), + v1_9_R1(false, false, false, false, false, false), + v1_9_R2(false, false, false, false, false, false), + v1_10_R1(false, false, false, false, false, false), + v1_11_R1(false, false, false, false, false, false), + v1_12_R1(false, false, false, false, false, false), + v1_12_R2(false, false, false, false, false, false), + v1_13_R1(false, false, false, false, false, false), + v1_13_R2(true, true, false, false, false, false), + v1_14_R1(true, true, true, false, false, false), + v1_14_R2(true, true, true, false, false, false), + v1_15_R1(true, true, true, false, false, false), + v1_15_R2(true, true, true, false, false, false), + v1_16_R1(true, true, true, false, false, false), + v1_16_R2(true, true, true, false, false, false), + v1_16_R3(true, true, true, false, false, false), + v1_16_R4(true, true, true, false, false, false), + v1_17_R1(true, true, true, true, true, true), + UNKNOWN(true, true, true, true, true, true); /** * CoreSupports - Check does QuickShop most features supports this server version */ @@ -76,18 +80,15 @@ public enum GameVersion { private final boolean newNmsName; /** - * Utilities to help QuickShop quickly check server supported features - * - * @param coreSupports Does QuickShop most features supports this server version - * @param virtualDisplaySupports Does QuickShop VirtualDisplayItem feature this server version - * @param persistentStorageApiSupports Does server support PersistentStorage API + * Sign Glowing Support */ - GameVersion(boolean coreSupports, boolean virtualDisplaySupports, boolean persistentStorageApiSupports, boolean newNmsName) { - this.coreSupports = coreSupports; - this.virtualDisplaySupports = virtualDisplaySupports; - this.persistentStorageApiSupports = persistentStorageApiSupports; - this.newNmsName = newNmsName; - } + private final boolean signGlowingSupport; + + /** + * Sign Glowing Support + */ + private final boolean signTextDyeSupport; + /** * Matches the version that QuickShop supports or not @@ -105,19 +106,4 @@ public enum GameVersion { return UNKNOWN; } - public boolean isCoreSupports() { - return coreSupports; - } - - public boolean isVirtualDisplaySupports() { - return virtualDisplaySupports; - } - - public boolean isPersistentStorageApiSupports() { - return persistentStorageApiSupports; - } - - public boolean isNewNmsName() { - return newNmsName; - } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c98d1744d..fe6fcf9e3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -22,7 +22,7 @@ # TO EDIT QUICKSHOP'S CONFIGURATION, USE THE "config.yml" FILE! #Do not touch this if you don't know what you're doing! -config-version: 132 +config-version: 133 #Select the language you want to use, (e.g de), use only supported language codes from the list below. #If you use a not existant/not supported language, then QuickShop will use en_US. @@ -265,6 +265,13 @@ shop: #Should we automatically create the sign for the chest? auto-sign: true + #Sign use glowing effects + sign-glowing: false + + #Sign use dye color https://hub.spigotmc.org/javadocs/spigot/org/bukkit/DyeColor.html + sign-dye-color: null + #sign-dye-color: WHITE + #Should we pay/take money to/from unlimited shops owners? pay-unlimited-shop-owners: false