use of dev.rosewood.rosestacker.nms.NMSHandler in project RoseStacker by Rosewood-Development.
the class ItemUtils method getStackedItemEntityType.
public static EntityType getStackedItemEntityType(ItemStack itemStack) {
if (itemStack.getType() != Material.SPAWNER)
return null;
// First, check our NBT value
NMSHandler nmsHandler = NMSAdapter.getHandler();
String entityTypeName = nmsHandler.getItemStackNBTString(itemStack, "EntityType");
if (!entityTypeName.isEmpty()) {
try {
return EntityType.valueOf(entityTypeName);
} catch (Exception ignored) {
}
}
// Try formats from other plugins/servers
// Purpur servers
entityTypeName = nmsHandler.getItemStackNBTString(itemStack, "Purpur.mob_type");
// EpicSpawners Pre-v7
if (entityTypeName.isEmpty())
entityTypeName = nmsHandler.getItemStackNBTString(itemStack, "type").toUpperCase().replace(' ', '_');
// EpicSpawners Post-v7
if (entityTypeName.isEmpty())
entityTypeName = nmsHandler.getItemStackNBTString(itemStack, "data");
if (!entityTypeName.isEmpty()) {
try {
NamespacedKey entityTypeKey = NamespacedKey.fromString(entityTypeName);
for (EntityType entityType : EntityType.values()) if (entityType != EntityType.UNKNOWN && entityType.getKey().equals(entityTypeKey) || entityTypeName.equalsIgnoreCase(entityType.name()))
return EntityType.valueOf(entityTypeName);
} catch (Exception ignored) {
}
}
// Try checking the spawner data then?
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null)
return EntityType.PIG;
BlockStateMeta blockStateMeta = (BlockStateMeta) itemMeta;
CreatureSpawner creatureSpawner = (CreatureSpawner) blockStateMeta.getBlockState();
if (creatureSpawner.getSpawnedType() != EntityType.PIG)
return creatureSpawner.getSpawnedType();
// Use the name to determine the type, name must be colored
String name = ChatColor.stripColor(itemMeta.getDisplayName());
if (!name.equals(itemMeta.getDisplayName())) {
try {
// This tries to support other spawner plugins by checking the item name
name = name.toUpperCase();
int spawnerIndex = name.indexOf("SPAWNER");
String entityName = name.substring(0, spawnerIndex).trim();
return EntityType.valueOf(entityName.replaceAll(" ", "_"));
} catch (Exception ignored) {
}
}
return EntityType.PIG;
}
use of dev.rosewood.rosestacker.nms.NMSHandler in project RoseStacker by Rosewood-Development.
the class ItemUtils method getStackedItemStackAmount.
public static int getStackedItemStackAmount(ItemStack itemStack) {
NMSHandler nmsHandler = NMSAdapter.getHandler();
int stackSize = nmsHandler.getItemStackNBTInt(itemStack, "StackSize");
return Math.max(stackSize, 1);
}
use of dev.rosewood.rosestacker.nms.NMSHandler in project RoseStacker by Rosewood-Development.
the class ItemUtils method getSpawnerAsStackedItemStack.
public static ItemStack getSpawnerAsStackedItemStack(EntityType entityType, int amount) {
ItemStack itemStack = new ItemStack(Material.SPAWNER);
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null)
return itemStack;
SpawnerStackSettings stackSettings = RoseStacker.getInstance().getManager(StackSettingManager.class).getSpawnerStackSettings(entityType);
StringPlaceholders placeholders = StringPlaceholders.builder("amount", amount).addPlaceholder("name", stackSettings.getDisplayName()).build();
String displayString;
if (amount == 1) {
displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("spawner-stack-display-single", placeholders);
} else {
displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("spawner-stack-display", placeholders);
}
itemMeta.setDisplayName(displayString);
// Set the lore, if defined
List<String> lore = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessages("stack-item-lore-spawner", placeholders);
if (!lore.isEmpty())
itemMeta.setLore(lore);
// Set the spawned type directly onto the spawner item for hopeful compatibility with other plugins
BlockStateMeta blockStateMeta = (BlockStateMeta) itemMeta;
CreatureSpawner creatureSpawner = (CreatureSpawner) blockStateMeta.getBlockState();
creatureSpawner.setSpawnedType(entityType);
blockStateMeta.setBlockState(creatureSpawner);
itemStack.setItemMeta(itemMeta);
// Set stack size and spawned entity type
NMSHandler nmsHandler = NMSAdapter.getHandler();
itemStack = nmsHandler.setItemStackNBT(itemStack, "StackSize", amount);
itemStack = nmsHandler.setItemStackNBT(itemStack, "EntityType", entityType.name());
return itemStack;
}
use of dev.rosewood.rosestacker.nms.NMSHandler in project RoseStacker by Rosewood-Development.
the class StackerUtils method deconstructStackedEntities.
public static List<LivingEntity> deconstructStackedEntities(StackedEntity stackedEntity) {
List<StackedEntityDataEntry<?>> stackedEntityDataEntry = stackedEntity.getStackedEntityNBT().getAll();
List<LivingEntity> livingEntities = new ArrayList<>(stackedEntityDataEntry.size());
Location location = stackedEntity.getLocation();
NMSHandler nmsHandler = NMSAdapter.getHandler();
for (StackedEntityDataEntry<?> nbt : stackedEntityDataEntry) livingEntities.add(nmsHandler.createEntityFromNBT(nbt, location, false, stackedEntity.getEntity().getType()));
return livingEntities;
}
use of dev.rosewood.rosestacker.nms.NMSHandler in project RoseStacker by Rosewood-Development.
the class PersistentDataUtils method applyDisabledAi.
public static void applyDisabledAi(LivingEntity entity) {
if (isAiDisabled(entity) || Setting.ENTITY_DISABLE_ALL_MOB_AI.getBoolean()) {
if (Setting.SPAWNER_DISABLE_MOB_AI_OPTIONS_REMOVE_GOALS.getBoolean()) {
NMSHandler nmsHandler = NMSAdapter.getHandler();
nmsHandler.removeEntityGoals(entity);
}
if (Setting.SPAWNER_DISABLE_MOB_AI_OPTIONS_SILENCE.getBoolean())
entity.setSilent(true);
if (Setting.SPAWNER_DISABLE_MOB_AI_OPTIONS_NO_KNOCKBACK.getBoolean()) {
// Make the entity unable to take knockback
AttributeInstance knockbackAttribute = entity.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
if (knockbackAttribute != null)
knockbackAttribute.setBaseValue(Double.MAX_VALUE);
}
}
}
Aggregations