Add world whitelist
This commit is contained in:
1 parent
ead1832422
commit
031bc8347d
6 files changed
+108
-3
No files matched your search
@@ -18,6 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.tcoded.playerbountiesplus.PlayerBountiesOG;
|
||||
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
|
||||
import com.tcoded.playerbountiesplus.util.BountyWorldUtil;
|
||||
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.cacheddata.CachedMetaData;
|
||||
@@ -54,6 +55,14 @@ public class BountyAddCmd {
|
||||
|
||||
}
|
||||
|
||||
if (!BountyWorldUtil.isBountyWorldAllowed(plugin, player)) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, plugin.getLang().getColored("command.bounty.world-not-whitelisted")
|
||||
.replace("{worlds}", BountyWorldUtil.formatBountyWorldWhitelist(plugin)));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, plugin.getLang().getColored("command.bounty.add.missing-args"));
|
||||
@@ -91,6 +100,14 @@ public class BountyAddCmd {
|
||||
double parsedAmount, boolean saveData)
|
||||
{
|
||||
|
||||
if (!BountyWorldUtil.isBountyWorldAllowed(plugin, setter)) {
|
||||
|
||||
UtilitiesOG.trueogMessage(setter, plugin.getLang().getColored("command.bounty.world-not-whitelisted")
|
||||
.replace("{worlds}", BountyWorldUtil.formatBountyWorldWhitelist(plugin)));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
final String safeTargetName = StringUtils.defaultIfBlank(targetName,
|
||||
Bukkit.getOfflinePlayer(targetUuid).getName());
|
||||
if (safeTargetName == null || safeTargetName.isBlank()) {
|
||||
@@ -345,4 +362,4 @@ public class BountyAddCmd {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import com.tcoded.playerbountiesplus.PlayerBountiesOG;
|
||||
import com.tcoded.playerbountiesplus.event.BountySetEvent;
|
||||
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
|
||||
import com.tcoded.playerbountiesplus.util.BountyWorldUtil;
|
||||
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.cacheddata.CachedMetaData;
|
||||
@@ -67,6 +68,14 @@ public class BountySetCmd {
|
||||
|
||||
}
|
||||
|
||||
if (sender instanceof Player player && !BountyWorldUtil.isBountyWorldAllowed(plugin, player)) {
|
||||
|
||||
UtilitiesOG.trueogMessage(player, plugin.getLang().getColored("command.bounty.world-not-whitelisted")
|
||||
.replace("{worlds}", BountyWorldUtil.formatBountyWorldWhitelist(plugin)));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
final String playerNameArg = args[1];
|
||||
final double parsedAmount;
|
||||
try {
|
||||
@@ -422,4 +431,4 @@ public class BountySetCmd {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import com.tcoded.playerbountiesplus.event.BountyClaimEvent;
|
||||
import com.tcoded.playerbountiesplus.hook.team.TeamHook;
|
||||
import com.tcoded.playerbountiesplus.manager.BountyDataManager;
|
||||
import com.tcoded.playerbountiesplus.util.BountyHeadData;
|
||||
import com.tcoded.playerbountiesplus.util.BountyWorldUtil;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.cacheddata.CachedMetaData;
|
||||
import net.luckperms.api.model.user.User;
|
||||
@@ -74,6 +75,14 @@ public class DeathListener implements Listener {
|
||||
|
||||
}
|
||||
|
||||
if (!BountyWorldUtil.isBountyWorldAllowed(plugin, victim.getWorld())) {
|
||||
|
||||
UtilitiesOG.trueogMessage(killer, plugin.getLang().getColored("death.world-not-whitelisted")
|
||||
.replace("{worlds}", BountyWorldUtil.formatBountyWorldWhitelist(plugin)));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
final TeamHook teamHook = this.plugin.getTeamHook();
|
||||
if (teamHook != null && teamHook.isFriendly(killer, victim)) {
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.tcoded.playerbountiesplus.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tcoded.playerbountiesplus.PlayerBountiesOG;
|
||||
|
||||
public final class BountyWorldUtil {
|
||||
|
||||
private static final String BOUNTY_WORLD_WHITELIST_KEY = "bounty-world-whitelist";
|
||||
private static final List<String> DEFAULT_BOUNTY_WORLD_WHITELIST = List.of("world", "world_nether",
|
||||
"world_the_end");
|
||||
|
||||
private BountyWorldUtil() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isBountyWorldAllowed(PlayerBountiesOG plugin, Player player) {
|
||||
|
||||
return player != null && isBountyWorldAllowed(plugin, player.getWorld());
|
||||
|
||||
}
|
||||
|
||||
public static boolean isBountyWorldAllowed(PlayerBountiesOG plugin, World world) {
|
||||
|
||||
return world != null && isBountyWorldAllowed(plugin, world.getName());
|
||||
|
||||
}
|
||||
|
||||
public static boolean isBountyWorldAllowed(PlayerBountiesOG plugin, String worldName) {
|
||||
|
||||
final List<String> worldWhitelist = getBountyWorldWhitelist(plugin);
|
||||
final boolean hasConfiguredWorld = worldWhitelist.stream().anyMatch(world -> !StringUtils.isBlank(world));
|
||||
|
||||
return !hasConfiguredWorld || worldWhitelist.stream()
|
||||
.anyMatch(world -> StringUtils.equalsIgnoreCase(StringUtils.trim(world), worldName));
|
||||
|
||||
}
|
||||
|
||||
public static String formatBountyWorldWhitelist(PlayerBountiesOG plugin) {
|
||||
|
||||
final List<String> worldWhitelist = getBountyWorldWhitelist(plugin).stream().map(StringUtils::trimToEmpty)
|
||||
.filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
||||
|
||||
return worldWhitelist.isEmpty() ? "every world" : StringUtils.join(worldWhitelist, ", ");
|
||||
|
||||
}
|
||||
|
||||
private static List<String> getBountyWorldWhitelist(PlayerBountiesOG plugin) {
|
||||
|
||||
if (plugin.getConfig().contains(BOUNTY_WORLD_WHITELIST_KEY)) {
|
||||
|
||||
return plugin.getConfig().getStringList(BOUNTY_WORLD_WHITELIST_KEY);
|
||||
|
||||
}
|
||||
|
||||
return DEFAULT_BOUNTY_WORLD_WHITELIST;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,10 @@ bounty-maximum: 1000000.0
|
||||
# If we should give the bounty money to the killer.
|
||||
bounty-claimable: true
|
||||
|
||||
# Worlds where players may set, add to, and claim bounties.
|
||||
# Leave empty to allow bounty placement and claims in every world. World names are case-insensitive.
|
||||
bounty-world-whitelist: ["world", "world_nether", "world_the_end"]
|
||||
|
||||
# Give more or less money to the killer. This value can be negative if you want to.
|
||||
bounty-claim-multiplier: 1.0
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
death:
|
||||
same-team: "&aThe player you killed has an active bounty but you are in the same team as they are!"
|
||||
no-permission: "&cYou are not allowed to claim bounties!"
|
||||
world-not-whitelisted: "&cYou can only claim bounties in these worlds: {worlds}."
|
||||
|
||||
command:
|
||||
no-permission: "&cYou don't have the permission to use this command!"
|
||||
@@ -37,6 +38,7 @@ command:
|
||||
bounty:
|
||||
no-action: "&cYou need to specify an action! /bounty <set/add/top/check>"
|
||||
invalid-action: "&cThat's not a valid action!"
|
||||
world-not-whitelisted: "&cYou can only set or increase bounties in these worlds: {worlds}."
|
||||
set:
|
||||
missing-args: "&cYou need to specify a player and an amount! /bounty set <player> <amount>"
|
||||
amount-nan: "&cThat's not a valid number!"
|
||||
@@ -69,4 +71,3 @@ command:
|
||||
gui:
|
||||
main:
|
||||
title: "&eBounties"
|
||||
|
||||
Reference in new issue
Block a user