Update adventure for 1.19
This commit is contained in:
@@ -56,9 +56,11 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -70,6 +72,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlayerVaults extends JavaPlugin {
|
||||
public static boolean DEBUG;
|
||||
@@ -358,6 +361,11 @@ public class PlayerVaults extends JavaPlugin {
|
||||
}
|
||||
|
||||
try {
|
||||
Path langPath = this.getDataFolder().toPath().resolve("lang.conf");
|
||||
List<String> lines = Files.readAllLines(langPath);
|
||||
List<String> updatedLines = new ArrayList<>();
|
||||
lines.forEach(line -> updatedLines.add(line.replaceAll("\\{(vault|player|price|count|item)}", "<$1>")));
|
||||
Files.write(langPath, updatedLines.stream().collect(Collectors.joining("\n")).getBytes());
|
||||
Loader.loadAndSave("lang", this.translation);
|
||||
} catch (IOException | IllegalAccessException e) {
|
||||
this.getLogger().log(Level.SEVERE, "Could not load lang.", e);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class HelpMeCommand implements CommandExecutor {
|
||||
if (args.length >= 1 && args[0].equalsIgnoreCase("mini")) {
|
||||
Audience audience = PlayerVaults.getInstance().getPlatform().sender(sender);
|
||||
for (String string : mainInfo.toString().split("\n")) {
|
||||
audience.sendMessage(MiniMessage.miniMessage().parse((sender instanceof Player ? "<rainbow>" : "<green>") + string));
|
||||
audience.sendMessage(MiniMessage.miniMessage().deserialize((sender instanceof Player ? "<rainbow>" : "<green>") + string));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -115,9 +115,9 @@ public class HelpMeCommand implements CommandExecutor {
|
||||
String delKey = result.getPaste().get().getDeletionKey().orElse("No deletion key");
|
||||
String url = "https://paste.gg/anonymous/" + result.getPaste().get().getId();
|
||||
audience.sendMessage(Component.text("URL generated: ").append(Component.text().clickEvent(ClickEvent.openUrl(url)).content(url)));
|
||||
audience.sendMessage(MiniMessage.miniMessage().parse((sender instanceof Player ? "<rainbow>" : "<green>") + "Deletion key:</rainbow> " + delKey));
|
||||
audience.sendMessage(MiniMessage.miniMessage().deserialize((sender instanceof Player ? "<rainbow>" : "<green>") + "Deletion key:</rainbow> " + delKey));
|
||||
} else {
|
||||
audience.sendMessage(MiniMessage.miniMessage().parse("<red>Failed to generate output. See console for details."));
|
||||
audience.sendMessage(MiniMessage.miniMessage().deserialize("<red>Failed to generate output. See console for details."));
|
||||
PlayerVaults.getInstance().getLogger().warning("Received: " + result.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class HelpMeCommand implements CommandExecutor {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerVaults.getInstance().getPlatform().sender(sender).sendMessage(MiniMessage.miniMessage().parse("<red>Failed to generate output. See console for details."));
|
||||
PlayerVaults.getInstance().getPlatform().sender(sender).sendMessage(MiniMessage.miniMessage().deserialize("<red>Failed to generate output. See console for details."));
|
||||
}
|
||||
}.runTask(PlayerVaults.getInstance());
|
||||
}
|
||||
|
||||
@@ -6,7 +6,12 @@ import com.google.common.collect.ImmutableMap;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -17,19 +22,12 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class Translation {
|
||||
public static class TL extends ArrayList<String> {
|
||||
private static transient PlayerVaults plugin;
|
||||
private static transient final Pattern REPLACEMENT_PATTERN = Pattern.compile("(?:\\{([a-zA-Z0-9\\-_]+)(?:(?::)([a-zA-Z0-9_\\-|]+))?})");
|
||||
private static transient final Pattern TAG_PATTERN = Pattern.compile("(?:<(/?)([a-zA-Z\\-_]+)>)");
|
||||
private static transient final String SKIP_LINE_IF_MISSING = "s";
|
||||
private static transient final String BLANK_IF_MISSING = "b";
|
||||
private static transient final String PRE_FORMATTED = "p";
|
||||
|
||||
private static @NonNull TL of(@NonNull String... strings) {
|
||||
TL list = new TL();
|
||||
@@ -44,6 +42,7 @@ public class Translation {
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
private transient String randomNum = "475087174643246031314442067831418947468567422217%%__USER__%%0876702565715325383665";
|
||||
private transient ImmutableMap.Builder<String, String> map;
|
||||
private transient TL title;
|
||||
|
||||
@@ -94,67 +93,24 @@ public class Translation {
|
||||
|
||||
private void send(@NonNull Audience audience, @NonNull Map<String, String> map, @Nullable TL title) {
|
||||
this.forEach(line -> {
|
||||
Component component = this.getComponent(line, map, title);
|
||||
if (component != null) {
|
||||
audience.sendMessage(component);
|
||||
if (line == null || line.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
audience.sendMessage(this.getComponent(line, map, title));
|
||||
});
|
||||
}
|
||||
|
||||
private @Nullable Component getComponent(@NonNull String line, @NonNull Map<String, String> map, @Nullable TL title) {
|
||||
private @NonNull Component getComponent(@NonNull String line, @NonNull Map<String, String> map, @Nullable TL title) {
|
||||
if (title != null && !title.isEmpty()) {
|
||||
line = title.get(0) + line;
|
||||
}
|
||||
StringBuffer builder = null;
|
||||
String found;
|
||||
String foundDetails;
|
||||
String repl;
|
||||
String[] features;
|
||||
Matcher replMatcher = TL.REPLACEMENT_PATTERN.matcher(line);
|
||||
while (replMatcher.find()) {
|
||||
if (builder == null) {
|
||||
builder = new StringBuffer();
|
||||
}
|
||||
found = replMatcher.group(1);
|
||||
foundDetails = replMatcher.group(2);
|
||||
features = foundDetails == null ? null : foundDetails.split("\\|");
|
||||
repl = map.get(found);
|
||||
if (repl == null) {
|
||||
if (this.arrContains(features, TL.SKIP_LINE_IF_MISSING)) {
|
||||
return null;
|
||||
}
|
||||
if (this.arrContains(features, TL.BLANK_IF_MISSING)) {
|
||||
replMatcher.appendReplacement(builder, "");
|
||||
}
|
||||
} else {
|
||||
if (this.arrContains(features, TL.PRE_FORMATTED)) {
|
||||
repl = MiniMessage.miniMessage().escapeTokens(repl).replace("\\", "\\\\");
|
||||
}
|
||||
replMatcher.appendReplacement(builder, repl);
|
||||
}
|
||||
}
|
||||
if (builder != null) {
|
||||
replMatcher.appendTail(builder);
|
||||
line = builder.toString();
|
||||
builder = null;
|
||||
}
|
||||
|
||||
Matcher tagMatcher = TL.TAG_PATTERN.matcher(line);
|
||||
while (tagMatcher.find()) {
|
||||
if (builder == null) {
|
||||
builder = new StringBuffer();
|
||||
}
|
||||
found = tagMatcher.group(2);
|
||||
repl = TL.plugin.getTL().colorMappings().get(found);
|
||||
if (repl != null) {
|
||||
tagMatcher.appendReplacement(builder, '<' + tagMatcher.group(1) + repl + '>');
|
||||
}
|
||||
}
|
||||
if (builder != null) {
|
||||
tagMatcher.appendTail(builder);
|
||||
line = builder.toString();
|
||||
}
|
||||
return MiniMessage.miniMessage().parse(line);
|
||||
TagResolver.Builder tagResolverBuilder = TagResolver.builder();
|
||||
TL.plugin.getTL().colorMappings().forEach((k, v) -> {
|
||||
TextColor color = v.startsWith("#") ? TextColor.fromHexString(v) : NamedTextColor.NAMES.value(v);
|
||||
tagResolverBuilder.tag(k, Tag.styling(color == null ? NamedTextColor.WHITE : color));
|
||||
});
|
||||
map.forEach((k, v) -> tagResolverBuilder.resolver(Placeholder.unparsed(k, v)));
|
||||
return MiniMessage.miniMessage().deserialize(line, tagResolverBuilder.build());
|
||||
}
|
||||
|
||||
public @NonNull String getLegacy() {
|
||||
@@ -191,33 +147,33 @@ public class Translation {
|
||||
}
|
||||
|
||||
private static class Translations {
|
||||
private TL openVault = TL.of("<normal>Opening vault <info>{vault}</info>");
|
||||
private TL openOtherVault = TL.of("<normal>Opening vault <info>{vault}</info> of <info>{player}</info>");
|
||||
private TL openVault = TL.of("<normal>Opening vault <info><vault></info>");
|
||||
private TL openOtherVault = TL.of("<normal>Opening vault <info><vault></info> of <info><player></info>");
|
||||
private TL invalidArgs = TL.of("<error>Invalid args!");
|
||||
private TL deleteVault = TL.of("<normal>Deleted vault <info>{vault}</info>");
|
||||
private TL deleteOtherVault = TL.of("<normal>Deleted vault <info>{vault}</info> <normal>of <info>{player}</info>");
|
||||
private TL deleteOtherVaultAll = TL.of("<dark_red>Deleted all vaults belonging to <info>{player}</info>");
|
||||
private TL deleteVault = TL.of("<normal>Deleted vault <info><vault></info>");
|
||||
private TL deleteOtherVault = TL.of("<normal>Deleted vault <info><vault></info> <normal>of <info><player></info>");
|
||||
private TL deleteOtherVaultAll = TL.of("<dark_red>Deleted all vaults belonging to <info><player></info>");
|
||||
private TL playerOnly = TL.of("<error>Sorry but that can only be run by a player!");
|
||||
private TL mustBeNumber = TL.of("<error>You need to specify a valid number.");
|
||||
private TL noPerms = TL.of("<error>You don't have permission for that!");
|
||||
private TL insufficientFunds = TL.of("<error>You don't have enough money for that!");
|
||||
private TL refundAmount = TL.of("<normal>You were refunded <info>{price}</info> for deleting that vault.");
|
||||
private TL costToCreate = TL.of("<normal>You were charged <info>{price}</info> for creating a vault.");
|
||||
private TL costToOpen = TL.of("<normal>You were charged <info>{price}</info> for opening that vault.");
|
||||
private TL refundAmount = TL.of("<normal>You were refunded <info><price></info> for deleting that vault.");
|
||||
private TL costToCreate = TL.of("<normal>You were charged <info><price></info> for creating a vault.");
|
||||
private TL costToOpen = TL.of("<normal>You were charged <info><price></info> for opening that vault.");
|
||||
private TL vaultDoesNotExist = TL.of("<error>That vault does not exist!");
|
||||
private TL clickASign = TL.of("<normal>Now click a sign!");
|
||||
private TL notASign = TL.of("<error>You must click a sign!");
|
||||
private TL setSign = TL.of("<normal>You have successfully set a PlayerVault access sign!");
|
||||
private TL existingVaults = TL.of("<normal>{player} has vaults: <info>{vault}</info>");
|
||||
private TL vaultTitle = TL.of("<dark_red>Vault #{vault}");
|
||||
private TL openWithSign = TL.of("<normal>Opening vault <info>{vault}</info> of <info>{player}</info>");
|
||||
private TL noOwnerFound = TL.of("<error>Cannot find vault owner: <info>{player}</info>");
|
||||
private TL existingVaults = TL.of("<normal><player> has vaults: <info><vault></info>");
|
||||
private TL vaultTitle = TL.of("<dark_red>Vault #<vault>");
|
||||
private TL openWithSign = TL.of("<normal>Opening vault <info><vault></info> of <info><player></info>");
|
||||
private TL noOwnerFound = TL.of("<error>Cannot find vault owner: <info><player></info>");
|
||||
private TL convertPluginNotFound = TL.of("<error>No converter found for that plugin.");
|
||||
private TL convertComplete = TL.of("<normal>Converted <info>{count}</info> players to PlayerVaults.");
|
||||
private TL convertComplete = TL.of("<normal>Converted <info><count></info> players to PlayerVaults.");
|
||||
private TL convertBackground = TL.of("<normal>Conversion has been forked to the background. See console for updates.");
|
||||
private TL locked = TL.of("<error>Vaults are currently locked while conversion occurs. Please try again in a moment!");
|
||||
private TL help = TL.of("/pv <number>");
|
||||
private TL blockedItem = TL.of("<gold>{item}</gold> <error>is blocked from vaults.");
|
||||
private TL blockedItem = TL.of("<gold><item></gold> <error>is blocked from vaults.");
|
||||
private TL signsDisabled = TL.of("<error>Vault signs are currently disabled.");
|
||||
private TL blockedBadItem = TL.of("<error>This item is not allowed in a vault.");
|
||||
}
|
||||
|
||||
@@ -127,6 +127,9 @@ public class Listeners implements Listener {
|
||||
if (event.getHotbarButton() > -1 && event.getWhoClicked().getInventory().getItem(event.getHotbarButton()) != null) {
|
||||
items[1] = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
|
||||
}
|
||||
if (event.getClick().name().equals("SWAP_OFFHAND")) {
|
||||
items[1] = event.getWhoClicked().getInventory().getItemInOffHand();
|
||||
}
|
||||
|
||||
for (ItemStack item : items) {
|
||||
if (item == null) {
|
||||
|
||||
Reference in New Issue
Block a user