diff --git a/pom.xml b/pom.xml
index dddb0b6b9..1aae7472a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.lokka30
LevelledMobs
- 3.7.0 b691
+ 3.7.0 b693
jar
LevelledMobs
The Ultimate RPG Mob Levelling Plugin
diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonMobOptions.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonMobOptions.java
index 64259a19a..1a0234920 100644
--- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonMobOptions.java
+++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonMobOptions.java
@@ -1,6 +1,7 @@
package me.lokka30.levelledmobs.commands.subcommands;
-import me.lokka30.levelledmobs.misc.LivingEntityPlaceHolder;
+import me.lokka30.levelledmobs.misc.LivingEntityPlaceholder;
+import me.lokka30.levelledmobs.misc.LivingEntityPlaceholder;
import me.lokka30.levelledmobs.misc.RequestedLevel;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -8,18 +9,20 @@
public class SummonMobOptions {
- SummonMobOptions(@NotNull final LivingEntityPlaceHolder lmPlaceHolder,
- final CommandSender sender) {
- this.lmPlaceHolder = lmPlaceHolder;
+ SummonMobOptions(
+ @NotNull final LivingEntityPlaceholder lmPlaceholder,
+ @NotNull final CommandSender sender
+ ) {
+ this.lmPlaceholder = lmPlaceholder;
this.sender = sender;
}
- @NotNull final LivingEntityPlaceHolder lmPlaceHolder;
+ public final LivingEntityPlaceholder lmPlaceholder;
public final CommandSender sender;
- SummonSubcommand.SummonType summonType;
+ public SummonSubcommand.SummonType summonType;
public int amount;
- RequestedLevel requestedLevel;
+ public RequestedLevel requestedLevel;
public Player player;
public boolean override;
- String nbtData;
+ public String nbtData;
}
diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonSubcommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonSubcommand.java
index 122734224..b420e608b 100644
--- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonSubcommand.java
+++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonSubcommand.java
@@ -14,7 +14,7 @@
import me.lokka30.levelledmobs.managers.LevelManager;
import me.lokka30.levelledmobs.misc.AdditionalLevelInformation;
import me.lokka30.levelledmobs.misc.LevellableState;
-import me.lokka30.levelledmobs.misc.LivingEntityPlaceHolder;
+import me.lokka30.levelledmobs.misc.LivingEntityPlaceholder;
import me.lokka30.levelledmobs.misc.LivingEntityWrapper;
import me.lokka30.levelledmobs.misc.RequestedLevel;
import me.lokka30.levelledmobs.util.PaperUtils;
@@ -39,6 +39,7 @@
* Summons a levelled mob with a specific level and criteria
*
* @author stumper66
+ * @author lokka30
* @since v2.0.0
*/
public class SummonSubcommand extends MessagesBase implements Subcommand {
@@ -48,8 +49,12 @@ public SummonSubcommand(final LevelledMobs main) {
}
@Override
- public void parseSubcommand(final LevelledMobs main, final @NotNull CommandSender sender,
- final String label, @NotNull final String @NotNull [] args) {
+ public void parseSubcommand(
+ @NotNull final LevelledMobs main,
+ @NotNull final CommandSender sender,
+ @NotNull final String label,
+ @NotNull final String... args
+ ) {
commandSender = sender;
messageLabel = label;
@@ -169,7 +174,7 @@ private void parseSubcommand2(final String @NotNull [] args, final boolean overr
return;
}
- final LivingEntityPlaceHolder lmPlaceHolder = LivingEntityPlaceHolder.getInstance(
+ final LivingEntityPlaceholder lmPlaceHolder = LivingEntityPlaceholder.getInstance(
entityType, location, main);
final SummonMobOptions options = new SummonMobOptions(lmPlaceHolder, commandSender);
@@ -213,7 +218,7 @@ private void parseSubcommand2(final String @NotNull [] args, final boolean overr
return;
}
- final LivingEntityPlaceHolder lmPlaceHolder = LivingEntityPlaceHolder.getInstance(
+ final LivingEntityPlaceholder lmPlaceHolder = LivingEntityPlaceholder.getInstance(
entityType, location, main);
final SummonMobOptions options = new SummonMobOptions(lmPlaceHolder, commandSender);
options.amount = amount;
@@ -261,7 +266,7 @@ private void parseSubcommand2(final String @NotNull [] args, final boolean overr
if (location == null || location.getWorld() == null) {
showMessage("command.levelledmobs.summon.atLocation.invalid-location");
} else {
- final LivingEntityPlaceHolder lmPlaceHolder = LivingEntityPlaceHolder.getInstance(
+ final LivingEntityPlaceholder lmPlaceHolder = LivingEntityPlaceholder.getInstance(
entityType, location, main);
final SummonMobOptions options = new SummonMobOptions(lmPlaceHolder,
commandSender);
@@ -395,30 +400,30 @@ enum SummonType {
private void summonMobs(@NotNull final SummonMobOptions options) {
final CommandSender sender = options.sender;
- final LevelledMobs main = options.lmPlaceHolder.getMainInstance();
+ final LevelledMobs main = options.lmPlaceholder.getMainInstance();
final Player target = options.player;
- Location location = options.lmPlaceHolder.getLocation();
+ Location location = options.lmPlaceholder.getLocation();
if (main.levelManager.FORCED_BLOCKED_ENTITY_TYPES.contains(
- options.lmPlaceHolder.getEntityType())) {
+ options.lmPlaceholder.getEntityType())) {
List messages = main.messagesCfg.getStringList(
"command.levelledmobs.summon.not-levellable");
messages = Utils.replaceAllInList(messages, "%prefix%", main.configUtils.getPrefix());
messages = Utils.replaceAllInList(messages, "%entity%",
- options.lmPlaceHolder.getTypeName());
+ options.lmPlaceholder.getTypeName());
messages = Utils.colorizeAllInList(messages);
messages.forEach(sender::sendMessage);
return;
}
if (!sender.isOp() && !options.override
- && main.levelInterface.getLevellableState(options.lmPlaceHolder)
+ && main.levelInterface.getLevellableState(options.lmPlaceholder)
!= LevellableState.ALLOWED) {
List messages = main.messagesCfg.getStringList(
"command.levelledmobs.summon.not-levellable");
messages = Utils.replaceAllInList(messages, "%prefix%", main.configUtils.getPrefix());
messages = Utils.replaceAllInList(messages, "%entity%",
- options.lmPlaceHolder.getTypeName());
+ options.lmPlaceholder.getTypeName());
messages = Utils.colorizeAllInList(messages);
messages.forEach(sender::sendMessage);
return;
@@ -445,7 +450,7 @@ private void summonMobs(@NotNull final SummonMobOptions options) {
messages.forEach(sender::sendMessage);
}
- final int[] levels = main.levelManager.getMinAndMaxLevels(options.lmPlaceHolder);
+ final int[] levels = main.levelManager.getMinAndMaxLevels(options.lmPlaceholder);
final int minLevel = levels[0];
final int maxLevel = levels[1];
@@ -515,11 +520,12 @@ private void summonMobs(@NotNull final SummonMobOptions options) {
options.requestedLevel.level;
final Entity entity = location.getWorld()
- .spawnEntity(location, options.lmPlaceHolder.getEntityType());
+ .spawnEntity(location, options.lmPlaceholder.getEntityType());
if (entity instanceof LivingEntity) {
- final LivingEntityWrapper lmEntity = LivingEntityWrapper.getInstance(
- (LivingEntity) entity, main);
+ final LivingEntityWrapper lmEntity = LivingEntityWrapper
+ .getInstance((LivingEntity) entity, main);
+
lmEntity.setSummonedLevel(useLevel);
lmEntity.isNewlySpawned = true;
synchronized (LevelManager.summonedOrSpawnEggs_Lock) {
@@ -542,20 +548,21 @@ private void summonMobs(@NotNull final SummonMobOptions options) {
switch (options.summonType) {
case HERE -> showMessage("command.levelledmobs.summon.here.success",
new String[]{"%amount%", "%level%", "%entity%"},
+ new String[]{String.valueOf(options.amount), options.requestedLevel.toString(),
+ options.lmPlaceholder.getTypeName()}
+ );
+ case AT_LOCATION -> showMessage("command.levelledmobs.summon.atLocation.success",
+ new String[]{"%amount%", "%level%", "%entity%", "%x%", "%y%", "%z%", "%world%"},
new String[]{
String.valueOf(options.amount),
options.requestedLevel.toString(),
- options.lmPlaceHolder.getTypeName()
+ options.lmPlaceholder.getTypeName(),
+ Integer.toString(location.getBlockX()),
+ Integer.toString(location.getBlockY()),
+ Integer.toString(location.getBlockZ()),
+ location.getWorld() == null ? "(null)" : location.getWorld().getName()
}
);
- case AT_LOCATION -> showMessage("command.levelledmobs.summon.atLocation.success",
- new String[]{"%amount%", "%level%", "%entity%", "%x%", "%x%", "%x%", "%world%"},
- new String[]{String.valueOf(options.amount), options.requestedLevel.toString(),
- options.lmPlaceHolder.getTypeName(),
- String.valueOf(location.getBlockX()), String.valueOf(location.getBlockY()),
- String.valueOf(location.getBlockX()),
- location.getWorld() == null ? "(null)" : location.getWorld().getName()}
- );
case AT_PLAYER -> {
final String playerName = VersionUtils.isRunningPaper() ?
@@ -565,7 +572,7 @@ private void summonMobs(@NotNull final SummonMobOptions options) {
new String[]{"%amount%", "%level%", "%entity%", "%targetUsername%",
"%targetDisplayname%"},
new String[]{String.valueOf(options.amount), options.requestedLevel.toString(),
- options.lmPlaceHolder.getTypeName(),
+ options.lmPlaceholder.getTypeName(),
target == null ? "(null)" : target.getName(),
target == null ? "(null)" : playerName}
);
diff --git a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityPlaceHolder.java b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityPlaceholder.java
similarity index 87%
rename from src/main/java/me/lokka30/levelledmobs/misc/LivingEntityPlaceHolder.java
rename to src/main/java/me/lokka30/levelledmobs/misc/LivingEntityPlaceholder.java
index 42d36761e..0f1718d64 100644
--- a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityPlaceHolder.java
+++ b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityPlaceholder.java
@@ -21,20 +21,24 @@
* @author stumper66
* @since 3.0.0
*/
-public class LivingEntityPlaceHolder extends LivingEntityWrapperBase implements
- LivingEntityInterface {
+public class LivingEntityPlaceholder
+ extends LivingEntityWrapperBase
+ implements
+ LivingEntityInterface
+{
- private LivingEntityPlaceHolder(final @NotNull LevelledMobs main) {
+ private LivingEntityPlaceholder(final @NotNull LevelledMobs main) {
super(main);
}
private EntityType entityType;
private final static Object cachedPlaceHolders_Lock = new Object();
- private final static Stack cache = new Stack<>();
+ private final static Stack cache = new Stack<>();
- @NotNull public static LivingEntityPlaceHolder getInstance(final EntityType entityType,
+ @NotNull
+ public static LivingEntityPlaceholder getInstance(final EntityType entityType,
final @NotNull Location location, final @NotNull LevelledMobs main) {
- final LivingEntityPlaceHolder leph;
+ final LivingEntityPlaceholder leph;
if (location.getWorld() == null) {
throw new NullPointerException("World can't be null");
@@ -42,7 +46,7 @@ private LivingEntityPlaceHolder(final @NotNull LevelledMobs main) {
synchronized (cachedPlaceHolders_Lock) {
if (cache.empty()) {
- leph = new LivingEntityPlaceHolder(main);
+ leph = new LivingEntityPlaceholder(main);
} else {
leph = cache.pop();
}
diff --git a/src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java b/src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java
index 2d90d34b9..f0709b743 100644
--- a/src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java
+++ b/src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java
@@ -5,6 +5,8 @@
import me.lokka30.levelledmobs.LevelledMobs;
import me.lokka30.levelledmobs.managers.ExternalCompatibilityManager;
import me.lokka30.levelledmobs.util.Utils;
+import me.lokka30.microlib.messaging.MessageUtils;
+import me.lokka30.microlib.other.VersionUtils;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -19,13 +21,7 @@ public class NMSHandler {
public NMSHandler(final @NotNull LevelledMobs main) {
this.main = main;
- boolean hasKiori = false;
- try {
- Class.forName("net.kyori.adventure.text.Component");
- hasKiori = true;
- } catch (ClassNotFoundException ignored) { }
-
- this.hasKiori = hasKiori;
+ this.hasPaper = VersionUtils.isRunningPaper();
parseBukkitVersion();
}
@@ -36,7 +32,7 @@ public NMSHandler(final @NotNull LevelledMobs main) {
private NMSUtil currentUtil;
public double minecraftVersion;
public boolean isUsingProtocolLib;
- public final boolean hasKiori;
+ public final boolean hasPaper;
private void parseBukkitVersion() {
// example: org.bukkit.craftbukkit.v1_18_R2.CraftServer
@@ -75,10 +71,10 @@ private void parseBukkitVersion() {
// supported is paper >= 1.18 or spigot >= 1.19
// otherwise protocollib is used
- if (hasKiori && this.minecraftVersion >= 1.18 ||
- !hasKiori && this.minecraftVersion >= 1.19) {
+ if (hasPaper && this.minecraftVersion >= 1.18 ||
+ !hasPaper && this.minecraftVersion >= 1.19) {
// 1.18 and newer we support with direct nms
- this.currentUtil = new NametagSender(nmsVersionString, hasKiori);
+ this.currentUtil = new NametagSender(nmsVersionString, hasPaper);
Utils.logger.info(
String.format("Using NMS version %s for nametag support", nmsVersionString));
} else if (ExternalCompatibilityManager.hasProtocolLibInstalled()) {
diff --git a/src/main/java/me/lokka30/levelledmobs/nms/NametagSender.java b/src/main/java/me/lokka30/levelledmobs/nms/NametagSender.java
index 403953a05..4d55d2d30 100644
--- a/src/main/java/me/lokka30/levelledmobs/nms/NametagSender.java
+++ b/src/main/java/me/lokka30/levelledmobs/nms/NametagSender.java
@@ -14,7 +14,6 @@
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
-import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -79,7 +78,6 @@ public void sendNametag(final @NotNull LivingEntity livingEntity, @NotNull Namet
}
}
- @SuppressWarnings("deprecation")
private @NotNull Optional buildNametagComponent(final @NotNull LivingEntity livingEntity,
final @NotNull NametagResult nametag){
if (nametag.isNullOrEmpty())
@@ -118,7 +116,7 @@ public void sendNametag(final @NotNull LivingEntity livingEntity, @NotNull Namet
null;
final Component mobNameComponent = nametag.overriddenName == null ?
- Component.translatable(Bukkit.getUnsafe().getTranslationKey(livingEntity.getType())) :
+ Component.translatable(getTranslationKey(livingEntity.getType())) :
Component.literal(nametag.overriddenName);
MutableComponent comp = Component.empty();
@@ -138,6 +136,11 @@ public void sendNametag(final @NotNull LivingEntity livingEntity, @NotNull Namet
return Optional.of(comp);
}
+ @SuppressWarnings("deprecation")
+ private String getTranslationKey(final org.bukkit.entity.@NotNull EntityType type) {
+ return net.minecraft.world.entity.EntityType.byString(type.getName()).map(net.minecraft.world.entity.EntityType::getDescriptionId).orElse(null);
+ }
+
private void buildReflection(){
try {
this.clazz_CraftChatMessage = Class.forName(