Merge branch 'master' into taah-cmd-blocker

# Conflicts:
#	src/main/java/dev/plex/Plex.java
#	src/main/java/dev/plex/listener/impl/CommandListener.java
#	src/main/java/dev/plex/services/impl/CommandBlockerService.java
#	src/main/resources/commands.yml
This commit is contained in:
Taah 2022-04-10 00:04:06 -07:00
commit 09bc47f3fb
49 changed files with 415 additions and 147 deletions

4
.gitignore vendored
View File

@ -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/

View File

@ -1,46 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="20" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" />
<package name="" withSubpackages="true" static="true" />
</value>
</option>
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
</JetCodeStyleSettings>
<codeStyleSettings language="JAVA">
<option name="BRACE_STYLE" value="2" />
<option name="CLASS_BRACE_STYLE" value="2" />
<option name="METHOD_BRACE_STYLE" value="2" />
<option name="LAMBDA_BRACE_STYLE" value="2" />
<option name="ELSE_ON_NEW_LINE" value="true" />
<option name="WHILE_ON_NEW_LINE" value="true" />
<option name="CATCH_ON_NEW_LINE" value="true" />
<option name="FINALLY_ON_NEW_LINE" value="true" />
<option name="SPACE_AFTER_TYPE_CAST" value="false" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -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 doesnt 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.

View File

@ -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

View File

@ -1 +1 @@
rootProject.name = 'Plex'
rootProject.name = "Plex"

View File

@ -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
*/

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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 + ")";
}
}

View File

@ -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<BaseCommand> 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<String> 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<Command> 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<String> 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;
}
}

View File

@ -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() + ")";
}
}

View File

@ -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() + ")";
}
}

View File

@ -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;

View File

@ -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("<aqua>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("<red>That command could not be found!");
}
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
}
return null;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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"))

View File

@ -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 = "/<command> <message>", description = "Displays a message to everyone")
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
public class RawSayCMD extends PlexCommand
{
@Override

View File

@ -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 = "/<command> <message>", 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;
}
}

View File

@ -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 <prefix>");
}
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("<newline>", "").replace("<br>", ""), 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));
}

View File

@ -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 = "/<command>", aliases = "td")
public class ToggleDropsCMD extends PlexCommand

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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()));

View File

@ -28,7 +28,7 @@ public class BlockListener extends PlexListener
@EventHandler(priority = EventPriority.LOW)
public void onBlockPlace(BlockPlaceEvent event)
{
List<String> blockedBlocksConfig = plugin.config.getStringList("blockedBlocks");
List<String> 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));

View File

@ -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", "<white>"))).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", "<white>"))).append(sourceDisplayName)
.append(Component.space())
.append(Component.text("»").color(NamedTextColor.GRAY))
.append(Component.space())

View File

@ -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);
}
}
}

View File

@ -77,7 +77,7 @@ public class PlayerListener extends PlexListener
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
if (!loginMessage.isEmpty())
{
PlexUtils.broadcast(MiniMessage.miniMessage().deserialize("<aqua>" + player.getName() + " is " + loginMessage));
PlexUtils.broadcast(PlexUtils.mmDeserialize("<aqua>" + player.getName() + " is " + loginMessage));
}
if (plugin.getStorageType() != StorageType.MONGODB)

View File

@ -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
{

View File

@ -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
{

View File

@ -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;

View File

@ -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())
{

View File

@ -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()))
{

View File

@ -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()

View File

@ -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()

View File

@ -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())

View File

@ -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;

View File

@ -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";

View File

@ -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();
}

View File

@ -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("<rainbow>" + 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));

View File

@ -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, "<green>Downloading latest Plex jar file: " + name);
sender.sendMessage(PlexUtils.mmDeserialize("<green>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, "<green>Saved new jar. Please restart your server.");
sender.sendMessage(PlexUtils.mmDeserialize("<green>Saved new jar. Please restart your server."));
}
catch (IOException e)
{

View File

@ -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 <red> or <rainbow>
max-tag-length: 64
# Color code for name color
name-color: 'f'
# Color tag for name color
name-color: '<white>'
# 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"

View File

@ -166,4 +166,9 @@ noRemovedEntities: "<gray>No entities were removed."
removedMobs: "<red>{0} - Removed {1} mobs"
autoWipeDisabled: "<gray>Item wiping is currently disabled in the config!"
allowDropsDisabled: "<gray>No longer allowing drops from players."
allowDropsEnabled: "<gray>Now allowing drops from players."
allowDropsEnabled: "<gray>Now allowing drops from players."
blockedCommandColor: "<gray>"
commandBlocked: "That command is blocked."
# 0 - The command sender
# 1 - The message being said
sayCommand: "[Server: {0}] {1}"