public static Machine fromString(String input) { JSONObject machine = null; try { machine = (JSONObject) new JSONParser().parse(input); } catch (ParseException e) { e.printStackTrace(); } JSONObject cutObj = (JSONObject) machine.get("cuttingface"); Block cutFace = Bukkit.getWorld((String) cutObj.get("world")) .getBlockAt( (Integer) getNumber((String) cutObj.get("x")), (Integer) getNumber((String) cutObj.get("y")), (Integer) getNumber((String) cutObj.get("z"))); OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString((String) machine.get("owner"))); JSONObject dis = (JSONObject) machine.get("dispenser"); Block dispenser = Bukkit.getWorld((String) dis.get("world")) .getBlockAt( (Integer) getNumber((String) dis.get("x")), (Integer) getNumber((String) dis.get("y")), (Integer) getNumber((String) dis.get("z"))); return new Machine(cutFace, dispenser, owner); }
public static void drop(Player p) { Location loc = new Location(Bukkit.getWorld("world"), 0, 0, 0); Random rand = new Random(); loc.setX(rand.nextInt(8000)); loc.setY(100); loc.setZ(rand.nextInt(8000)); loc.setY(Bukkit.getWorld("world").getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY()); loc.getBlock().setType(Material.CHEST); Block bb = loc.getBlock(); bb.setType(Material.CHEST); Chest chest = (Chest) bb.getState(); Inventory inv = chest.getInventory(); for (ItemStack stack : items) { inv.addItem(stack); } Bukkit.broadcastMessage( ChatColor.RED + "A tornado has appeared in the world, and left valuble supplies!"); Bukkit.broadcastMessage( ChatColor.translateAlternateColorCodes( '&', "&7Coords: X: &c" + loc.getBlockX() + "&7 Y:&c " + loc.getBlockY() + "&7 Z: &c" + loc.getBlockZ())); }
@Override public void undo(Undo undo) { World w = Bukkit.getWorld(worldName); Location loc = new Location(Bukkit.getWorld(worldName), blockX, blockY, blockZ); w.getBlockAt(loc).setType(Material.AIR); undo.chunks.add(loc.getChunk()); }
public void startStage(Player p, Stage s) { switch (s) { case FIRST: Bukkit.dispatchCommand( Bukkit.getConsoleSender(), "campaign forceadd " + p.getName() + " tutorial"); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "campaign forceready " + p.getName()); break; case SECOND: Bukkit.dispatchCommand( Bukkit.getConsoleSender(), "campaign forceadd " + p.getName() + " tutorial2"); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "campaign forceready " + p.getName()); break; case THIRD: p.teleport(new Location(Bukkit.getWorld("OrbiA"), -2268.0, 98.0, -3436.0)); p.sendMessage( ChatColor.GREEN + "Betrete das Dungeon über der Kaserne in Angin! (x: -2167 y: 145 z: -3529)"); break; case FOURTH: Bukkit.dispatchCommand( Bukkit.getConsoleSender(), "campaign forceadd " + p.getName() + " tutorial3"); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "campaign forceready " + p.getName()); case FITH: p.teleport(new Location(Bukkit.getWorld("OrbiA"), -2433.0, 202.0, -3659.0)); p.sendMessage( ChatColor.GREEN + "Wähle eine Klasse bei einem der Graubärte (Rechtsklick auf den Graubart! Gehe dann zurück zu Gondolf und rede mit ihm!"); default: break; } }
@Override public boolean isValid(ConversationContext context, String input) { if (input.contains(" ")) { String[] split = input.split("\\s"); if (split.length == 4) { if (Bukkit.getWorld(split[0]) != null) { for (int i = 1; i <= 3; i++) { if (!GeneralUtil.isInt(split[i])) { context.setSessionData("fail_int", true); return false; } } this.location = new Location( Bukkit.getWorld(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3])); } else { context.setSessionData("fail_world", true); return false; } } else { context.setSessionData("fail_format", true); return false; } } else { context.setSessionData("fail_format", true); return false; } return true; }
public static List<Location> getSpawns() { List<Location> list = new ArrayList<Location>(); list.add(new Location(Bukkit.getWorld("world"), 38.5D, 85.0D, 2221.5, 135.0F, 0.0F)); list.add(new Location(Bukkit.getWorld("world"), 6.5D, 85.0D, 2220.5D, -135.0F, 0.0F)); list.add(new Location(Bukkit.getWorld("world"), 6.5D, 85.0D, 2187.5, -45.0F, 0.0F)); list.add(new Location(Bukkit.getWorld("world"), 38.5, 85.0D, 2190.5D, 45.0F, 0.0F)); return list; }
public static void addSpectator(Player p) { p.teleport(new Location(Bukkit.getWorld("world"), -303, 28, -304)); p.setGameMode(GameMode.CREATIVE); spectators.add(p); for (Player pl : Bukkit.getOnlinePlayers()) { pl.hidePlayer(p); } for (Player pl : spectators) { p.hidePlayer(pl); } p.teleport(new Location(Bukkit.getWorld("world"), -303, 28, -304)); p.getInventory() .setItem(0, itemStack(Material.COMPASS, 1, null, "§aTeleporter", "Right click to use")); }
@Override public void setBlockFast(int x, int y, int z, String world, int typeID, byte data) { Chunk c = Bukkit.getWorld(world).getChunkAt(x >> 4, z >> 4); net.minecraft.server.v1_5_R2.Chunk chunk = ((org.bukkit.craftbukkit.v1_5_R2.CraftChunk) c).getHandle(); chunk.a(x & 15, y, z & 15, typeID, data); }
public void loadSign(int a) { try { Walls.debug("walls-system.lobby.signs." + a + ".world"); World w = Bukkit.getWorld(s.getString("walls-system.lobby.signs." + a + ".world")); int x1 = s.getInt("walls-system.lobby.signs." + a + ".x1"); int y1 = s.getInt("walls-system.lobby.signs." + a + ".y1"); int z1 = s.getInt("walls-system.lobby.signs." + a + ".z1"); int x2 = s.getInt("walls-system.lobby.signs." + a + ".x2"); // int y2 = s.getInt("walls-system.lobby.signs." + a + ".y2"); int z2 = s.getInt("walls-system.lobby.signs." + a + ".z2"); int gameid = s.getInt("walls-system.lobby.signs." + a + ".id"); LobbyWall ls = new LobbyWall(gameid); if (ls.loadSign(w, x1, x2, z1, z2, y1)) { ArrayList<LobbyWall> t = signs.get(gameid); if (t == null) { t = new ArrayList<LobbyWall>(); signs.put(gameid, t); } t.add(ls); ls.update(); // TODO } else { /*s.set("walls-system.lobby.signs." + a, null); SettingsManager.getInstance().saveSystemConfig();*/ } } catch (Exception e) { s.set("walls-system.lobby.signs." + a, null); s.set("walls-system.lobby.signno", s.getInt("walls-system.lobby.signno") - 1); } }
public void deleteWorld(String dimension) { World world = Bukkit.getWorld(dimension); File worldFolder = world.getWorldFolder(); Bukkit.unloadWorld(dimension, true); scheduleWorldDeletion(worldFolder, dimension); }
@Override public void rollback(Rollback rollback) { Location loc = new Location(Bukkit.getWorld(worldName), blockX, blockY, blockZ); setBlockFast(loc, Material.WOOD_DOOR.getId(), blockData); setBlockFast(getOtherDoorBlock(loc), Material.WOOD_DOOR.getId(), blockData); rollback.chunks.add(loc.getChunk()); }
public static void removeGuest(String worldname, Player guest, Player moderator) { World world = Bukkit.getWorld(worldname); if (!worlds.containsKey(world)) { moderator.sendMessage(ChatColor.RED + "This world cannot have guests."); return; } FOPMR_GuestList list = guestlists.get(world); if (!list.isGuest(guest.getName())) { moderator.sendMessage(ChatColor.RED + "This player is not a guest of this world."); return; } if (FOPMR_Rank.getRank(moderator).level < worlds.get(world).level) { moderator.sendMessage( ChatColor.RED + "You do not have permission to remove guests from this world."); return; } list.removeGuest(guest.getName()); moderator.sendMessage( ChatColor.RED + "You have removed " + guest.getName() + " from the " + worldname + " guest list."); }
public static void spawnGuildVender(Location location) { Villager villager = (Villager) Bukkit.getWorld("world").spawn(location, (Class) Villager.class); villager.setCustomName("§aGuild Vender"); villager.setCustomNameVisible(true); villager.setProfession(Villager.Profession.LIBRARIAN); villager.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 999999, 20)); }
public static void loadBlocks(Chunk chunk) { ResultSet r = null; try { r = (new SQLQuery( "select l.world,l.x,l.y,l.z,b.dayPlaced,b.id from £.locations l, £.nonnatural b where l.id=b.location and l.chunkx=" + chunk.getX() + " and l.chunkz=" + chunk.getZ() + ";", msqlc)) .excecuteQuery(); } catch (MySQLSyntaxErrorException e1) { e1.printStackTrace(); } try { while (r.next()) { GregorianCalendar g = new GregorianCalendar(); g.setTime(r.getDate(5)); BlockManager.loadBlock( (new Location(Bukkit.getWorld(r.getString(1)), r.getInt(2), r.getInt(3), r.getInt(4))) .getBlock(), g, r.getInt(6)); } } catch (SQLException e) { e.printStackTrace(); } }
public void info() { World world = null; if (this.args.length == 1 && this.sender instanceof Player) { world = ((Player) this.sender).getLocation().getWorld(); } else if (this.args.length > 1) { world = Bukkit.getWorld(this.args[1]); if (world == null) { message("World <" + this.args[1] + "> does not exist"); return; } } else return; Map map = this.editor.getMap(world); if (map == null) { message("World <" + world.getName() + "> is not oppened in editor"); return; } // Informations sur la map message(ChatColor.DARK_AQUA + "Map <" + map.getWorldName() + ">"); message("Object count : " + map.getSigns().size()); message( "Available objects (" + ObjectType.getObjectTypeNames().size() + ") : " + ObjectType.getObjectTypeNames()); }
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length != 1) { return false; } if (!FreedomOpModRemastered.configs.getWorlds().getConfig().contains(args[0])) { sender.sendMessage( ChatColor.RED + "The world does not exist or is not a custom FOPM: R world."); return true; } if (Bukkit.getWorld(args[0]) != null) { CUtils_Methods.unloadWorld(Bukkit.getWorld(args[0])); } FreedomOpModRemastered.configs.getWorlds().getConfig().set(args[0], null); FreedomOpModRemastered.configs.getWorlds().saveConfig(); return true; }
@Override public void run() { String message = this.getMessage(); if (this.scope.equals(ZRScope.REGION)) { List<String> players = Zones.getZone(this.tag).getPlayers(); for (String x : players) { if (Bukkit.getPlayer(x).isOnline()) Bukkit.getPlayer(x).sendMessage(message); } } else if (this.scope.equals(ZRScope.WORLD)) { List<Player> players = Bukkit.getWorld(Zones.getZone(this.tag).getWorldName()).getPlayers(); for (Player p : players) { if (p.isOnline()) p.sendMessage(message); } } else if (this.scope.equals(ZRScope.SERVER)) { Player[] players = Bukkit.getServer().getOnlinePlayers(); for (Player player : players) { player.sendMessage(message); } } }
private boolean spawnMob() { if (myConfig.getDisabledWorlds().contains(world)) return false; final int maxHeight = 10; int x = this.radius - (int) (Math.random() * this.radius * 2.0D); int z = this.radius - (int) (Math.random() * this.radius * 2.0D); long d = x * x + z * z; if (d >= radius * radius) { x *= radius / (2 * d); z *= radius / (2 * d); } Location l1 = new Location( Bukkit.getWorld(this.world), this.m.getX() + x, this.m.getY(), this.m.getZ() + z); int p = l1.getBlock().getType().equals(Material.AIR) ? -1 : 1; for (int h = 0; h < maxHeight; h++) { l1.setY(this.m.getY() + h * p); if ((!l1.getBlock().getType().equals(Material.AIR)) && (l1.getBlock().getRelative(BlockFace.UP).getType().equals(Material.AIR))) { l1.setY(l1.getY() + 2.0D); return Mob.spawnEntity(this.mob, l1, this.m) != null; } } return false; }
/** * drop an item at a powerup spawn point * * @param item the item to drop */ protected void dropItemOnSpawn(Material item) { debug.i("calculating item spawn location"); Location aim = SpawnManager.getCoords(arena, "powerup").add(0, 1, 0).toLocation(); debug.i("dropping item on spawn: " + aim.toString()); Bukkit.getWorld(arena.getWorld()).dropItem(aim, new ItemStack(item, 1)); }
/** * commit the powerup item spawn * * @param item the material to spawn */ protected void commitPowerupItemSpawn(Material item) { debug.i("dropping item?"); if (arena.getArenaConfig().getBoolean(CFG.MODULES_POWERUPS_DROPSPAWN)) { dropItemOnSpawn(item); } else { Set<ArenaRegionShape> ars = arena.getRegionsByType(RegionType.BATTLE); for (ArenaRegionShape ar : ars) { PABlockLocation min = ar.getMinimumLocation(); PABlockLocation max = ar.getMaximumLocation(); Random r = new Random(); int x = r.nextInt(max.getX() - min.getX()); int z = r.nextInt(max.getZ() - min.getZ()); World w = Bukkit.getWorld(min.getWorldName()); w.dropItem( w.getHighestBlockAt(min.getX() + x, min.getZ() + z) .getRelative(BlockFace.UP) .getLocation(), new ItemStack(item, 1)); break; } } }
@Override public void ExecuteClass(Player player, String[] args) { Location loc = Bukkit.getWorld(args[2]).getSpawnLocation(); player.teleport(loc); Managers.hubManager.leaveHub(player); }
public TeleportEvent(String packName, String instructions) throws InstructionParseException { super(packName, instructions); String[] parts = instructions.split(" "); if (parts.length < 2) { throw new InstructionParseException("Location not specified"); } String[] location = parts[1].split(";"); if (location.length < 4) { throw new InstructionParseException("Wrong location format"); } World world = Bukkit.getWorld(location[3]); if (world == null) { throw new InstructionParseException("World does not exists"); } double x, y, z; float yaw = 0, pitch = 0; try { x = Double.parseDouble(location[0]); y = Double.parseDouble(location[1]); z = Double.parseDouble(location[2]); if (location.length == 6) { yaw = Float.parseFloat(location[4]); pitch = Float.parseFloat(location[5]); } } catch (NumberFormatException e) { throw new InstructionParseException("Could not parse coordinates"); } loc = new Location(world, x, y, z, yaw, pitch); }
public void loadAll() { shelves.clear(); for (int i = 0; i < getFile().size(); i++) { String key = (String) getFile().keySet().toArray()[i]; int x; int y; int z; World world; Location location; try { x = Integer.parseInt(key.split(",")[1]); y = Integer.parseInt(key.split(",")[2]); z = Integer.parseInt(key.split(",")[3]); } catch (NumberFormatException e) { BenCmd.log( Level.WARNING, "Shelf (" + getFile().keySet().toArray()[i] + ")'s location is invalid!"); continue; } catch (IndexOutOfBoundsException e) { BenCmd.log( Level.WARNING, "Shelf (" + getFile().keySet().toArray()[i] + ")'s location is invalid!"); continue; } if ((world = Bukkit.getWorld(key.split(",")[0])) == null) { BenCmd.log( Level.WARNING, "Shelf (" + getFile().keySet().toArray()[i] + ")'s location is invalid!"); continue; } location = new Location(world, x, y, z); String text = getFile().getProperty(key); shelves.put(location, new Shelf(location, text)); } }
public static void addGuest(String worldname, Player guest, Player moderator) { World world = Bukkit.getWorld(worldname); if (!worlds.containsKey(world)) { moderator.sendMessage(ChatColor.RED + "This world cannot have guests."); return; } FOPMR_GuestList list = guestlists.get(world); if (canAccess(world.getName(), guest)) { moderator.sendMessage(ChatColor.RED + "The player can already access the world."); return; } if (FOPMR_Rank.getRank(moderator).level < worlds.get(world).level) { moderator.sendMessage(ChatColor.RED + "You cannot add guests to this world."); return; } list.addGuest(guest.getName(), moderator.getName()); moderator.sendMessage( ChatColor.GREEN + "You have added " + guest.getName() + " to the " + worldname + " guest list."); guest.sendMessage(ChatColor.GREEN + "You now have access to the world: " + worldname); }
public void open() { if (this.args.length == 2) { String worldName = this.args[1]; World world = Bukkit.getWorld(worldName); if (world == null) { message("World <" + worldName + "> was not loaded. Loading world..."); world = Bukkit.createWorld(WorldCreator.name(worldName)); message("World <" + worldName + "> loaded"); } if (this.editor.getWorlds().keySet().contains(world)) { message("World <" + worldName + "> is already openned in editor"); return; } try { this.editor.addWorld(world); } catch (IOException e) { message("Error loading script map for world <" + worldName + ">..."); e.printStackTrace(); return; } this.editor.buildSigns(world); message("World <" + worldName + "> openned in editor"); NSCore.log("World <" + worldName + "> openned in editor by " + this.sender.getName()); } }
@Override public Object fromConfig(Class type, Object section, ParameterizedType genericType) throws Exception { Map<String, Object> locationMap; if (section instanceof Map) { locationMap = (Map<String, Object>) section; } else { locationMap = (Map<String, Object>) ((ConfigSection) section).getRawMap(); } Float yaw; if (locationMap.get("yaw") instanceof Double) { Double dYaw = (Double) locationMap.get("yaw"); yaw = dYaw.floatValue(); } else { yaw = (Float) locationMap.get("yaw"); } Float pitch; if (locationMap.get("pitch") instanceof Double) { Double dPitch = (Double) locationMap.get("pitch"); pitch = dPitch.floatValue(); } else { pitch = (Float) locationMap.get("pitch"); } return new org.bukkit.Location( Bukkit.getWorld((String) locationMap.get("world")), (Double) locationMap.get("x"), (Double) locationMap.get("y"), (Double) locationMap.get("z"), yaw, pitch); }
public static Location parseLocation(String s) { String[] split = s.split(","); Location loc = null; try { World world = Bukkit.getWorld(split[0]); if (split.length == 6) { double x = Double.parseDouble(split[1]); double y = Double.parseDouble(split[2]); double z = Double.parseDouble(split[3]); float yaw = Float.parseFloat(split[4]); float pitch = Float.parseFloat(split[5]); loc = new Location(world, x, y, z, yaw, pitch); } else if (split.length == 4) { int x = Integer.parseInt(split[1]); int y = Integer.parseInt(split[2]); int z = Integer.parseInt(split[3]); loc = new Location(world, x, y, z); } } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { System.err.println("[SurvivalGames] Cannot parse location from string: " + s); } return loc; }
// @EventHandler(priority = EventPriority.NORMAL) public void explodingArrow(ProjectileHitEvent event) { Entity projectile = event.getEntity(); World w = projectile.getWorld(); Location hit = projectile.getLocation(); if (w.getName().equals(name)) { if (projectile instanceof Arrow) { Arrow arrow = (Arrow) projectile; Entity shooter = arrow.getShooter(); Location l = shooter.getLocation(); Block bl = l.getBlock(); Block b = bl.getRelative(BlockFace.DOWN, 2); Material mat = b.getType(); if (shooter instanceof Player) { Player p = (Player) shooter; ItemStack is = p.getItemInHand(); Material i = is.getType(); if (i == Material.BOW && mat == Material.SPONGE) { p.getInventory().removeItem(new ItemStack(Material.ARROW, 20)); w.createExplosion(hit, 8); int strikes = 0; while (strikes < 20) { strikes++; w.strikeLightning(hit); } } Bukkit.getWorld(name).playEffect(arrow.getLocation(), Effect.STEP_SOUND, 10); } } } }
private static Location loadLocation(ConfigurationSection section) { String world = section.getString("world"); double x = section.getDouble("x"); double y = section.getDouble("y"); double z = section.getDouble("z"); return new Location(Bukkit.getWorld(world), x, y, z); }
/* * loads signs locations from file */ public void loadLocations() { File file = new File( "plugins" + File.separator + TaxCollector.pluginName + File.separator + "data.yml"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { log.info("Can't create signs file!"); e.printStackTrace(); return; } } YamlConfiguration locations = YamlConfiguration.loadConfiguration(file); if (locations.contains("signs")) { for (String key : locations.getConfigurationSection("signs").getKeys(false)) { if (!locations.contains("signs." + key + ".world") || !locations.contains("signs." + key + ".x") || !locations.contains("signs." + key + ".y") || !locations.contains("signs." + key + ".z")) { continue; // location is broken, can't load } Location loc = new Location( Bukkit.getWorld(locations.getString("signs." + key + ".world")), locations.getDouble("signs." + key + ".x"), locations.getDouble("signs." + key + ".y"), locations.getDouble("signs." + key + ".z")); this.addLocation(loc); } } }