public static void tpNext() { checkId++; if (checkId >= wakeups.size()) { p.msg(checkPlayer, p.languageReader.get("Player_WakeLast")); checkId = -1; checkPlayer = null; return; } Wakeup wakeup = wakeups.get(checkId); if (!wakeup.active) { tpNext(); return; } String world = wakeup.loc.getWorld().getName(); int x = (int) wakeup.loc.getX(); int y = (int) wakeup.loc.getY(); int z = (int) wakeup.loc.getZ(); if (wakeup.check()) { p.msg( checkPlayer, p.languageReader.get("Player_WakeTeleport", "" + checkId, world, "" + x, "" + y, "" + z)); checkPlayer.teleport(wakeup.loc); } else { p.msg( checkPlayer, p.languageReader.get("Player_WakeFilled", "" + checkId, world, "" + x, "" + y, "" + z)); } p.msg(checkPlayer, p.languageReader.get("Player_WakeHint1")); p.msg(checkPlayer, p.languageReader.get("Player_WakeHint2")); }
// get the nearest of two random Wakeup-Locations public static Location getRandom(Location playerLoc) { if (wakeups.isEmpty()) { return null; } ArrayList<Wakeup> worldWakes = new ArrayList<>(); for (Wakeup wakeup : wakeups) { if (wakeup.active) { if (wakeup.loc.getWorld().equals(playerLoc.getWorld())) { worldWakes.add(wakeup); } } } if (worldWakes.isEmpty()) { return null; } Wakeup w1 = calcRandom(worldWakes); worldWakes.remove(w1); if (w1 == null) return null; while (!w1.check()) { p.errorLog("Please Check Wakeup-Location with id: &6" + wakeups.indexOf(w1)); w1 = calcRandom(worldWakes); if (w1 == null) { return null; } worldWakes.remove(w1); } Wakeup w2 = calcRandom(worldWakes); if (w2 != null) { worldWakes.remove(w2); while (!w2.check()) { p.errorLog("Please Check Wakeup-Location with id: &6" + wakeups.indexOf(w2)); w2 = calcRandom(worldWakes); if (w2 == null) { return w1.loc; } worldWakes.remove(w2); } if (w1.loc.distance(playerLoc) > w2.loc.distance(playerLoc)) { return w2.loc; } } return w1.loc; }
public static void remove(CommandSender sender, int id) { if (wakeups.isEmpty() || id < 0 || id >= wakeups.size()) { p.msg( sender, p.languageReader.get( "Player_WakeNotExist", "" + id)); // "&cDer Aufwachpunkt mit der id: &6" + id + " &cexistiert nicht!"); return; } Wakeup wakeup = wakeups.get(id); if (wakeup.active) { wakeup.active = false; p.msg(sender, p.languageReader.get("Player_WakeDeleted", "" + id)); } else { p.msg(sender, p.languageReader.get("Player_WakeAlreadyDeleted", "" + id)); } }
public static void check(CommandSender sender, int id, boolean all) { if (sender instanceof Player) { Player player = (Player) sender; if (!all) { if (wakeups.isEmpty() || id >= wakeups.size()) { p.msg(sender, p.languageReader.get("Player_WakeNotExist", "" + id)); return; } Wakeup wakeup = wakeups.get(id); if (wakeup.check()) { player.teleport(wakeup.loc); } else { String world = wakeup.loc.getWorld().getName(); int x = (int) wakeup.loc.getX(); int y = (int) wakeup.loc.getY(); int z = (int) wakeup.loc.getZ(); p.msg( sender, p.languageReader.get("Player_WakeFilled", "" + id, world, "" + x, "" + y, "" + z)); } } else { if (wakeups.isEmpty()) { p.msg(sender, p.languageReader.get("Player_WakeNoPoints")); return; } if (checkPlayer != null && checkPlayer != player) { checkId = -1; } checkPlayer = player; tpNext(); } } else { p.msg(sender, p.languageReader.get("Error_PlayerCommand")); } }