mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-02-19 03:21:20 +01:00
Use adventure text api in order to fix hover issues
This also has the side-effect of restoring CraftBukkit compatibility Also move all libraries into a dedicated Libs package
This commit is contained in:
parent
8aff3da550
commit
51e9d5f267
43
pom.xml
43
pom.xml
@ -83,11 +83,31 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>de.themoep</groupId>
|
||||
<artifactId>minedown</artifactId>
|
||||
<version>1.6.1-SNAPSHOT</version>
|
||||
<artifactId>minedown-adventure</artifactId>
|
||||
<version>1.6.2-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-gson</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Should be kept in sync with Mojang -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
@ -312,7 +332,7 @@
|
||||
<dependency>
|
||||
<groupId>de.themoep.showitem</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>1.2.24</version>
|
||||
<version>1.6.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@ -375,6 +395,7 @@
|
||||
<includes>
|
||||
<include>de.themoep:*</include>
|
||||
<include>de.themoep.utils:*</include>
|
||||
<include>net.kyori:*</include>
|
||||
<include>org.bstats:*</include>
|
||||
<include>net.gravitydevelopment.updater</include>
|
||||
<include>com.j256.ormlite</include>
|
||||
@ -385,11 +406,15 @@
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>de.themoep.utils.lang</pattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.Lang</shadedPattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.Libs.Lang</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>de.themoep.minedown</pattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.MineDown</shadedPattern>
|
||||
<pattern>de.themoep.minedown.adventure</pattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.Libs.MineDown</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori</pattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.Libs.Kyori</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
@ -401,11 +426,11 @@
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.j256.ormlite</pattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.ORMlite</shadedPattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.Libs.ORMlite</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>javax.persistence</pattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.javax.persistence</shadedPattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.Libs.javax.persistence</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
@ -506,7 +531,7 @@
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -6,12 +6,10 @@ import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||
import com.Acrobot.ChestShop.Events.MaterialParseEvent;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import de.themoep.ShowItem.api.ShowItem;
|
||||
import de.themoep.minedown.Replacer;
|
||||
import de.themoep.minedown.adventure.Replacer;
|
||||
import info.somethingodd.OddItem.OddItem;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConstructor;
|
||||
@ -21,7 +19,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
@ -35,7 +32,6 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.Acrobot.Breeze.Utils.StringUtil.getMinecraftCharWidth;
|
||||
import static com.Acrobot.Breeze.Utils.StringUtil.getMinecraftStringWidth;
|
||||
@ -541,29 +537,27 @@ public class MaterialUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> itemJson = new ArrayList<>();
|
||||
Component itemComponent = Component.empty();
|
||||
for (ItemStack item : InventoryUtil.mergeSimilarStacks(stock)) {
|
||||
try {
|
||||
itemJson.add(showItem.getItemConverter().createComponent(item, Level.FINE).toJsonString(player));
|
||||
itemComponent.append(showItem.getItemConverter().createComponent(item, Level.FINE).toTextComponent(player));
|
||||
} catch (Exception e) {
|
||||
ChestShop.getPlugin().getLogger().log(Level.WARNING, "Error while trying to send message '" + message + "' to player " + player.getName() + ": " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
String joinedItemJson = itemJson.stream().collect(Collectors.joining("," + new JSONObject(ImmutableMap.of("text", " ")).toJSONString() + ", "));
|
||||
|
||||
Map<String, String> newMap = new LinkedHashMap<>(replacementMap);
|
||||
newMap.put("material", "item");
|
||||
BaseComponent[] components = new Replacer()
|
||||
Component component = new Replacer()
|
||||
.placeholderSuffix("")
|
||||
.replace("item", ComponentSerializer.parse("[" + joinedItemJson + "]"))
|
||||
.replaceIn(message.getComponents(player, true, newMap, replacements));
|
||||
.replace("item",itemComponent)
|
||||
.replaceIn(message.getComponent(player, true, newMap, replacements));
|
||||
if (player != null) {
|
||||
player.spigot().sendMessage(components);
|
||||
ChestShop.getAudiences().player(player).sendMessage(component);
|
||||
return true;
|
||||
} else if (playerName != null) {
|
||||
ChestShop.sendBungeeMessage(playerName, components);
|
||||
ChestShop.sendBungeeMessage(playerName, component);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,9 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.apache.logging.log4j.Level;
|
||||
@ -93,6 +96,8 @@ public class ChestShop extends JavaPlugin {
|
||||
private static Server server;
|
||||
private static PluginDescriptionFile description;
|
||||
|
||||
private static BukkitAudiences audiences;
|
||||
|
||||
private static File dataFolder;
|
||||
private static ItemDatabase itemDatabase;
|
||||
|
||||
@ -116,6 +121,7 @@ public class ChestShop extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
audiences = BukkitAudiences.create(this);
|
||||
turnOffDatabaseLogging();
|
||||
if (!handleMigrations()) {
|
||||
return;
|
||||
@ -518,6 +524,10 @@ public class ChestShop extends JavaPlugin {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static BukkitAudiences getAudiences() {
|
||||
return audiences;
|
||||
}
|
||||
|
||||
public static void registerListener(Listener listener) {
|
||||
plugin.registerEvent(listener);
|
||||
}
|
||||
@ -527,7 +537,7 @@ public class ChestShop extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static void sendBungeeMessage(String playerName, Messages.Message message, Map<String, String> replacementMap, String... replacements) {
|
||||
sendBungeeMessage(playerName, message.getComponents(null, true, replacementMap, replacements));
|
||||
sendBungeeMessage(playerName, message.getComponent(null, true, replacementMap, replacements));
|
||||
}
|
||||
|
||||
public static void sendBungeeMessage(String playerName, String message) {
|
||||
@ -538,6 +548,10 @@ public class ChestShop extends JavaPlugin {
|
||||
sendBungeeMessage(playerName, "MessageRaw", ComponentSerializer.toString(message));
|
||||
}
|
||||
|
||||
public static void sendBungeeMessage(String playerName, Component message) {
|
||||
sendBungeeMessage(playerName, "MessageRaw", GsonComponentSerializer.gson().serialize(message));
|
||||
}
|
||||
|
||||
private static void sendBungeeMessage(String playerName, String channel, String message) {
|
||||
if (Properties.BUNGEECORD_MESSAGES && !Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
@ -2,11 +2,13 @@ package com.Acrobot.ChestShop.Configuration;
|
||||
|
||||
import com.Acrobot.Breeze.Configuration.Configuration;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import de.themoep.minedown.MineDown;
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import de.themoep.utils.lang.bukkit.BukkitLanguageConfig;
|
||||
import de.themoep.utils.lang.bukkit.LanguageManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
@ -154,22 +156,27 @@ public class Messages {
|
||||
}
|
||||
|
||||
public void sendWithPrefix(CommandSender sender, Map<String, String> replacementMap, String... replacements) {
|
||||
sender.spigot().sendMessage(getComponents(sender, true, replacementMap, replacements));
|
||||
ChestShop.getAudiences().sender(sender).sendMessage(getComponent(sender, true, replacementMap, replacements));
|
||||
}
|
||||
|
||||
public void sendWithPrefix(CommandSender sender, Map<String, String> replacements) {
|
||||
sender.spigot().sendMessage(getComponents(sender, true, replacements));
|
||||
ChestShop.getAudiences().sender(sender).sendMessage(getComponent(sender, true, replacements));
|
||||
}
|
||||
|
||||
public void sendWithPrefix(CommandSender sender, String... replacements) {
|
||||
sender.spigot().sendMessage(getComponents(sender, true, Collections.emptyMap(), replacements));
|
||||
ChestShop.getAudiences().sender(sender).sendMessage(getComponent(sender, true, Collections.emptyMap(), replacements));
|
||||
}
|
||||
|
||||
public void send(CommandSender sender, String... replacements) {
|
||||
sender.spigot().sendMessage(getComponents(sender, false, Collections.emptyMap(), replacements));
|
||||
ChestShop.getAudiences().sender(sender).sendMessage(getComponent(sender, false, Collections.emptyMap(), replacements));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BaseComponent[] getComponents(CommandSender sender, boolean prefixSuffix, Map<String, String> replacementMap, String... replacements) {
|
||||
return BungeeComponentSerializer.get().serialize(getComponent(sender, prefixSuffix, replacementMap, replacements));
|
||||
}
|
||||
|
||||
public Component getComponent(CommandSender sender, boolean prefixSuffix, Map<String, String> replacementMap, String... replacements) {
|
||||
MineDown mineDown = new MineDown("%prefix" + getLang(sender));
|
||||
mineDown.placeholderSuffix("");
|
||||
mineDown.replace("prefix", prefixSuffix ? prefix.getLang(sender) : "");
|
||||
@ -183,7 +190,7 @@ public class Messages {
|
||||
}
|
||||
|
||||
public String getTextWithPrefix(CommandSender sender, Map<String, String> replacementMap, String... replacements) {
|
||||
return TextComponent.toLegacyText(getComponents(sender, true, replacementMap, replacements));
|
||||
return LegacyComponentSerializer.legacySection().serialize(getComponent(sender, true, replacementMap, replacements));
|
||||
}
|
||||
|
||||
public String getTextWithPrefix(CommandSender sender, String... replacements) {
|
||||
|
Loading…
Reference in New Issue
Block a user