Finish up core and bukkit json

This commit is contained in:
dordsor21 2020-08-08 12:16:48 +01:00
parent 11af906c79
commit 74a5c48214
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
8 changed files with 53 additions and 59 deletions

View File

@ -685,18 +685,6 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
Bukkit.getScheduler().cancelTasks(this);
}
@Override public void log(@Nonnull String message) {
try {
message = Captions.color(message);
if (!Settings.Chat.CONSOLE_COLOR) {
message = ChatColor.stripColor(message);
}
this.getServer().getConsoleSender().sendMessage(message);
} catch (final Throwable ignored) {
System.out.println(ConsoleColors.fromString(message));
}
}
@Override public void shutdown() {
this.getServer().getPluginManager().disablePlugin(this);
}

View File

@ -32,14 +32,14 @@ import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.UpdateUtility;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.listener.PlayerBlockEventType;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.MetaDataAccess;
import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.player.PlotPlayer;
@ -118,6 +118,7 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType;
import io.papermc.lib.PaperLib;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.Template;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -707,17 +708,16 @@ import java.util.regex.Pattern;
this.eventDispatcher.doJoinTask(pp);
}, TaskTime.seconds(1L));
if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.toString())
&& Settings.Enabled_Components.UPDATE_NOTIFICATIONS
&& PremiumVerification.isPremium()
&& UpdateUtility.hasUpdate) {
Caption upperBoundary = TranslatableCaption.of("update.update_boundary");
if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.toString()) && Settings.Enabled_Components.UPDATE_NOTIFICATIONS
&& PremiumVerification.isPremium() && UpdateUtility.hasUpdate) {
Caption boundary = TranslatableCaption.of("update.update_boundary");
Caption updateNotification = TranslatableCaption.of("update.update_notification");
Template internalVersion = Template.of("p2version", String.valueOf(UpdateUtility.internalVersion.versionString()));
Template spigotVersion = Template.of("spigotversion", UpdateUtility.spigotVersion);
Template downloadUrl = Template.of("downloadurl", "https://www.spigotmc.org/resources/77506/updates");
Caption lowerBoundary = TranslatableCaption.of("update.update_boundary");
pp.sendMessage(upperBoundary, updateNotification, internalVersion, spigotVersion, downloadUrl, lowerBoundary);
pp.sendMessage(boundary);
pp.sendMessage(updateNotification, internalVersion, spigotVersion, downloadUrl);
pp.sendMessage(boundary);
}
}
@ -1024,40 +1024,48 @@ import java.util.regex.Pattern;
return;
}
event.setCancelled(true);
Caption msg = TranslatableCaption.of("chat.plot_chat_format");
Template msgTemplate = Template.of("msg", event.getMessage());
Template plotTemplate = Template.of("plot_id", String.valueOf(plot.getId()));
Template senderTemplate = Template.of("sender", event.getPlayer().getDisplayName());
plotPlayer.sendMessage(msg, msgTemplate, plotTemplate, senderTemplate);
Set<Player> recipients = event.getRecipients();
recipients.clear();
Set<Player> spies = new HashSet<>();
Set<PlotPlayer<?>> spies = new HashSet<>();
Set<PlotPlayer<?>> plotRecipients = new HashSet<>();
for (final PlotPlayer<?> pp : PlotSquared.platform().getPlayerManager().getPlayers()) {
if (pp.getAttribute("chatspy")) {
spies.add(((BukkitPlayer) pp).player);
spies.add(pp);
} else {
Plot current = pp.getCurrentPlot();
if (current != null && current.getBasePlot(false).equals(plot)) {
recipients.add(((BukkitPlayer) pp).player);
plotRecipients.add(pp);
}
}
}
String partial = ChatColor.translateAlternateColorCodes('&',
format.replace("%plot_id%", id.getX() + ";" + id.getY()).replace("%sender%", sender));
String message = event.getMessage();
String sender = event.getPlayer().getDisplayName();
PlotId id = plot.getId();
Caption msg = TranslatableCaption.of("chat.plot_chat_format");
Template msgTemplate;
Template plotTemplate = Template.of("plot_id", id.toString());
Template senderTemplate = Template.of("sender", sender);
// If we do/don't want colour, we need to be careful about how to go about it, as players could attempt either <gold></gold> or &6 etc.
// In both cases, we want to use a Component Template to ensure that the player cannot use any placeholders in their message on purpose
// or accidentally, as component templates are done at the end. We also need to deserialize from legacy color codes to a Component if
// allowing colour.
if (plotPlayer.hasPermission("plots.chat.color")) {
message = Captions.color(message);
msgTemplate = Template
.of("msg", BukkitUtil.LEGACY_COMPONENT_SERIALIZER.deserialize(ChatColor.translateAlternateColorCodes('&', message)));
} else {
msgTemplate = Template.of("msg", BukkitUtil.MINI_MESSAGE.deserialize(
ChatColor.stripColor(BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(TextComponent.builder(message).build()))));
}
String full = partial.replace("%msg%", message);
for (Player receiver : recipients) {
receiver.sendMessage(full);
for (PlotPlayer<?> receiver : plotRecipients) {
receiver.sendMessage(msg, msgTemplate, plotTemplate, senderTemplate);
}
if (!spies.isEmpty()) {
Caption spymsg = TranslatableCaption.of("chat.plot_chat_spy_format");
Template plotidTemplate = Template.of("plot_id", id.getX() + ";" + id.getY());
Template spysenderTemplate = Template.of("sender", sender);
Template spymessageTemplate = Template.of("msg", message);
for (Player player : spies) {
plotPlayer.sendMessage(spymsg, plotidTemplate, spysenderTemplate, spymessageTemplate);
Template spymessageTemplate = Template.of("msg", TextComponent.builder(message).build());
for (PlotPlayer<?> player : spies) {
player.sendMessage(spymsg, plotidTemplate, spysenderTemplate, spymessageTemplate);
}
}
// TODO: Re-implement

View File

@ -35,6 +35,7 @@ import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.item.ItemType;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Container;
@ -161,9 +162,7 @@ public class StateWrapper {
.replace("\"underlined\":true,", "&n").replace("\"italic\":true,", "&o")
.replace("[{\"text\":\"", "&0").replace("{\"text\":\"", "&0").replace("\"},", "")
.replace("\"}]", "").replace("\"}", "");
for (Entry<String, String> entry : Captions.replacements.entrySet()) {
str = str.replace(entry.getKey(), entry.getValue());
}
str = ChatColor.translateAlternateColorCodes('&', str);
return str;
}

View File

@ -60,13 +60,6 @@ import java.util.Map;
*/
public interface PlotPlatform<P> extends LocaleHolder {
/**
* Logs a message to console.
*
* @param message the message to log
*/
void log(String message);
/**
* Gets the directory which contains PlotSquared files. The directory may not exist.
*

View File

@ -217,7 +217,7 @@ public final class FlagCommand extends Command {
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
new HelpMenu(player).setCategory(CommandCategory.SETTINGS)
.setCommands(this.getCommands()).generateMaxPages()
.generatePage(0, getParent().toString()).render();
.generatePage(0, getParent().toString(), player).render();
return CompletableFuture.completedFuture(true);
}
return super.execute(player, args, confirm, whenDone);

View File

@ -120,7 +120,8 @@ public class Help extends Command {
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.asComponent())));
return true;
}
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(page - 1, getParent().toString()).render();
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(page - 1, getParent().toString(), player)
.render();
return true;
});
}

View File

@ -67,7 +67,7 @@ public class HelpMenu {
return this;
}
public HelpMenu generatePage(int currentPage, String label) {
public HelpMenu generatePage(int currentPage, String label, PlotPlayer<?> audience) {
if (currentPage > this.maxPage) {
currentPage = this.maxPage;
}
@ -77,7 +77,7 @@ public class HelpMenu {
this.page = new HelpPage(this.commandCategory, currentPage, this.maxPage);
int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), this.commands.size());
for (int i = currentPage * PER_PAGE; i < max; i++) {
this.page.addHelpItem(new HelpObject(this.commands.get(i), label));
this.page.addHelpItem(new HelpObject(this.commands.get(i), label, audience));
}
return this;
}

View File

@ -27,19 +27,24 @@ package com.plotsquared.core.util.helpmenu;
import com.plotsquared.core.command.Argument;
import com.plotsquared.core.command.Command;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.StringMan;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
public class HelpObject {
static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
private final String _rendered;
public HelpObject(final Command command, final String label) {
_rendered = StringMan.replaceAll(Captions.HELP_ITEM.getTranslated(), "%usage%",
command.getUsage().replaceAll("\\{label\\}", label), "[%alias%]",
!command.getAliases().isEmpty() ?
"(" + StringMan.join(command.getAliases(), "|") + ")" :
"", "%desc%", command.getDescription(), "%arguments%",
buildArgumentList(command.getRequiredArguments()), "{label}", label);
public HelpObject(final Command command, final String label, final PlotPlayer<?> audience) {
_rendered = MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("help.help_item").getComponent(audience),
Template.of("usage", command.getUsage().replaceAll("\\{label\\}", label)),
Template.of("alias", command.getAliases().isEmpty() ? StringMan.join(command.getAliases(), "|") : ""),
Template.of("desc", command.getDescription()), Template.of("arguments", buildArgumentList(command.getRequiredArguments())),
Template.of("label", label)));
}
@Override public String toString() {