Files
src
build.gradle
Code
4 241
src/main/java/com/kodari/reefleggings/ReefLeggingsPlugin.java
package com.kodari.reefleggings;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public final class ReefLeggingsPlugin extends JavaPlugin implements CommandExecutor {
private final Map<UUID, ReefLeggingsModel> models = new HashMap<>();
@Override
public void onEnable() {
getCommand("reefleggings").setExecutor(this);
}
@Override
public void onDisable() {
models.values().forEach(ReefLeggingsModel::remove);
models.clear();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("This command can only be used in-game.");
return true;
}
UUID playerId = player.getUniqueId();
if (args.length > 0 && args[0].equalsIgnoreCase("remove")) {
ReefLeggingsModel model = models.remove(playerId);
if (model == null) {
player.sendMessage(ChatColor.YELLOW + "You do not have an active reef leggings model.");
} else {
model.remove();
player.sendMessage(ChatColor.GREEN + "Removed your reef leggings model.");
}
return true;
}
ReefLeggingsModel previous = models.remove(playerId);
if (previous != null) {
previous.remove();
}
ReefLeggingsModel model = new ReefLeggingsModel(this, player.getLocation().add(2.0, 0.0, 0.0));
models.put(playerId, model);
player.sendMessage(ChatColor.AQUA + "Spawned the animated axolotl reef leggings. Use /reefleggings remove to clear it.");
return true;
}
}