/** * Returns the distance from the given location to the border. * * <p>If the location is inside the border, or not in the same world, this returns 0. * * @param location The location to be checked. * @param diameter The "diameter" of the squared wall (i.e. the size of a side of the wall). * @return the distance from the given location to the border. */ private int getDistanceToSquaredBorder(Location location, int diameter) { if (!location.getWorld().equals(Bukkit.getWorlds().get(0))) { // The nether is not limited. return 0; } if (isInsideBorder(location, diameter)) { return 0; } Integer halfMapSize = (int) Math.floor(diameter / 2); Integer x = location.getBlockX(); Integer z = location.getBlockZ(); Location spawn = Bukkit.getWorlds().get(0).getSpawnLocation(); Integer limitXInf = spawn.add(-halfMapSize, 0, 0).getBlockX(); spawn = Bukkit.getWorlds().get(0).getSpawnLocation(); Integer limitXSup = spawn.add(halfMapSize, 0, 0).getBlockX(); spawn = Bukkit.getWorlds().get(0).getSpawnLocation(); Integer limitZInf = spawn.add(0, 0, -halfMapSize).getBlockZ(); spawn = Bukkit.getWorlds().get(0).getSpawnLocation(); Integer limitZSup = spawn.add(0, 0, halfMapSize).getBlockZ(); if (x > limitXSup && z < limitZSup && z > limitZInf) { // East of the border return Math.abs(x - limitXSup); } else if (x < limitXInf && z < limitZSup && z > limitZInf) { // West of the border return Math.abs(x - limitXInf); } else if (z > limitZSup && x < limitXSup && x > limitXInf) { // South of the border return Math.abs(z - limitZSup); } else if (z < limitZInf && x < limitXSup && x > limitXInf) { // North of the border return Math.abs(z - limitZInf); } else if (x > limitXSup && z < limitZInf) { // N-E return (int) location.distance( new Location(location.getWorld(), limitXSup, location.getBlockY(), limitZInf)); } else if (x > limitXSup && z > limitZSup) { // S-E return (int) location.distance( new Location(location.getWorld(), limitXSup, location.getBlockY(), limitZSup)); } else if (x < limitXInf && z > limitZSup) { // S-O return (int) location.distance( new Location(location.getWorld(), limitXInf, location.getBlockY(), limitZSup)); } else if (x < limitXInf && z < limitZInf) { // N-O return (int) location.distance( new Location(location.getWorld(), limitXInf, location.getBlockY(), limitZInf)); } else { return 0; // Should never happen. } }
public void onDisable() { // emulate each world unloading. // cancel ALL pending tasks. Bukkit.getScheduler().cancelTasks(this); this.dataStore.saveClaimData(); for (World iterate : Bukkit.getWorlds()) { ww.WorldUnload(new WorldUnloadEvent(iterate)); } ww = null; // save data for any online players Player[] players = this.getServer().getOnlinePlayers(); for (int i = 0; i < players.length; i++) { Player player = players[i]; String playerName = player.getName(); PlayerData playerData = this.dataStore.getPlayerData(playerName); this.dataStore.savePlayerData(playerName, playerData); } this.dataStore.close(); // instance=null; this.cmdHandler = null; dataStore = null; AddLogEntry("GriefPrevention disabled."); }
@Override public void run() { _i++; int total = Bukkit.getOnlinePlayers().length; _total += total; if (total < _min) { _min = total; } if (total > _max) { _max = total; } for (World world : Bukkit.getWorlds()) { String w = world.getName(); int t = world.getPlayers().size(); if (_worlds_total.containsKey(w)) { _worlds_total.put(w, _worlds_total.get(w) + t); if (t < _worlds_min.get(w)) { _worlds_min.put(w, t); } if (t > _worlds_max.get(w)) { _worlds_max.put(w, t); } } } }
@EventHandler(priority = EventPriority.LOW) public void onJoin(PlayerJoinEvent event) { final Player player = event.getPlayer(); String prefix = ChatColor.translateAlternateColorCodes( '&', Core.chat.getGroupPrefix(Bukkit.getWorlds().get(0), Core.chat.getPrimaryGroup(player))); player.setDisplayName(prefix + player.getName()); if (!player.hasPermission( ConfigUtil.get().getConfig().getString("joinleavemessage.permission"))) { event.setJoinMessage(null); } else { event.setJoinMessage( ChatColor.translateAlternateColorCodes( '&', ConfigUtil.get() .getConfig() .getString("joinleavemessage.join-message") .replaceAll("%player%", player.getDisplayName()))); } if (ConfigUtil.get().getConfig().getBoolean("tp-to-spawn")) { Location teleportTo = LocationUtil.get().deserialize(ConfigUtil.get().getConfig().getString("spawn.location")); event.getPlayer().teleport(teleportTo); } EconomyUtil.get().createRowForPlayer(player); }
static Player getOfflinePlayer(String player, UUID uuid) { Player pplayer = null; try { File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); for (File playerfile : playerfolder.listFiles()) { String filename = playerfile.getName(); String playername = filename.substring(0, filename.length() - 4); GameProfile profile = new GameProfile(uuid, playername); if (playername.trim().equalsIgnoreCase(player)) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); EntityPlayer entity = new EntityPlayer( server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); Player target = entity == null ? null : (Player) entity.getBukkitEntity(); if (target != null) { target.loadData(); return target; } } } } catch (Exception e) { return null; } return pplayer; }
@EventHandler(ignoreCancelled = false) public void onCmd(ConsoleCommandEvent e) { String path = e.getType().split(" ")[0]; if (!containsKey(path + ".Script")) { VTUtils.s(e.getSender(), "You haven't defined that console command in your script file!"); } else { if (getLong("ActiveCooldown") <= System.currentTimeMillis()) { if (getLong(path + ".ActiveCooldown") <= System.currentTimeMillis()) { new VTParser( main, "ConsoleCommand.yml", path, getList(path + ".Script"), new Location(Bukkit.getWorlds().get(0), 0, 0, 0), getCustoms(e), "Console") .start(); set( path + ".ActiveCooldown", (System.currentTimeMillis() + getLong(path + ".Cooldown") * 1000L)); cooldown(); } } } }
public static Location getNeededBlockLocation() { if (neededBlock != null) { return neededBlock; } else { return new Location(Bukkit.getWorlds().get(0), 0, 0, 0); } }
/** * @param types * @param type * @param worlds worlds or null for all * @return All entities of this type in the given worlds */ @SuppressWarnings({"null", "unchecked"}) public static final <E extends Entity> E[] getAll( final EntityData<?>[] types, final Class<E> type, @Nullable World[] worlds) { assert types.length > 0; if (type == Player.class) { if (worlds == null && types.length == 1 && types[0] instanceof PlayerData && ((PlayerData) types[0]).op == 0) return (E[]) Bukkit.getOnlinePlayers(); final List<Player> list = new ArrayList<Player>(); for (final Player p : Bukkit.getOnlinePlayers()) { if (worlds != null && !CollectionUtils.contains(worlds, p.getWorld())) continue; for (final EntityData<?> t : types) { if (t.isInstance(p)) { list.add(p); break; } } } return (E[]) list.toArray(new Player[list.size()]); } final List<E> list = new ArrayList<E>(); if (worlds == null) worlds = Bukkit.getWorlds().toArray(new World[0]); for (final World w : worlds) { for (final E e : w.getEntitiesByClass(type)) { for (final EntityData<?> t : types) { if (t.isInstance(e)) { list.add(e); break; } } } } return list.toArray((E[]) Array.newInstance(type, list.size())); }
private void removePlayer(PlayerInfo player, PlayerInfo owner, CommandSender sender) { Player onlinePlayer = player.getPlayer(); if (onlinePlayer != null) { onlinePlayer.sendMessage( ChatColor.RED + "You have been kicked from " + owner.getPlayerName() + "'s skyblock."); if (uSkyBlock.isSkyBlockWorld(onlinePlayer.getWorld())) { if (Settings.extras_sendToSpawn) Misc.safeTeleport(onlinePlayer, Bukkit.getWorlds().get(0).getSpawnLocation()); else Misc.safeTeleport(onlinePlayer, uSkyBlock.getSkyBlockWorld().getSpawnLocation()); } } sender.sendMessage( ChatColor.GREEN + player.getPlayerName() + " has been removed from the island."); player.setLeaveParty(); player.setHomeLocation(null); owner.getMembers().remove(player.getPlayerName()); if (Settings.island_protectWithWorldGuard && Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) WorldGuardHandler.removePlayerFromRegion(owner.getPlayerName(), player.getPlayerName()); player.save(); }
@Override public void unloadAll() { saveAll(); for (World world : Bukkit.getWorlds()) { unloadWorld(world); } }
@Override public void onEnable() { THIS = this; PS.instance = new PS(this); if (Settings.METRICS) { try { final Metrics metrics = new Metrics(this); metrics.start(); log(C.PREFIX.s() + "&6Metrics enabled."); } catch (final Exception e) { log(C.PREFIX.s() + "&cFailed to load up metrics."); } } else { log("&dUsing metrics will allow us to improve the plugin, please consider it :)"); } List<World> worlds = Bukkit.getWorlds(); if (worlds.size() > 0) { UUIDHandler.cacheAll(worlds.get(0).getName()); for (World world : worlds) { try { SetGenCB.setGenerator(world); } catch (Exception e) { log("Failed to reload world: " + world.getName()); Bukkit.getServer().unloadWorld(world, false); } } } }
private boolean disableWorld(CommandSender sender, String worldName) { if (worldName == null) return false; for (World world : Bukkit.getWorlds()) { if (!world.getName().equalsIgnoreCase(worldName)) continue; if (settings == null) settings = new Settings(); settings.worldsToUnload.remove(worldName); settings.worldsToDisable.add(worldName); Bukkit.getServer().unloadWorld(world, true); String msg = "NoPreload"; msg = String.format("%s[%s]", ChatColor.DARK_AQUA, msg); msg = String.format("%s%s ", msg, ChatColor.WHITE); msg += worldName + " has been disabled."; sender.sendMessage(msg); return true; } String msg = "NoPreload"; msg = String.format("%s[%s]", ChatColor.DARK_AQUA, msg); msg = String.format("%s%s ", msg, ChatColor.WHITE); msg += worldName + " does not appear to exist."; sender.sendMessage(msg); return true; }
public void onEnable() { loadSettings(); if (settings == null) return; for (World world : Bukkit.getWorlds()) { boolean disabled = false; for (String worldName : settings.worldsToDisable) { if (!world.getName().equalsIgnoreCase(worldName)) continue; Bukkit.getServer().unloadWorld(world, true); disabled = true; break; } if (disabled) continue; for (String worldName : settings.worldsToUnload) { if (!world.getName().equalsIgnoreCase(worldName)) continue; world.setKeepSpawnInMemory(false); break; } } getServer().getPluginManager().registerEvents(this, this); getCommand("nopreload").setExecutor(this); }
public void unload() { if (!this.isLoaded()) { throw new IllegalStateException("World not loaded"); } // Teleport players to another world final Location spawn = this.plugin .getWorlds() .get(Bukkit.getWorlds().get(0).getName()) .spawnLocation .toBukkitLocation(); for (final Player p : Bukkit.getWorld(this.worldName).getPlayers()) { this.plugin.sendMessage(p, MessageId.world_teleportedBecauseOfWorldUnload); p.teleport(spawn); } // Unload the world Bukkit.getScheduler() .runTaskLater( this.plugin, new BukkitRunnable() { @Override public void run() { Bukkit.unloadWorld( fr.ribesg.bukkit.nworld.world.GeneralWorld.this.getWorldName(), true); } }, 1L); this.setEnabled(false); }
@EventHandler public void onPlayerMove(PlayerMoveEvent e) { Player p = e.getPlayer(); Location loc = new Location( e.getTo().getWorld(), (int) e.getTo().getX(), (int) e.getTo().getY(), (int) e.getTo().getZ()); if (Main.getInstance().redSpawnArea.contains(loc)) { Bukkit.getPluginManager().callEvent(new AreaWalkEvent(Area.RED_SPAWN, p)); } if (Main.getInstance().blueSpawnArea.contains(loc)) { Bukkit.getPluginManager().callEvent(new AreaWalkEvent(Area.BLUE_SPAWN, p)); } if (Main.getInstance().blockspawnAreas.contains(loc)) { Bukkit.getPluginManager().callEvent(new AreaWalkEvent(getArea(loc), p)); } if (blockManager.canPickUpBlock(p)) { blockManager.pickUpBlock(p); } if (canGetNeededBlock(p)) { if (p.getGameMode() == GameMode.SURVIVAL) { gameManager.setCarrying(p, nexusManager.getCurrentNexusColor()); String[] data = neededBlockMaterial.split(";"); neededBlock .getBlock() .setTypeIdAndData(Integer.valueOf(data[0]), Byte.valueOf(data[1]), false); neededBlock = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); Bukkit.broadcastMessage( Color.np( "&6The needed block was picked up by the " + teamManager.getTeam(p).getTeamName() + "&6 team!")); } } if ((int) e.getFrom().getX() != (int) e.getTo().getX() || (int) e.getFrom().getZ() != (int) e.getTo().getZ() || (int) e.getFrom().getY() != (int) e.getTo().getY()) { if (getTurret(loc) != null) { Bukkit.getPluginManager().callEvent(new TurretWalkEvent(p, getTurret(loc))); } if (isInTurret(p)) { Turret t = getTurret(p); if (t.containsUser()) { e.getPlayer().teleport(e.getFrom()); } } } if ((int) e.getFrom().getX() != (int) e.getTo().getX() || (int) e.getFrom().getZ() != (int) e.getTo().getZ()) { if (!released || stunned.contains(p.getName())) { if (GameState.getState() == GameState.INGAME) { e.getPlayer().teleport(e.getFrom()); } } } }
/** Disable * */ public void onDisable() { /** Remove entities * */ for (World w : Bukkit.getWorlds()) { for (Entity e : w.getEntities()) { e.remove(); } } }
@Override public synchronized void saveAll() { closeAll(); for (World world : Bukkit.getWorlds()) { saveWorld(world); } }
@Override public synchronized void unloadAll() { closeAll(); for (World world : Bukkit.getWorlds()) { unloadWorld(world); } }
private boolean unloadWorld(CommandSender sender, String worldName) { if (worldName == null) return false; for (World world : Bukkit.getWorlds()) { if (!world.getName().equalsIgnoreCase(worldName)) continue; if (settings == null) settings = new Settings(); settings.worldsToUnload.add(worldName); settings.worldsToDisable.remove(worldName); world.setKeepSpawnInMemory(false); String msg = "NoPreload"; msg = String.format("%s[%s]", ChatColor.DARK_AQUA, msg); msg = String.format("%s%s ", msg, ChatColor.WHITE); msg += worldName + " has been set to unload spawn."; sender.sendMessage(msg); return true; } if (settings == null) { String msg = "NoPreload"; msg = String.format("%s[%s]", ChatColor.DARK_AQUA, msg); msg = String.format("%s%s ", msg, ChatColor.WHITE); msg += worldName + " does not appear to exist."; sender.sendMessage(msg); return true; } for (String world : settings.worldsToDisable) { if (!world.equalsIgnoreCase(worldName)) continue; settings.worldsToUnload.add(worldName); settings.worldsToDisable.remove(worldName); String msg = "NoPreload"; msg = String.format("%s[%s]", ChatColor.DARK_AQUA, msg); msg = String.format("%s%s ", msg, ChatColor.WHITE); String msg1 = msg; msg1 += worldName + " has been set to unload spawn."; sender.sendMessage(msg1); String msg2 = msg; msg2 += "However, the server needs to be restarted "; msg2 += "to load the world."; sender.sendMessage(msg2); return true; } String msg = "NoPreload"; msg = String.format("%s[%s]", ChatColor.DARK_AQUA, msg); msg = String.format("%s%s ", msg, ChatColor.WHITE); msg += worldName + " does not appear to exist."; sender.sendMessage(msg); return true; }
@Override public Iterable<WorldGroup> importWorldGroups(BetterEnderChest plugin) { Set<WorldGroup> worldGroups = new HashSet<WorldGroup>(); WorldGroup standardGroup = new WorldGroup(BetterEnderChest.STANDARD_GROUP_NAME); standardGroup.setInventoryImporter(this); standardGroup.addWorlds(Bukkit.getWorlds()); worldGroups.add(standardGroup); return worldGroups; }
/** Get random location * */ public Location getRandomLocation() { Random r = new Random(); return new Location( Bukkit.getWorlds().get(0), 1647 + r.nextInt(40) - 20, 32 + r.nextInt(8), 411 + r.nextInt(40) - 20); }
@Override public void postReload() { statsDatabase = new DefaultStatsDatabase(this); disguiser = new DefaultDisguiser(this); listener.resetBorderDamager(); for (World world : Bukkit.getWorlds()) { getGameManager().getGame(world); } }
@Override public boolean execute(CommandSender sender, String currentAlias, String[] args) { if (!testPermission(sender)) return true; for (World world : Bukkit.getWorlds()) { world.setAutoSave(true); } Command.broadcastCommandMessage(sender, "Enabled level saving.."); return true; }
@Override public boolean execute(CommandSender sender, String currentAlias, String[] args) { if (!testPermission(sender)) return true; for (World world : Bukkit.getWorlds()) { world.setAutoSave(true); } Command.broadcastCommandMessage(sender, "Автоматическое сохранение мира включено."); return true; }
public static void gotoWorld(Player player, String targetWorld) { if (player == null) { return; } if (player.getWorld().getName().equalsIgnoreCase(targetWorld)) { playerMsg(player, "Going to main world.", ChatColor.GRAY); player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation()); return; } for (World world : Bukkit.getWorlds()) { if (world.getName().equalsIgnoreCase(targetWorld)) { playerMsg(player, "Going to world: " + targetWorld, ChatColor.GRAY); player.teleport(world.getSpawnLocation()); return; } } playerMsg(player, "World " + targetWorld + " not found.", ChatColor.GRAY); }
private boolean invite(CommandSender sender, String[] args) { if (!(sender instanceof Player)) { return true; } Player player = (Player) sender; if (args.length != 1) { return false; } // check if leader Party party = plugin.parties.get(player.getName().toLowerCase()); if (party == null) { party = new Party(player); } if (!party.isLeader(player)) { player.sendMessage("You can only invite someone if you are the party leader."); return true; } // get target player Player target = null; List<Player> matches = Bukkit.matchPlayer(args[0]); if (matches.size() == 1) { target = matches.get(0); } if (target == null) { player.sendMessage("No such player found."); return true; } // check if target is already in a party if (plugin.parties.containsKey(target.getName().toLowerCase())) { player.sendMessage("That player is already in a party."); return true; } // check if target is in an instance if (!target.getWorld().equals(Bukkit.getWorlds().get(0))) { player.sendMessage("That player is in an instance."); return true; } // invite to party plugin.parties.put(player.getName().toLowerCase(), party); target.sendMessage(player.getDisplayName() + " has invited you to join a party."); target.sendMessage("Type 'yes' to accept this invitation."); PendingAction action = new PendingAction(target, ActionType.JOIN_PARTY, player.getName().toLowerCase()); plugin.addPendingAction(action); player.sendMessage("Invitation sent."); return true; }
public static void gotoWorld(CommandSender sender, String targetworld) { if (sender instanceof Player) { Player player = (Player) sender; if (player.getWorld().getName().equalsIgnoreCase(targetworld)) { sender.sendMessage(ChatColor.GRAY + "Going to main world."); player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation()); return; } for (World world : Bukkit.getWorlds()) { if (world.getName().equalsIgnoreCase(targetworld)) { sender.sendMessage(ChatColor.GRAY + "Going to world: " + targetworld); player.teleport(world.getSpawnLocation()); return; } } sender.sendMessage(ChatColor.GRAY + "World " + targetworld + " not found."); } else { sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); } }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length != 0) { plugin.sendMessageWarning( sender, ChatColor.translateAlternateColorCodes( '&', plugin.languageGetConfig().getString("buyland.general.parameters"))); plugin.sendMessageInfo(sender, "Usage: /buyland list"); } else { // See if the person requesting the information is a player if (sender instanceof Player) { Player player = (Player) sender; String playerName = player.getName(); // See if the player has permission to this command if (player.hasPermission("buyland.list") || player.hasPermission("buyland.all")) { // State who the list is for plugin.sendMessageInfo(sender, "You own regions: "); // Loop through all the worlds for (World world : Bukkit.getWorlds()) { // get the list of regions for the selected world Map<String, ProtectedRegion> regionMap = WGBukkit.getRegionManager(world).getRegions(); // Loop through all the regions for (ProtectedRegion region : regionMap.values()) { // see if the person is an owner of the region if (region.isOwner(playerName)) { // see if the region is buyable if (region.getFlag(DefaultFlag.BUYABLE) == null) { // if it is null, it is not purchased by anyone. } else { // See if the region was purchased. if (region.getFlag(DefaultFlag.BUYABLE) == false) { // list this as owned by the player in question plugin.sendMessageInfo( sender, " " + world.getName() + ": " + region.getId(), false); } } } } } } } else { plugin.sendMessageInfo(sender, "Currently not available at console."); } } // command was utilized. return true; }
@Override @javax.annotation.Nullable protected Entity[] get(Event arg0) { Entity returnEnt = null; for (World w : Bukkit.getWorlds()) { for (Entity e : w.getEntities()) { if (e.getUniqueId().toString() == uuid.getSingle(arg0)) { return new Entity[] {e}; } } } return null; }
public static OfflinePlayer findOfflinePlayer(String name) { OfflinePlayer p = findPlayer(name); if (p != null) { return p; } else { /// Iterate over the worlds to see if a player.dat file exists for (World w : Bukkit.getWorlds()) { File f = new File(w.getName() + "/players/" + name + ".dat"); if (f.exists()) { return Bukkit.getOfflinePlayer(name); } } return null; } }