Files
src
build.gradle.kts
README.md
settings.gradle.kts
Code
13 1,886
src/main/java/me/doni/doniadmin/DoniAdmin.java
package me.doni.doniadmin;
import java.time.Duration;
import java.util.Locale;
import me.doni.doniadmin.gui.AdminListener;
import me.doni.doniadmin.gui.AdminPanel;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Sound;
import org.bukkit.attribute.Attribute;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public final class DoniAdmin extends JavaPlugin {
private AdminState adminState;
private TargetResolver targetResolver;
private CrateManager crateManager;
private GodItemManager godItemManager;
@Override
public void onEnable() {
saveDefaultConfig();
getConfig().options().copyDefaults(true);
saveConfig();
adminState = new AdminState();
targetResolver = new TargetResolver(this);
crateManager = new CrateManager(this);
godItemManager = new GodItemManager();
CommandHandler commandHandler = new CommandHandler(this);
for (String name : new String[]{"admpanel", "ntfy", "freeze", "unfreeze", "jail", "unjail", "setjail", "bring", "tphere", "heal", "feed", "launch", "vanish", "crate", "godgive"}) {
PluginCommand command = getCommand(name);
if (command != null) {
command.setExecutor(commandHandler);
command.setTabCompleter(commandHandler);
}
}
Bukkit.getPluginManager().registerEvents(new AdminListener(this), this);
getLogger().info("DoniAdmin 1.0.0 enabled successfully.");
}
@Override
public void onDisable() {
if (adminState != null) {
for (Player vanished : Bukkit.getOnlinePlayers()) {
if (adminState.isVanished(vanished)) {
for (Player viewer : Bukkit.getOnlinePlayers()) {
if (viewer != vanished) {
viewer.showPlayer(this, vanished);
}
}
}
}
}
getLogger().info("DoniAdmin disabled.");
}
public AdminState getAdminState() {
return adminState;
}
public TargetResolver getTargetResolver() {
return targetResolver;
}
public CrateManager getCrateManager() {
return crateManager;
}
public GodItemManager getGodItemManager() {
return godItemManager;
}
public void sendMessage(CommandSender recipient, String key, String... replacements) {
String message = getConfig().getString("messages." + key, key);
for (int i = 0; i + 1 < replacements.length; i += 2) {
message = message.replace("%" + replacements[i] + "%", replacements[i + 1]);
}
recipient.sendMessage(color(getConfig().getString("messages.prefix", "") + message));
}
public String color(String text) {
return org.bukkit.ChatColor.translateAlternateColorCodes('&', text);
}
public Location getJailLocation() {
String worldName = getConfig().getString("jail.world", "");
if (worldName == null || worldName.isBlank()) {
return null;
}
org.bukkit.World world = Bukkit.getWorld(worldName);
if (world == null) {
return null;
}
return new Location(world,
getConfig().getDouble("jail.x"),
getConfig().getDouble("jail.y"),
getConfig().getDouble("jail.z"),
(float) getConfig().getDouble("jail.yaw"),
(float) getConfig().getDouble("jail.pitch"));
}
public void setJailLocation(Location location) {
getConfig().set("jail.world", location.getWorld().getName());
getConfig().set("jail.x", location.getX());
getConfig().set("jail.y", location.getY());
getConfig().set("jail.z", location.getZ());
getConfig().set("jail.yaw", location.getYaw());
getConfig().set("jail.pitch", location.getPitch());
saveConfig();
}
public void notifyEveryone(String message) {
LegacyComponentSerializer serializer = LegacyComponentSerializer.legacyAmpersand();
net.kyori.adventure.text.Component title = serializer.deserialize(message);
net.kyori.adventure.text.Component subtitle = serializer.deserialize(getConfig().getString("notifications.subtitle", ""));
long fadeIn = Math.max(0, getConfig().getLong("notifications.fade-in", 10)) * 50L;
long stay = Math.max(0, getConfig().getLong("notifications.stay", 60)) * 50L;
long fadeOut = Math.max(0, getConfig().getLong("notifications.fade-out", 10)) * 50L;
net.kyori.adventure.title.Title.Times times = net.kyori.adventure.title.Title.Times.times(
Duration.ofMillis(fadeIn), Duration.ofMillis(stay), Duration.ofMillis(fadeOut));
net.kyori.adventure.title.Title notification = net.kyori.adventure.title.Title.title(title, subtitle, times);
for (Player player : Bukkit.getOnlinePlayers()) {
player.showTitle(notification);
playConfiguredSound(player, "notifications.sound", "ui.toast.challenge_complete",
"notifications.volume", "notifications.pitch");
}
}
public void launch(Player player) {
player.setVelocity(new org.bukkit.util.Vector(0, getConfig().getDouble("launch.strength", 1.5), 0));
if (getConfig().getBoolean("launch.particles", true)) {
String particleName = getConfig().getString("launch.particle", "cloud");
NamespacedKey particleKey = namespacedKey(particleName);
org.bukkit.Particle particle = particleKey == null ? null : Registry.PARTICLE_TYPE.get(particleKey);
if (particle == null) {
particle = Registry.PARTICLE_TYPE.get(NamespacedKey.minecraft("cloud"));
}
if (particle != null) {
player.getWorld().spawnParticle(particle, player.getLocation().add(0, 1, 0), 20, 0.25, 0.3, 0.25, 0.05);
}
}
playConfiguredSound(player, "launch.sound", "entity.firework_rocket.launch", "launch.volume", "launch.pitch");
}
public Attribute getMaximumHealthAttribute() {
return Registry.ATTRIBUTE.get(NamespacedKey.minecraft("max_health"));
}
private void playConfiguredSound(Player player, String soundPath, String fallback,
String volumePath, String pitchPath) {
String configured = getConfig().getString(soundPath, fallback);
NamespacedKey key = namespacedKey(configured);
Sound sound = key == null ? null : Registry.SOUNDS.get(key);
if (sound == null) {
NamespacedKey fallbackKey = namespacedKey(fallback);
sound = fallbackKey == null ? null : Registry.SOUNDS.get(fallbackKey);
}
if (sound != null) {
player.playSound(player.getLocation(), sound,
(float) getConfig().getDouble(volumePath, 1.0),
(float) getConfig().getDouble(pitchPath, 1.0));
}
}
private NamespacedKey namespacedKey(String value) {
if (value == null || value.isBlank()) {
return null;
}
String normalized = value.toLowerCase(Locale.ROOT);
return normalized.contains(":") ? NamespacedKey.fromString(normalized) : NamespacedKey.minecraft(normalized);
}
public void openPanel(Player player, Player target) {
new AdminPanel(this, player, target).open();
}
}