Search in sources :

Example 1 with CraftCreatureSpawner

use of org.bukkit.craftbukkit.v1_8_R1.block.CraftCreatureSpawner in project SilkSpawners by timbru31.

the class NMSHandler method getMobNameOfSpawner.

@Override
public String getMobNameOfSpawner(final BlockState blockState) {
    // Get our spawner;
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    // Get the mob ID ourselves if we can
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        // Get the name from the field of our spawner
        final MinecraftKey minecraftKey = tile.getSpawner().getMobName();
        return minecraftKey != null ? minecraftKey.b() : "";
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return "";
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_11_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_11_R1.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_11_R1.MinecraftKey)

Example 2 with CraftCreatureSpawner

use of org.bukkit.craftbukkit.v1_8_R1.block.CraftCreatureSpawner in project SilkSpawners by timbru31.

the class NMSHandler method setMobNameOfSpawner.

@Override
public boolean setMobNameOfSpawner(final BlockState blockState, final String mobID) {
    // Prevent ResourceKeyInvalidException: Non [a-z0-9/._-] character in path of location
    final String safeMobID = caseFormatOf(mobID.replace(" ", "_")).to(CaseFormat.LOWER_UNDERSCORE, mobID.replace(" ", "_")).toLowerCase(Locale.ENGLISH);
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        tile.getSpawner().setMobName(new MinecraftKey(safeMobID));
        return true;
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return false;
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_12_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_12_R1.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_12_R1.MinecraftKey)

Example 3 with CraftCreatureSpawner

use of org.bukkit.craftbukkit.v1_8_R1.block.CraftCreatureSpawner in project SilkSpawners by timbru31.

the class NMSHandler method getMobNameOfSpawner.

@Override
public String getMobNameOfSpawner(final BlockState blockState) {
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        final MinecraftKey minecraftKey = tile.getSpawner().getMobName();
        return minecraftKey != null ? minecraftKey.getKey() : "";
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return "";
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_13_R2.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_13_R2.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_13_R2.MinecraftKey)

Example 4 with CraftCreatureSpawner

use of org.bukkit.craftbukkit.v1_8_R1.block.CraftCreatureSpawner in project SilkSpawners by timbru31.

the class NMSHandler method getMobNameOfSpawner.

@Override
public String getMobNameOfSpawner(final BlockState blockState) {
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        final MinecraftKey minecraftKey = tile.getSpawner().getMobName();
        return minecraftKey != null ? minecraftKey.getKey() : "";
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return "";
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_15_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_15_R1.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_15_R1.MinecraftKey)

Example 5 with CraftCreatureSpawner

use of org.bukkit.craftbukkit.v1_8_R1.block.CraftCreatureSpawner in project SilkSpawners by timbru31.

the class NMSHandler method getMobNameOfSpawner.

@Override
public String getMobNameOfSpawner(final BlockState blockState) {
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        final MinecraftKey minecraftKey = tile.getSpawner().getMobName();
        return minecraftKey != null ? minecraftKey.getKey() : "";
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return "";
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_16_R2.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_16_R2.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Aggregations

SpawnerBlockEntity (net.minecraft.world.level.block.entity.SpawnerBlockEntity)6 ResourceLocation (net.minecraft.resources.ResourceLocation)4 EntityType (net.minecraft.world.entity.EntityType)3 BlockEntityType (net.minecraft.world.level.block.entity.BlockEntityType)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 MinecraftKey (net.minecraft.server.v1_11_R1.MinecraftKey)2 TileEntityMobSpawner (net.minecraft.server.v1_11_R1.TileEntityMobSpawner)2 MinecraftKey (net.minecraft.server.v1_12_R1.MinecraftKey)2 TileEntityMobSpawner (net.minecraft.server.v1_12_R1.TileEntityMobSpawner)2 MinecraftKey (net.minecraft.server.v1_13_R2.MinecraftKey)2 TileEntityMobSpawner (net.minecraft.server.v1_13_R2.TileEntityMobSpawner)2 MinecraftKey (net.minecraft.server.v1_14_R1.MinecraftKey)2 TileEntityMobSpawner (net.minecraft.server.v1_14_R1.TileEntityMobSpawner)2 MinecraftKey (net.minecraft.server.v1_15_R1.MinecraftKey)2 TileEntityMobSpawner (net.minecraft.server.v1_15_R1.TileEntityMobSpawner)2 MinecraftKey (net.minecraft.server.v1_16_R1.MinecraftKey)2 TileEntityMobSpawner (net.minecraft.server.v1_16_R1.TileEntityMobSpawner)2 MinecraftKey (net.minecraft.server.v1_16_R2.MinecraftKey)2 TileEntityMobSpawner (net.minecraft.server.v1_16_R2.TileEntityMobSpawner)2 MinecraftKey (net.minecraft.server.v1_16_R3.MinecraftKey)2