diff --git a/.gitignore b/.gitignore index 2f98ae1..3fee597 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ /.idea/codeStyles/codeStyleConfig.xml *.iml /target/ -/src/main/resources/build.properties +src/main/resources/build.properties # OS .DS_Store @@ -14,4 +14,4 @@ Thumbs.db # Gradle /build/ -/.gradle/ +/.gradle/ \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 86bb373..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 2661a6f..f5a22f5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# Plex +# Plex [![Build Status](https://ci.plex.us.org/job/Plex/job/master/badge/icon)](https://ci.plex.us.org/job/Plex/job/master/) -A new freedom plugin. +Plex is a new freedom plugin. It is an alternative to TotalFreedomMod. It has many of the features that make a freedom server unique, but also many features that TotalFreedomMod doesn’t have. For example, there is full support for using a permissions plugin instead of ranks. It is also much more performance oriented. You can use Redis to store indefinite bans and store player data in MongoDB, MariaDB, or SQLite. Plex is also fully customizable as you can change almost all of the messages within the plugin. Plex also has a module system which can be used to add additional functionality. Plex is not a rewrite, "debloat", or related to TotalFreedomMod. Plex is an entirely new experience. diff --git a/build.gradle b/build.gradle index 5f45e99..e4644ed 100644 --- a/build.gradle +++ b/build.gradle @@ -38,9 +38,9 @@ dependencies { library "org.apache.maven.resolver:maven-resolver-connector-basic:1.7.3" library "org.apache.maven.resolver:maven-resolver-transport-http:1.7.3" library "org.apache.maven:maven-resolver-provider:3.8.5" - library "org.eclipse.jetty:jetty-server:11.0.8" - library "org.eclipse.jetty:jetty-servlet:11.0.8" - library "org.eclipse.jetty:jetty-proxy:11.0.8" + library "org.eclipse.jetty:jetty-server:11.0.9" + library "org.eclipse.jetty:jetty-servlet:11.0.9" + library "org.eclipse.jetty:jetty-proxy:11.0.9" library "com.google.code.gson:gson:2.9.0" compileOnly "io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT" implementation "org.bstats:bstats-base:3.0.0" @@ -48,14 +48,21 @@ dependencies { } group = "dev.plex" -version = "0.10-SNAPSHOT" +version = "1.0.1-SNAPSHOT" description = "Plex" shadowJar { archiveClassifier.set("") + archiveBaseName.set("Plex") + archiveVersion.set("") relocate "org.bstats", "dev.plex" } +tasks.jar { + archiveBaseName.set("Plex") + archiveVersion.set("") +} + bukkit { name = "Plex" version = rootProject.version diff --git a/settings.gradle b/settings.gradle index 642a692..21f255b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'Plex' \ No newline at end of file +rootProject.name = "Plex" \ No newline at end of file diff --git a/src/main/java/dev/plex/admin/AdminList.java b/src/main/java/dev/plex/admin/AdminList.java index 007d1fd..b866449 100644 --- a/src/main/java/dev/plex/admin/AdminList.java +++ b/src/main/java/dev/plex/admin/AdminList.java @@ -54,7 +54,7 @@ public class AdminList extends PlexBase } /** - * Gathers every admin's username (cached and in the database) + * Gathers every admins username (cached and in the database) * * @return An array list of the names of every admin */ diff --git a/src/main/java/dev/plex/cache/DataUtils.java b/src/main/java/dev/plex/cache/DataUtils.java index 156f291..d038660 100644 --- a/src/main/java/dev/plex/cache/DataUtils.java +++ b/src/main/java/dev/plex/cache/DataUtils.java @@ -5,7 +5,6 @@ import dev.plex.cache.player.PlayerCache; import dev.plex.player.PlexPlayer; import dev.plex.storage.StorageType; import java.util.UUID; -import org.bukkit.Bukkit; /** * Parent cache class diff --git a/src/main/java/dev/plex/cache/notes/PlayerNotes.java b/src/main/java/dev/plex/cache/notes/PlayerNotes.java index 658d455..397e8ef 100644 --- a/src/main/java/dev/plex/cache/notes/PlayerNotes.java +++ b/src/main/java/dev/plex/cache/notes/PlayerNotes.java @@ -1,15 +1,11 @@ package dev.plex.cache.notes; -import com.google.common.reflect.TypeToken; -import com.google.gson.Gson; import dev.plex.Plex; -import dev.plex.cache.player.PlayerCache; import dev.plex.player.PlexPlayer; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; import java.util.UUID; public class PlayerNotes diff --git a/src/main/java/dev/plex/command/PlexCommand.java b/src/main/java/dev/plex/command/PlexCommand.java index 0c11f5c..1a1e1a1 100644 --- a/src/main/java/dev/plex/command/PlexCommand.java +++ b/src/main/java/dev/plex/command/PlexCommand.java @@ -125,7 +125,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage()))); return true; - } else + } + else { if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive()) { @@ -133,14 +134,16 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC return true; } } - } else if (plugin.getSystem().equalsIgnoreCase("permissions")) + } + else if (plugin.getSystem().equalsIgnoreCase("permissions")) { if (!player.hasPermission(perms.permission())) { send(sender, messageComponent("noPermissionNode", perms.permission())); return true; } - } else + } + else { PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!"); send(sender, "There is a server misconfiguration. Please alert a developer or the owner"); @@ -149,14 +152,15 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC } try { - Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args); + Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args); if (component != null) { send(sender, component); } - } catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex) + } + catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex) { - send(sender, MiniMessage.miniMessage().deserialize(ex.getMessage())); + send(sender, PlexUtils.mmDeserialize(ex.getMessage())); } return true; } @@ -178,7 +182,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC return true; } } - } else if (params.aliases().split(",").length < 1) + } + else if (params.aliases().split(",").length < 1) { return getName().equalsIgnoreCase(label); } @@ -232,7 +237,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { if (!isConsole(sender)) { - return checkRank((Player) sender, rank, permission); + return checkRank((Player)sender, rank, permission); } return true; } @@ -263,7 +268,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage()))); } - } else if (plugin.getSystem().equalsIgnoreCase("permissions")) + } + else if (plugin.getSystem().equalsIgnoreCase("permissions")) { if (!player.hasPermission(permission)) { @@ -283,7 +289,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC if (plugin.getSystem().equalsIgnoreCase("ranks")) { return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank); - } else if (plugin.getSystem().equalsIgnoreCase("permissions")) + } + else if (plugin.getSystem().equalsIgnoreCase("permissions")) { return player.hasPermission(permission); } @@ -303,7 +310,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { if (!isConsole(sender)) { - return checkTab((Player) sender, rank, permission); + return checkTab((Player)sender, rank, permission); } return true; } @@ -323,7 +330,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC if (plugin.getSystem().equalsIgnoreCase("ranks")) { return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank); - } else if (plugin.getSystem().equalsIgnoreCase("permissions")) + } + else if (plugin.getSystem().equalsIgnoreCase("permissions")) { return player.hasPermission(permission); } @@ -536,7 +544,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC */ protected Component mmString(String s) { - return MiniMessage.miniMessage().deserialize(s); + return PlexUtils.mmDeserialize(s); } public Rank getLevel() diff --git a/src/main/java/dev/plex/command/blocker/BaseCommand.java b/src/main/java/dev/plex/command/blocker/BaseCommand.java new file mode 100644 index 0000000..ae5850c --- /dev/null +++ b/src/main/java/dev/plex/command/blocker/BaseCommand.java @@ -0,0 +1,22 @@ +package dev.plex.command.blocker; + +import dev.plex.rank.enums.Rank; +import lombok.Getter; + +@Getter +public class BaseCommand +{ + private final Rank rank; + private final String message; + + public BaseCommand(Rank r, String m) + { + rank = r; + message = m; + } + + public String toString() + { + return "BaseCommand (Rank: " + (rank == null ? "ALL" : rank.name()) + ", Message: " + message + ")"; + } +} diff --git a/src/main/java/dev/plex/command/blocker/CommandBlockerManager.java b/src/main/java/dev/plex/command/blocker/CommandBlockerManager.java new file mode 100644 index 0000000..f44feab --- /dev/null +++ b/src/main/java/dev/plex/command/blocker/CommandBlockerManager.java @@ -0,0 +1,122 @@ +package dev.plex.command.blocker; + +import dev.plex.PlexBase; +import dev.plex.rank.enums.Rank; +import dev.plex.util.PlexLog; +import dev.plex.util.PlexUtils; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.command.*; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.SimplePluginManager; + +import java.lang.reflect.Field; +import java.util.*; +import java.util.regex.Pattern; + +@Getter +public class CommandBlockerManager extends PlexBase +{ + private Set blockedCommands = new HashSet<>(); + + public boolean loadedYet; + + private static CommandMap getCommandMap() + { + return plugin.getServer().getCommandMap(); + } + + public void syncCommands() + { + loadedYet = false; + blockedCommands.clear(); + + CommandMap commandMap = getCommandMap(); + + List raw = plugin.blockedCommands.getStringList("blockedCommands"); + + for (String cmd : raw) + { + int lastDelim = cmd.lastIndexOf(':'); + + String cmdWithoutMsg = cmd.substring(0, lastDelim); + String[] rawPieces = cmdWithoutMsg.split(":", 3); + + String rawType = rawPieces[0].toLowerCase(); + String rawRank = rawPieces[1].toLowerCase(); + String regexOrMatch = rawPieces[2]; + String message = cmd.substring(lastDelim + 1); + + if (message.equals("_")) + { + message = PlexUtils.messageString("commandBlocked"); + } + + Rank rank = switch (rawRank) + { + case "e" -> null; + case "a" -> Rank.ADMIN; + case "s" -> Rank.SENIOR_ADMIN; + default -> null; + }; + + if (rawType.equals("r")) + { + blockedCommands.add(new RegexCommand(Pattern.compile(regexOrMatch, Pattern.CASE_INSENSITIVE), rank, message)); + } + else if (rawType.equals("m")) + { + int ind = regexOrMatch.indexOf(' '); + if (ind == -1 && regexOrMatch.endsWith(":")) + { + String pluginName = regexOrMatch.substring(0, regexOrMatch.length() - 1); + Plugin plugin = Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins()).filter(pl -> pl.getName().equalsIgnoreCase(pluginName)).findAny().orElse(null); + if (plugin != null) + { + List commandList = PluginCommandYamlParser.parse(plugin); + for (Command command : commandList) + { + blockedCommands.add(new MatchCommand(command.getName(), rank, message)); + blockedCommands.add(new MatchCommand(pluginName + ":" + command.getName(), rank, message)); + for (String alias : command.getAliases()) + { + blockedCommands.add(new MatchCommand(alias, rank, message)); + blockedCommands.add(new MatchCommand(pluginName + ":" + alias, rank, message)); + } + } + } + } + String blockedArgs = ind == -1 ? "" : regexOrMatch.substring(ind + 1); + if (!blockedArgs.isEmpty()) + { + blockedArgs = " " + blockedArgs; // necessary in case no args + } + String cmdForSearch = ind == -1 ? regexOrMatch : regexOrMatch.substring(0, ind); + PluginCommand pluginCommand = Bukkit.getServer().getPluginCommand(cmdForSearch); + Plugin plugin = null; + if (pluginCommand != null) plugin = pluginCommand.getPlugin(); + Command command = null; + if (commandMap != null) command = commandMap.getCommand(cmdForSearch); + if (command != null) + { + String pluginName = plugin == null ? null : plugin.getName(); + blockedCommands.add(new MatchCommand(command.getName() + blockedArgs, rank, message)); + if (pluginName != null) blockedCommands.add(new MatchCommand(pluginName + ":" + command.getName() + blockedArgs, rank, message)); + List aliases = command.getAliases(); + for (String alias : aliases) + { + blockedCommands.add(new MatchCommand(alias + blockedArgs, rank, message)); + if (pluginName != null) blockedCommands.add(new MatchCommand(pluginName + ":" + alias + blockedArgs, rank, message)); + } + } + else + { + // fallback to basic blocking + blockedCommands.add(new MatchCommand(cmdForSearch + blockedArgs, rank, message)); + } + } + } + + loadedYet = true; + } +} diff --git a/src/main/java/dev/plex/command/blocker/MatchCommand.java b/src/main/java/dev/plex/command/blocker/MatchCommand.java new file mode 100644 index 0000000..8ad36ae --- /dev/null +++ b/src/main/java/dev/plex/command/blocker/MatchCommand.java @@ -0,0 +1,21 @@ +package dev.plex.command.blocker; + +import dev.plex.rank.enums.Rank; +import lombok.Getter; + +@Getter +public class MatchCommand extends BaseCommand +{ + private final String match; + + public MatchCommand(String r1, Rank r2, String m1) + { + super(r2, m1); + match = r1; + } + + public String toString() + { + return "MatchCommand (Rank: " + (getRank() == null ? "ALL" : getRank().name()) + ", Match: " + match + ", Message: " + getMessage() + ")"; + } +} diff --git a/src/main/java/dev/plex/command/blocker/RegexCommand.java b/src/main/java/dev/plex/command/blocker/RegexCommand.java new file mode 100644 index 0000000..ea75e8b --- /dev/null +++ b/src/main/java/dev/plex/command/blocker/RegexCommand.java @@ -0,0 +1,23 @@ +package dev.plex.command.blocker; + +import dev.plex.rank.enums.Rank; +import lombok.Getter; + +import java.util.regex.Pattern; + +@Getter +public class RegexCommand extends BaseCommand +{ + private final Pattern regex; + + public RegexCommand(Pattern r1, Rank r2, String m1) + { + super(r2, m1); + regex = r1; + } + + public String toString() + { + return "RegexCommand (Rank: " + (getRank() == null ? "ALL" : getRank().name()) + ", Regex: " + regex.toString() + ", Message: " + getMessage() + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/dev/plex/command/impl/CommandSpyCMD.java b/src/main/java/dev/plex/command/impl/CommandSpyCMD.java index 652fad3..f043adf 100644 --- a/src/main/java/dev/plex/command/impl/CommandSpyCMD.java +++ b/src/main/java/dev/plex/command/impl/CommandSpyCMD.java @@ -7,9 +7,7 @@ import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import dev.plex.player.PlexPlayer; import dev.plex.rank.enums.Rank; -import dev.plex.util.PlexUtils; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/dev/plex/command/impl/DebugCMD.java b/src/main/java/dev/plex/command/impl/DebugCMD.java index b22326f..bf00bc5 100644 --- a/src/main/java/dev/plex/command/impl/DebugCMD.java +++ b/src/main/java/dev/plex/command/impl/DebugCMD.java @@ -8,12 +8,15 @@ import dev.plex.command.annotation.System; import dev.plex.rank.enums.Rank; import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; + +import java.util.Arrays; import java.util.List; import java.util.Locale; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -59,6 +62,16 @@ public class DebugCMD extends PlexCommand } return mmString("Re-applied game all the game rules!"); } + if (args[0].equalsIgnoreCase("aliases")) + { + String commandName = args[1]; + Command command = plugin.getServer().getCommandMap().getCommand(commandName); + if (command == null) + { + return mmString("That command could not be found!"); + } + return mmString("Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0]))); + } return null; } diff --git a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java index a31a625..d22179d 100644 --- a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java +++ b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java @@ -1,6 +1,5 @@ package dev.plex.command.impl; -import com.google.common.collect.ImmutableList; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; @@ -8,10 +7,8 @@ import dev.plex.command.source.RequiredCommandSource; import dev.plex.rank.enums.Rank; import dev.plex.util.PlexUtils; import java.util.ArrayList; -import java.util.Collections; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; diff --git a/src/main/java/dev/plex/command/impl/ListCMD.java b/src/main/java/dev/plex/command/impl/ListCMD.java index 0ca1355..b22eb67 100644 --- a/src/main/java/dev/plex/command/impl/ListCMD.java +++ b/src/main/java/dev/plex/command/impl/ListCMD.java @@ -37,6 +37,10 @@ public class ListCMD extends PlexCommand .append(Component.space()) .append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY)); send(sender, header); + if (players.size() == 0) + { + return null; + } for (int i = 0; i < players.size(); i++) { Player player = players.get(i); diff --git a/src/main/java/dev/plex/command/impl/MuteCMD.java b/src/main/java/dev/plex/command/impl/MuteCMD.java index e300c19..1d3640d 100644 --- a/src/main/java/dev/plex/command/impl/MuteCMD.java +++ b/src/main/java/dev/plex/command/impl/MuteCMD.java @@ -11,7 +11,6 @@ import dev.plex.rank.enums.Rank; import dev.plex.util.PlexUtils; import java.time.LocalDateTime; import java.util.List; -import java.util.UUID; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/dev/plex/command/impl/PlexCMD.java b/src/main/java/dev/plex/command/impl/PlexCMD.java index bec340b..1eef019 100644 --- a/src/main/java/dev/plex/command/impl/PlexCMD.java +++ b/src/main/java/dev/plex/command/impl/PlexCMD.java @@ -51,13 +51,16 @@ public class PlexCMD extends PlexCommand plugin.indefBans.load(false); plugin.getPunishmentManager().mergeIndefiniteBans(); send(sender, "Reloaded indefinite bans"); + plugin.blockedCommands.load(); + plugin.getCommandBlockerManager().syncCommands(); + send(sender, "Reloaded blocked commands file"); plugin.getRankManager().importDefaultRanks(); send(sender, "Imported ranks"); - send(sender, "Plex successfully reloaded."); plugin.setSystem(plugin.config.getString("system")); plugin.getServiceManager().endServices(); plugin.getServiceManager().startServices(); PlexLog.debug("Restarted services"); + send(sender, "Plex successfully reloaded."); return null; } else if (args[0].equalsIgnoreCase("redis")) diff --git a/src/main/java/dev/plex/command/impl/RawSayCMD.java b/src/main/java/dev/plex/command/impl/RawSayCMD.java index caa269b..d942fc9 100644 --- a/src/main/java/dev/plex/command/impl/RawSayCMD.java +++ b/src/main/java/dev/plex/command/impl/RawSayCMD.java @@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @CommandPermissions(level = Rank.SENIOR_ADMIN, permission = "plex.rawsay", source = RequiredCommandSource.ANY) -@CommandParameters(name = "rawsay", usage = "/ ", description = "Displays a message to everyone") +@CommandParameters(name = "rawsay", usage = "/ ", description = "Displays a raw message to everyone") public class RawSayCMD extends PlexCommand { @Override diff --git a/src/main/java/dev/plex/command/impl/SayCMD.java b/src/main/java/dev/plex/command/impl/SayCMD.java new file mode 100644 index 0000000..10c1493 --- /dev/null +++ b/src/main/java/dev/plex/command/impl/SayCMD.java @@ -0,0 +1,31 @@ +package dev.plex.command.impl; + +import dev.plex.command.PlexCommand; +import dev.plex.command.annotation.CommandParameters; +import dev.plex.command.annotation.CommandPermissions; +import dev.plex.command.source.RequiredCommandSource; +import dev.plex.rank.enums.Rank; +import dev.plex.util.PlexUtils; +import net.kyori.adventure.text.Component; +import org.apache.commons.lang.StringUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@CommandPermissions(level = Rank.ADMIN, permission = "plex.say", source = RequiredCommandSource.ANY) +@CommandParameters(name = "say", usage = "/ ", description = "Displays a message to everyone") +public class SayCMD extends PlexCommand +{ + @Override + protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) + { + if (args.length == 0) + { + return usage(); + } + + PlexUtils.broadcast(PlexUtils.messageComponent("sayCommand", sender.getName(), StringUtils.join(args, " "))); + return null; + } +} \ No newline at end of file diff --git a/src/main/java/dev/plex/command/impl/TagCMD.java b/src/main/java/dev/plex/command/impl/TagCMD.java index deff701..78110bd 100644 --- a/src/main/java/dev/plex/command/impl/TagCMD.java +++ b/src/main/java/dev/plex/command/impl/TagCMD.java @@ -7,8 +7,11 @@ import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import dev.plex.player.PlexPlayer; import dev.plex.rank.enums.Rank; +import dev.plex.util.PlexUtils; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import net.kyori.adventure.text.minimessage.tag.standard.StandardTags; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.apache.commons.lang.StringUtils; @@ -47,15 +50,15 @@ public class TagCMD extends PlexCommand return usage("/tag set "); } String prefix = StringUtils.join(args, " ", 1, args.length); - Component convertedComponent = removeEvents(noColorComponentFromString(prefix)); - convertedComponent = removeEvents(MiniMessage.miniMessage().deserialize(LegacyComponentSerializer.legacySection().serialize(convertedComponent))); + + Component convertedComponent = removeEvents(PlexUtils.mmCustomDeserialize(prefix = prefix.replace("", "").replace("
", ""), StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())); //noColorComponentFromString(prefix) if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16)) { return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16)); } - player.setPrefix(MiniMessage.miniMessage().serialize(convertedComponent)); + player.setPrefix(prefix); DataUtils.update(player); return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent)); } diff --git a/src/main/java/dev/plex/command/impl/ToggleDropsCMD.java b/src/main/java/dev/plex/command/impl/ToggleDropsCMD.java index ca396ea..67e51f2 100644 --- a/src/main/java/dev/plex/command/impl/ToggleDropsCMD.java +++ b/src/main/java/dev/plex/command/impl/ToggleDropsCMD.java @@ -5,24 +5,12 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import dev.plex.rank.enums.Rank; -import dev.plex.services.ServiceManager; -import dev.plex.services.impl.AutoWipeService; -import dev.plex.util.PlexUtils; import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; - @CommandPermissions(level = Rank.ADMIN, permission = "plex.toggledrops", source = RequiredCommandSource.ANY) @CommandParameters(name = "toggledrops", description = "Toggle immediately removing drops.", usage = "/", aliases = "td") public class ToggleDropsCMD extends PlexCommand diff --git a/src/main/java/dev/plex/command/impl/UnbanCMD.java b/src/main/java/dev/plex/command/impl/UnbanCMD.java index dc1d0d1..8022fc5 100644 --- a/src/main/java/dev/plex/command/impl/UnbanCMD.java +++ b/src/main/java/dev/plex/command/impl/UnbanCMD.java @@ -47,7 +47,7 @@ public class UnbanCMD extends PlexCommand PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID); if (!aBoolean) { - send(sender, MiniMessage.miniMessage().deserialize(new PlayerNotBannedException().getMessage())); + send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage())); return; } plugin.getPunishmentManager().unban(targetUUID); diff --git a/src/main/java/dev/plex/config/Config.java b/src/main/java/dev/plex/config/Config.java index e374fde..893b8cb 100644 --- a/src/main/java/dev/plex/config/Config.java +++ b/src/main/java/dev/plex/config/Config.java @@ -65,7 +65,7 @@ public class Config extends YamlConfiguration if (loadFromFile) { YamlConfiguration externalYamlConfig = YamlConfiguration.loadConfiguration(file); - InputStreamReader internalConfigFileStream = new InputStreamReader(Plex.get().getResource(name), StandardCharsets.UTF_8); + InputStreamReader internalConfigFileStream = new InputStreamReader(plugin.getResource(name), StandardCharsets.UTF_8); YamlConfiguration internalYamlConfig = YamlConfiguration.loadConfiguration(internalConfigFileStream); // Gets all the keys inside the internal file and iterates through all of it's key pairs @@ -76,6 +76,7 @@ public class Config extends YamlConfiguration { // If it doesn't contain the key, we set the key based off what was found inside the plugin jar externalYamlConfig.setComments(string, internalYamlConfig.getComments(string)); + externalYamlConfig.setInlineComments(string, internalYamlConfig.getInlineComments(string)); externalYamlConfig.set(string, internalYamlConfig.get(string)); PlexLog.log("Setting key: " + string + " in " + this.name + " to the default value(s) since it does not exist!"); added = true; diff --git a/src/main/java/dev/plex/event/AdminAddEvent.java b/src/main/java/dev/plex/event/AdminAddEvent.java index 190b44f..1ad453c 100644 --- a/src/main/java/dev/plex/event/AdminAddEvent.java +++ b/src/main/java/dev/plex/event/AdminAddEvent.java @@ -8,7 +8,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; /** - * Event that is ran when a player is added to the admin list + * Event that is run when a player is added to the admin list */ @EqualsAndHashCode(callSuper = false) @Data diff --git a/src/main/java/dev/plex/event/AdminRemoveEvent.java b/src/main/java/dev/plex/event/AdminRemoveEvent.java index 06b0e6c..ec215ce 100644 --- a/src/main/java/dev/plex/event/AdminRemoveEvent.java +++ b/src/main/java/dev/plex/event/AdminRemoveEvent.java @@ -8,7 +8,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; /** - * Event that is ran when a player is removed from the admin list + * Event that is run when a player is removed from the admin list */ @EqualsAndHashCode(callSuper = false) @Data diff --git a/src/main/java/dev/plex/event/AdminSetRankEvent.java b/src/main/java/dev/plex/event/AdminSetRankEvent.java index eee0304..db0b990 100644 --- a/src/main/java/dev/plex/event/AdminSetRankEvent.java +++ b/src/main/java/dev/plex/event/AdminSetRankEvent.java @@ -9,7 +9,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; /** - * Event that is ran when an admin's rank is set + * Event that is run when an admins rank is set */ @EqualsAndHashCode(callSuper = false) @Data diff --git a/src/main/java/dev/plex/event/PunishedPlayerEvent.java b/src/main/java/dev/plex/event/PunishedPlayerEvent.java index 92bf4e7..4b4f04d 100644 --- a/src/main/java/dev/plex/event/PunishedPlayerEvent.java +++ b/src/main/java/dev/plex/event/PunishedPlayerEvent.java @@ -1,7 +1,6 @@ package dev.plex.event; import dev.plex.player.PlexPlayer; -import java.util.UUID; import lombok.Getter; import lombok.Setter; import org.bukkit.Bukkit; diff --git a/src/main/java/dev/plex/listener/impl/AdminListener.java b/src/main/java/dev/plex/listener/impl/AdminListener.java index a6f0af3..5609761 100644 --- a/src/main/java/dev/plex/listener/impl/AdminListener.java +++ b/src/main/java/dev/plex/listener/impl/AdminListener.java @@ -18,16 +18,17 @@ public class AdminListener extends PlexListener { String userSender = event.getSender().getName(); PlexPlayer target = event.getPlexPlayer(); - if (!target.getRank().isEmpty()) + if (target.getRankFromString().isAtLeast(Rank.ADMIN)) + { + PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable())); + } + else { - PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable())); - } else { target.setRank(Rank.ADMIN.name()); PlexUtils.broadcast(messageComponent("newAdminAdded", userSender, target.getName())); } target.setAdminActive(true); DataUtils.update(target); - } @EventHandler @@ -35,7 +36,6 @@ public class AdminListener extends PlexListener { String userSender = event.getSender().getName(); PlexPlayer target = event.getPlexPlayer(); -// target.setRank(""); target.setAdminActive(false); DataUtils.update(target); PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName())); diff --git a/src/main/java/dev/plex/listener/impl/BlockListener.java b/src/main/java/dev/plex/listener/impl/BlockListener.java index d01bb07..f9f6e52 100644 --- a/src/main/java/dev/plex/listener/impl/BlockListener.java +++ b/src/main/java/dev/plex/listener/impl/BlockListener.java @@ -28,7 +28,7 @@ public class BlockListener extends PlexListener @EventHandler(priority = EventPriority.LOW) public void onBlockPlace(BlockPlaceEvent event) { - List blockedBlocksConfig = plugin.config.getStringList("blockedBlocks"); + List blockedBlocksConfig = plugin.config.getStringList("blocked_blocks"); if (blockedBlocksConfig != cachedBlockedBlocksConfig) { blockedBlocks.clear(); @@ -57,17 +57,17 @@ public class BlockListener extends PlexListener if (blockedBlocks.contains(block.getType())) { block.setType(Material.CAKE); - PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5,0.5,0.5)); + PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5, 0.5, 0.5)); } - if(SIGNS.contains(block.getType())) + if (SIGNS.contains(block.getType())) { - Sign sign = (Sign) block.getState(); + Sign sign = (Sign)block.getState(); boolean anythingChanged = false; for (int i = 0; i < sign.lines().size(); i++) { Component line = sign.line(i); - if(line.clickEvent() != null) + if (line.clickEvent() != null) { anythingChanged = true; sign.line(i, line.clickEvent(null)); diff --git a/src/main/java/dev/plex/listener/impl/ChatListener.java b/src/main/java/dev/plex/listener/impl/ChatListener.java index c5ae208..11b8205 100644 --- a/src/main/java/dev/plex/listener/impl/ChatListener.java +++ b/src/main/java/dev/plex/listener/impl/ChatListener.java @@ -9,7 +9,10 @@ import io.papermc.paper.event.player.AsyncChatEvent; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.jetbrains.annotations.NotNull; @@ -51,14 +54,14 @@ public class ChatListener extends PlexListener return Component.empty() .append(prefix) .append(Component.space()) - .append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName))) + .append(MiniMessage.miniMessage().deserialize(plugin.config.getString("chat.name-color", ""))).append(sourceDisplayName) .append(Component.space()) .append(Component.text("»").color(NamedTextColor.GRAY)) .append(Component.space()) .append(message); } return Component.empty() - .append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName))) + .append(MiniMessage.miniMessage().deserialize(plugin.config.getString("chat.name-color", ""))).append(sourceDisplayName) .append(Component.space()) .append(Component.text("»").color(NamedTextColor.GRAY)) .append(Component.space()) diff --git a/src/main/java/dev/plex/listener/impl/DropListener.java b/src/main/java/dev/plex/listener/impl/DropListener.java index 1aa2dfb..732fb65 100644 --- a/src/main/java/dev/plex/listener/impl/DropListener.java +++ b/src/main/java/dev/plex/listener/impl/DropListener.java @@ -9,6 +9,9 @@ public class DropListener extends PlexListener @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { - if (!plugin.config.getBoolean("allowdrops")) event.setCancelled(true); + if (!plugin.config.getBoolean("allowdrops")) + { + event.setCancelled(true); + } } } diff --git a/src/main/java/dev/plex/listener/impl/PlayerListener.java b/src/main/java/dev/plex/listener/impl/PlayerListener.java index 7ab342c..b0848a1 100644 --- a/src/main/java/dev/plex/listener/impl/PlayerListener.java +++ b/src/main/java/dev/plex/listener/impl/PlayerListener.java @@ -77,7 +77,7 @@ public class PlayerListener extends PlexListener String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer); if (!loginMessage.isEmpty()) { - PlexUtils.broadcast(MiniMessage.miniMessage().deserialize("" + player.getName() + " is " + loginMessage)); + PlexUtils.broadcast(PlexUtils.mmDeserialize("" + player.getName() + " is " + loginMessage)); } if (plugin.getStorageType() != StorageType.MONGODB) diff --git a/src/main/java/dev/plex/listener/impl/ServerListener.java b/src/main/java/dev/plex/listener/impl/ServerListener.java index 584d6d1..3bb025f 100644 --- a/src/main/java/dev/plex/listener/impl/ServerListener.java +++ b/src/main/java/dev/plex/listener/impl/ServerListener.java @@ -1,6 +1,7 @@ package dev.plex.listener.impl; import com.destroystokyo.paper.event.server.PaperServerListPingEvent; +import com.destroystokyo.paper.event.server.ServerTickEndEvent; import dev.plex.listener.PlexListener; import dev.plex.util.PlexUtils; import java.util.List; @@ -8,6 +9,7 @@ import java.util.stream.Collectors; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerKickEvent; public class ServerListener extends PlexListener { diff --git a/src/main/java/dev/plex/listener/impl/SpawnListener.java b/src/main/java/dev/plex/listener/impl/SpawnListener.java index b52b33e..13eac77 100644 --- a/src/main/java/dev/plex/listener/impl/SpawnListener.java +++ b/src/main/java/dev/plex/listener/impl/SpawnListener.java @@ -39,7 +39,7 @@ public class SpawnListener extends PlexListener return; } - if (plugin.config.getStringList("blockedEntities").stream().anyMatch(type -> type.equalsIgnoreCase(event.getEntityType().name()))) + if (plugin.config.getStringList("blocked_entities").stream().anyMatch(type -> type.equalsIgnoreCase(event.getEntityType().name()))) { event.setCancelled(true); Location location = event.getLocation(); @@ -56,7 +56,7 @@ public class SpawnListener extends PlexListener if (SPAWN_EGGS.contains(itemType)) { Block block = event.getBlock(); - Location blockLoc = block.getLocation().add(0.5,0.5,0.5).add(((Directional) block.getBlockData()).getFacing().getDirection().multiply(0.8)); + Location blockLoc = block.getLocation().add(0.5, 0.5, 0.5).add(((Directional)block.getBlockData()).getFacing().getDirection().multiply(0.8)); EntityType eggType = spawnEggToEntityType(itemType); if (eggType != null) { @@ -109,7 +109,8 @@ public class SpawnListener extends PlexListener } } - private static EntityType spawnEggToEntityType(Material mat){ + private static EntityType spawnEggToEntityType(Material mat) + { EntityType eggType; try { diff --git a/src/main/java/dev/plex/listener/impl/WorldListener.java b/src/main/java/dev/plex/listener/impl/WorldListener.java index b2b319e..355b212 100644 --- a/src/main/java/dev/plex/listener/impl/WorldListener.java +++ b/src/main/java/dev/plex/listener/impl/WorldListener.java @@ -21,7 +21,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/dev/plex/player/PlexPlayer.java b/src/main/java/dev/plex/player/PlexPlayer.java index 62502b9..4ae582b 100644 --- a/src/main/java/dev/plex/player/PlexPlayer.java +++ b/src/main/java/dev/plex/player/PlexPlayer.java @@ -98,7 +98,7 @@ public class PlexPlayer public Rank getRankFromString() { OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); - if (rank.isEmpty()) + if (rank.isEmpty() || !isAdminActive()) { if (player.isOp()) { diff --git a/src/main/java/dev/plex/rank/RankManager.java b/src/main/java/dev/plex/rank/RankManager.java index a71f81f..5ccf246 100644 --- a/src/main/java/dev/plex/rank/RankManager.java +++ b/src/main/java/dev/plex/rank/RankManager.java @@ -15,6 +15,7 @@ import lombok.SneakyThrows; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.tag.standard.StandardTags; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONTokener; @@ -95,7 +96,7 @@ public class RankManager { if (!player.getPrefix().equals("")) { - return MiniMessage.miniMessage().deserialize(player.getPrefix()); + return PlexUtils.mmCustomDeserialize(player.getPrefix(), StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition()); } if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName())) { diff --git a/src/main/java/dev/plex/rank/enums/Rank.java b/src/main/java/dev/plex/rank/enums/Rank.java index 177b9a0..b114085 100644 --- a/src/main/java/dev/plex/rank/enums/Rank.java +++ b/src/main/java/dev/plex/rank/enums/Rank.java @@ -1,5 +1,6 @@ package dev.plex.rank.enums; +import dev.plex.util.PlexUtils; import lombok.Getter; import lombok.Setter; import net.kyori.adventure.text.Component; @@ -47,7 +48,7 @@ public enum Rank public Component getPrefix() { - return MiniMessage.miniMessage().deserialize(this.prefix); + return PlexUtils.mmDeserialize(this.prefix); } public JSONObject toJSON() diff --git a/src/main/java/dev/plex/rank/enums/Title.java b/src/main/java/dev/plex/rank/enums/Title.java index ac52169..641b2cc 100644 --- a/src/main/java/dev/plex/rank/enums/Title.java +++ b/src/main/java/dev/plex/rank/enums/Title.java @@ -1,5 +1,6 @@ package dev.plex.rank.enums; +import dev.plex.util.PlexUtils; import lombok.Getter; import lombok.Setter; import net.kyori.adventure.text.Component; @@ -39,7 +40,7 @@ public enum Title public Component getPrefix() { - return MiniMessage.miniMessage().deserialize(this.prefix); + return PlexUtils.mmDeserialize(this.prefix); } public JSONObject toJSON() diff --git a/src/main/java/dev/plex/services/ServiceManager.java b/src/main/java/dev/plex/services/ServiceManager.java index 3aeddb8..2253f48 100644 --- a/src/main/java/dev/plex/services/ServiceManager.java +++ b/src/main/java/dev/plex/services/ServiceManager.java @@ -43,7 +43,16 @@ public class ServiceManager { if (!service.isRepeating()) { - BukkitTask task = Bukkit.getScheduler().runTask(Plex.get(), service::run); + int time = service.repeatInSeconds(); + BukkitTask task; + if (time == 0) + { + task = Bukkit.getScheduler().runTask(Plex.get(), service::run); + } + else + { + task = Bukkit.getScheduler().runTaskLater(Plex.get(), service::run, time); + } service.setTaskId(task.getTaskId()); } else if (service.isRepeating() && service.isAsynchronous()) diff --git a/src/main/java/dev/plex/services/impl/AutoWipeService.java b/src/main/java/dev/plex/services/impl/AutoWipeService.java index aff79b5..92e5659 100644 --- a/src/main/java/dev/plex/services/impl/AutoWipeService.java +++ b/src/main/java/dev/plex/services/impl/AutoWipeService.java @@ -5,7 +5,6 @@ import dev.plex.services.AbstractService; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import java.util.List; diff --git a/src/main/java/dev/plex/storage/MongoConnection.java b/src/main/java/dev/plex/storage/MongoConnection.java index 23768fb..9f21631 100644 --- a/src/main/java/dev/plex/storage/MongoConnection.java +++ b/src/main/java/dev/plex/storage/MongoConnection.java @@ -1,6 +1,5 @@ package dev.plex.storage; -import com.mongodb.*; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import dev.morphia.Datastore; @@ -32,10 +31,14 @@ public class MongoConnection extends PlexBase if (database != null && !database.isEmpty()) { connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database; - } else { + } + else + { connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/"; } - } else { + } + else + { connectionString = "mongodb://" + host + ":" + port + "/"; } connectionString += "?uuidRepresentation=STANDARD"; diff --git a/src/main/java/dev/plex/storage/SQLConnection.java b/src/main/java/dev/plex/storage/SQLConnection.java index 07a6ced..d810625 100644 --- a/src/main/java/dev/plex/storage/SQLConnection.java +++ b/src/main/java/dev/plex/storage/SQLConnection.java @@ -19,7 +19,7 @@ public class SQLConnection extends PlexBase { if (!plugin.config.getString("data.central.storage").equalsIgnoreCase("sqlite") && !plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb")) { - return; + return; } String host = plugin.config.getString("data.central.hostname"); @@ -45,7 +45,8 @@ public class SQLConnection extends PlexBase { dataSource.setJdbcUrl("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath()); plugin.setStorageType(StorageType.SQLITE); - } else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb")) + } + else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb")) { Class.forName("org.mariadb.jdbc.Driver"); dataSource.setJdbcUrl("jdbc:mariadb://" + host + ":" + port + "/" + database); @@ -53,7 +54,8 @@ public class SQLConnection extends PlexBase dataSource.setPassword(password); Plex.get().setStorageType(StorageType.MARIADB); } - } catch (ClassNotFoundException throwables) + } + catch (ClassNotFoundException throwables) { throwables.printStackTrace(); } @@ -90,7 +92,8 @@ public class SQLConnection extends PlexBase "`note` VARCHAR(2000), " + "`timestamp` BIGINT" + ");").execute(); - } catch (SQLException throwables) + } + catch (SQLException throwables) { throwables.printStackTrace(); } @@ -105,7 +108,8 @@ public class SQLConnection extends PlexBase try { return dataSource.getConnection(); - } catch (SQLException e) + } + catch (SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/dev/plex/util/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java index 37653a4..218abb3 100644 --- a/src/main/java/dev/plex/util/PlexUtils.java +++ b/src/main/java/dev/plex/util/PlexUtils.java @@ -7,14 +7,23 @@ import dev.plex.PlexBase; import dev.plex.config.Config; import dev.plex.storage.StorageType; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.Context; import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.ParsingException; +import net.kyori.adventure.text.minimessage.tag.Tag; +import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import net.kyori.adventure.text.minimessage.tag.standard.*; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.*; import org.bukkit.command.Command; import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; @@ -28,6 +37,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.time.Instant; import java.time.LocalDateTime; +import java.time.Month; import java.time.ZoneId; import java.util.*; import java.util.concurrent.ThreadLocalRandom; @@ -145,6 +155,50 @@ public class PlexUtils extends PlexBase return ChatColor.translateAlternateColorCodes('&', string); } + private static final MiniMessage safeMessage = MiniMessage.builder().tags(TagResolver.builder().resolvers( + StandardTags.color(), + StandardTags.decorations(), + StandardTags.gradient(), + StandardTags.rainbow(), + StandardTags.reset() + ).build()).build(); + + private static final MiniMessage eggMessage = MiniMessage.builder().tags(new TagResolver() + { + @Override + public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException + { + return StandardTags.rainbow().resolve("rainbow", arguments, ctx); + } + + @Override + public boolean has(@NotNull String name) + { + return true; + } + } + ).build(); + + public static Component mmDeserialize(String input) + { + /*Calendar calendar = Calendar.getInstance(); + MiniMessage mm = (calendar.get(Calendar.MONTH) == Calendar.APRIL && calendar.get(Calendar.DAY_OF_MONTH) == 1 && (!plugin.config.contains("april_fools") || plugin.config.getBoolean("april_fools"))) ? eggMessage : safeMessage; + return mm.deserialize(PlainTextComponentSerializer.plainText().serialize(LegacyComponentSerializer.legacySection().deserialize(input)));*/ + boolean aprilFools = plugin.config.getBoolean("april_fools"); + LocalDateTime date = LocalDateTime.now(); + if (aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1) + { + Component component = PlainTextComponentSerializer.plainText().deserialize(input); + return MiniMessage.miniMessage().deserialize("" + PlainTextComponentSerializer.plainText().serialize(component)); + } + return MiniMessage.miniMessage().deserialize(input); + } + + public static Component mmCustomDeserialize(String input, TagResolver... resolvers) + { + return MiniMessage.builder().tags(TagResolver.builder().resolvers(resolvers).build()).build().deserialize(input); + } + public static Component messageComponent(String entry, Object... objects) { return MiniMessage.miniMessage().deserialize(messageString(entry, objects)); diff --git a/src/main/java/dev/plex/util/UpdateChecker.java b/src/main/java/dev/plex/util/UpdateChecker.java index 4a03dd1..15b1065 100644 --- a/src/main/java/dev/plex/util/UpdateChecker.java +++ b/src/main/java/dev/plex/util/UpdateChecker.java @@ -147,11 +147,6 @@ public class UpdateChecker extends PlexBase } } - private void sendMini(CommandSender sender, String message) - { - sender.sendMessage(MiniMessage.miniMessage().deserialize(message)); - } - public void updateJar(CommandSender sender) { CloseableHttpClient client = HttpClients.createDefault(); @@ -162,7 +157,7 @@ public class UpdateChecker extends PlexBase JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)); JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0); String name = artifact.getString("fileName"); - sendMini(sender, "Downloading latest Plex jar file: " + name); + sender.sendMessage(PlexUtils.mmDeserialize("Downloading latest Plex jar file: " + name)); CompletableFuture.runAsync(() -> { try @@ -171,7 +166,7 @@ public class UpdateChecker extends PlexBase new URL(DOWNLOAD_PAGE + "job/" + branch + "/lastSuccessfulBuild/artifact/build/libs/" + name), new File(Bukkit.getUpdateFolderFile(), name) ); - sendMini(sender, "Saved new jar. Please restart your server."); + sender.sendMessage(PlexUtils.mmDeserialize("Saved new jar. Please restart your server.")); } catch (IOException e) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d3c17c0..e3955a7 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -24,8 +24,8 @@ chat: # The maximum amount of characters a player can have for their tag # This does not include color tags such as or max-tag-length: 64 - # Color code for name color - name-color: 'f' + # Color tag for name color + name-color: '' # Should Plex use a "true op" system with ranks or only permission nodes # Options are "permissions" or "ranks" @@ -139,13 +139,13 @@ autowipe: allowdrops: true # What blocks should be blocked? -blockedBlocks: +blocked_blocks: - "SPAWNER" - "STRUCTURE_BLOCK" - "JIGSAW" # What entities should be blocked? -blockedEntities: +blocked_entities: - "WITHER" - "ENDER_DRAGON" - "MINECART_TNT" diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 275138d..2894798 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -166,4 +166,9 @@ noRemovedEntities: "No entities were removed." removedMobs: "{0} - Removed {1} mobs" autoWipeDisabled: "Item wiping is currently disabled in the config!" allowDropsDisabled: "No longer allowing drops from players." -allowDropsEnabled: "Now allowing drops from players." \ No newline at end of file +allowDropsEnabled: "Now allowing drops from players." +blockedCommandColor: "" +commandBlocked: "That command is blocked." +# 0 - The command sender +# 1 - The message being said +sayCommand: "[Server: {0}] {1}" \ No newline at end of file