Search in sources :

Example 11 with TileEntityMobSpawner

use of net.minecraft.server.v1_16_R3.TileEntityMobSpawner 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)

Example 12 with TileEntityMobSpawner

use of net.minecraft.server.v1_16_R3.TileEntityMobSpawner 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(IRegistry.ENTITY_TYPE.get(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_16_R2.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_16_R2.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Example 13 with TileEntityMobSpawner

use of net.minecraft.server.v1_16_R3.TileEntityMobSpawner 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_R3.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_16_R3.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_16_R3.MinecraftKey)

Example 14 with TileEntityMobSpawner

use of net.minecraft.server.v1_16_R3.TileEntityMobSpawner 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.UPPER_CAMEL, mobID.replace(" ", "_"));
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        tile.getSpawner().setMobName(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_8_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_8_R1.TileEntityMobSpawner)

Example 15 with TileEntityMobSpawner

use of net.minecraft.server.v1_16_R3.TileEntityMobSpawner 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(IRegistry.ENTITY_TYPE.get(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_16_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_16_R1.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_16_R1.MinecraftKey)

Aggregations

WildLoadersPlugin (com.bgsoftware.wildloaders.WildLoadersPlugin)8 Hologram (com.bgsoftware.wildloaders.api.holograms.Hologram)8 ChunkLoader (com.bgsoftware.wildloaders.api.loaders.ChunkLoader)8 ChunkLoaderNPC (com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC)8 ITileEntityChunkLoader (com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader)8 WChunkLoader (com.bgsoftware.wildloaders.loaders.WChunkLoader)8 Collection (java.util.Collection)8 Collections (java.util.Collections)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 UUID (java.util.UUID)8 Location (org.bukkit.Location)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TileEntityMobSpawner (net.minecraft.server.v1_16_R3.TileEntityMobSpawner)6 TileEntityMobSpawner (net.minecraft.server.v1_12_R1.TileEntityMobSpawner)5 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)4 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)3 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)3 TileEntityMobSpawner (net.minecraft.server.v1_16_R2.TileEntityMobSpawner)3