Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.playgroundhc.spawn;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Villager;
- import org.bukkit.plugin.java.JavaPlugin;
- import pl.playgroundhc.spawn.actions.compassClick;
- import pl.playgroundhc.spawn.events.joinEvent;
- import pl.playgroundhc.spawn.events.npcClick;
- import pl.playgroundhc.spawn.events.spawnProt;
- import java.util.Objects;
- import java.util.UUID;
- public final class Spawn extends JavaPlugin {
- public static boolean doesEntityExist(UUID uuid, World world) {
- if (world != null) {
- for (Entity entity : world.getEntities()) {
- if (entity.getUniqueId().equals(uuid)) {
- return true;
- }
- }
- }
- return false;
- }
- private void createAndSaveNPC() {
- Location survivalNPCLocation = new Location(Bukkit.getWorld("spawn"), 17.466, 5, 8.646);
- survivalNPC = (Villager) Objects.requireNonNull(Bukkit.getWorld("spawn")).spawnEntity(survivalNPCLocation, EntityType.VILLAGER);
- survivalNPC.setAI(false);
- survivalNPC.setCollidable(false);
- survivalNPC.setCustomName(ChatColor.GREEN + "Survival");
- survivalNPC.setCustomNameVisible(true);
- survivalNPC.setRotation(survivalNPC.getLocation().getYaw() + 90, 0);
- getConfig().set("playgroundhc.npc.survival.uuid", survivalNPC.getUniqueId().toString());
- saveConfig();
- }
- private static Spawn instance;
- public static Spawn getInstance() {
- return instance;
- }
- private Villager survivalNPC;
- @Override
- public void onEnable() {
- instance = this;
- getServer().getPluginManager().registerEvents(new joinEvent(), this);
- getServer().getPluginManager().registerEvents(new npcClick(), this);
- getServer().getPluginManager().registerEvents(new compassClick(), this);
- this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
- getServer().getPluginManager().registerEvents(new spawnProt(), this);
- reloadConfig();
- String survivalID = getConfig().getString("playgroundhc.npc.survival.uuid");
- UUID survivalUUID;
- if (survivalID != null){
- survivalUUID = UUID.fromString(survivalID);
- if (!doesEntityExist(survivalUUID,Bukkit.getWorld("survival"))){
- createAndSaveNPC();
- }
- }
- else{
- createAndSaveNPC();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment