Okay, so I am attempting to make a custom spawners plugin, but I've already hit a bit issue.. I cannot figure out how to change what creature the spawner summons. The code I have currently can be found below (This is a SpawnerSpawnEvent, also everything works other than the spawning of the skeleton, The console gets sent the 'File exists' message, The file does indeed exist (This is done in the block place event, I will also include this below, not sure if it is needed.) so I am very confused on how I could achieve this..) Thank you in advance for your time.
SpawnerSpawnEvent »
package me.askingg.events;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import me.askingg.golems.Main;
public class CreatureSpawn implements Listener {
Main plugin;
@EventHandler
public void coalSpawn(SpawnerSpawnEvent event) {
CreatureSpawner spawner = (CreatureSpawner) event.getSpawner().getBlock().getState();
Location location = spawner.getLocation();
String world = spawner.getWorld().getName().toString();
File locationFile = new File("plugins/Golems/Locations", world + " - " + location.getBlockX() + "-"
+ location.getBlockY() + "-" + location.getBlockZ() + ".yml");
if (locationFile.exists()) {
Bukkit.getConsoleSender().sendMessage(Main.colorCodes(Main.prefix + "&fThe file exists..."));
spawner.setSpawnedType(EntityType.SKELETON);
spawner.update();
}
}
}
BlockPlaceEvent »
package me.askingg.events;
import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import me.askingg.golems.Main;
public class BlockPlace implements Listener {
@EventHandler
public void spawnerPlace(BlockPlaceEvent event) {
Player player = (Player) event.getPlayer();
Block block = event.getBlock();
Location location = block.getLocation();
String world = block.getWorld().getName().toString();
if (block.getType().equals(Material.SPAWNER)) {
if (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName()
.equals(Main.colorCodes("&fSkeleton Spawner"))) {
File locationFile = new File("plugins/Golems/Locations", world + " - " + location.getBlockX() + "-"
+ location.getBlockY() + "-" + location.getBlockZ() + ".yml");
if (!(locationFile.exists())) {
try {
locationFile.createNewFile();
Bukkit.getConsoleSender()
.sendMessage(Main.colorCodes(Main.prefix
+ "&aSuccessfully&f created a new &fSkeleton Spawner&f location &8(&a"
+ world + " &8-&a " + location.getBlockX() + "&8-&a" + location.getBlockY() + "&8-&a"
+ location.getBlockZ() + "&8)"));
} catch (IOException e) {
}
}
}
}
}
}