mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Finish up core and bukkit json
This commit is contained in:
parent
11af906c79
commit
74a5c48214
@ -685,18 +685,6 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
|||||||
Bukkit.getScheduler().cancelTasks(this);
|
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() {
|
@Override public void shutdown() {
|
||||||
this.getServer().getPluginManager().disablePlugin(this);
|
this.getServer().getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,14 @@ import com.plotsquared.bukkit.player.BukkitPlayer;
|
|||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.bukkit.util.UpdateUtility;
|
import com.plotsquared.bukkit.util.UpdateUtility;
|
||||||
import com.plotsquared.core.PlotSquared;
|
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.Settings;
|
||||||
|
import com.plotsquared.core.configuration.caption.Caption;
|
||||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||||
import com.plotsquared.core.database.DBFunc;
|
import com.plotsquared.core.database.DBFunc;
|
||||||
import com.plotsquared.core.listener.PlayerBlockEventType;
|
import com.plotsquared.core.listener.PlayerBlockEventType;
|
||||||
import com.plotsquared.core.listener.PlotListener;
|
import com.plotsquared.core.listener.PlotListener;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.permissions.Permission;
|
||||||
import com.plotsquared.core.player.MetaDataAccess;
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
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.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -707,17 +708,16 @@ import java.util.regex.Pattern;
|
|||||||
this.eventDispatcher.doJoinTask(pp);
|
this.eventDispatcher.doJoinTask(pp);
|
||||||
}, TaskTime.seconds(1L));
|
}, TaskTime.seconds(1L));
|
||||||
|
|
||||||
if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.toString())
|
if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.toString()) && Settings.Enabled_Components.UPDATE_NOTIFICATIONS
|
||||||
&& Settings.Enabled_Components.UPDATE_NOTIFICATIONS
|
&& PremiumVerification.isPremium() && UpdateUtility.hasUpdate) {
|
||||||
&& PremiumVerification.isPremium()
|
Caption boundary = TranslatableCaption.of("update.update_boundary");
|
||||||
&& UpdateUtility.hasUpdate) {
|
|
||||||
Caption upperBoundary = TranslatableCaption.of("update.update_boundary");
|
|
||||||
Caption updateNotification = TranslatableCaption.of("update.update_notification");
|
Caption updateNotification = TranslatableCaption.of("update.update_notification");
|
||||||
Template internalVersion = Template.of("p2version", String.valueOf(UpdateUtility.internalVersion.versionString()));
|
Template internalVersion = Template.of("p2version", String.valueOf(UpdateUtility.internalVersion.versionString()));
|
||||||
Template spigotVersion = Template.of("spigotversion", UpdateUtility.spigotVersion);
|
Template spigotVersion = Template.of("spigotversion", UpdateUtility.spigotVersion);
|
||||||
Template downloadUrl = Template.of("downloadurl", "https://www.spigotmc.org/resources/77506/updates");
|
Template downloadUrl = Template.of("downloadurl", "https://www.spigotmc.org/resources/77506/updates");
|
||||||
Caption lowerBoundary = TranslatableCaption.of("update.update_boundary");
|
pp.sendMessage(boundary);
|
||||||
pp.sendMessage(upperBoundary, updateNotification, internalVersion, spigotVersion, downloadUrl, lowerBoundary);
|
pp.sendMessage(updateNotification, internalVersion, spigotVersion, downloadUrl);
|
||||||
|
pp.sendMessage(boundary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1024,40 +1024,48 @@ import java.util.regex.Pattern;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
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();
|
Set<Player> recipients = event.getRecipients();
|
||||||
recipients.clear();
|
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()) {
|
for (final PlotPlayer<?> pp : PlotSquared.platform().getPlayerManager().getPlayers()) {
|
||||||
if (pp.getAttribute("chatspy")) {
|
if (pp.getAttribute("chatspy")) {
|
||||||
spies.add(((BukkitPlayer) pp).player);
|
spies.add(pp);
|
||||||
} else {
|
} else {
|
||||||
Plot current = pp.getCurrentPlot();
|
Plot current = pp.getCurrentPlot();
|
||||||
if (current != null && current.getBasePlot(false).equals(plot)) {
|
if (current != null && current.getBasePlot(false).equals(plot)) {
|
||||||
recipients.add(((BukkitPlayer) pp).player);
|
plotRecipients.add(pp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String partial = ChatColor.translateAlternateColorCodes('&',
|
String message = event.getMessage();
|
||||||
format.replace("%plot_id%", id.getX() + ";" + id.getY()).replace("%sender%", sender));
|
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")) {
|
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 (PlotPlayer<?> receiver : plotRecipients) {
|
||||||
for (Player receiver : recipients) {
|
receiver.sendMessage(msg, msgTemplate, plotTemplate, senderTemplate);
|
||||||
receiver.sendMessage(full);
|
|
||||||
}
|
}
|
||||||
if (!spies.isEmpty()) {
|
if (!spies.isEmpty()) {
|
||||||
Caption spymsg = TranslatableCaption.of("chat.plot_chat_spy_format");
|
Caption spymsg = TranslatableCaption.of("chat.plot_chat_spy_format");
|
||||||
Template plotidTemplate = Template.of("plot_id", id.getX() + ";" + id.getY());
|
Template plotidTemplate = Template.of("plot_id", id.getX() + ";" + id.getY());
|
||||||
Template spysenderTemplate = Template.of("sender", sender);
|
Template spysenderTemplate = Template.of("sender", sender);
|
||||||
Template spymessageTemplate = Template.of("msg", message);
|
Template spymessageTemplate = Template.of("msg", TextComponent.builder(message).build());
|
||||||
for (Player player : spies) {
|
for (PlotPlayer<?> player : spies) {
|
||||||
plotPlayer.sendMessage(spymsg, plotidTemplate, spysenderTemplate, spymessageTemplate);
|
player.sendMessage(spymsg, plotidTemplate, spysenderTemplate, spymessageTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Re-implement
|
// TODO: Re-implement
|
||||||
|
@ -35,6 +35,7 @@ import com.sk89q.jnbt.Tag;
|
|||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.world.item.ItemType;
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Container;
|
import org.bukkit.block.Container;
|
||||||
@ -161,9 +162,7 @@ public class StateWrapper {
|
|||||||
.replace("\"underlined\":true,", "&n").replace("\"italic\":true,", "&o")
|
.replace("\"underlined\":true,", "&n").replace("\"italic\":true,", "&o")
|
||||||
.replace("[{\"text\":\"", "&0").replace("{\"text\":\"", "&0").replace("\"},", "")
|
.replace("[{\"text\":\"", "&0").replace("{\"text\":\"", "&0").replace("\"},", "")
|
||||||
.replace("\"}]", "").replace("\"}", "");
|
.replace("\"}]", "").replace("\"}", "");
|
||||||
for (Entry<String, String> entry : Captions.replacements.entrySet()) {
|
str = ChatColor.translateAlternateColorCodes('&', str);
|
||||||
str = str.replace(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,13 +60,6 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public interface PlotPlatform<P> extends LocaleHolder {
|
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.
|
* Gets the directory which contains PlotSquared files. The directory may not exist.
|
||||||
*
|
*
|
||||||
|
@ -217,7 +217,7 @@ public final class FlagCommand extends Command {
|
|||||||
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
||||||
new HelpMenu(player).setCategory(CommandCategory.SETTINGS)
|
new HelpMenu(player).setCategory(CommandCategory.SETTINGS)
|
||||||
.setCommands(this.getCommands()).generateMaxPages()
|
.setCommands(this.getCommands()).generateMaxPages()
|
||||||
.generatePage(0, getParent().toString()).render();
|
.generatePage(0, getParent().toString(), player).render();
|
||||||
return CompletableFuture.completedFuture(true);
|
return CompletableFuture.completedFuture(true);
|
||||||
}
|
}
|
||||||
return super.execute(player, args, confirm, whenDone);
|
return super.execute(player, args, confirm, whenDone);
|
||||||
|
@ -120,7 +120,8 @@ public class Help extends Command {
|
|||||||
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.asComponent())));
|
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.asComponent())));
|
||||||
return true;
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public class HelpMenu {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HelpMenu generatePage(int currentPage, String label) {
|
public HelpMenu generatePage(int currentPage, String label, PlotPlayer<?> audience) {
|
||||||
if (currentPage > this.maxPage) {
|
if (currentPage > this.maxPage) {
|
||||||
currentPage = this.maxPage;
|
currentPage = this.maxPage;
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ public class HelpMenu {
|
|||||||
this.page = new HelpPage(this.commandCategory, currentPage, this.maxPage);
|
this.page = new HelpPage(this.commandCategory, currentPage, this.maxPage);
|
||||||
int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), this.commands.size());
|
int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), this.commands.size());
|
||||||
for (int i = currentPage * PER_PAGE; i < max; i++) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -27,19 +27,24 @@ package com.plotsquared.core.util.helpmenu;
|
|||||||
|
|
||||||
import com.plotsquared.core.command.Argument;
|
import com.plotsquared.core.command.Argument;
|
||||||
import com.plotsquared.core.command.Command;
|
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 com.plotsquared.core.util.StringMan;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
|
||||||
public class HelpObject {
|
public class HelpObject {
|
||||||
|
|
||||||
|
static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
|
||||||
|
|
||||||
private final String _rendered;
|
private final String _rendered;
|
||||||
|
|
||||||
public HelpObject(final Command command, final String label) {
|
public HelpObject(final Command command, final String label, final PlotPlayer<?> audience) {
|
||||||
_rendered = StringMan.replaceAll(Captions.HELP_ITEM.getTranslated(), "%usage%",
|
_rendered = MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("help.help_item").getComponent(audience),
|
||||||
command.getUsage().replaceAll("\\{label\\}", label), "[%alias%]",
|
Template.of("usage", command.getUsage().replaceAll("\\{label\\}", label)),
|
||||||
!command.getAliases().isEmpty() ?
|
Template.of("alias", command.getAliases().isEmpty() ? StringMan.join(command.getAliases(), "|") : ""),
|
||||||
"(" + StringMan.join(command.getAliases(), "|") + ")" :
|
Template.of("desc", command.getDescription()), Template.of("arguments", buildArgumentList(command.getRequiredArguments())),
|
||||||
"", "%desc%", command.getDescription(), "%arguments%",
|
Template.of("label", label)));
|
||||||
buildArgumentList(command.getRequiredArguments()), "{label}", label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override public String toString() {
|
||||||
|
Loading…
Reference in New Issue
Block a user