Merge pull request #8 from true-og/codex/implement-bounty-gui-enhancements
Use LuckPerms ranks in bounty GUI and add global celebration on claim
This commit was merged in pull request #8.
This commit is contained in:
4 files changed
+83
-6
No files matched your search
@@ -203,6 +203,12 @@ public final class PlayerBountiesOG extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
public LuckPerms getLuckPerms() {
|
||||
|
||||
return this.luckPerms;
|
||||
|
||||
}
|
||||
|
||||
// Utilities.
|
||||
private static void findPluginWithQuery(List<Plugin> plugins, String pluginNameQuery, String... excludeStrings) {
|
||||
|
||||
@@ -291,4 +297,4 @@ public final class PlayerBountiesOG extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@ import org.bukkit.entity.Player;
|
||||
import com.tcoded.playerbountiesplus.PlayerBountiesOG;
|
||||
import com.tcoded.playerbountiesplus.gui.MainBountyGui;
|
||||
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.cacheddata.CachedMetaData;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.trueog.diamondbankog.api.DiamondBankAPIJava;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
|
||||
@@ -63,7 +66,9 @@ public class BountyTopCmd {
|
||||
|
||||
}
|
||||
|
||||
entries.add(new MainBountyGui.BountyGuiEntry(entry.getKey(), targetName, entry.getValue()));
|
||||
final String rankName = resolveLuckPermsRankName(plugin.getLuckPerms(), entry.getKey());
|
||||
|
||||
entries.add(new MainBountyGui.BountyGuiEntry(entry.getKey(), targetName, rankName, entry.getValue()));
|
||||
|
||||
}
|
||||
|
||||
@@ -71,6 +76,41 @@ public class BountyTopCmd {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static String resolveLuckPermsRankName(LuckPerms luckPerms, UUID playerId) {
|
||||
|
||||
if (luckPerms == null) {
|
||||
|
||||
return "&7Unranked";
|
||||
|
||||
}
|
||||
|
||||
final User user = luckPerms.getUserManager().getUser(playerId);
|
||||
if (user == null) {
|
||||
|
||||
return "&7Unranked";
|
||||
|
||||
}
|
||||
|
||||
final CachedMetaData meta = user.getCachedData().getMetaData();
|
||||
final String prefix = meta.getPrefix();
|
||||
if (prefix != null && !prefix.isBlank()) {
|
||||
|
||||
return StringUtils.trim(prefix).replace('§', '&');
|
||||
|
||||
}
|
||||
|
||||
final String primaryGroup = user.getPrimaryGroup();
|
||||
if (primaryGroup == null || primaryGroup.isBlank()) {
|
||||
|
||||
return "&7Unranked";
|
||||
|
||||
}
|
||||
|
||||
return "&7" + primaryGroup;
|
||||
|
||||
}
|
||||
|
||||
private static void sendTextTopList(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI,
|
||||
CommandSender sender)
|
||||
{
|
||||
|
||||
@@ -246,10 +246,12 @@ public class MainBountyGui extends GUIBase {
|
||||
private GUIItem createBountyItem(BountyGuiEntry entry, int rank) {
|
||||
|
||||
final String targetName = safeName(entry.targetName());
|
||||
final String rankName = safeRank(entry.rankName());
|
||||
final ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
lore.add("&cRank: &f#" + rank);
|
||||
lore.add("&cPosition: &f#" + rank);
|
||||
lore.add("&cTarget: &f" + targetName);
|
||||
lore.add("&cRank: " + rankName);
|
||||
lore.add("&cBounty: &b" + formatBounty(entry.bountyDiamonds()));
|
||||
lore.add("");
|
||||
lore.add("&6Claiming the bounty will give you a 50% chance of beheading the victim.");
|
||||
@@ -257,11 +259,11 @@ public class MainBountyGui extends GUIBase {
|
||||
final GUIItem item;
|
||||
if (isUsableHeadName(targetName)) {
|
||||
|
||||
item = new GUIItem(Material.PLAYER_HEAD, 1, " &f" + targetName, targetName);
|
||||
item = new GUIItem(Material.PLAYER_HEAD, 1, " " + rankName + " &f" + targetName, targetName);
|
||||
|
||||
} else {
|
||||
|
||||
item = new GUIItem(Material.PAPER, 1, "&6&l#" + rank + " &f" + targetName);
|
||||
item = new GUIItem(Material.PAPER, 1, "&6&l#" + rank + " " + rankName + " &f" + targetName);
|
||||
|
||||
}
|
||||
|
||||
@@ -343,6 +345,18 @@ public class MainBountyGui extends GUIBase {
|
||||
|
||||
}
|
||||
|
||||
private String safeRank(String rankName) {
|
||||
|
||||
if (rankName == null || rankName.isBlank()) {
|
||||
|
||||
return "&7Unranked";
|
||||
|
||||
}
|
||||
|
||||
return rankName;
|
||||
|
||||
}
|
||||
|
||||
private boolean isUsableHeadName(String name) {
|
||||
|
||||
return name != null && !name.isBlank() && !"Unknown Player".equals(name)
|
||||
@@ -350,7 +364,7 @@ public class MainBountyGui extends GUIBase {
|
||||
|
||||
}
|
||||
|
||||
public static record BountyGuiEntry(UUID targetUuid, String targetName, double bountyDiamonds) {
|
||||
public static record BountyGuiEntry(UUID targetUuid, String targetName, String rankName, double bountyDiamonds) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -153,6 +155,7 @@ public class DeathListener implements Listener {
|
||||
}
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> UtilitiesOG.trueogMessage(player, message));
|
||||
playGlobalCelebrationEffects(killer, victim);
|
||||
|
||||
}
|
||||
|
||||
@@ -170,6 +173,20 @@ public class DeathListener implements Listener {
|
||||
|
||||
}
|
||||
|
||||
private void playGlobalCelebrationEffects(Player killer, Player victim) {
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
|
||||
player.playSound(player.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1.0F, 1.0F);
|
||||
|
||||
player.spawnParticle(Particle.FIREWORK, killer.getLocation().add(0D, 1D, 0D), 40, 0.6D, 0.8D, 0.6D, 0.01D);
|
||||
player.spawnParticle(Particle.FIREWORK, victim.getLocation().add(0D, 1D, 0D), 40, 0.6D, 0.8D, 0.6D, 0.01D);
|
||||
player.spawnParticle(Particle.TOTEM, killer.getLocation().add(0D, 1D, 0D), 20, 0.5D, 0.7D, 0.5D, 0.01D);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private String formatDiamonds(double diamonds) {
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user