Untitled
unknown
plain_text
2 years ago
3.1 kB
8
Indexable
package org.lifestealsmp.npcteleport;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.plugin.java.JavaPlugin;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
public class main extends JavaPlugin implements Listener {
private List<Integer> npcIdsToTeleport = Arrays.asList(32);
@Override
public void onEnable() {
Bukkit.getServer().getPluginManager().registerEvents(this, this);
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
checkAndTeleportNPCs();
}
}, 0, 20);
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
FiveMinuteNPCTeleport();
}
}, 0, (20 * 60) * 5);
}
private void checkAndTeleportNPCs() {
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (!npc.isSpawned()) {
continue;
}
Location currentLocation = npc.getEntity().getLocation();
if (currentLocation.getY() <= 152 || currentLocation.getY() >= 160) {
// Define a list of safe locations
List<Location> safeLocations = new ArrayList<>();
World spawn = Bukkit.getServer().getWorld("spawn");
// Add locations to the list
safeLocations.add(new Location(spawn, 17, 158, 27)); // First location
safeLocations.add(new Location(spawn, 20, 154, -12)); // Add more locations as needed
safeLocations.add(new Location(spawn, -11, 154, -48));
// ... Add as many locations as you want
// Choose a random location from the list
Random random = new Random();
Location randomSafeLocation = safeLocations.get(random.nextInt(safeLocations.size()));
// Teleport the NPC to the randomly chosen location
npc.teleport(randomSafeLocation, TeleportCause.PLUGIN);
}
}
}
private void FiveMinuteNPCTeleport() {
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (!npc.isSpawned() || !npcIdsToTeleport.contains(npc.getId())) {
continue;
}
// Define a list of safe locations
List<Location> safeLocations = new ArrayList<>();
World spawn = Bukkit.getServer().getWorld("spawn");
// Add locations to the list
safeLocations.add(new Location(spawn, 17, 158, 27)); // First location
safeLocations.add(new Location(spawn, 20, 154, -12)); // Add more locations as needed
safeLocations.add(new Location(spawn, -11, 154, -48));
// ... Add as many locations as you want
// Choose a random location from the list
Random random = new Random();
Location randomSafeLocation = safeLocations.get(random.nextInt(safeLocations.size()));
// Teleport the NPC to the randomly chosen location
npc.teleport(randomSafeLocation, TeleportCause.PLUGIN);
}
}
}
Editor is loading...
Leave a Comment