LuckPerms Integration (1.5/2)

This commit is contained in:
Paul Reilly 2023-03-29 22:00:35 -05:00
parent 65540b7f3a
commit cc244fc4f7
24 changed files with 230 additions and 209 deletions

View File

@ -1,6 +1,5 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode;
@ -8,7 +7,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH)
@CommandPermissions(permission = "creative", source = SourceType.BOTH)
@CommandParameters(description = "Quickly change your own gamemode to creative, define someone's username to change theirs, or change everyone's gamemode on the server.", usage = "/<command> <-a | [partialname]>", aliases = "gmc")
public class Command_creative extends FreedomCommand
{
@ -28,7 +27,7 @@ public class Command_creative extends FreedomCommand
return true;
}
checkPermission(Rank.ADMIN);
checkPermission("tfm.creative.other");
if (args[0].equals("-a"))
{

View File

@ -1,13 +1,12 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandPermissions(permission = "lightningrod", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Obtain a lightning rod", usage = "/<command>")
public class Command_lightningrod extends FreedomCommand
{
@ -15,7 +14,8 @@ public class Command_lightningrod extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.sh == null) {
if (plugin.sh == null)
{
msg("The shop is currently disabled.", ChatColor.RED);
return true;
}
@ -24,8 +24,7 @@ public class Command_lightningrod extends FreedomCommand
{
playerSender.getInventory().addItem(plugin.sh.getLightningRod());
msg("You have been given a Lightning Rod", ChatColor.GREEN);
}
else
} else
{
msg("You do not own a Lightning Rod! Purchase one from the shop.", ChatColor.RED);
}

View File

@ -1,13 +1,12 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandPermissions(permission = "linkdiscord", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Link your Discord account to your Minecraft account", usage = "/<command> [<name> <id>]")
public class Command_linkdiscord extends FreedomCommand
{

View File

@ -1,9 +1,5 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -11,7 +7,11 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH)
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@CommandPermissions(permission = "links", source = SourceType.BOTH)
@CommandParameters(description = "See TotalFreedom's social media links.", usage = "/<command>", aliases = "link")
public class Command_links extends FreedomCommand
{
@ -30,16 +30,15 @@ public class Command_links extends FreedomCommand
.stream()
.filter(key -> values.get(key) instanceof String)
.forEach(key ->
{
String link = (String) values.get(key);
lines.add(ChatColor.GOLD + "- " + key + ": " + ChatColor.AQUA + link);
});
{
String link = (String) values.get(key);
lines.add(ChatColor.GOLD + "- " + key + ": " + ChatColor.AQUA + link);
});
msg("Social Media Links:", ChatColor.AQUA);
sender.sendMessage(lines.toArray(new String[0]));
return true;
}
else
} else
{
msg("There are no links added in the configuration file.", ChatColor.RED);
}

View File

@ -1,7 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.StringUtils;
@ -11,7 +10,7 @@ import org.bukkit.entity.Player;
import java.util.List;
@CommandPermissions(rank = Rank.NON_OP, source = SourceType.BOTH)
@CommandPermissions(permission = "list", source = SourceType.BOTH)
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -v]", aliases = "who,lsit")
public class Command_list extends FreedomCommand
{
@ -31,12 +30,12 @@ public class Command_list extends FreedomCommand
case "-s", "-a" -> listFilter = ListFilter.ADMINS;
case "-v" ->
{
checkPermission(Rank.ADMIN);
checkPermission("tfm.list.vanished");
listFilter = ListFilter.VANISHED_ADMINS;
}
case "-t" ->
{
checkPermission(Rank.ADMIN);
checkPermission("tfm.list.telnet");
listFilter = ListFilter.TELNET_SESSIONS;
}
default ->
@ -44,8 +43,7 @@ public class Command_list extends FreedomCommand
return false;
}
}
}
else
} else
{
listFilter = ListFilter.PLAYERS;
}
@ -58,16 +56,15 @@ public class Command_list extends FreedomCommand
players = plugin.btb.getConnectedAdmins().stream().map(Admin::getName).toList();
onlineStats = ChatColor.BLUE + "There are " + ChatColor.RED + players.size() + ChatColor.BLUE
+ " admins connected to telnet.";
}
else
} else
{
onlineStats = ChatColor.BLUE + "There are " + ChatColor.RED + FUtil.getFakePlayerCount() + ChatColor.BLUE
+ " out of a maximum " + ChatColor.RED + server.getMaxPlayers() + ChatColor.BLUE + " players online.";
players = server.getOnlinePlayers().stream().filter(pl ->
(listFilter == ListFilter.ADMINS && plugin.al.isAdmin(pl) && !plugin.al.isVanished(pl.getUniqueId()))
|| (listFilter == ListFilter.VANISHED_ADMINS && plugin.al.isVanished(pl.getUniqueId()))
|| (listFilter == ListFilter.PLAYERS && !plugin.al.isVanished(pl.getUniqueId()))).map(player ->
|| (listFilter == ListFilter.VANISHED_ADMINS && plugin.al.isVanished(pl.getUniqueId()))
|| (listFilter == ListFilter.PLAYERS && !plugin.al.isVanished(pl.getUniqueId()))).map(player ->
plugin.rm.getDisplay(player).getColoredTag() + player.getName()).toList();
}
@ -78,8 +75,7 @@ public class Command_list extends FreedomCommand
{
msg(ChatColor.stripColor(onlineStats));
msg(ChatColor.stripColor(onlineUsers));
}
else
} else
{
msg(onlineStats);
msg(onlineUsers);

View File

@ -1,12 +1,11 @@
package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.NON_OP, source = SourceType.ONLY_IN_GAME)
@CommandPermissions(permission = "localspawn", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Teleport to the spawn point for the current world, instead of the Essentials spawn point.", usage = "/<command>", aliases = "worldspawn,gotospawn")
public class Command_localspawn extends FreedomCommand
{

View File

@ -1,16 +1,17 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@CommandPermissions(rank = Rank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandPermissions(permission = "lockup", source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "This is evil, and I never should have wrote it - blocks specified player's input.", usage = "/<command> <all | purge | <<partialname> on | off> [-q]>")
public class Command_lockup extends FreedomCommand
{
@ -30,8 +31,7 @@ public class Command_lockup extends FreedomCommand
startLockup(player);
}
msgNew("Locked up all players.");
}
else if (args[0].equalsIgnoreCase("purge"))
} else if (args[0].equalsIgnoreCase("purge"))
{
FUtil.adminAction(sender.getName(), "Unlocking all players", true);
for (Player player : server.getOnlinePlayers())
@ -40,13 +40,11 @@ public class Command_lockup extends FreedomCommand
}
msgNew("Unlocked all players.");
}
else
} else
{
return false;
}
}
else if (args.length == 2)
} else if (args.length == 2)
{
if (args[1].equalsIgnoreCase("on"))
{
@ -64,8 +62,7 @@ public class Command_lockup extends FreedomCommand
}
startLockup(player);
msgNew("Locked up <player>.", Placeholder.unparsed("player", player.getName()));
}
else if ("off".equals(args[1]))
} else if ("off".equals(args[1]))
{
final Player player = getPlayer(args[0]);
@ -81,13 +78,11 @@ public class Command_lockup extends FreedomCommand
}
cancelLockup(player);
msgNew("Unlocked <player>.", Placeholder.unparsed("player", player.getName()));
}
else
} else
{
return false;
}
}
else
} else
{
return false;
}
@ -124,9 +119,8 @@ public class Command_lockup extends FreedomCommand
{
if (player.isOnline())
{
player.openInventory(player.getInventory());
}
else
player.openInventory(Bukkit.createInventory(null, 9, Component.text("You are locked up!"))); // TODO: Use MiniMessage instead of using Component.
} else
{
cancelLockup(playerdata);
}

View File

@ -1,15 +1,14 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandPermissions(permission = "loginmessage", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Change your login message", usage = "/<command> [message]")
public class Command_loginmessage extends FreedomCommand
{
@ -28,7 +27,7 @@ public class Command_loginmessage extends FreedomCommand
return true;
}
checkPermission(Rank.ADMIN);
checkPermission("tfm.loginmessage.custom");
String message = StringUtils.join(args, " ");
if (!message.contains("%rank%") && !message.contains("%coloredrank%"))

View File

@ -1,20 +1,24 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
@CommandPermissions(permission = "manageshop", source = SourceType.BOTH)
@CommandParameters(description = "Manage the shop", usage = "/<command> <coins: <add | set | remove> <amount> <player | all> | items: <give | take> <item> <player>", aliases = "ms")
public class Command_manageshop extends FreedomCommand
{
// These are here because SonarLint said "use a constant instead of duplicating this literal".
public static final String AMOUNT = "amount";
public static final String PLAYER = "player";
public static final String BALANCE = "balance";
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
@ -41,7 +45,7 @@ public class Command_manageshop extends FreedomCommand
}
switch (args[1])
{
case "add":
case "add" ->
{
try
{
@ -57,19 +61,18 @@ public class Command_manageshop extends FreedomCommand
playerData.setCoins(playerData.getCoins() + amount);
plugin.pl.save(playerData);
msgNew("<green>Successfully gave <amount> coins to <player>. Their new balance is <balance>.",
Placeholder.unparsed("amount", String.valueOf(amount)),
Placeholder.unparsed("player", playerData.getName()),
Placeholder.unparsed("balance", String.valueOf(playerData.getCoins())));
Placeholder.unparsed(AMOUNT, String.valueOf(amount)),
Placeholder.unparsed(PLAYER, playerData.getName()),
Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins())));
Player player = getPlayer(args[3]);
if (player != null)
{
msgNew(player, "<green><player> gave you <amount> coins. Your new balance is <balance>.",
Placeholder.unparsed("player", sender.getName()),
Placeholder.unparsed("amount", String.valueOf(amount)),
Placeholder.unparsed("balance", String.valueOf(playerData.getCoins())));
Placeholder.unparsed(PLAYER, sender.getName()),
Placeholder.unparsed(AMOUNT, String.valueOf(amount)),
Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins())));
}
}
else
} else
{
for (Player player : server.getOnlinePlayers())
{
@ -78,23 +81,22 @@ public class Command_manageshop extends FreedomCommand
plugin.pl.save(playerData);
msgNew(player, "<green><player> gave you <amount> coins. Your new balance is <balance>.",
Placeholder.unparsed("player", sender.getName()),
Placeholder.unparsed("amount", String.valueOf(amount)),
Placeholder.unparsed("balance", String.valueOf(playerData.getCoins())));
Placeholder.unparsed(PLAYER, sender.getName()),
Placeholder.unparsed(AMOUNT, String.valueOf(amount)),
Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins())));
}
msgNew("<green>Successfully gave <amount> coins to all online players.",
Placeholder.unparsed("amount", String.valueOf(amount)));
Placeholder.unparsed(AMOUNT, String.valueOf(amount)));
}
return true;
}
catch (NumberFormatException ex)
} catch (NumberFormatException ex)
{
msgNew("<red>Invalid number: <amount>", Placeholder.unparsed("amount", args[2]));
msgNew("<red>Invalid number: <amount>", Placeholder.unparsed(AMOUNT, args[2]));
return true;
}
}
case "remove":
case "remove" ->
{
try
{
@ -114,20 +116,19 @@ public class Command_manageshop extends FreedomCommand
}
plugin.pl.save(playerData);
msgNew("<green>Successfully took <amount> coins from <player>. Their new balance is <balance>.",
Placeholder.unparsed("amount", String.valueOf(amount)),
Placeholder.unparsed("player", playerData.getName()),
Placeholder.unparsed("balance", String.valueOf(playerData.getCoins())));
Placeholder.unparsed(AMOUNT, String.valueOf(amount)),
Placeholder.unparsed(PLAYER, playerData.getName()),
Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins())));
Player player = getPlayer(args[3]);
if (player != null)
{
msgNew(player, "<red><player> took <amount> coins from you. Your new balance is <balance>.",
Placeholder.unparsed("player", sender.getName()),
Placeholder.unparsed("amount", String.valueOf(amount)),
Placeholder.unparsed("balance", String.valueOf(playerData.getCoins())));
Placeholder.unparsed(PLAYER, sender.getName()),
Placeholder.unparsed(AMOUNT, String.valueOf(amount)),
Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins())));
}
}
else
} else
{
for (Player player : server.getOnlinePlayers())
{
@ -140,23 +141,22 @@ public class Command_manageshop extends FreedomCommand
plugin.pl.save(playerData);
msgNew(player, "<red><player> took <amount> coins from you. Your new balance is <balance>.",
Placeholder.unparsed("player", sender.getName()),
Placeholder.unparsed("amount", String.valueOf(amount)),
Placeholder.unparsed("balance", String.valueOf(playerData.getCoins())));
Placeholder.unparsed(PLAYER, sender.getName()),
Placeholder.unparsed(AMOUNT, String.valueOf(amount)),
Placeholder.unparsed(BALANCE, String.valueOf(playerData.getCoins())));
}
msgNew("<green>Successfully took <amount> coins from all online players.",
Placeholder.unparsed("amount", String.valueOf(amount)));
Placeholder.unparsed(AMOUNT, String.valueOf(amount)));
}
return true;
}
catch (NumberFormatException ex)
} catch (NumberFormatException ex)
{
msgNew("<red>Invalid number: <amount>", Placeholder.unparsed("amount", args[2]));
msgNew("<red>Invalid number: <amount>", Placeholder.unparsed(AMOUNT, args[2]));
return true;
}
}
case "set":
case "set" ->
{
try
{
@ -171,31 +171,29 @@ public class Command_manageshop extends FreedomCommand
plugin.pl.save(playerData);
msgNew("<green>Successfully set <player>'s coin balance to <amount>.",
Placeholder.unparsed("player", playerData.getName()),
Placeholder.unparsed("amount", String.valueOf(amount)));
Placeholder.unparsed(PLAYER, playerData.getName()),
Placeholder.unparsed(AMOUNT, String.valueOf(amount)));
Player player = getPlayer(args[3]);
if (player != null)
{
msgNew(player, "<green><player> set your coin balance to <amount>.",
Placeholder.unparsed("player", sender.getName()),
Placeholder.unparsed("amount", String.valueOf(amount)));
Placeholder.unparsed(PLAYER, sender.getName()),
Placeholder.unparsed(AMOUNT, String.valueOf(amount)));
}
return true;
}
catch (NumberFormatException ex)
} catch (NumberFormatException ex)
{
msgNew("<red>Invalid number: <amount>", Placeholder.unparsed("amount", args[2]));
msgNew("<red>Invalid number: <amount>", Placeholder.unparsed(AMOUNT, args[2]));
return true;
}
}
default:
default ->
{
return false;
}
}
}
else if (args[0].equals("items"))
} else if (args[0].equals("items"))
{
if (args[1].equals("list"))
{
@ -227,18 +225,17 @@ public class Command_manageshop extends FreedomCommand
plugin.pl.save(playerData);
msgNew("<green>Successfully gave the <item> to <player>.",
Placeholder.unparsed("item", item.getName()),
Placeholder.unparsed("player", playerData.getName()));
Placeholder.unparsed(PLAYER, playerData.getName()));
Player player = getPlayer(args[3]);
if (player != null)
{
msgNew(player, "<green><player> gave the <item> to you.",
Placeholder.unparsed("item", item.getName()),
Placeholder.unparsed("player", sender.getName()));
Placeholder.unparsed(PLAYER, sender.getName()));
}
return true;
}
else if (args[1].equals("take"))
} else if (args[1].equals("take"))
{
ShopItem item = ShopItem.findItem(args[2].toUpperCase());
if (item == null)
@ -258,14 +255,14 @@ public class Command_manageshop extends FreedomCommand
msgNew("<green>Successfully took the <item> from <player>.",
Placeholder.unparsed("item", item.getName()),
Placeholder.unparsed("player", playerData.getName()));
Placeholder.unparsed(PLAYER, playerData.getName()));
Player player = getPlayer(args[3]);
if (player != null)
{
msgNew(player, "<red><player> took the <item> from you.",
Placeholder.unparsed("item", item.getName()),
Placeholder.unparsed("player", sender.getName()));
Placeholder.unparsed(PLAYER, sender.getName()));
}
return true;
}

View File

@ -1,8 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
@ -10,7 +8,9 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH)
import java.util.List;
@CommandPermissions(permission = "masterbuilderinfo", source = SourceType.BOTH)
@CommandParameters(description = "Information on how to apply for Master Builder.", usage = "/<command>", aliases = "mbi")
public class Command_masterbuilderinfo extends FreedomCommand
{
@ -23,8 +23,7 @@ public class Command_masterbuilderinfo extends FreedomCommand
if (masterBuilderInfo.isEmpty())
{
msg("The master builder information section of the config.yml file has not been configured.", ChatColor.RED);
}
else
} else
{
msg(FUtil.colorize(StringUtils.join(masterBuilderInfo, "\n")));
}

View File

@ -1,10 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.world.WorldTime;
import me.totalfreedom.totalfreedommod.world.WorldWeather;
import org.bukkit.World;
@ -12,7 +8,11 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH)
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "masterbuilderworld", source = SourceType.BOTH)
@CommandParameters(description = "Allows for master builders to configure the time, the weather of the MasterBuilder, and allows for players to go to the MasterBuilderWorld.",
usage = "/<command> [time <morning | noon | evening | night> | weather <off | rain | storm>]",
aliases = "mbw,mbworld")
@ -27,14 +27,12 @@ public class Command_masterbuilderworld extends FreedomCommand
if (args.length == 0)
{
commandMode = CommandMode.TELEPORT;
}
else if (args.length >= 2)
} else if (args.length >= 2)
{
if ("time".equalsIgnoreCase(args[0]))
{
commandMode = CommandMode.TIME;
}
else if ("weather".equalsIgnoreCase(args[0]))
} else if ("weather".equalsIgnoreCase(args[0]))
{
commandMode = CommandMode.WEATHER;
}
@ -60,8 +58,7 @@ public class Command_masterbuilderworld extends FreedomCommand
try
{
masterBuilderWorld = plugin.wm.masterBuilderWorld.getWorld();
}
catch (Exception ignored)
} catch (Exception ignored)
{
}
@ -69,8 +66,7 @@ public class Command_masterbuilderworld extends FreedomCommand
{
msg("Going to the main world.");
PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation());
}
else
} else
{
msg("Going to the Master Builder world");
plugin.wm.masterBuilderWorld.sendToWorld(playerSender);
@ -89,13 +85,11 @@ public class Command_masterbuilderworld extends FreedomCommand
{
plugin.wm.masterBuilderWorld.setTimeOfDay(timeOfDay);
msg("MasterBuilder world time set to: " + timeOfDay.name());
}
else
} else
{
msg("Invalid time of day. Can be: sunrise, noon, sunset, midnight");
}
}
else
} else
{
return false;
}
@ -113,13 +107,11 @@ public class Command_masterbuilderworld extends FreedomCommand
{
plugin.wm.masterBuilderWorld.setWeatherMode(weatherMode);
msg("MasterBuilder world weather set to: " + weatherMode.name());
}
else
} else
{
msg("Invalid weather mode. Can be: off, rain, storm");
}
}
else
} else
{
return false;
}
@ -131,8 +123,7 @@ public class Command_masterbuilderworld extends FreedomCommand
return false;
}
}
}
catch (PermissionDeniedException ex)
} catch (PermissionDeniedException ex)
{
if (ex.getMessage().isEmpty())
{
@ -155,14 +146,12 @@ public class Command_masterbuilderworld extends FreedomCommand
if (args.length == 1)
{
return Arrays.asList("time", "weather");
}
else if (args.length == 2)
} else if (args.length == 2)
{
if (args[0].equals("time"))
{
return Arrays.asList("morning", "noon", "evening", "night");
}
else if (args[0].equals("weather"))
} else if (args[0].equals("weather"))
{
return Arrays.asList("off", "rain", "storm");
}

View File

@ -1,10 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
@ -12,7 +8,11 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.OP, source = SourceType.BOTH)
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "mbconfig", source = SourceType.BOTH)
@CommandParameters(description = "List, add, or remove master builders. Master builders can also clear their own IPs.", usage = "/<command> <list | clearip <ip> | clearips | <<add | remove> <username>>>")
public class Command_mbconfig extends FreedomCommand
{
@ -125,8 +125,7 @@ public class Command_mbconfig extends FreedomCommand
{
plugin.rm.updateDisplay(player);
}
}
else
} else
{
msg("That player is already on the Master Builder list.");
}
@ -175,18 +174,15 @@ public class Command_mbconfig extends FreedomCommand
if (args.length == 1)
{
return Arrays.asList("add", "remove", "list", "clearips", "clearip");
}
else if (args.length == 2)
} else if (args.length == 2)
{
if (args[0].equalsIgnoreCase("add"))
{
return FUtil.getPlayerList();
}
else if (args[0].equalsIgnoreCase("remove"))
} else if (args[0].equalsIgnoreCase("remove"))
{
return plugin.pl.getMasterBuilderNames();
}
else if (args[0].equalsIgnoreCase("clearip"))
} else if (args[0].equalsIgnoreCase("clearip"))
{
PlayerData data = plugin.pl.getData(sender.getName());
if (data.isMasterBuilder())

View File

@ -2,13 +2,12 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.GameRuleHandler;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
@CommandPermissions(permission = "moblimiter", source = SourceType.BOTH)
@CommandParameters(description = "Control mob limiting parameters.", usage = "/<command> <on | off | setmax <count> | dragon | giant | ghast | slime>")
public class Command_moblimiter extends FreedomCommand
{
@ -24,10 +23,14 @@ public class Command_moblimiter extends FreedomCommand
{
case "on" -> ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(true);
case "off" -> ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(false);
case "dragon" -> ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean());
case "giant" -> ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean());
case "slime" -> ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean());
case "ghast" -> ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean());
case "dragon" ->
ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean());
case "giant" ->
ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean());
case "slime" ->
ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean());
case "ghast" ->
ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean());
case "setmax" ->
{
if (args.length < 2)
@ -38,8 +41,7 @@ public class Command_moblimiter extends FreedomCommand
try
{
ConfigEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1]))));
}
catch (Exception ex)
} catch (Exception ex)
{
msg("Invalid number: " + args[1], ChatColor.RED);
return true;
@ -59,8 +61,7 @@ public class Command_moblimiter extends FreedomCommand
msg("Giant: " + (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean() ? "disabled" : "enabled") + ".");
msg("Slime: " + (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean() ? "disabled" : "enabled") + ".");
msg("Ghast: " + (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean() ? "disabled" : "enabled") + ".");
}
else
} else
{
msg("Moblimiter is disabled. No mob restrictions are in effect.");
}

View File

@ -1,8 +1,5 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.ChatColor;
@ -11,7 +8,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "mobpurge", source = SourceType.BOTH)
@CommandParameters(description = "Purge all mobs in all worlds.", usage = "/<command> [name]", aliases = "mp")
public class Command_mobpurge extends FreedomCommand
{
@ -25,8 +26,7 @@ public class Command_mobpurge extends FreedomCommand
try
{
type = EntityType.valueOf(args[0].toUpperCase());
}
catch (Exception e)
} catch (Exception e)
{
msg(args[0] + " is not a valid mob type.", ChatColor.RED);
return true;

View File

@ -1,9 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Objects;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
@ -11,7 +9,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@CommandPermissions(rank = Rank.OP, source = SourceType.ONLY_IN_GAME)
import java.util.Objects;
@CommandPermissions(permission = "mp44", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Modern weaponry, FTW. Use 'draw' to start firing, 'sling' to stop firing.", usage = "/<command> <draw | sling>")
public class Command_mp44 extends FreedomCommand
{
@ -40,8 +40,7 @@ public class Command_mp44 extends FreedomCommand
msg("Type /mp44 sling to disable. -by Madgeek1450", ChatColor.GREEN);
Objects.requireNonNull(playerSender.getEquipment()).setItemInMainHand(new ItemStack(Material.GUNPOWDER, 1));
}
else
} else
{
playerdata.disarmMP44();

View File

@ -1,19 +1,18 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.*;
import me.totalfreedom.totalfreedommod.punishments.Punishment;
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
import java.util.*;
@CommandPermissions(permission = "tfm.mute", source = SourceType.BOTH)
@CommandParameters(description = "Mutes a player with brute force.", usage = "/<command> <[-q] <player> [reason] | list | purge | all>", aliases = "stfu")
public class Command_mute extends FreedomCommand
{
@ -34,8 +33,7 @@ public class Command_mute extends FreedomCommand
if (muted.isEmpty())
{
msgNew("Nobody is currently muted.");
}
else
} else
{
msgNew("Muted players: <players>", Placeholder.unparsed("players", FUtil.listToString(muted)));
}
@ -93,8 +91,7 @@ public class Command_mute extends FreedomCommand
{
msgNew("<red><player> is an admin, and as such can't be muted.", Placeholder.unparsed("player", player.getName()));
return;
}
else if (plugin.pl.getPlayer(player).isMuted())
} else if (plugin.pl.getPlayer(player).isMuted())
{
msgNew("<red><player> is already muted.", Placeholder.unparsed("player", player.getName()));
return;
@ -122,8 +119,7 @@ public class Command_mute extends FreedomCommand
if (quiet)
{
msgNew("Muted <player>.", Placeholder.unparsed("player", player.getName()));
}
else
} else
{
msgNew("Quietly muted <player>.", Placeholder.unparsed("player", player.getName()));
}

View File

@ -13,7 +13,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.ADMIN, source = SourceType.BOTH)
@CommandPermissions(permission = "notes", source = SourceType.BOTH)
@CommandParameters(description = "Manage notes for a player", usage = "/<command> <name> <list | add <note> | remove <id> | clear>")
public class Command_notes extends FreedomCommand
{

View File

@ -1,12 +1,14 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.luckperms.api.model.user.User;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(rank = Rank.NON_OP, source = SourceType.ONLY_IN_GAME)
@CommandPermissions(permission = "opme", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "OPs the command sender.", usage = "/<command>")
public class Command_opme extends FreedomCommand
{
@ -15,7 +17,8 @@ public class Command_opme extends FreedomCommand
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
FUtil.adminAction(sender.getName(), "Opping " + sender.getName(), false);
sender.setOp(true);
User user = GroupProvider.getUser(playerSender);
user.setPrimaryGroup(GroupProvider.OP.getGroup().getLuckPermsGroup().getName());
msg(YOU_ARE_OP);
plugin.rm.updateDisplay(playerSender);
return true;

View File

@ -1,5 +1,9 @@
package me.totalfreedom.totalfreedommod.rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.ChatColor;
public interface Displayable
@ -21,7 +25,7 @@ public interface Displayable
String getColoredName();
String getColoredTag();
Component getColoredTag();
String getColoredLoginMessage();
@ -29,4 +33,15 @@ public interface Displayable
boolean hasDefaultLoginMessage();
default Component generateColoredTag(String colorAndTag)
{
Component open = Component.text("[").color(NamedTextColor.DARK_GRAY);
Component close = Component.text("]").color(NamedTextColor.DARK_GRAY);
Component tagComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(colorAndTag);
return Component.join(JoinConfiguration
.builder()
.separator(Component.text(" "))
.build(), open, tagComponent, close);
}
}

View File

@ -1,12 +1,17 @@
package me.totalfreedom.totalfreedommod.rank;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import net.kyori.adventure.text.Component;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.node.types.PrefixNode;
import net.luckperms.api.node.types.WeightNode;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
public class DisplayableGroup implements Displayable
{
@ -17,10 +22,11 @@ public class DisplayableGroup implements Displayable
private final String abbr;
private final String plural;
private final String article;
private final int weight;
private final String tag;
private final String coloredTag;
private final Component coloredTag;
private final ChatColor color;
@ -33,6 +39,7 @@ public class DisplayableGroup implements Displayable
public DisplayableGroup(String group,
String plural,
String tag,
int weight,
ChatColor color,
org.bukkit.ChatColor teamColor,
boolean hasTeam,
@ -41,7 +48,22 @@ public class DisplayableGroup implements Displayable
Group matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
if (matched == null) {
throw new IllegalArgumentException("Group " + group + " does not exist!");
CompletableFuture<Group> cfg = TotalFreedomMod.getPlugin()
.lpb
.getAPI()
.getGroupManager()
.createAndLoadGroup(group);
cfg.thenAcceptAsync(g -> {
WeightNode weightNode = WeightNode.builder(weight).build();
PrefixNode prefixNode = PrefixNode.builder().prefix(ChatColor.DARK_GRAY + "[" + color + tag + ChatColor.DARK_GRAY + "]" + getColor()).build();
g.getData(DataType.NORMAL).add(prefixNode);
g.getData(DataType.NORMAL).add(weightNode);
}).join(); // Block until the group is created and loaded.
matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
if (matched == null) throw new IllegalArgumentException("Group " + group + " does not exist and could not be created.");
}
this.group = matched;
@ -49,11 +71,12 @@ public class DisplayableGroup implements Displayable
this.plural = plural;
this.article = StringUtils.startsWithAny(this.name.toLowerCase(Locale.ROOT), new String[]{"a", "e", "i", "o", "u"}) ? "an" : "a";
this.abbr = tag;
this.weight = weight;
this.tag = "[" + tag + "]";
this.color = color;
this.teamColor = teamColor;
this.hasTeam = hasTeam;
this.coloredTag = ChatColor.DARK_GRAY + "[" + getColor() + getTag() + ChatColor.DARK_GRAY + "]" + getColor();
this.coloredTag = generateColoredTag(color + tag);
this.hasDefaultLoginMessage = hasDefaultLoginMessage;
}
@ -116,7 +139,7 @@ public class DisplayableGroup implements Displayable
}
@Override
public String getColoredTag()
public Component getColoredTag()
{
return coloredTag;
}

View File

@ -3,18 +3,18 @@ package me.totalfreedom.totalfreedommod.rank;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import net.luckperms.api.model.user.User;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
import java.util.Set;
@FunctionalInterface
public interface GroupProvider<T extends DisplayableGroup>
{
GroupProvider<DisplayableGroup> NON_OP = () -> new DisplayableGroup("non_op", "Non-Ops", "", ChatColor.WHITE, null, false, false);
GroupProvider<DisplayableGroup> OP = () -> new DisplayableGroup("op", "Operators", "Op", ChatColor.GREEN, null, false, false);
GroupProvider<DisplayableGroup> ADMIN = () -> new DisplayableGroup("admin", "Administrators", "Admin", ChatColor.DARK_GREEN, org.bukkit.ChatColor.DARK_GREEN, true, true);
GroupProvider<DisplayableGroup> SENIOR_ADMIN = () -> new DisplayableGroup("senior", "Senior Administrators", "SrA", ChatColor.GOLD, org.bukkit.ChatColor.GOLD, true, true);
GroupProvider<DisplayableGroup> NON_OP = () -> new DisplayableGroup("non_op", "Non-Ops", "", 0, ChatColor.WHITE, null, false, false);
GroupProvider<DisplayableGroup> OP = () -> new DisplayableGroup("op", "Operators", "Op", 1, ChatColor.GREEN, null, false, false);
GroupProvider<DisplayableGroup> MASTER_BUILDER = () -> new DisplayableGroup("builder", "Master Builders", "MB", 2, ChatColor.DARK_AQUA, org.bukkit.ChatColor.DARK_AQUA, true, true);
GroupProvider<DisplayableGroup> ADMIN = () -> new DisplayableGroup("admin", "Administrators", "Admin", 3, ChatColor.DARK_GREEN, org.bukkit.ChatColor.DARK_GREEN, true, true);
GroupProvider<DisplayableGroup> SENIOR_ADMIN = () -> new DisplayableGroup("senior", "Senior Administrators", "SrA", 4, ChatColor.GOLD, org.bukkit.ChatColor.GOLD, true, true);
static User getUser(Player player)
{
@ -24,15 +24,21 @@ public interface GroupProvider<T extends DisplayableGroup>
.getUser(player);
}
T getGroup();
static GroupProvider<DisplayableGroup> fromArgument(String arg) {
static GroupProvider<DisplayableGroup> fromArgument(String arg)
{
return switch (arg.toLowerCase())
{
case "op" -> OP;
case "builder" -> MASTER_BUILDER;
case "admin" -> ADMIN;
case "senior" -> SENIOR_ADMIN;
default -> NON_OP;
};
}
static Set<GroupProvider<DisplayableGroup>> providerSet() {
return Set.of(NON_OP, OP, MASTER_BUILDER, ADMIN, SENIOR_ADMIN);
}
T getGroup();
}

View File

@ -6,7 +6,10 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.node.types.PrefixNode;
import net.luckperms.api.node.types.WeightNode;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -18,18 +21,23 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class RankManager extends FreedomService
{
@Override
public void onStart()
{
// We don't need to do anything here.
}
@Override
public void onStop()
{
// We don't need to do anything here.
}
public Displayable getDisplay(CommandSender sender)

View File

@ -1,5 +1,9 @@
package me.totalfreedom.totalfreedommod.rank;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.ChatColor;
public enum Title implements Displayable
@ -21,7 +25,7 @@ public enum Title implements Displayable
private final String tag;
private final String coloredTag;
private final Component coloredTag;
private final ChatColor color;
@ -35,7 +39,7 @@ public enum Title implements Displayable
this.article = article;
this.name = name;
this.plural = plural;
this.coloredTag = ChatColor.DARK_GRAY + "[" + color + tag + ChatColor.DARK_GRAY + "]" + color;
this.coloredTag = generateColoredTag(color + tag);
this.abbr = tag;
this.tag = "[" + tag + "]";
this.color = color;
@ -99,7 +103,7 @@ public enum Title implements Displayable
}
@Override
public String getColoredTag()
public Component getColoredTag()
{
return coloredTag;
}

View File

@ -9,6 +9,7 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.rank.Title;
import me.totalfreedom.totalfreedommod.util.FLog;
@ -52,15 +53,15 @@ public class TFM_Bridge
}
else if (role.getId().equals(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake()))
{
return Rank.SENIOR_ADMIN.getColoredTag();
return GroupProvider.SENIOR_ADMIN.getGroup().getColoredTag().toString();
}
else if (role.getId().equals(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake()))
{
return Rank.ADMIN.getColoredTag();
return GroupProvider.ADMIN.getGroup().getColoredTag().toString();
}
else if (role.getId().equals(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake()))
{
return Title.MASTER_BUILDER.getColoredTag();
return GroupProvider.MASTER_BUILDER.getGroup().getColoredTag().toString());
}
else
{