This commit is contained in:
BuildTools committed 2024-02-01 15:38:22 +05:00
1 parent 407f3ccf0b
commit f9bf102504
3 files changed
+28 -6

No files matched your search

@@ -1,5 +1,7 @@
package su.nightexpress.nightcore;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.command.base.ReloadSubCommand;
import su.nightexpress.nightcore.config.PluginDetails;
@@ -11,7 +13,8 @@ import su.nightexpress.nightcore.core.command.CheckPermCommand;
import su.nightexpress.nightcore.dialog.Dialog;
import su.nightexpress.nightcore.integration.VaultHook;
import su.nightexpress.nightcore.language.LangAssets;
import su.nightexpress.nightcore.menu.impl.EditorMenu;
import su.nightexpress.nightcore.util.EntityUtil;
import su.nightexpress.nightcore.util.ItemUtil;
import su.nightexpress.nightcore.util.Plugins;
import su.nightexpress.nightcore.util.blocktracker.PlayerBlockTracker;
@@ -38,6 +41,7 @@ public class NightCore extends NightPlugin {
}
this.getBaseCommand().addChildren(new ReloadSubCommand(this, CorePerms.COMMAND_RELOAD));
this.testMethods();
this.coreManager.setup();
}
@@ -70,4 +74,16 @@ public class NightCore extends NightPlugin {
public Set<NightCorePlugin> getChildrens() {
return new HashSet<>(this.childrens);
}
private void testMethods() {
if (EntityUtil.ENTITY_COUNTER == null) {
this.warn("Entity Id Counter: NULL!");
}
else this.info("Entity Id Counter: OK.");
if (ItemUtil.compress(new ItemStack(Material.DIAMOND_SWORD)) == null) {
this.warn("Item NBT Compress: FAILED!");
}
else this.info("Item NBT Compress: OK.");
}
}
@@ -10,17 +10,22 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.util.random.Rnd;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
public class EntityUtil {
/*@Deprecated
public static boolean isNPC(@NotNull Entity entity) {
return entity.hasMetadata("NPC");
}*/
private static final Class<?> NMS_ENTITY = Reflex.getClass("net.minecraft.world.entity", "Entity");
private static final String ENTITY_COUNTER_NAME = Version.isAtLeast(Version.V1_19_R3) ? "d" : "c";
public static final AtomicInteger ENTITY_COUNTER = (AtomicInteger) Reflex.getFieldValue(NMS_ENTITY, ENTITY_COUNTER_NAME);
public static int nextEntityId() {
return ENTITY_COUNTER == null ? Rnd.nextInt(9999) : ENTITY_COUNTER.incrementAndGet();
}
public static double getAttribute(@NotNull LivingEntity entity, @NotNull Attribute attribute) {
AttributeInstance instance = entity.getAttribute(attribute);
@@ -277,7 +277,8 @@ public class ItemUtil {
@Nullable
public static String compress(@NotNull ItemStack item) {
if (NBT_TAG_COMPOUND_NEW == null || AS_NMS_COPY == null || NMS_SAVE == null || NBT_IO_WRITE == null) {
throw new UnsupportedOperationException("Unsupported server version!");
//throw new UnsupportedOperationException("Unsupported server version!");
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();