Merge branch 'RELEASE-2023.03' into proper-resultset-retrieval

This commit is contained in:
Paul Reilly 2023-04-05 16:39:50 -05:00
commit 55f8c29036
18 changed files with 160 additions and 556 deletions

View File

@ -105,7 +105,6 @@ public class TotalFreedomMod extends JavaPlugin
public LibsDisguisesBridge ldb;
public CoreProtectBridge cpb;
public WorldEditBridge web;
public WorldGuardBridge wgb;
public LuckPermsBridge lpb;
public static TotalFreedomMod getPlugin()
@ -327,7 +326,6 @@ public class TotalFreedomMod extends JavaPlugin
esb = new EssentialsBridge();
ldb = new LibsDisguisesBridge();
web = new WorldEditBridge();
wgb = new WorldGuardBridge();
lpb = new LuckPermsBridge();
}

View File

@ -1,16 +1,12 @@
package me.totalfreedom.totalfreedommod.bridge;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.track.TrackManager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.UnknownDependencyException;
import java.util.concurrent.Executor;
public class LuckPermsBridge
{
private final LuckPerms luckPerms;
@ -38,7 +34,8 @@ public class LuckPermsBridge
if (!trackManager.isLoaded("fakeOp"))
{
trackManager.createAndLoadTrack("fakeOp").whenComplete((track, exception) -> {
trackManager.createAndLoadTrack("fakeOp").whenComplete((track, exception) ->
{
track.appendGroup(GroupProvider.NON_OP.getGroup().getLuckPermsGroup());
track.appendGroup(GroupProvider.OP.getGroup().getLuckPermsGroup());
});
@ -46,7 +43,8 @@ public class LuckPermsBridge
if (!trackManager.isLoaded("admin"))
{
trackManager.createAndLoadTrack("admin").whenComplete((track, exception) -> {
trackManager.createAndLoadTrack("admin").whenComplete((track, exception) ->
{
track.appendGroup(GroupProvider.ADMIN.getGroup().getLuckPermsGroup());
track.appendGroup(GroupProvider.SENIOR_ADMIN.getGroup().getLuckPermsGroup());
});
@ -54,9 +52,8 @@ public class LuckPermsBridge
if (!trackManager.isLoaded("builder"))
{
trackManager.createAndLoadTrack("builder").whenComplete((track, exception) -> {
track.appendGroup(GroupProvider.MASTER_BUILDER.getGroup().getLuckPermsGroup());
});
trackManager.createAndLoadTrack("builder").whenComplete((track, exception) ->
track.appendGroup(GroupProvider.MASTER_BUILDER.getGroup().getLuckPermsGroup()));
}
}
}

View File

@ -1,48 +0,0 @@
package me.totalfreedom.totalfreedommod.bridge;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import me.totalfreedom.totalfreedommod.FreedomService;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class WorldGuardBridge extends FreedomService
{
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
public boolean canEditCurrentWorld(Player player)
{
// If WorldGuard integration is enabled, do a check with it.
if (isEnabled())
{
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
return query.testBuild(localPlayer.getLocation(), localPlayer);
}
// If the plugin isn't present, return true.
return true;
}
public boolean isEnabled()
{
Plugin plugin = server.getPluginManager().getPlugin("WorldGuard");
return plugin != null && plugin.isEnabled();
}
}

View File

@ -1,60 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(permission = "adventure", source = SourceType.BOTH)
@CommandParameters(description = "Quickly change your own gamemode to adventure, define someone's username to change theirs, or change everyone's gamemode on the server.", usage = "/<command> <[partialname] | -a>", aliases = "gma")
public class Command_adventure extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
if (isConsole())
{
msgNew("When used from the console, you must define a target player.");
return true;
}
playerSender.setGameMode(GameMode.ADVENTURE);
msgNew("Your gamemode has been set to adventure.");
return true;
}
checkPermission("tfm.adventure.other");
if (args[0].equals("-a"))
{
FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to adventure", false);
server.getOnlinePlayers().forEach(player ->
{
player.setGameMode(GameMode.ADVENTURE);
msgNew("Your gamemode has been set to adventure.");
});
return true;
}
Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
msgNew("Setting <player> to game mode adventure.", Placeholder.unparsed("player", player.getName()));
player.setGameMode(GameMode.ADVENTURE);
msgNew(player, "<sender> set your game mode to adventure.", Placeholder.unparsed("sender", sender.getName()));
return true;
}
}

View File

@ -1,72 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "clearinventory", source = SourceType.BOTH)
@CommandParameters(description = "Clear your inventory.", usage = "/<command> [player]", aliases = "ci,clear")
public class Command_clearinventory extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
if (senderIsConsole)
{
return false;
}
playerSender.getInventory().clear();
msgNew("<green>Your inventory has been cleared.");
} else
{
if (plugin.al.isAdmin(sender))
{
if (args[0].equals("-a"))
{
FUtil.adminAction(sender.getName(), "Clearing everyone's inventory", true);
server.getOnlinePlayers().forEach(player -> player.getInventory().clear());
msgNew("<green>Successfully cleared everyone's inventory.");
} else
{
Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
player.getInventory().clear();
msgNew("<green>Successfully cleared <player>'s inventory.", Placeholder.unparsed("player", player.getName()));
msgNew(player, "<sender> has cleared your inventory.", Placeholder.unparsed("sender", sender.getName()));
}
} else
{
return noPerms();
}
}
return true;
}
@Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{
if (args.length == 1 && plugin.al.isAdmin(sender))
{
List<String> players = FUtil.getPlayerList();
players.add("-a");
return players;
}
return Collections.emptyList();
}
}

View File

@ -1,58 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@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
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
if (isConsole())
{
msgNew("When used from the console, you must define a target player.");
return true;
}
playerSender.setGameMode(GameMode.CREATIVE);
msgNew("Your gamemode has been set to creative.");
return true;
}
checkPermission("tfm.creative.other");
if (args[0].equals("-a"))
{
FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false);
server.getOnlinePlayers().forEach(player ->
{
player.setGameMode(GameMode.CREATIVE);
msgNew(player, "Your gamemode has been set to creative.");
});
return true;
}
Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
msgNew("Setting <player> to gamemode creative.", Placeholder.unparsed("player", player.getName()));
msgNew(player, "<sender> set your gamemode to creative.", Placeholder.unparsed("sender", sender.getName()));
player.setGameMode(GameMode.CREATIVE);
return true;
}
}

View File

@ -1,97 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.api.Interpolator;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
@CommandPermissions(permission = "nickgradient", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/<command> <hex> <hex> <nick>", aliases = "nickgr")
public class Command_nickgradient extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!server.getPluginManager().isPluginEnabled("Essentials"))
{
msg("Essentials is not enabled on this server.");
return true;
}
if (args.length != 3)
{
return false;
}
String nick = args[2].trim();
if (nick.length() < 3 || nick.length() > 30)
{
msg("Your nickname must be between 3 and 30 characters long.");
return true;
}
for (Player player : Bukkit.getOnlinePlayers())
{
if (player == playerSender)
{
continue;
}
if (player.getName().equalsIgnoreCase(nick) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nick))
{
msg("That nickname is already in use.");
return true;
}
}
String from = "", to = "";
java.awt.Color awt1, awt2;
try
{
if (args[0].equalsIgnoreCase("random") ||
args[0].equalsIgnoreCase("r"))
{
awt1 = FUtil.getRandomAWTColor();
from = " (From: " + FUtil.getHexStringOfAWTColor(awt1) + ")";
} else
{
awt1 = java.awt.Color.decode(args[0]);
}
if (args[1].equalsIgnoreCase("random") ||
args[1].equalsIgnoreCase("r"))
{
awt2 = FUtil.getRandomAWTColor();
to = " (To: " + FUtil.getHexStringOfAWTColor(awt2) + ")";
} else
{
awt2 = java.awt.Color.decode(args[1]);
}
} catch (NumberFormatException ex)
{
msg("Invalid hex values.");
return true;
}
Color c1 = FUtil.fromAWT(awt1);
Color c2 = FUtil.fromAWT(awt2);
List<Color> gradient = FUtil.createColorGradient(c1, c2, nick.length());
String[] splitNick = nick.split("");
for (int i = 0; i < splitNick.length; i++)
{
splitNick[i] = net.md_5.bungee.api.ChatColor.of(FUtil.toAWT(gradient.get(i))) + splitNick[i];
}
nick = StringUtils.join(splitNick, "");
final String outputNick = FUtil.colorize(nick);
plugin.esb.setNickname(sender.getName(), outputNick);
msg("Your nickname is now: '" + outputNick + ChatColor.GRAY + "'" + from + to);
return true;
}
}

View File

@ -0,0 +1,44 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(permission = "nickmm", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = """
Essentials Interface Command - Colorify your nickname.
For Example: /nickmm <red><name> will color your name red.
You can also use tags like <gradient> and <rainbow>.
For example: /nickmm <gradient:red:green:blue><name>""", usage = "/<command> <nickname>")
public class Command_nickmm extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!server.getPluginManager().isPluginEnabled("Essentials"))
{
msg("Essentials is not enabled on this server.");
return true;
}
if (args[0].isEmpty()) {
return false;
}
if (args[0].matches(ChatColor.COLOR_CHAR + "[0-9a-fkm-o]"))
{
msgNew("<red>That nickname contains invalid characters.");
return true;
}
Component parsed = FUtil.miniMessage(args[0], Placeholder.unparsed("<name>", sender.getName()));
plugin.esb.setNickname(sender.getName(), FUtil.miniMessage(parsed));
msgNew("Your nickname is now: " + FUtil.miniMessage(parsed));
return false;
}
}

View File

@ -1,64 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(permission = "nickrainbow", source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/<command> <nick>")
public class Command_nickrainbow extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!server.getPluginManager().isPluginEnabled("Essentials"))
{
msgNew("<red>Essentials is not enabled on this server.");
return true;
}
if (args.length != 1)
{
return false;
}
final String nickPlain = ChatColor.stripColor(FUtil.colorize(args[0].trim()));
if (!nickPlain.matches("^[a-zA-Z_0-9" + ChatColor.COLOR_CHAR + "]+$"))
{
msgNew("<red>That nickname contains invalid characters.");
return true;
}
if (nickPlain.length() < 3 || nickPlain.length() > 30)
{
msgNew("<red>Your nickname must be between 3 and 30 characters long.");
return true;
}
for (Player player : Bukkit.getOnlinePlayers())
{
if (player == playerSender)
{
continue;
}
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
{
msgNew("<red>That nickname is already in use.");
return true;
}
}
final String newNick = FUtil.rainbowify(ChatColor.stripColor(FUtil.colorize(nickPlain)));
plugin.esb.setNickname(sender.getName(), newNick);
msgNew("Your nickname is now: <new>", Placeholder.component("new", FUtil.colorizeAsComponent(newNick)));
return true;
}
}

View File

@ -1,42 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(permission = "spectate", source = SourceType.BOTH)
@CommandParameters(description = "Quickly change your own gamemode to spectator, or define someone's username to change theirs.", usage = "/<command> <[partialname]>", aliases = "gmsp")
public class Command_spectator extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
if (isConsole())
{
msgNew("When used from the console, you must define a target player.");
return true;
}
playerSender.setGameMode(GameMode.SPECTATOR);
msgNew("Your gamemode has been set to spectator.");
return true;
}
Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
msgNew("Setting <player> to gamemode spectator", Placeholder.unparsed("player", player.getName()));
player.setGameMode(GameMode.SPECTATOR);
msgNew(player, "<sender> set your gamemode to spectator.", Placeholder.unparsed("sender", sender.getName()));
return true;
}
}

View File

@ -1,59 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(permission = "survival", source = SourceType.BOTH)
@CommandParameters(description = "Quickly change your own gamemode to survival, or define someone's username to change theirs.", usage = "/<command> <[partialname] | -a>", aliases = "gms")
public class Command_survival extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
if (isConsole())
{
msgNew("When used from the console, you must define a target player.");
return true;
}
playerSender.setGameMode(GameMode.SURVIVAL);
msgNew("Your gamemode has been set to survival.");
return true;
}
checkPermission("tfm.survival.other");
if (args[0].equals("-a"))
{
FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to survival", false);
server.getOnlinePlayers().forEach(player ->
{
player.setGameMode(GameMode.SURVIVAL);
msgNew(player, "Your gamemode has been set to survival.");
});
return true;
}
Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
msgNew("Setting <player> to gamemode survival", Placeholder.unparsed("player", player.getName()));
player.setGameMode(GameMode.SURVIVAL);
msgNew(player, "<sender> set your gamemode to survival.", Placeholder.unparsed("sender", sender.getName()));
return true;
}
}

View File

@ -9,9 +9,7 @@ import net.luckperms.api.model.group.Group;
import net.luckperms.api.node.types.InheritanceNode;
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.bukkit.util.FileUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
@ -52,20 +50,23 @@ public class DisplayableGroup implements Displayable
{
Group matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
if (matched == null) {
if (matched == null)
{
CompletableFuture<Group> cfg = TotalFreedomMod.getPlugin()
.lpb
.getAPI()
.getGroupManager()
.createAndLoadGroup(group);
cfg.thenAcceptAsync(g -> {
cfg.thenAcceptAsync(g ->
{
WeightNode weightNode = WeightNode.builder(weight).build();
PrefixNode prefixNode = PrefixNode.builder()
.prefix(FUtil.miniMessage(GroupProvider.OPEN.append(tag.color(color)).append(GroupProvider.CLOSE)))
.priority(1)
.build();
if (inheritance != null) {
if (inheritance != null)
{
InheritanceNode inheritanceNode = InheritanceNode.builder(inheritance).build();
g.getData(DataType.NORMAL).add(inheritanceNode);
}
@ -75,7 +76,8 @@ public class DisplayableGroup implements Displayable
matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
if (matched == null) throw new IllegalArgumentException("Group " + group + " does not exist and could not be created.");
if (matched == null)
throw new IllegalArgumentException("Group " + group + " does not exist and could not be created.");
}
this.group = matched;
@ -103,7 +105,8 @@ public class DisplayableGroup implements Displayable
return weight;
}
public Group getLuckPermsGroup() {
public Group getLuckPermsGroup()
{
return this.group;
}

View File

@ -1,7 +1,6 @@
package me.totalfreedom.totalfreedommod.rank;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
@ -9,11 +8,7 @@ import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.luckperms.api.context.ContextSetFactory;
import net.luckperms.api.track.TrackManager;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
@ -174,8 +169,7 @@ public class RankManager extends FreedomService
if (plugin.al.isAdmin(player) || data.isMasterBuilder() || FUtil.isDeveloper(player))
{
player.playerListName(Component.text(player.getName()).color(display.getColor()));
}
else
} else
{
fPlayer.setTag(null);
player.setPlayerListName(null);
@ -230,8 +224,7 @@ public class RankManager extends FreedomService
if (playerData.hasLoginMessage())
{
message = playerData.getLoginMessage();
}
else
} else
{
if (display.hasDefaultLoginMessage())
{

View File

@ -6,7 +6,6 @@ import net.kyori.adventure.text.format.TextColor;
public enum Title implements Displayable
{
MASTER_BUILDER(Component.text("a"),
Component.text("Master Builder"),
Component.text("Master Builders"),

View File

@ -88,6 +88,7 @@ public class FUtil
StandardTags.color(),
StandardTags.rainbow(),
StandardTags.gradient(),
StandardTags.newline(),
StandardTags.decorations(TextDecoration.ITALIC),
StandardTags.decorations(TextDecoration.BOLD),
StandardTags.decorations(TextDecoration.STRIKETHROUGH),

View File

@ -1,6 +1,8 @@
package me.totalfreedom.totalfreedommod.util;
import me.totalfreedom.totalfreedommod.api.Interpolator;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Color;
import java.util.LinkedHashSet;
@ -55,4 +57,54 @@ public class Interpolation
}
return gradient;
}
public LinkedHashSet<Color> rgbGradient(int length, Color from, Color to, Interpolator interpolator)
{
final double[] r = interpolator.interpolate(from.getRed(), to.getRed(), length);
final double[] g = interpolator.interpolate(from.getGreen(), to.getGreen(), length);
final double[] b = interpolator.interpolate(from.getBlue(), to.getBlue(), length);
final LinkedHashSet<Color> gradient = new LinkedHashSet<>();
for (int i = 0; i < length; i++)
{
final Color color = Color.fromRGB((int) r[i], (int) g[i], (int) b[i]);
gradient.add(color);
}
return gradient;
}
public LinkedHashSet<TextColor> componentRGBGradient(int length, TextColor from, TextColor to, Interpolator interpolator)
{
final double[] r = interpolator.interpolate(from.red(), to.red(), length);
final double[] g = interpolator.interpolate(from.green(), to.green(), length);
final double[] b = interpolator.interpolate(from.blue(), to.blue(), length);
final LinkedHashSet<TextColor> gradient = new LinkedHashSet<>();
for (int i = 0; i < length; i++)
{
final TextColor color = TextColor.color((int) r[i], (int) g[i], (int) b[i]);
gradient.add(color);
}
return gradient;
}
public LinkedHashSet<TextColor> rainbowComponent(int length)
{
LinkedHashSet<TextColor> base = new LinkedHashSet<>();
LinkedHashSet<TextColor> redToOrange = componentRGBGradient(length, NamedTextColor.RED, NamedTextColor.GOLD, this::linear);
LinkedHashSet<TextColor> orangeToYellow = componentRGBGradient(length, NamedTextColor.GOLD, NamedTextColor.YELLOW, this::linear);
LinkedHashSet<TextColor> yellowToGreen = componentRGBGradient(length, NamedTextColor.YELLOW, NamedTextColor.GREEN, this::linear);
LinkedHashSet<TextColor> greenToBlue = componentRGBGradient(length, NamedTextColor.GREEN, NamedTextColor.BLUE, this::linear);
LinkedHashSet<TextColor> blueToPurple = componentRGBGradient(length, NamedTextColor.BLUE, NamedTextColor.LIGHT_PURPLE, this::linear);
LinkedHashSet<TextColor> purpleToRed = componentRGBGradient(length, TextColor.color(75, 0, 130), TextColor.color(255, 0, 0), this::linear);
base.addAll(redToOrange);
base.addAll(orangeToYellow);
base.addAll(yellowToGreen);
base.addAll(greenToBlue);
base.addAll(blueToPurple);
base.addAll(purpleToRed);
return base;
}
}

View File

@ -129,7 +129,9 @@ public class AdminChatListener
// Server Owner
if (server == null) throw new IllegalStateException();
return member.getRoles().map(role ->
return member.getRoles()
.filter(role -> SnowflakeEntry.acceptableRoleIDs().contains(role.getId()))
.map(role ->
{
if (role.getId().equals(SnowflakeEntry.OWNER_ROLE_ID.getSnowflake()))
{
@ -154,7 +156,7 @@ public class AdminChatListener
return GroupProvider.MASTER_BUILDER.getGroup();
} else
{
return null;
return GroupProvider.OP.getGroup(); // This should only be reached when a user doesn't
}
}).blockFirst();
}

View File

@ -3,6 +3,9 @@ package me.totalfreedom.discord.util;
import discord4j.common.util.Snowflake;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import java.util.HashSet;
import java.util.Set;
public enum SnowflakeEntry
{
ADMIN_CHAT_CHANNEL_ID(ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID),
@ -32,4 +35,16 @@ public enum SnowflakeEntry
{
return Snowflake.of(entry.getString());
}
public static Set<Snowflake> acceptableRoleIDs() {
Set<Snowflake> acceptableRoleIDs = new HashSet<>();
acceptableRoleIDs.add(SnowflakeEntry.OWNER_ROLE_ID.getSnowflake());
acceptableRoleIDs.add(SnowflakeEntry.DEVELOPER_ROLE_ID.getSnowflake());
acceptableRoleIDs.add(SnowflakeEntry.EXECUTIVE_ROLE_ID.getSnowflake());
acceptableRoleIDs.add(SnowflakeEntry.ASSISTANT_EXECUTIVE_ROLE_ID.getSnowflake());
acceptableRoleIDs.add(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake());
acceptableRoleIDs.add(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake());
acceptableRoleIDs.add(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake());
return acceptableRoleIDs;
}
}