Hallo. Ich programmiere gerade ein Plugin. Eigendlich funktioniert es, doch es gibt ein problem. Es solten 2 Spieler an verschiedenen orten Teleportirt werden, doch beide Spieler werden an ein Ort Teleportiert. Hier der Code:
public class TeleportEvent implements Listener {
public static Bootrennen plugin;
public TeleportEvent(Bootrennen plugin) {
TeleportEvent.plugin = plugin;
}
public static void start() {
Location location = plugin.getConfig().getLocation("location.start1");
Location loc = plugin.getConfig().getLocation("location.start2");
int i = 1;
for(Player current : Bukkit.getOnlinePlayers()) {
Location playerLocation = plugin.getConfig().getLocation("location.start" + i);
current.teleport(playerLocation);
if (location != null) {
if(location.getBlock() != current.getLocation().getBlock()) {
i = 1;
current.teleport(Objects.requireNonNull(plugin.getConfig().getLocation("location.start1")));
Boat bt = (Boat) current.getWorld().spawnEntity(location, EntityType.BOAT);
bt.addPassenger(current);
} else {
if (loc != null) {
i = 2;
current.teleport(Objects.requireNonNull(plugin.getConfig().getLocation("location.start2")));
Boat bt = (Boat) current.getWorld().spawnEntity(location, EntityType.BOAT);
bt.addPassenger(current);
i++;
}
}
}
}
}
@EventHandler
public void onExit(VehicleExitEvent e) {
Player player = (Player) e.getExited();
if (e.getExited().hasPermission("Operator")) {
e.setCancelled(false);
} else {
player.sendMessage(ChatColor.RED + "Du darfst das nicht!");
e.setCancelled(true);
}
}
}