Upload folder via GUI - src
This commit is contained in:
@@ -3,18 +3,11 @@ package de.nexuslobby.modules.gadgets;
|
||||
import de.nexuslobby.NexusLobby;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fox;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
@@ -57,14 +50,6 @@ public class PetManager implements Listener {
|
||||
* Spawnt ein echtes Tier-Entity für den Spieler.
|
||||
*/
|
||||
public static void spawnEntityPet(Player player, String type) {
|
||||
spawnEntityPet(player, type, false);
|
||||
}
|
||||
|
||||
public static void spawnEntityPet(Player player, String type, boolean baby) {
|
||||
spawnEntityPet(player, type, baby, null);
|
||||
}
|
||||
|
||||
public static void spawnEntityPet(Player player, String type, boolean baby, String variantName) {
|
||||
removePet(player);
|
||||
|
||||
EntityType entityType;
|
||||
@@ -78,42 +63,15 @@ public class PetManager implements Listener {
|
||||
Location loc = player.getLocation();
|
||||
Entity pet = player.getWorld().spawnEntity(loc, entityType);
|
||||
|
||||
String agePrefix = baby ? "§bBaby " : "";
|
||||
String petName = buildPetDisplayName(type, variantName);
|
||||
pet.setCustomName(agePrefix + petName);
|
||||
pet.setCustomName("§d" + player.getName() + "'s " + capitalize(type.toLowerCase()));
|
||||
pet.setCustomNameVisible(true);
|
||||
pet.setInvulnerable(true);
|
||||
pet.setPersistent(false);
|
||||
applyNeutralPetTeam(pet);
|
||||
|
||||
if (pet instanceof LivingEntity) {
|
||||
LivingEntity le = (LivingEntity) pet;
|
||||
le.setRemoveWhenFarAway(false);
|
||||
|
||||
if (le instanceof Ageable) {
|
||||
Ageable ageable = (Ageable) le;
|
||||
if (baby) {
|
||||
ageable.setBaby();
|
||||
} else {
|
||||
ageable.setAdult();
|
||||
}
|
||||
}
|
||||
|
||||
if (le instanceof Wolf && variantName != null && !variantName.isEmpty()) {
|
||||
Wolf.Variant variant = resolveWolfVariant(variantName);
|
||||
if (variant != null) {
|
||||
((Wolf) le).setVariant(variant);
|
||||
}
|
||||
}
|
||||
|
||||
if (le instanceof Fox && variantName != null && !variantName.isEmpty()) {
|
||||
try {
|
||||
((Fox) le).setFoxType(Fox.Type.valueOf(variantName));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// Ignorieren: Unbekannte Variante
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Verhindert, dass das Pet andere angreift
|
||||
if (le instanceof Tameable) {
|
||||
((Tameable) le).setTamed(true);
|
||||
@@ -160,16 +118,13 @@ public class PetManager implements Listener {
|
||||
|
||||
public static void removePet(Player player) {
|
||||
if (activePets.containsKey(player.getUniqueId())) {
|
||||
Entity pet = activePets.get(player.getUniqueId());
|
||||
removeFromPetTeam(pet);
|
||||
pet.remove();
|
||||
activePets.get(player.getUniqueId()).remove();
|
||||
activePets.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearAll() {
|
||||
for (Entity pet : activePets.values()) {
|
||||
removeFromPetTeam(pet);
|
||||
pet.remove();
|
||||
}
|
||||
activePets.clear();
|
||||
@@ -180,49 +135,6 @@ public class PetManager implements Listener {
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
}
|
||||
|
||||
private static String buildPetDisplayName(String type, String variantName) {
|
||||
String baseType = capitalize(type.toLowerCase());
|
||||
if (variantName == null || variantName.isEmpty()) return baseType;
|
||||
String variant = capitalize(variantName.toLowerCase());
|
||||
return variant + " " + baseType;
|
||||
}
|
||||
|
||||
private static Wolf.Variant resolveWolfVariant(String variantName) {
|
||||
String keyName = variantName.toLowerCase();
|
||||
NamespacedKey key = NamespacedKey.minecraft(keyName);
|
||||
return Registry.WOLF_VARIANT.get(key);
|
||||
}
|
||||
|
||||
private static Team getOrCreatePetTeam() {
|
||||
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
Team team = scoreboard.getTeam("nexus_pets");
|
||||
if (team == null) {
|
||||
team = scoreboard.registerNewTeam("nexus_pets");
|
||||
team.setPrefix("");
|
||||
team.setSuffix("");
|
||||
}
|
||||
return team;
|
||||
}
|
||||
|
||||
private static void applyNeutralPetTeam(Entity pet) {
|
||||
Team team = getOrCreatePetTeam();
|
||||
String entry = pet.getUniqueId().toString();
|
||||
if (!team.hasEntry(entry)) {
|
||||
team.addEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeFromPetTeam(Entity pet) {
|
||||
if (pet == null) return;
|
||||
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
Team team = scoreboard.getTeam("nexus_pets");
|
||||
if (team == null) return;
|
||||
String entry = pet.getUniqueId().toString();
|
||||
if (team.hasEntry(entry)) {
|
||||
team.removeEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Events um die Pets zu schützen ---
|
||||
|
||||
@EventHandler
|
||||
|
||||
Reference in New Issue
Block a user