Guest User

Untitled

a guest
Nov 27th, 2023
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1. package pl.playgroundhc.spawn;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.World;
  7. import org.bukkit.entity.Entity;
  8. import org.bukkit.entity.EntityType;
  9. import org.bukkit.entity.Villager;
  10. import org.bukkit.plugin.java.JavaPlugin;
  11. import pl.playgroundhc.spawn.actions.compassClick;
  12. import pl.playgroundhc.spawn.events.joinEvent;
  13. import pl.playgroundhc.spawn.events.npcClick;
  14. import pl.playgroundhc.spawn.events.spawnProt;
  15.  
  16. import java.util.Objects;
  17. import java.util.UUID;
  18.  
  19. public final class Spawn extends JavaPlugin {
  20.     public static boolean doesEntityExist(UUID uuid, World world) {
  21.         if (world != null) {
  22.             for (Entity entity : world.getEntities()) {
  23.                 if (entity.getUniqueId().equals(uuid)) {
  24.                     return true;
  25.                 }
  26.             }
  27.         }
  28.         return false;
  29.     }
  30.     private void createAndSaveNPC() {
  31.         Location survivalNPCLocation = new Location(Bukkit.getWorld("spawn"), 17.466, 5, 8.646);
  32.         survivalNPC = (Villager) Objects.requireNonNull(Bukkit.getWorld("spawn")).spawnEntity(survivalNPCLocation, EntityType.VILLAGER);
  33.         survivalNPC.setAI(false);
  34.         survivalNPC.setCollidable(false);
  35.         survivalNPC.setCustomName(ChatColor.GREEN + "Survival");
  36.         survivalNPC.setCustomNameVisible(true);
  37.         survivalNPC.setRotation(survivalNPC.getLocation().getYaw() + 90, 0);
  38.  
  39.         getConfig().set("playgroundhc.npc.survival.uuid", survivalNPC.getUniqueId().toString());
  40.         saveConfig();
  41.     }
  42.  
  43.  
  44.     private static Spawn instance;
  45.  
  46.     public static Spawn getInstance() {
  47.         return instance;
  48.     }
  49.     private Villager survivalNPC;
  50.     @Override
  51.     public void onEnable() {
  52.         instance = this;
  53.         getServer().getPluginManager().registerEvents(new joinEvent(), this);
  54.         getServer().getPluginManager().registerEvents(new npcClick(), this);
  55.         getServer().getPluginManager().registerEvents(new compassClick(), this);
  56.         this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
  57.         getServer().getPluginManager().registerEvents(new spawnProt(), this);
  58.  
  59.         reloadConfig();
  60.         String survivalID = getConfig().getString("playgroundhc.npc.survival.uuid");
  61.         UUID survivalUUID;
  62.         if (survivalID != null){
  63.             survivalUUID = UUID.fromString(survivalID);
  64.             if (!doesEntityExist(survivalUUID,Bukkit.getWorld("survival"))){
  65.                 createAndSaveNPC();
  66.             }
  67.         }
  68.         else{
  69.             createAndSaveNPC();
  70.         }
  71.  
  72.  
  73.  
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment