Update formatting

This commit is contained in:
NotAlexNoyle committed 2026-03-09 04:54:50 -04:00
1 parent efa90b8101
commit 2d10ab8eb6
6 files changed
+636 -619

No files matched your search

@@ -24,97 +24,99 @@ import net.trueog.utilitiesog.UtilitiesOG;
public class BountyCommand implements CommandExecutor, TabCompleter {
private final PlayerBountiesOG plugin;
private final DiamondBankAPIJava diamondBankAPI;
private final PlayerBountiesOG plugin;
private final DiamondBankAPIJava diamondBankAPI;
public BountyCommand(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI) {
public BountyCommand(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI) {
this.plugin = plugin;
this.diamondBankAPI = diamondBankAPI;
this.plugin = plugin;
this.diamondBankAPI = diamondBankAPI;
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
if (!(sender instanceof Player)) {
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), "&cERROR: Only players can use this command.");
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), "&cERROR: Only players can use this command.");
return true;
return true;
}
}
if (args.length < 1) {
if (args.length < 1) {
// If "/bounty" is run without a valid subcommand, treat it as "/bounty top".
return BountyTopCmd.handleCmd(plugin, diamondBankAPI, sender, cmd, cmdName, args);
// If "/bounty" is run without a valid subcommand, treat it as "/bounty top".
return BountyTopCmd.handleCmd(plugin, diamondBankAPI, sender, cmd, cmdName, args);
}
}
final String action = StringUtils.lowerCase(args[0]);
switch (action) {
final String action = StringUtils.lowerCase(args[0]);
switch (action) {
case "set" -> {
case "set" -> {
return BountySetCmd.handleCmd(plugin, sender, cmd, cmdName, args);
return BountySetCmd.handleCmd(plugin, sender, cmd, cmdName, args);
}
}
case "top" -> {
case "top" -> {
return BountyTopCmd.handleCmd(plugin, diamondBankAPI, sender, cmd, cmdName, args);
return BountyTopCmd.handleCmd(plugin, diamondBankAPI, sender, cmd, cmdName, args);
}
}
case "check" -> {
case "check" -> {
return BountyCheckCmd.handleCmd(plugin, sender, cmd, cmdName, args);
return BountyCheckCmd.handleCmd(plugin, sender, cmd, cmdName, args);
}
default -> {
}
default -> {
// If "/bounty" is run without a valid subcommand, treat it as "/bounty top".
return BountyTopCmd.handleCmd(plugin, diamondBankAPI, sender, cmd, cmdName, args);
// If "/bounty" is run without a valid subcommand, treat it as "/bounty top".
return BountyTopCmd.handleCmd(plugin, diamondBankAPI, sender, cmd, cmdName, args);
}
}
}
}
}
}
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args)
{
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args)
{
if (args.length == 1) {
if (args.length == 1) {
return Lists.newArrayList("set", "top", "check").stream()
.filter(action -> StringUtils.startsWith(action, StringUtils.lowerCase(args[0]))).collect(Collectors.toList());
return Lists.newArrayList("set", "top", "check").stream()
.filter(action -> StringUtils.startsWith(action, StringUtils.lowerCase(args[0])))
.collect(Collectors.toList());
}
else if (args.length > 1) {
} else if (args.length > 1) {
final String subCommand = StringUtils.lowerCase(args[0]);
return switch (subCommand) {
final String subCommand = StringUtils.lowerCase(args[0]);
return switch (subCommand) {
case "set" -> BountySetCmd.onTabComplete(sender, args).stream()
.filter(suggestion -> StringUtils.startsWith(StringUtils.lowerCase(suggestion), StringUtils.lowerCase(args[1])))
.collect(Collectors.toList());
case "check" -> BountyCheckCmd.onTabComplete(sender, args).stream()
.filter(suggestion -> StringUtils.startsWith(StringUtils.lowerCase(suggestion), StringUtils.lowerCase(args[1])))
.collect(Collectors.toList());
case "top" -> Collections.emptyList();
default -> Collections.emptyList();
case "set" -> BountySetCmd
.onTabComplete(sender, args).stream().filter(suggestion -> StringUtils
.startsWith(StringUtils.lowerCase(suggestion), StringUtils.lowerCase(args[1])))
.collect(Collectors.toList());
case "check" -> BountyCheckCmd
.onTabComplete(sender, args).stream().filter(suggestion -> StringUtils
.startsWith(StringUtils.lowerCase(suggestion), StringUtils.lowerCase(args[1])))
.collect(Collectors.toList());
case "top" -> Collections.emptyList();
default -> Collections.emptyList();
};
};
}
}
return Collections.emptyList();
return Collections.emptyList();
}
}
}
@@ -20,269 +20,270 @@ import net.trueog.utilitiesog.UtilitiesOG;
public class BountySetCmd {
public static boolean handleCmd(PlayerBountiesOG plugin, CommandSender sender, Command cmd, String cmdName,
String[] args)
{
public static boolean handleCmd(PlayerBountiesOG plugin, CommandSender sender, Command cmd, String cmdName,
String[] args)
{
if (args.length < 3) {
if (args.length < 3) {
final String missingArgumentsMessage = plugin.getLang().getColored("command.bounty.set.missing-args");
if (!(sender instanceof Player)) {
final String missingArgumentsMessage = plugin.getLang().getColored("command.bounty.set.missing-args");
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), missingArgumentsMessage);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), missingArgumentsMessage);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, missingArgumentsMessage);
UtilitiesOG.trueogMessage((Player) sender, missingArgumentsMessage);
}
}
return true;
return true;
}
}
if (sender instanceof Player && !sender.hasPermission("playerbountiesplus.command.bounty.set")) {
if (sender instanceof Player && !sender.hasPermission("playerbountiesplus.command.bounty.set")) {
final String noPerm = plugin.getLang().getColored("command.no-permission");
final String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
.replace("{no-permission-msg}", noPerm)
.replace("{permission}", "playerbountiesplus.command.bounty.set");
if (!(sender instanceof Player)) {
final String noPerm = plugin.getLang().getColored("command.no-permission");
final String noPermDetailed = plugin.getLang().getColored("command.no-permission-detailed")
.replace("{no-permission-msg}", noPerm)
.replace("{permission}", "playerbountiesplus.command.bounty.set");
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), noPermDetailed);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), noPermDetailed);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, noPermDetailed);
UtilitiesOG.trueogMessage((Player) sender, noPermDetailed);
}
}
return true;
return true;
}
}
final String playerNameArg = args[1];
final double parsedAmount;
try {
final String playerNameArg = args[1];
final double parsedAmount;
try {
parsedAmount = Integer.parseInt(args[2]);
parsedAmount = Integer.parseInt(args[2]);
} catch (NumberFormatException numberFormatException) {
} catch (NumberFormatException numberFormatException) {
final String notNumberMessage = plugin.getLang().getColored("command.bounty.set.amount-nan");
if (!(sender instanceof Player)) {
final String notNumberMessage = plugin.getLang().getColored("command.bounty.set.amount-nan");
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), notNumberMessage);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), notNumberMessage);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, notNumberMessage);
UtilitiesOG.trueogMessage((Player) sender, notNumberMessage);
}
}
return true;
return true;
}
}
final Player target = plugin.getServer().getPlayerExact(playerNameArg);
if (target == null) {
final Player target = plugin.getServer().getPlayerExact(playerNameArg);
if (target == null) {
final String playerNotFoundMessage = plugin.getLang().getColored("command.bounty.set.player-not-found");
if (!(sender instanceof Player)) {
final String playerNotFoundMessage = plugin.getLang().getColored("command.bounty.set.player-not-found");
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), playerNotFoundMessage);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), playerNotFoundMessage);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, playerNotFoundMessage);
UtilitiesOG.trueogMessage((Player) sender, playerNotFoundMessage);
}
}
return true;
return true;
}
}
// Check limits.
final double minimum = plugin.getConfig().getDouble("bounty-minimum", 1.0);
if (parsedAmount < minimum) {
// Check limits.
final double minimum = plugin.getConfig().getDouble("bounty-minimum", 1.0);
if (parsedAmount < minimum) {
final String underMinimumMessage = plugin.getLang().getColored("command.bounty.set.under-minimum")
.replace("{minimum}", String.valueOf(minimum));
if (!(sender instanceof Player)) {
final String underMinimumMessage = plugin.getLang().getColored("command.bounty.set.under-minimum")
.replace("{minimum}", String.valueOf(minimum));
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), underMinimumMessage);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), underMinimumMessage);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, underMinimumMessage);
UtilitiesOG.trueogMessage((Player) sender, underMinimumMessage);
}
}
return true;
return true;
}
}
final double maximum = plugin.getConfig().getDouble("bounty-maximum", 1000000.0);
if (parsedAmount > maximum) {
final double maximum = plugin.getConfig().getDouble("bounty-maximum", 1000000.0);
if (parsedAmount > maximum) {
final String overMaximumMessage = plugin.getLang().getColored("command.bounty.set.over-maximum")
.replace("{maximum}", String.valueOf(maximum));
if (!(sender instanceof Player)) {
final String overMaximumMessage = plugin.getLang().getColored("command.bounty.set.over-maximum")
.replace("{maximum}", String.valueOf(maximum));
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), overMaximumMessage);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), overMaximumMessage);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, overMaximumMessage);
UtilitiesOG.trueogMessage((Player) sender, overMaximumMessage);
}
}
return true;
return true;
}
}
// Apply bounty multiplier.
double amount = parsedAmount * plugin.getConfig().getDouble("bounty-multiplier", 1.0);
// Apply bounty multiplier.
double amount = parsedAmount * plugin.getConfig().getDouble("bounty-multiplier", 1.0);
// Trigger bounty set event.
final BountySetEvent event = new BountySetEvent(sender instanceof Player ? (Player) sender : null, target,
(float) amount);
plugin.getServer().getPluginManager().callEvent(event);
amount = event.getAmount();
// Trigger bounty set event.
final BountySetEvent event = new BountySetEvent(sender instanceof Player ? (Player) sender : null, target,
(float) amount);
plugin.getServer().getPluginManager().callEvent(event);
amount = event.getAmount();
// Check if event was cancelled.
if (event.isCancelled()) {
// Check if event was cancelled.
if (event.isCancelled()) {
final String cancelledBounty = plugin.getLang().getColored("command.bounty.set.cancelled");
if (!(sender instanceof Player)) {
final String cancelledBounty = plugin.getLang().getColored("command.bounty.set.cancelled");
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), cancelledBounty);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), cancelledBounty);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, cancelledBounty);
UtilitiesOG.trueogMessage((Player) sender, cancelledBounty);
}
}
return true;
return true;
}
}
// Sanity check final amount.
if (amount <= 0) {
// Sanity check final amount.
if (amount <= 0) {
final String invalidValueMessage = plugin.getLang().getColored("command.bounty.set.internal-invalid-value");
if (!(sender instanceof Player)) {
final String invalidValueMessage = plugin.getLang().getColored("command.bounty.set.internal-invalid-value");
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), invalidValueMessage);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), invalidValueMessage);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, invalidValueMessage);
UtilitiesOG.trueogMessage((Player) sender, invalidValueMessage);
}
}
return true;
return true;
}
}
// Check economy. Only charge if sender is a player.
if (sender instanceof Player player) {
// Check economy. Only charge if sender is a player.
if (sender instanceof Player player) {
final boolean allowed = plugin.getEcoHook().takeEco(player, target, amount);
final boolean allowed = plugin.getEcoHook().takeEco(player, target, amount);
if (!allowed) {
if (!allowed) {
final String notEnoughDiamondsMessage = plugin.getLang()
.getColored("command.bounty.set.not-enough-money");
if (!(sender instanceof Player)) {
final String notEnoughDiamondsMessage = plugin.getLang()
.getColored("command.bounty.set.not-enough-money");
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), notEnoughDiamondsMessage);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), notEnoughDiamondsMessage);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, notEnoughDiamondsMessage);
UtilitiesOG.trueogMessage((Player) sender, notEnoughDiamondsMessage);
}
}
return true;
return true;
}
}
}
}
final UUID playerUUID = target.getUniqueId();
final UUID playerUUID = target.getUniqueId();
// Calculate total bounty including previous bounties.
final BountyDataManager bountyDataManager = plugin.getBountyDataManager();
final double bountyAlreadyPresent = bountyDataManager.getBounty(playerUUID);
final double chargeAndBountyAmount = (int) amount;
final double totalBounty = chargeAndBountyAmount + bountyAlreadyPresent;
bountyDataManager.setBounty(playerUUID, totalBounty);
// Calculate total bounty including previous bounties.
final BountyDataManager bountyDataManager = plugin.getBountyDataManager();
final double bountyAlreadyPresent = bountyDataManager.getBounty(playerUUID);
final double chargeAndBountyAmount = (int) amount;
final double totalBounty = chargeAndBountyAmount + bountyAlreadyPresent;
bountyDataManager.setBounty(playerUUID, totalBounty);
// Confirmation.
final String bountySetSuccessMessage = plugin.getLang().getColored("command.bounty.set.success")
.replace("{bounty}", String.valueOf(chargeAndBountyAmount))
.replace("{total}", String.valueOf(totalBounty)).replace("{target}", target.getName())
.replace("{player}", sender.getName());
if (!(sender instanceof Player)) {
// Confirmation.
final String bountySetSuccessMessage = plugin.getLang().getColored("command.bounty.set.success")
.replace("{bounty}", String.valueOf(chargeAndBountyAmount))
.replace("{total}", String.valueOf(totalBounty)).replace("{target}", target.getName())
.replace("{player}", sender.getName());
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), bountySetSuccessMessage);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), bountySetSuccessMessage);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, bountySetSuccessMessage);
UtilitiesOG.trueogMessage((Player) sender, bountySetSuccessMessage);
}
}
// Announcement.
final String extra;
if (bountyAlreadyPresent == 0) {
// Announcement.
final String extra;
if (bountyAlreadyPresent == 0) {
extra = "";
extra = "";
} else {
} else {
extra = plugin.getLang().getColored("command.bounty.set.announce-extra").replace("{total}",
String.valueOf(totalBounty));
extra = plugin.getLang().getColored("command.bounty.set.announce-extra").replace("{total}",
String.valueOf(totalBounty));
}
}
if (plugin.getConfig().getBoolean("bounty-placed-announce", true)) {
if (plugin.getConfig().getBoolean("bounty-placed-announce", true)) {
Bukkit.getOnlinePlayers()
.forEach((Player player) -> UtilitiesOG.trueogMessage(player, PlayerBountiesOG.getPrefix() + "&a" +
plugin.getLang().getColored("command.bounty.set.announce")
.replace("{bounty}", String.valueOf(chargeAndBountyAmount))
.replace("{target}", target.getName()).replace("{player}", sender.getName())
.replace("{extra}", extra)));
Bukkit.getOnlinePlayers()
.forEach((Player player) -> UtilitiesOG.trueogMessage(player,
PlayerBountiesOG.getPrefix() + "&a"
+ plugin.getLang().getColored("command.bounty.set.announce")
.replace("{bounty}", String.valueOf(chargeAndBountyAmount))
.replace("{target}", target.getName()).replace("{player}", sender.getName())
.replace("{extra}", extra)));
}
}
bountyDataManager.saveBountiesAsync();
bountyDataManager.saveBountiesAsync();
return true;
return true;
}
}
@Nullable
public static List<String> onTabComplete(@NotNull CommandSender sender, @NotNull String[] args) {
@Nullable
public static List<String> onTabComplete(@NotNull CommandSender sender, @NotNull String[] args) {
if (args.length == 2) {
if (args.length == 2) {
// Suggest online player names for the username.
return sender.getServer().getOnlinePlayers().stream().map(Player::getName)
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase())).collect(Collectors.toList());
// Suggest online player names for the username.
return sender.getServer().getOnlinePlayers().stream().map(Player::getName)
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase())).collect(Collectors.toList());
} else if (args.length == 3) {
} else if (args.length == 3) {
// Suggest a placeholder for the amount.
return Collections.singletonList("<amount>");
// Suggest a placeholder for the amount.
return Collections.singletonList("<amount>");
}
}
return Collections.emptyList();
return Collections.emptyList();
}
}
}
@@ -20,115 +20,115 @@ import net.trueog.utilitiesog.UtilitiesOG;
public class BountyTopCmd {
public static boolean handleCmd(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI, CommandSender sender,
Command cmd, String cmdName, String[] args)
{
public static boolean handleCmd(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI, CommandSender sender,
Command cmd, String cmdName, String[] args)
{
if (sender instanceof Player player) {
if (sender instanceof Player player) {
new MainBountyGui(plugin, player, () -> buildGuiEntries(plugin), diamondBankAPI).open();
new MainBountyGui(plugin, player, () -> buildGuiEntries(plugin), diamondBankAPI).open();
return true;
return true;
}
}
sendTextTopList(plugin, diamondBankAPI, sender);
sendTextTopList(plugin, diamondBankAPI, sender);
return true;
return true;
}
}
private static List<MainBountyGui.BountyGuiEntry> buildGuiEntries(PlayerBountiesOG plugin) {
private static List<MainBountyGui.BountyGuiEntry> buildGuiEntries(PlayerBountiesOG plugin) {
final Set<Map.Entry<UUID, Double>> bountiesSet = plugin.getBountyDataManager().getBounties().entrySet();
final List<Map.Entry<UUID, Double>> bounties = new ArrayList<>(bountiesSet);
final Set<Map.Entry<UUID, Double>> bountiesSet = plugin.getBountyDataManager().getBounties().entrySet();
final List<Map.Entry<UUID, Double>> bounties = new ArrayList<>(bountiesSet);
bounties.sort((a, b) -> Double.compare(b.getValue(), a.getValue()));
bounties.sort((a, b) -> Double.compare(b.getValue(), a.getValue()));
final List<MainBountyGui.BountyGuiEntry> entries = new ArrayList<>();
for (Map.Entry<UUID, Double> entry : bounties) {
final List<MainBountyGui.BountyGuiEntry> entries = new ArrayList<>();
for (Map.Entry<UUID, Double> entry : bounties) {
if (entry.getValue() == null || entry.getValue() <= 0D) {
if (entry.getValue() == null || entry.getValue() <= 0D) {
continue;
continue;
}
}
final OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(entry.getKey());
String targetName = offlinePlayer.getName();
final OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(entry.getKey());
String targetName = offlinePlayer.getName();
if (targetName == null || targetName.isBlank()) {
if (targetName == null || targetName.isBlank()) {
targetName = "Unknown Player";
targetName = "Unknown Player";
}
}
entries.add(new MainBountyGui.BountyGuiEntry(entry.getKey(), targetName, entry.getValue()));
entries.add(new MainBountyGui.BountyGuiEntry(entry.getKey(), targetName, entry.getValue()));
}
}
return entries;
return entries;
}
}
private static void sendTextTopList(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI,
CommandSender sender)
{
private static void sendTextTopList(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI,
CommandSender sender)
{
final Set<Map.Entry<UUID, Double>> bountiesSet = plugin.getBountyDataManager().getBounties().entrySet();
final List<Map.Entry<UUID, Double>> bounties = new ArrayList<>(bountiesSet);
final Set<Map.Entry<UUID, Double>> bountiesSet = plugin.getBountyDataManager().getBounties().entrySet();
final List<Map.Entry<UUID, Double>> bounties = new ArrayList<>(bountiesSet);
bounties.sort((a, b) -> Double.compare(b.getValue(), a.getValue()));
bounties.sort((a, b) -> Double.compare(b.getValue(), a.getValue()));
final StringBuilder strb = new StringBuilder();
strb.append(plugin.getLang().getColored("command.bounty.top.top-10")).append('\n');
final StringBuilder strb = new StringBuilder();
strb.append(plugin.getLang().getColored("command.bounty.top.top-10")).append('\n');
final int bountiesSize = bounties.size();
final int maxInList = Math.min(10, bountiesSize);
if (bountiesSize > 0) {
final int bountiesSize = bounties.size();
final int maxInList = Math.min(10, bountiesSize);
if (bountiesSize > 0) {
for (int i = 0; i < maxInList; i++) {
for (int i = 0; i < maxInList; i++) {
final Map.Entry<UUID, Double> entry = bounties.get(i);
final OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(entry.getKey());
final Map.Entry<UUID, Double> entry = bounties.get(i);
final OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(entry.getKey());
String targetName = offlinePlayer.getName();
if (targetName == null || targetName.isBlank()) {
String targetName = offlinePlayer.getName();
if (targetName == null || targetName.isBlank()) {
targetName = "Unknown Player";
targetName = "Unknown Player";
}
}
final String formattedBounty = diamondBankAPI
.shardsToDiamonds(diamondBankAPI.diamondsToShards(entry.getValue()));
final String formattedBounty = diamondBankAPI
.shardsToDiamonds(diamondBankAPI.diamondsToShards(entry.getValue()));
strb.append("&7 - ");
strb.append(targetName);
strb.append(": ");
strb.append(formattedBounty);
strb.append('\n');
strb.append("&7 - ");
strb.append(targetName);
strb.append(": ");
strb.append(formattedBounty);
strb.append('\n');
}
}
} else {
} else {
strb.append(plugin.getLang().getColored("command.bounty.top.no-bounties")).append('\n');
strb.append(plugin.getLang().getColored("command.bounty.top.no-bounties")).append('\n');
}
}
String message = strb.toString();
message = StringUtils.substring(message, 0, message.length() - 1);
String message = strb.toString();
message = StringUtils.substring(message, 0, message.length() - 1);
if (!(sender instanceof Player)) {
if (!(sender instanceof Player)) {
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), message);
UtilitiesOG.logToConsole(PlayerBountiesOG.getPrefix(), message);
} else {
} else {
UtilitiesOG.trueogMessage((Player) sender, message);
UtilitiesOG.trueogMessage((Player) sender, message);
}
}
}
}
}
@@ -20,335 +20,337 @@ import net.trueog.gxui.GUIItem;
public class MainBountyGui extends GUIBase {
private static final List<Integer> PYRAMID_SLOTS = List.of(4, 12, 13, 14, 20, 21, 22, 23, 24, 28, 29, 30, 31, 32,
33, 34, 36, 37, 38, 39, 40, 41, 42, 43, 44);
private static final List<Integer> PYRAMID_SLOTS = List.of(4, 12, 13, 14, 20, 21, 22, 23, 24, 28, 29, 30, 31, 32,
33, 34, 36, 37, 38, 39, 40, 41, 42, 43, 44);
private static final int PREVIOUS_PAGE_SLOT = 47;
private static final int PAGE_INFO_SLOT = 49;
private static final int NEXT_PAGE_SLOT = 51;
private static final int CLOSE_SLOT = 53;
private static final int PREVIOUS_PAGE_SLOT = 47;
private static final int PAGE_INFO_SLOT = 49;
private static final int NEXT_PAGE_SLOT = 51;
private static final int CLOSE_SLOT = 53;
private static final Pattern MINECRAFT_USERNAME_PATTERN = Pattern.compile("^[A-Za-z0-9_]{1,16}$");
private static final Pattern MINECRAFT_USERNAME_PATTERN = Pattern.compile("^[A-Za-z0-9_]{1,16}$");
private final PlayerBountiesOG plugin;
private final Player viewer;
private final Supplier<List<BountyGuiEntry>> bountySupplier;
private final DiamondBankAPIJava diamondBankAPI;
private final int page;
private final PlayerBountiesOG plugin;
private final Player viewer;
private final Supplier<List<BountyGuiEntry>> bountySupplier;
private final DiamondBankAPIJava diamondBankAPI;
private final int page;
public MainBountyGui(PlayerBountiesOG plugin, Player viewer, Supplier<List<BountyGuiEntry>> bountySupplier,
DiamondBankAPIJava diamondBankAPI) {
public MainBountyGui(PlayerBountiesOG plugin, Player viewer, Supplier<List<BountyGuiEntry>> bountySupplier,
DiamondBankAPIJava diamondBankAPI)
{
this(plugin, viewer, bountySupplier, 0, diamondBankAPI);
this(plugin, viewer, bountySupplier, 0, diamondBankAPI);
}
}
private MainBountyGui(PlayerBountiesOG plugin, Player viewer, Supplier<List<BountyGuiEntry>> bountySupplier,
int page, DiamondBankAPIJava diamondBankAPITransporter) {
private MainBountyGui(PlayerBountiesOG plugin, Player viewer, Supplier<List<BountyGuiEntry>> bountySupplier,
int page, DiamondBankAPIJava diamondBankAPITransporter)
{
super(plugin, viewer, plugin.getLang().getColored("gui.main.title"), 54, true);
super(plugin, viewer, plugin.getLang().getColored("gui.main.title"), 54, true);
this.plugin = plugin;
this.viewer = viewer;
this.bountySupplier = bountySupplier;
this.diamondBankAPI = diamondBankAPITransporter;
this.page = Math.max(0, page);
this.plugin = plugin;
this.viewer = viewer;
this.bountySupplier = bountySupplier;
this.diamondBankAPI = diamondBankAPITransporter;
this.page = Math.max(0, page);
}
}
public void open() {
public void open() {
super.open(false);
super.open(false);
}
}
@Override
public void setupItems() {
@Override
public void setupItems() {
final List<BountyGuiEntry> sortedBounties = getSortedBounties();
final int maxPage = getMaxPage(sortedBounties);
final int currentPage = Math.min(page, maxPage);
final List<BountyGuiEntry> sortedBounties = getSortedBounties();
final int maxPage = getMaxPage(sortedBounties);
final int currentPage = Math.min(page, maxPage);
addNavigationItems(currentPage, maxPage, sortedBounties.size());
addNavigationItems(currentPage, maxPage, sortedBounties.size());
if (sortedBounties.isEmpty()) {
if (sortedBounties.isEmpty()) {
addItem(22,
createStaticItem(Material.WRITABLE_BOOK, "&6&lNo Active Bounties",
List.of("&7Nobody currently has a bounty.", "&7Place one with your bounty command to get",
"&7this leaderboard populated again.")));
return;
addItem(22,
createStaticItem(Material.WRITABLE_BOOK, "&6&lNo Active Bounties",
List.of("&7Nobody currently has a bounty.", "&7Place one with your bounty command to get",
"&7this leaderboard populated again.")));
return;
}
}
final int startIndex = currentPage * PYRAMID_SLOTS.size();
final int endIndex = Math.min(startIndex + PYRAMID_SLOTS.size(), sortedBounties.size());
final int startIndex = currentPage * PYRAMID_SLOTS.size();
final int endIndex = Math.min(startIndex + PYRAMID_SLOTS.size(), sortedBounties.size());
int pyramidIndex = 0;
for (int i = startIndex; i < endIndex; i++) {
int pyramidIndex = 0;
for (int i = startIndex; i < endIndex; i++) {
final BountyGuiEntry entry = sortedBounties.get(i);
final int globalRank = i + 1;
final BountyGuiEntry entry = sortedBounties.get(i);
final int globalRank = i + 1;
addItem(PYRAMID_SLOTS.get(pyramidIndex), createBountyItem(entry, globalRank));
addItem(PYRAMID_SLOTS.get(pyramidIndex), createBountyItem(entry, globalRank));
pyramidIndex++;
pyramidIndex++;
}
}
}
}
private void addNavigationItems(int currentPage, int maxPage, int totalBounties) {
private void addNavigationItems(int currentPage, int maxPage, int totalBounties) {
if (currentPage > 0) {
if (currentPage > 0) {
addItem(PREVIOUS_PAGE_SLOT, createButtonItem(Material.ARROW, "&a&lPrevious Page",
List.of("&7Go to page &f" + currentPage), new GUIButton() {
addItem(PREVIOUS_PAGE_SLOT, createButtonItem(Material.ARROW, "&a&lPrevious Page",
List.of("&7Go to page &f" + currentPage), new GUIButton()
{
@Override
public boolean leftClick() {
@Override
public boolean leftClick() {
return openPage(currentPage - 1);
return openPage(currentPage - 1);
}
}
@Override
public boolean leftClickShift() {
@Override
public boolean leftClickShift() {
return openPage(currentPage - 1);
return openPage(currentPage - 1);
}
}
@Override
public boolean rightClick() {
@Override
public boolean rightClick() {
return openPage(currentPage - 1);
return openPage(currentPage - 1);
}
}
@Override
public boolean rightClickShift() {
@Override
public boolean rightClickShift() {
return openPage(currentPage - 1);
return openPage(currentPage - 1);
}
}
}));
}));
} else {
} else {
addItem(PREVIOUS_PAGE_SLOT,
createStaticItem(Material.GRAY_DYE, "&7Previous Page", List.of("&8Already on the first page.")));
addItem(PREVIOUS_PAGE_SLOT,
createStaticItem(Material.GRAY_DYE, "&7Previous Page", List.of("&8Already on the first page.")));
}
}
addItem(PAGE_INFO_SLOT,
createStaticItem(Material.BOOK, "&3&lPage " + (currentPage + 1) + "/" + (maxPage + 1),
List.of("&6Active bounties: &c" + totalBounties)));
addItem(PAGE_INFO_SLOT, createStaticItem(Material.BOOK, "&3&lPage " + (currentPage + 1) + "/" + (maxPage + 1),
List.of("&6Active bounties: &c" + totalBounties)));
if (currentPage < maxPage) {
if (currentPage < maxPage) {
addItem(NEXT_PAGE_SLOT, createButtonItem(Material.ARROW, "&a&lNext Page",
List.of("&7Go to page &f" + (currentPage + 2)), new GUIButton()
{
addItem(NEXT_PAGE_SLOT, createButtonItem(Material.ARROW, "&a&lNext Page",
List.of("&7Go to page &f" + (currentPage + 2)), new GUIButton()
{
@Override
public boolean leftClick() {
@Override
public boolean leftClick() {
return openPage(currentPage + 1);
return openPage(currentPage + 1);
}
}
@Override
public boolean leftClickShift() {
@Override
public boolean leftClickShift() {
return openPage(currentPage + 1);
return openPage(currentPage + 1);
}
}
@Override
public boolean rightClick() {
@Override
public boolean rightClick() {
return openPage(currentPage + 1);
return openPage(currentPage + 1);
}
}
@Override
public boolean rightClickShift() {
@Override
public boolean rightClickShift() {
return openPage(currentPage + 1);
return openPage(currentPage + 1);
}
}
}));
}));
} else {
} else {
addItem(NEXT_PAGE_SLOT,
createStaticItem(Material.GRAY_DYE, "&7Next Page", List.of("&8Already on the last page.")));
addItem(NEXT_PAGE_SLOT,
createStaticItem(Material.GRAY_DYE, "&7Next Page", List.of("&8Already on the last page.")));
}
}
addItem(CLOSE_SLOT,
createButtonItem(Material.BARRIER, "&c&lClose", List.of("&7Close the bounty menu."), new GUIButton()
{
addItem(CLOSE_SLOT,
createButtonItem(Material.BARRIER, "&c&lClose", List.of("&7Close the bounty menu."), new GUIButton()
{
@Override
public boolean leftClick() {
@Override
public boolean leftClick() {
viewer.closeInventory();
viewer.closeInventory();
return true;
return true;
}
}
@Override
public boolean leftClickShift() {
@Override
public boolean leftClickShift() {
viewer.closeInventory();
viewer.closeInventory();
return true;
return true;
}
}
@Override
public boolean rightClick() {
@Override
public boolean rightClick() {
viewer.closeInventory();
viewer.closeInventory();
return true;
return true;
}
}
@Override
public boolean rightClickShift() {
@Override
public boolean rightClickShift() {
viewer.closeInventory();
viewer.closeInventory();
return true;
return true;
}
}
}));
}));
}
}
private boolean openPage(int targetPage) {
private boolean openPage(int targetPage) {
new MainBountyGui(plugin, viewer, bountySupplier, targetPage, diamondBankAPI).open();
new MainBountyGui(plugin, viewer, bountySupplier, targetPage, diamondBankAPI).open();
return true;
return true;
}
}
private GUIItem createBountyItem(BountyGuiEntry entry, int rank) {
private GUIItem createBountyItem(BountyGuiEntry entry, int rank) {
final String targetName = safeName(entry.targetName());
final ArrayList<String> lore = new ArrayList<>();
final String targetName = safeName(entry.targetName());
final ArrayList<String> lore = new ArrayList<>();
lore.add("&cRank: &f#" + rank);
lore.add("&cTarget: &f" + targetName);
lore.add("&cBounty: &b" + formatBounty(entry.bountyDiamonds()));
lore.add("");
lore.add("&6Claiming the bounty will give you a 50% chance of beheading the victim.");
lore.add("&cRank: &f#" + rank);
lore.add("&cTarget: &f" + targetName);
lore.add("&cBounty: &b" + formatBounty(entry.bountyDiamonds()));
lore.add("");
lore.add("&6Claiming the bounty will give you a 50% chance of beheading the victim.");
final GUIItem item;
if (isUsableHeadName(targetName)) {
final GUIItem item;
if (isUsableHeadName(targetName)) {
item = new GUIItem(Material.PLAYER_HEAD, 1, " &f" + targetName, targetName);
item = new GUIItem(Material.PLAYER_HEAD, 1, " &f" + targetName, targetName);
} else {
} else {
item = new GUIItem(Material.PAPER, 1, "&6&l#" + rank + " &f" + targetName);
item = new GUIItem(Material.PAPER, 1, "&6&l#" + rank + " &f" + targetName);
}
}
item.lore(lore);
item.setPlayErrorSound(false);
item.lore(lore);
item.setPlayErrorSound(false);
return item;
return item;
}
}
private String formatBounty(double bountyDiamonds) {
private String formatBounty(double bountyDiamonds) {
final long shards = diamondBankAPI.diamondsToShards(bountyDiamonds);
final long shards = diamondBankAPI.diamondsToShards(bountyDiamonds);
return diamondBankAPI.shardsToDiamonds(shards) + " Diamonds";
return diamondBankAPI.shardsToDiamonds(shards) + " Diamonds";
}
}
private GUIItem createStaticItem(Material material, String displayName, List<String> lore) {
private GUIItem createStaticItem(Material material, String displayName, List<String> lore) {
final GUIItem item = new GUIItem(material, 1, displayName);
item.lore(new ArrayList<>(lore));
item.setPlayErrorSound(false);
final GUIItem item = new GUIItem(material, 1, displayName);
item.lore(new ArrayList<>(lore));
item.setPlayErrorSound(false);
return item;
return item;
}
}
private GUIItem createButtonItem(Material material, String displayName, List<String> lore, GUIButton button) {
private GUIItem createButtonItem(Material material, String displayName, List<String> lore, GUIButton button) {
final GUIItem item = new GUIItem(material, 1, displayName);
item.lore(new ArrayList<>(lore));
item.setButton(button);
item.setPlayErrorSound(false);
final GUIItem item = new GUIItem(material, 1, displayName);
item.lore(new ArrayList<>(lore));
item.setButton(button);
item.setPlayErrorSound(false);
return item;
return item;
}
}
private List<BountyGuiEntry> getSortedBounties() {
private List<BountyGuiEntry> getSortedBounties() {
final List<BountyGuiEntry> supplied = bountySupplier.get();
if (supplied == null || supplied.isEmpty()) {
final List<BountyGuiEntry> supplied = bountySupplier.get();
if (supplied == null || supplied.isEmpty()) {
return Collections.emptyList();
return Collections.emptyList();
}
}
final List<BountyGuiEntry> sorted = new ArrayList<>(supplied);
sorted.removeIf(entry -> entry == null || entry.bountyDiamonds() <= 0D);
sorted.sort(Comparator.comparingDouble(BountyGuiEntry::bountyDiamonds).reversed()
.thenComparing(entry -> safeName(entry.targetName()), String.CASE_INSENSITIVE_ORDER));
final List<BountyGuiEntry> sorted = new ArrayList<>(supplied);
sorted.removeIf(entry -> entry == null || entry.bountyDiamonds() <= 0D);
sorted.sort(Comparator.comparingDouble(BountyGuiEntry::bountyDiamonds).reversed()
.thenComparing(entry -> safeName(entry.targetName()), String.CASE_INSENSITIVE_ORDER));
return sorted;
return sorted;
}
}
private int getMaxPage(List<BountyGuiEntry> bounties) {
private int getMaxPage(List<BountyGuiEntry> bounties) {
if (bounties.isEmpty()) {
if (bounties.isEmpty()) {
return 0;
return 0;
}
}
return (bounties.size() - 1) / PYRAMID_SLOTS.size();
return (bounties.size() - 1) / PYRAMID_SLOTS.size();
}
}
private String safeName(String name) {
private String safeName(String name) {
if (name == null || name.isBlank()) {
if (name == null || name.isBlank()) {
return "Unknown Player";
return "Unknown Player";
}
}
return name;
return name;
}
}
private boolean isUsableHeadName(String name) {
private boolean isUsableHeadName(String name) {
return name != null && !name.isBlank() && !"Unknown Player".equals(name)
&& MINECRAFT_USERNAME_PATTERN.matcher(name).matches();
return name != null && !name.isBlank() && !"Unknown Player".equals(name)
&& MINECRAFT_USERNAME_PATTERN.matcher(name).matches();
}
}
public static record BountyGuiEntry(UUID targetUuid, String targetName, double bountyDiamonds) {
}
public static record BountyGuiEntry(UUID targetUuid, String targetName, double bountyDiamonds) {
}
}
@@ -23,251 +23,251 @@ import net.trueog.utilitiesog.UtilitiesOG;
public class DeathListener implements Listener {
private final PlayerBountiesOG plugin;
private final DiamondBankAPIJava diamondBankAPI;
private final LuckPerms luckPerms;
private final PlayerBountiesOG plugin;
private final DiamondBankAPIJava diamondBankAPI;
private final LuckPerms luckPerms;
public DeathListener(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI, LuckPerms luckPerms) {
public DeathListener(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI, LuckPerms luckPerms) {
this.plugin = plugin;
this.diamondBankAPI = diamondBankAPI;
this.luckPerms = luckPerms;
this.plugin = plugin;
this.diamondBankAPI = diamondBankAPI;
this.luckPerms = luckPerms;
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent event) {
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent event) {
final Player victim = event.getEntity();
final Player killer = victim.getKiller();
final Player victim = event.getEntity();
final Player killer = victim.getKiller();
if (killer == null) {
if (killer == null) {
return;
return;
}
}
if (!killer.hasPermission("playerbountiesplus.event.claim")) {
if (!killer.hasPermission("playerbountiesplus.event.claim")) {
UtilitiesOG.trueogMessage(killer, plugin.getLang().getColored("death.no-permission"));
return;
UtilitiesOG.trueogMessage(killer, plugin.getLang().getColored("death.no-permission"));
return;
}
}
final BountyDataManager bountyDataManager = this.plugin.getBountyDataManager();
final UUID victimId = victim.getUniqueId();
final BountyDataManager bountyDataManager = this.plugin.getBountyDataManager();
final UUID victimId = victim.getUniqueId();
if (!bountyDataManager.hasBounty(victimId)) {
if (!bountyDataManager.hasBounty(victimId)) {
return;
return;
}
}
final TeamHook teamHook = this.plugin.getTeamHook();
if (teamHook != null && teamHook.isFriendly(killer, victim)) {
final TeamHook teamHook = this.plugin.getTeamHook();
if (teamHook != null && teamHook.isFriendly(killer, victim)) {
UtilitiesOG.trueogMessage(killer, plugin.getLang().getColored("death.same-team"));
return;
UtilitiesOG.trueogMessage(killer, plugin.getLang().getColored("death.same-team"));
return;
}
}
final double bounty = bountyDataManager.getBounty(victimId);
if (bounty <= 0D) {
final double bounty = bountyDataManager.getBounty(victimId);
if (bounty <= 0D) {
bountyDataManager.removeBounty(victimId);
bountyDataManager.saveBountiesAsync();
return;
bountyDataManager.removeBounty(victimId);
bountyDataManager.saveBountiesAsync();
return;
}
}
final BountyClaimEvent claimEvent = new BountyClaimEvent(killer, victim, bounty);
this.plugin.getServer().getPluginManager().callEvent(claimEvent);
final BountyClaimEvent claimEvent = new BountyClaimEvent(killer, victim, bounty);
this.plugin.getServer().getPluginManager().callEvent(claimEvent);
if (claimEvent.isCancelled()) {
if (claimEvent.isCancelled()) {
return;
return;
}
}
final boolean bountyClaimable = plugin.getConfig().getBoolean("bounty-claimable", true);
final double claimMultiplier = plugin.getConfig().getDouble("bounty-claim-multiplier", 1.0D);
final double awardedAmount = Math.max(0D, bounty * claimMultiplier);
final boolean bountyClaimable = plugin.getConfig().getBoolean("bounty-claimable", true);
final double claimMultiplier = plugin.getConfig().getDouble("bounty-claim-multiplier", 1.0D);
final double awardedAmount = Math.max(0D, bounty * claimMultiplier);
if (bountyClaimable && awardedAmount > 0D) {
if (bountyClaimable && awardedAmount > 0D) {
try {
try {
this.plugin.getEcoHook().giveEco(killer, victim, awardedAmount);
this.plugin.getEcoHook().giveEco(killer, victim, awardedAmount);
} catch (RuntimeException runtimeException) {
} catch (RuntimeException runtimeException) {
plugin.getLogger().severe("Failed to award bounty payout to " + killer.getName() + " for killing "
+ victim.getName() + ": " + runtimeException.getMessage());
runtimeException.printStackTrace();
plugin.getLogger().severe("Failed to award bounty payout to " + killer.getName() + " for killing "
+ victim.getName() + ": " + runtimeException.getMessage());
runtimeException.printStackTrace();
UtilitiesOG.trueogMessage(killer,
"&cAn error occurred while awarding the bounty payout. The bounty was not removed.");
return;
UtilitiesOG.trueogMessage(killer,
"&cAn error occurred while awarding the bounty payout. The bounty was not removed.");
return;
}
}
}
}
// Suppress the normal Minecraft death message because this death is being
// handled as a bounty claim.
event.deathMessage(null);
// Suppress the normal Minecraft death message because this death is being
// handled as a bounty claim.
event.deathMessage(null);
if (plugin.getConfig().getBoolean("bounty-claimed-announce", true)) {
if (plugin.getConfig().getBoolean("bounty-claimed-announce", true)) {
final String killerDisplay = formatLuckPermsDisplay(killer);
final String victimDisplay = formatLuckPermsDisplay(victim);
final String bountyDisplay = formatDiamonds(bounty);
final String awardedDisplay = formatDiamonds(awardedAmount);
final String killerDisplay = formatLuckPermsDisplay(killer);
final String victimDisplay = formatLuckPermsDisplay(victim);
final String bountyDisplay = formatDiamonds(bounty);
final String awardedDisplay = formatDiamonds(awardedAmount);
final String message;
if (bountyClaimable && awardedAmount > 0D) {
final String message;
if (bountyClaimable && awardedAmount > 0D) {
if (Double.compare(awardedAmount, bounty) == 0) {
if (Double.compare(awardedAmount, bounty) == 0) {
message = killerDisplay + " &akilled " + victimDisplay + " &aand earned the &b" + awardedDisplay
+ " &abounty!";
message = killerDisplay + " &akilled " + victimDisplay + " &aand earned the &b" + awardedDisplay
+ " &abounty!";
} else {
} else {
message = killerDisplay + " &akilled " + victimDisplay + " &aand claimed the &b" + bountyDisplay
+ " &abounty for &b" + awardedDisplay + "&a!";
message = killerDisplay + " &akilled " + victimDisplay + " &aand claimed the &b" + bountyDisplay
+ " &abounty for &b" + awardedDisplay + "&a!";
}
}
} else {
} else {
message = killerDisplay + " &akilled " + victimDisplay + " &aand claimed the &b" + bountyDisplay
+ " &abounty!";
message = killerDisplay + " &akilled " + victimDisplay + " &aand claimed the &b" + bountyDisplay
+ " &abounty!";
}
}
Bukkit.getOnlinePlayers().forEach(player -> UtilitiesOG.trueogMessage(player, message));
Bukkit.getOnlinePlayers().forEach(player -> UtilitiesOG.trueogMessage(player, message));
}
}
bountyDataManager.removeBounty(victimId);
bountyDataManager.saveBountiesAsync();
bountyDataManager.removeBounty(victimId);
bountyDataManager.saveBountiesAsync();
}
}
private String formatDiamonds(double diamonds) {
private String formatDiamonds(double diamonds) {
try {
try {
return diamondBankAPI.shardsToDiamonds(diamondBankAPI.diamondsToShards(diamonds));
return diamondBankAPI.shardsToDiamonds(diamondBankAPI.diamondsToShards(diamonds));
} catch (RuntimeException runtimeException) {
} catch (RuntimeException runtimeException) {
return String.valueOf(diamonds);
return String.valueOf(diamonds);
}
}
}
}
private String formatLuckPermsDisplay(Player player) {
private String formatLuckPermsDisplay(Player player) {
final String prefix = stripLeadingReset(stripTrailingReset(getLuckPermsPrefixLegacy(player)));
final String leadingColorCodes = extractLeadingColorCodes(prefix);
final String prefix = stripLeadingReset(stripTrailingReset(getLuckPermsPrefixLegacy(player)));
final String leadingColorCodes = extractLeadingColorCodes(prefix);
if (prefix.isBlank()) {
if (prefix.isBlank()) {
return player.getName();
return player.getName();
}
}
if (leadingColorCodes.isBlank()) {
if (leadingColorCodes.isBlank()) {
return prefix + " " + player.getName();
return prefix + " " + player.getName();
}
}
return prefix + " " + leadingColorCodes + player.getName();
return prefix + " " + leadingColorCodes + player.getName();
}
}
private String getLuckPermsPrefixLegacy(Player player) {
private String getLuckPermsPrefixLegacy(Player player) {
if (luckPerms == null) {
if (luckPerms == null) {
return "";
return "";
}
}
final User user = luckPerms.getUserManager().getUser(player.getUniqueId());
if (user == null) {
final User user = luckPerms.getUserManager().getUser(player.getUniqueId());
if (user == null) {
return "";
return "";
}
}
final CachedMetaData meta = user.getCachedData().getMetaData();
final String prefix = meta.getPrefix();
final CachedMetaData meta = user.getCachedData().getMetaData();
final String prefix = meta.getPrefix();
if (prefix == null || prefix.isBlank()) {
if (prefix == null || prefix.isBlank()) {
return "";
return "";
}
}
return StringUtils.trim(prefix).replace('§', '&');
return StringUtils.trim(prefix).replace('§', '&');
}
}
private static String stripTrailingReset(String input) {
private static String stripTrailingReset(String input) {
if (input == null || input.isBlank()) {
if (input == null || input.isBlank()) {
return "";
return "";
}
}
return StringUtils.trim(input.replaceAll("(?i)(?:\\s*(?:<reset>|[&§]r))+$", ""));
return StringUtils.trim(input.replaceAll("(?i)(?:\\s*(?:<reset>|[&§]r))+$", ""));
}
}
private static String stripLeadingReset(String input) {
private static String stripLeadingReset(String input) {
if (input == null || input.isBlank()) {
if (input == null || input.isBlank()) {
return "";
return "";
}
}
return StringUtils.trim(input.replaceFirst("(?i)^(?:\\s*(?:<reset>|[&§]r))+", ""));
return StringUtils.trim(input.replaceFirst("(?i)^(?:\\s*(?:<reset>|[&§]r))+", ""));
}
}
private static String extractLeadingColorCodes(String input) {
private static String extractLeadingColorCodes(String input) {
if (input == null || input.length() < 2) {
if (input == null || input.length() < 2) {
return "";
return "";
}
}
final StringBuilder out = new StringBuilder();
for (int i = 0; i < input.length() - 1; i++) {
final StringBuilder out = new StringBuilder();
for (int i = 0; i < input.length() - 1; i++) {
final char current = input.charAt(i);
if (current != '&' && current != '§') {
final char current = input.charAt(i);
if (current != '&' && current != '§') {
break;
break;
}
}
out.append(current).append(input.charAt(i + 1));
out.append(current).append(input.charAt(i + 1));
i++;
i++;
}
}
return out.toString();
return out.toString();
}
}
}
@@ -23,11 +23,15 @@ public class GuiProtectionListener implements Listener {
public void onInventoryClick(InventoryClickEvent event) {
if (!isMainBountyGui(event.getView())) {
return;
}
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
event.setCancelled(true);
}
}
@@ -36,15 +40,21 @@ public class GuiProtectionListener implements Listener {
public void onInventoryDrag(InventoryDragEvent event) {
if (!isMainBountyGui(event.getView())) {
return;
}
final int topInventorySize = event.getView().getTopInventory().getSize();
for (int rawSlot : event.getRawSlots()) {
if (rawSlot < topInventorySize) {
event.setCancelled(true);
return;
}
}
}
@@ -53,7 +63,9 @@ public class GuiProtectionListener implements Listener {
final HumanEntity player = view.getPlayer();
if (player == null) {
return false;
}
return view.getTitle().equals(plugin.getLang().getColored("gui.main.title"));