Files
src
build.bat
build.sh
pom.xml
README.md
Code
24 2,557
src/main/java/com/saintsean/tiertest/SaintSeanTierTest.java
package com.saintsean.tiertest;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title;
import org.bukkit.*;
import org.bukkit.command.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.*;
public class SaintSeanTierTest extends JavaPlugin implements CommandExecutor, TabCompleter {
private List<String> gamemodes = new ArrayList<>();
private Set<String> tiers = new HashSet<>();
private boolean animationsEnabled = true;
private Title.Times titleTimes = Title.Times.times(
Duration.ofMillis(500),
Duration.ofMillis(2500),
Duration.ofMillis(750)
);
private Sound pullSound = Sound.ENTITY_ENDERMAN_TELEPORT;
private float pullSoundVolume = 1.0f;
private float pullSoundPitch = 1.2f;
private Sound tierAssignedSound = Sound.UI_TOAST_CHALLENGE_COMPLETE;
private float tierAssignedSoundVolume = 1.0f;
private float tierAssignedSoundPitch = 1.1f;
private Particle particleType = Particle.TOTEM_OF_UNDYING;
private int particleCount = 35;
private final Map<String, Deque<UUID>> queues = new HashMap<>();
private final Map<String, Boolean> openQueues = new HashMap<>();
private final Map<UUID, Map<String, String>> playerTiers = new HashMap<>();
private File tiersFile;
private FileConfiguration tiersConfig;
@Override
public void onEnable() {
saveDefaultConfig();
loadSettings();
loadTiers();
for (String cmd : List.of("tierqueue", "tester", "tier")) {
PluginCommand pc = getCommand(cmd);
if (pc != null) {
pc.setExecutor(this);
pc.setTabCompleter(this);
}
}
}
@Override
public void onDisable() {
saveTiers();
}
private void loadSettings() {
reloadConfig();
FileConfiguration cfg = getConfig();
List<String> rawModes = cfg.getStringList("gamemodes");
gamemodes = rawModes.isEmpty()
? List.of("sword", "crystal", "axe", "pot", "mace", "uhc")
: rawModes.stream().map(s -> s.toLowerCase(Locale.ROOT)).toList();
List<String> rawTiers = cfg.getStringList("tiers");
tiers = rawTiers.isEmpty()
? Set.of("HT1", "LT1", "HT2", "LT2", "HT3", "LT3", "HT4", "LT4", "HT5", "LT5")
: rawTiers.stream().map(s -> s.toUpperCase(Locale.ROOT)).collect(java.util.stream.Collectors.toSet());
for (String mode : gamemodes) {
queues.putIfAbsent(mode, new ArrayDeque<>());
openQueues.putIfAbsent(mode, false);
}
animationsEnabled = cfg.getBoolean("animations.enabled", true);
long fadeInMs = cfg.getLong("animations.title-fade-in-ticks", 10) * 50L;
long stayMs = cfg.getLong("animations.title-stay-ticks", 50) * 50L;
long fadeOutMs = cfg.getLong("animations.title-fade-out-ticks", 15) * 50L;
titleTimes = Title.Times.times(Duration.ofMillis(fadeInMs), Duration.ofMillis(stayMs), Duration.ofMillis(fadeOutMs));
pullSound = parseSound(cfg.getString("animations.pull-sound"), Sound.ENTITY_ENDERMAN_TELEPORT);
pullSoundVolume = (float) cfg.getDouble("animations.pull-sound-volume", 1.0);
pullSoundPitch = (float) cfg.getDouble("animations.pull-sound-pitch", 1.2);
tierAssignedSound = parseSound(cfg.getString("animations.tier-assigned-sound"), Sound.UI_TOAST_CHALLENGE_COMPLETE);
tierAssignedSoundVolume = (float) cfg.getDouble("animations.tier-assigned-sound-volume", 1.0);
tierAssignedSoundPitch = (float) cfg.getDouble("animations.tier-assigned-sound-pitch", 1.1);
particleType = parseParticle(cfg.getString("animations.particle-type"), Particle.TOTEM_OF_UNDYING);
particleCount = Math.max(0, cfg.getInt("animations.particle-count", 35));
}
private Sound parseSound(String name, Sound fallback) {
if (name == null) return fallback;
try {
return Registry.SOUNDS.get(NamespacedKey.minecraft(name.toLowerCase(Locale.ROOT).replace('_', '.')));
} catch (Exception ignored) {
try {
return Sound.valueOf(name.toUpperCase(Locale.ROOT));
} catch (Exception ignoredToo) {
return fallback;
}
}
}
private Particle parseParticle(String name, Particle fallback) {
if (name == null) return fallback;
try {
return Particle.valueOf(name.toUpperCase(Locale.ROOT));
} catch (Exception ignored) {
return fallback;
}
}
private void playPullAnimation(Player player, String mode) {
if (!animationsEnabled) return;
Title title = Title.title(
Component.text(mode.toUpperCase(Locale.ROOT) + " TEST", NamedTextColor.GOLD),
Component.text("Get ready!", NamedTextColor.YELLOW),
titleTimes
);
player.showTitle(title);
player.playSound(player.getLocation(), pullSound, pullSoundVolume, pullSoundPitch);
if (particleCount > 0) {
player.getWorld().spawnParticle(particleType, player.getLocation().add(0, 1, 0), particleCount, 0.5, 0.7, 0.5, 0.05);
}
}
private void playTierAssignedAnimation(Player player, String mode, String tier) {
if (!animationsEnabled) return;
Title title = Title.title(
Component.text(tier, NamedTextColor.AQUA),
Component.text("Achieved in " + mode.toUpperCase(Locale.ROOT), NamedTextColor.GOLD),
titleTimes
);
player.showTitle(title);
player.playSound(player.getLocation(), tierAssignedSound, tierAssignedSoundVolume, tierAssignedSoundPitch);
if (particleCount > 0) {
player.getWorld().spawnParticle(particleType, player.getLocation().add(0, 1, 0), particleCount, 0.6, 0.8, 0.6, 0.08);
}
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return switch (command.getName().toLowerCase(Locale.ROOT)) {
case "tierqueue" -> handleQueue(sender, args);
case "tester" -> handleTester(sender, args);
case "tier" -> handleLookup(sender, args);
default -> true;
};
}
private boolean handleQueue(CommandSender sender, String[] args) {
if (!(sender instanceof Player player)) return true;
if (args.length < 2) {
player.sendMessage(Component.text("Usage: /tierqueue <join|leave> <gamemode>", NamedTextColor.YELLOW));
return true;
}
String action = args[0].toLowerCase(Locale.ROOT);
String mode = args[1].toLowerCase(Locale.ROOT);
if (!gamemodes.contains(mode)) {
player.sendMessage(Component.text("Modes: " + String.join(", ", gamemodes), NamedTextColor.RED));
return true;
}
UUID id = player.getUniqueId();
if (action.equals("join")) {
if (!openQueues.getOrDefault(mode, false)) {
player.sendMessage(Component.text(mode + " queue is closed.", NamedTextColor.RED));
return true;
}
queues.values().forEach(q -> q.remove(id));
Deque<UUID> q = queues.computeIfAbsent(mode, k -> new ArrayDeque<>());
if (!q.contains(id)) q.addLast(id);
int pos = new ArrayList<>(q).indexOf(id) + 1;
player.sendMessage(Component.text("Joined " + mode + " queue (#" + pos + ").", NamedTextColor.GREEN));
} else if (action.equals("leave")) {
boolean removed = queues.getOrDefault(mode, new ArrayDeque<>()).remove(id);
player.sendMessage(Component.text(removed ? "Left " + mode + " queue." : "Not in " + mode + " queue.", removed ? NamedTextColor.GREEN : NamedTextColor.RED));
}
return true;
}
private boolean handleTester(CommandSender sender, String[] args) {
if (!sender.hasPermission("saintseantiertest.tester")) {
sender.sendMessage(Component.text("No permission.", NamedTextColor.RED));
return true;
}
if (args.length < 1) {
sender.sendMessage(Component.text("Usage: /tester <open|close|next|settier|reload> [gamemode] [player] [tier]", NamedTextColor.YELLOW));