Java Code Examples for org.bukkit.World

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project 16Blocks, under directory /src/main/java/de/minestar/sixteenblocks/Manager/.

Source file: AreaManager.java

  23 
vote

public void deletePlayerArea(SkinArea thisArea,Player player){
  this.blockArea(thisArea.getZoneXZ());
  World world=Bukkit.getWorlds().get(0);
  ZoneXZ thisZone=thisArea.getZoneXZ();
  AreaDeletionThread thisThread=new AreaDeletionThread(world,thisZone.getX() * Settings.getAreaSizeX() - (thisZone.getZ() % 2 != 0 ? (Settings.getAreaSizeX() >> 1) : 0),thisZone.getZ() * Settings.getAreaSizeZ(),thisZone,player.getName());
  thisThread.initTask(Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getInstance(),thisThread,0,Settings.getTicksBetweenReplace()));
}
 

Example 2

From project AdminCmd, under directory /src/main/java/be/Balor/bukkit/AdminCmd/.

Source file: ACHelper.java

  22 
vote

/** 
 * Set the spawn point.
 */
public void setSpawn(final CommandSender sender){
  if (Utils.isPlayer(sender)) {
    final Location loc=((Player)sender).getLocation();
    final World w=loc.getWorld();
    ACPluginManager.scheduleSyncTask(new Runnable(){
      @Override public void run(){
        w.setSpawnLocation(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ());
      }
    }
);
    ACWorld.getWorld(w.getName()).setSpawn(loc);
    Utils.sI18n(sender,"setSpawn");
  }
}
 

Example 3

From project AdminStuff, under directory /src/main/java/de/minestar/AdminStuff/commands/.

Source file: cmdWeather.java

  22 
vote

/** 
 * Representing the command <br> /weather <Weather> <br> This changes the worldweather
 * @param player Called the command
 * @param split split[0] is the weather
 */
@Override public void execute(String[] args,Player player){
  Weather weather=Weather.getWeather(args[0]);
  if (weather == null) {
    PlayerUtils.sendError(player,pluginName,"Falscher Paramater! Benutze einen der folgenden:");
    PlayerUtils.sendInfo(player,Weather.possibleNames());
  }
 else {
    World world=player.getWorld();
    world.setStorm(weather.isStorming());
    world.setThundering(weather.isThundering());
    PlayerUtils.sendSuccess(player,pluginName,"Wetter in deiner Welt gesetzt auf: '" + weather + "'");
  }
}
 

Example 4

From project Backpack, under directory /src/main/java/com/almuramc/backpack/bukkit/input/.

Source file: BackpackInputHandler.java

  22 
vote

@Override public void keyPressed(KeyBindingEvent keyBindingEvent){
  Player player=keyBindingEvent.getPlayer();
  if (player.getOpenInventory().getTopInventory().getTitle().equals("Backpack")) {
    Bukkit.getPluginManager().callEvent(new InventoryCloseEvent(player.getOpenInventory()));
    player.closeInventory();
  }
  if (!keyBindingEvent.getScreenType().equals(ScreenType.GAME_SCREEN)) {
    return;
  }
  World target=PermissionHelper.getWorldToOpen(player,player.getWorld());
  Inventory toOpen=BackpackPlugin.getInstance().getStore().load(player,target).getInventory();
  player.openInventory(toOpen);
}
 

Example 5

From project BetterShop_1, under directory /src/me/jascotty2/bettershop/regionshops/.

Source file: BSRegions.java

  22 
vote

public String getRegionName(Location loc){
  if (loc != null) {
    final World world=loc.getWorld();
    final RegionManager mgr=globalRegionManager.get(world);
    ApplicableRegionSet regions=mgr.getApplicableRegions(loc);
    if (regions.size() > 0) {
      Region r=regions.iterator().next();
      return r.getId();
    }
  }
  return null;
}
 

Example 6

From project Buildr, under directory /src/me/simplex/buildr/listener/.

Source file: Buildr_Listener_World.java

  22 
vote

@EventHandler public void onWorldLoad(WorldLoadEvent event){
  plugin.log("handle worldload");
  World world=event.getWorld();
  if (plugin.getConfigValue(world.getName())) {
    plugin.enterGlobalbuildmode(world);
    plugin.log("Enabled Globalbuildmode for world " + world.getName() + ". (ConfigValue)");
  }
}
 

Example 7

From project Catacombs, under directory /src/net/steeleyes/catacombs/.

Source file: CatGear.java

  22 
vote

public void dropGear(){
  World world=grave.getWorld();
  if (head != null)   world.dropItemNaturally(grave,head);
  if (chest != null)   world.dropItemNaturally(grave,chest);
  if (legs != null)   world.dropItemNaturally(grave,legs);
  if (feet != null)   world.dropItemNaturally(grave,feet);
  for (int i=0; i <= 35; i++) {
    ItemStack stk=gear.get(i);
    if (stk != null && stk.getType() != Material.AIR) {
      world.dropItemNaturally(grave,stk);
    }
  }
}
 

Example 8

From project ChessCraft, under directory /src/main/java/me/desht/chesscraft/.

Source file: ChessPersistence.java

  22 
vote

private static World findWorld(String worldName){
  World w=Bukkit.getServer().getWorld(worldName);
  if (w != null) {
    return w;
  }
 else {
    throw new IllegalArgumentException("World " + worldName + " was not found on the server.");
  }
}
 

Example 9

From project Citizens, under directory /src/core/net/citizensnpcs/utils/.

Source file: PacketUtils.java

  22 
vote

public static void sendPacketNearby(final Location location,double radius,final Packet packet,final Player except){
  radius*=radius;
  final World world=location.getWorld();
  for (  Player ply : Bukkit.getServer().getOnlinePlayers()) {
    if (ply == null || ply.equals(except) || world != ply.getWorld()) {
      continue;
    }
    if (location.distanceSquared(ply.getLocation()) > radius) {
      continue;
    }
    sendPacketToPlayer(ply,packet);
  }
}
 

Example 10

From project commandbook, under directory /src/main/java/com/sk89q/commandbook/locations/.

Source file: HomesComponent.java

  22 
vote

@Command(aliases={"del","delete","remove","rem"},usage="[name] [world]",desc="Remove a home",min=0,max=2) @CommandPermissions({"commandbook.home.remove"}) public void removeCmd(CommandContext args,CommandSender sender) throws CommandException {
  World world;
  String name=sender.getName();
  if (args.argsLength() == 2) {
    world=LocationUtil.matchWorld(sender,args.getString(1));
  }
 else {
    world=PlayerUtil.checkPlayer(sender).getWorld();
  }
  if (args.argsLength() > 0)   name=args.getString(0);
  remove(name,world,sender);
}
 

Example 11

From project craftbook, under directory /mechanisms/src/main/java/com/sk89q/craftbook/mech/.

Source file: Gate.java

  22 
vote

public int getFirstBlock(WorldVector pt){
  World world=((BukkitWorld)pt.getWorld()).getWorld();
  if (!isValidGateBlock(world.getBlockAt(pt.getBlockX(),pt.getBlockY(),pt.getBlockZ()))) {
    return 0;
  }
  return world.getBlockAt(pt.getBlockX(),pt.getBlockY(),pt.getBlockZ()).getTypeId();
}
 

Example 12

From project DimensionDoor, under directory /src/main/java/name/richardson/james/bukkit/dimensiondoor/management/.

Source file: SpawnCommand.java

  22 
vote

public void execute(CommandSender sender) throws CommandArgumentException, CommandPermissionException, name.richardson.james.bukkit.utilities.command.CommandUsageException {
  final Player player=(Player)sender;
  final World world=player.getWorld();
  final Integer x=(int)player.getLocation().getX();
  final Integer y=(int)player.getLocation().getY();
  final Integer z=(int)player.getLocation().getZ();
  world.setSpawnLocation(x,y,z);
  sender.sendMessage(this.getLocalisation().getMessage(this,"spawn-set",world.getName()));
}
 

Example 13

From project DropChest, under directory /src/main/java/com/narrowtux/dropchest/.

Source file: DropChestItem.java

  22 
vote

private Location locationFromString(ArrayList<String> args){
  World w=Bukkit.getServer().createWorld(new WorldCreator(args.get(0)).environment(Environment.valueOf(args.get(1))));
  int x=Integer.valueOf(args.get(2));
  int y=Integer.valueOf(args.get(3));
  int z=Integer.valueOf(args.get(4));
  return new Location(w,x,y,z);
}
 

Example 14

From project Flow, under directory /src/com/github/JamesNorris/Flow/Mechanics/.

Source file: RainFill.java

  22 
vote

private boolean isPlayerInRain(final Player player){
  final World world=player.getWorld();
  if (world.hasStorm()) {
    final Location loc=player.getLocation();
    final Biome biome=world.getBiome(loc.getBlockX(),loc.getBlockZ());
    if (!LiquidUtil.biomes.contains(biome) && world.getHighestBlockYAt(loc) <= loc.getBlockY()) {
      return true;
    }
  }
  return false;
}
 

Example 15

From project GameTools, under directory /src/main/java/me/nallar/gameTools/spells/.

Source file: Effects.java

  22 
vote

public static final void createLightningExplosion(Location l){
  World w=l.getWorld();
  w.createExplosion(l,0,true);
  w.playEffect(l,Effect.SMOKE,3);
  w.strikeLightningEffect(l);
}
 

Example 16

From project CookieMonster, under directory /src/com/pi/coelho/CookieMonster/.

Source file: CMRegions.java

  21 
vote

public void remove(CommandSender sender,String args[]){
  if (args.length < 2 || args.length > 3) {
    sender.sendMessage("Error parsing command: incorrect # of args");
    return;
  }
  String id=args[2];
  if (sender instanceof Player) {
    remove(sender,((Player)sender).getWorld(),id);
  }
 else {
    String worldname;
    if (id.contains(":") && id.indexOf(":") == id.lastIndexOf(":")) {
      worldname=id.substring(0,id.indexOf(":"));
      id=id.substring(id.indexOf(":") + 1);
    }
 else {
      sender.sendMessage("must specify world (world:region)");
      return;
    }
    World world=null;
    for (    final World w : sender.getServer().getWorlds()) {
      if (w.getName().equalsIgnoreCase(worldname)) {
        world=w;
        break;
      }
    }
    if (world == null) {
      sender.sendMessage("world not found");
      return;
    }
    remove(sender,world,id);
  }
}
 

Example 17

From project DragonTravel, under directory /src/main/java/com/xemsdoom/dt/listeners/.

Source file: BlockListener.java

  21 
vote

@EventHandler(priority=EventPriority.LOW) public void onDestinationSignDestory(BlockBreakEvent event){
  Block block=event.getBlock();
  Player player=event.getPlayer();
  String worldname=block.getLocation().getWorld().toString();
  if (block == null || block.getTypeId() == 0)   return;
  if (block.getType() != Material.SIGN && block.getType() != Material.SIGN_POST)   return;
  for (  String name : DragonTravelMain.signs.getIndices()) {
    double x=DragonTravelMain.signs.getDouble(name,"x");
    double y=DragonTravelMain.signs.getDouble(name,"y");
    double z=DragonTravelMain.signs.getDouble(name,"z");
    if (!worldname.equalsIgnoreCase(DragonTravelMain.signs.getString(name,"world")))     continue;
    World world=block.getWorld();
    Location compar=new Location(world,x,y,z);
    if (!compar.equals(block.getLocation()))     continue;
    if (!(player.hasPermission("dt.travelsigns"))) {
      player.sendMessage(MessagesLoader.replaceColors(DragonTravelMain.messages.getString("NoPermission")));
      event.setCancelled(true);
      break;
    }
    CommandHandlers.dtpCredit(player);
    DragonTravelMain.signs.removeEntry(name);
    DragonTravelMain.signs.push();
    player.sendMessage(MessagesLoader.replaceColors(DragonTravelMain.messages.getString("SignRemovedSuccessfully")));
  }
}
 

Example 18

From project EasyTravel, under directory /src/at/co/hohl/easytravel/ports/.

Source file: Destination.java

  21 
vote

/** 
 * Creates a Destination with the passed description.
 * @param server      the server which wants to load the destination.
 * @param description the string which contains all information.
 * @throws SyntaxException thrown when the description isn't formatted valid.
 */
public Destination(final Server server,final String description) throws SyntaxException {
  PropertiesParser parser=new PropertiesParser(description);
  if ("Destination".equals(parser.getType())) {
    double locx=parser.getDouble("locx");
    double locy=parser.getDouble("locy");
    double locz=parser.getDouble("locz");
    float pitch=parser.getFloat("pitch");
    float yaw=parser.getFloat("yaw");
    String worldName=parser.getString("world");
    if (worldName != null) {
      World world=server.getWorld(worldName);
      location=new Location(world,locx,locy,locz);
      location.setPitch(pitch);
      location.setYaw(yaw);
    }
 else {
      throw new SyntaxException("No world property found!");
    }
  }
 else {
    throw new SyntaxException("String isn't a valid description for a Destination!");
  }
}
 

Example 19

From project ExperienceMod, under directory /ExperienceMod/src/com/comphenix/xp/listeners/.

Source file: ExperienceEnhancementsListener.java

  21 
vote

private int getCustomBookshelfCount(Block table,int maxBookshelfCount,int yOffset){
  final int bookID=Material.BOOKSHELF.getId();
  final World world=table.getWorld();
  int height=(int)Math.ceil(maxBookshelfCount / 15.0);
  int x=table.getX();
  int y=table.getY();
  int z=table.getZ();
  int count=0;
  for (int i=yOffset; i < height; i++)   for (int j=-1; j <= 1; j++)   for (int k=-1; k <= 1; k++) {
    if ((j != 0 || k != 0) && world.getBlockTypeIdAt(x + k,y + i,z + j) == 0) {
      if (world.getBlockTypeIdAt(x + k * 2,y + i,z + j * 2) == bookID) {
        count++;
      }
      if (k != 0 && j != 0) {
        if (world.getBlockTypeIdAt(x + k * 2,y + i,z + j) == bookID) {
          count++;
        }
        if (world.getBlockTypeIdAt(x + k,y + i,z + j * 2) == bookID) {
          count++;
        }
      }
    }
  }
  return count;
}
 

Example 20

From project AntiCheat, under directory /src/main/java/net/h31ix/anticheat/util/.

Source file: Configuration.java

  19 
vote

public final void load(){
  micromanage.getPlugin().checkConfigs();
  config=CommentedConfiguration.loadConfig(configFile);
  level=CommentedConfiguration.loadConfig(levelFile);
  lang=CommentedConfiguration.loadConfig(langFile);
  magic=CommentedConfiguration.loadConfig(magicFile);
  language=new Language(lang);
  updateFolder=Bukkit.getUpdateFolder();
  logConsole=getBoolean("System.Log to console",false);
  logXRay=getBoolean("XRay.Log xray stats",true);
  autoUpdate=getBoolean("System.Auto update",true);
  verboseStartup=getBoolean("System.Verbose startup",false);
  alertXRay=getBoolean("XRay.Alert when xray is found",false);
  fileLogLevel=getInt("System.File log level",1);
  chatSpam=getBoolean("System.Block chat spam",true);
  commandSpam=getBoolean("System.Block command spam",false);
  silentMode=getBoolean("System.Silent mode",false);
  medThreshold=getInt("Events.Medium threshold",20);
  highThreshold=getInt("Events.High threshold",50);
  opExempt=getBoolean("System.Exempt op",false);
  trackCreativeXRay=getBoolean("XRay.Track creative",true);
  if (config.getList("Enable in") == null) {
    List<String> w=new ArrayList<String>();
    for (    World world : Bukkit.getServer().getWorlds()) {
      w.add(world.getName());
    }
    config.set("Enable in",w);
    save();
  }
  worlds=config.getStringList("Enable in");
  save();
}
 

Example 21

From project BleedingMobs, under directory /src/me/snowleo/bleedingmobs/.

Source file: BleedingMobs.java

  19 
vote

@Override public boolean setItemMergeRadius(final World world){
  if (cbPlusPlus) {
    try {
      if (!settings.isWorldEnabled(world)) {
        return true;
      }
      final Method itemMergeRadiusMethod=world.getClass().getMethod("setItemMergeRadius",double.class);
      itemMergeRadiusMethod.invoke(world,0.0);
      getLogger().log(Level.INFO,"CraftBukkit++ detected. Item Merge Radius set to 0.0 in world " + world.getName() + ".");
    }
 catch (    NoSuchMethodException ex) {
    }
catch (    Exception ex) {
      getLogger().log(Level.SEVERE,"Failed to inject into CraftBukkit++. BleedingMobs is now disabled.",ex);
      setEnabled(false);
      return false;
    }
  }
  return true;
}
 

Example 22

From project Bukkit-Plugin-Utilties, under directory /src/main/java/de/xzise/.

Source file: MinecraftUtil.java

  19 
vote

/** 
 * <p> Test if the player has ever joined on the given worlds. </p> <p> <b>Warning</b>: This method is using special behavior of CraftBukkit/Minecraft. </p>
 * @param name Name of the player.
 * @param worlds Worlds the player has to be. If there are no worlds set, it will test all worlds.
 * @return If the player has ever joined on the given worlds.
 */
public static boolean playerHasJoined(String name,World... worlds){
  if (worlds == null || worlds.length == 0) {
    worlds=Bukkit.getServer().getWorlds().toArray(new World[0]);
  }
  for (  World world : worlds) {
    File playerDirectory=new File(world.getName(),"players");
    for (    String playerName : playerDirectory.list()) {
      if (playerName.equals(name + ".dat")) {
        return true;
      }
    }
  }
  return false;
}
 

Example 23

From project ForceCraft, under directory /src/main/java/de/Lathanael/ForceCraft/Utils/.

Source file: Scheduler.java

  19 
vote

/** 
 * "Strikes" the provided player with lightnings and damages him every second for half a heart. Durations depend on the players Skill rank.
 * @param player - ForcePlayer object who casted Lightnings.
 * @param target - ForcePlayer object who should be hit.
 */
public void scheduleLightningTask(final ForcePlayer player,final ForcePlayer target){
  final int playerRank=player.getSkillRank("Lightning");
  if (playerRank == 0)   return;
  final int taskID=plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin,new Runnable(){
    public void run(){
      Player pTarget=target.getHandler();
      World targetWorld=pTarget.getWorld();
      targetWorld.strikeLightning(pTarget.getLocation());
      int health=pTarget.getHealth();
      int amount=plugin.powerInfo.getInt("Lightning.Amount." + String.valueOf(playerRank),1);
      if ((health - amount) < 0)       pTarget.setHealth(0);
 else       pTarget.setHealth(health - amount);
    }
  }
,0,20);
  ids.put(target.getHandler(),taskID);
}
 

Example 24

From project GriefPrevention, under directory /src/me/ryanhamshire/GriefPrevention/.

Source file: GriefPrevention.java

  19 
vote

public int getSeaLevel(World world){
  Integer overrideValue=this.config_seaLevelOverride.get(world.getName());
  if (overrideValue == null || overrideValue == -1) {
    return world.getSeaLevel();
  }
 else {
    return overrideValue;
  }
}
 

Example 25

From project Jobs, under directory /src/main/java/me/zford/jobs/bukkit/.

Source file: JobsPlugin.java

  19 
vote

/** 
 * Check World permissions
 */
public boolean hasWorldPermission(Permissible permissable,World world){
  if (!permissable.hasPermission("jobs.use")) {
    return false;
  }
 else {
    return permissable.hasPermission("jobs.world." + world.getName().toLowerCase());
  }
}
 

Example 26

From project JukeBukkit, under directory /src/main/java/cc/thedudeguy/jukebukkit/material/blocks/.

Source file: DiscBurner.java

  19 
vote

@Override public boolean onBlockInteract(World world,int x,int y,int z,SpoutPlayer player){
  Location location=new Location(world,(double)x,(double)y,(double)z);
  ItemStack inHand=player.getItemInHand();
  if (inHand != null && (new SpoutItemStack(inHand).isCustomItem())) {
    CustomItem customInHand=(CustomItem)new SpoutItemStack(inHand).getMaterial();
    if (customInHand instanceof BlankDisc) {
      if (!player.hasPermission(getUsePermission())) {
        player.sendMessage("You do not have permission to perform this action.");
        player.sendMessage("(" + getUsePermission() + ")");
        return false;
      }
      BurnOptionsGUI.openBurnGUI(player,world.getBlockAt(x,y,z));
      return true;
    }
  }
  SpoutManager.getSoundManager().playGlobalCustomSoundEffect(JukeBukkit.instance,"jb_error.wav",false,location,8);
  return true;
}
 

Example 27

From project LimitedCreative, under directory /src/de/jaschastarke/minecraft/integration/.

Source file: Communicator.java

  19 
vote

public boolean isCreative(World world){
  boolean creative=Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
  if (isMultiVerse()) {
    GameMode tmp=MultiVerse.getGameMode(world);
    if (tmp != null)     creative=tmp == GameMode.CREATIVE;
  }
  Core.debug("com: " + world.getName() + ": is creative: "+ creative);
  return creative;
}
 

Example 28

From project LyTreeHelper, under directory /src/net/darklikally/LyTreeHelper/BOB2/.

Source file: BOB2Generator.java

  19 
vote

public ArrayList<Block> getSurfaceBlocks(Chunk source,World world){
  ArrayList<Block> blocks=new ArrayList<Block>();
  for (int x=0; x < 16; x++) {
    for (int z=0; z < 16; z++) {
      Block b=source.getBlock(x,64,z);
      int y=world.getHighestBlockYAt(b.getX(),b.getZ());
      b=source.getBlock(x,y,z);
      blocks.add(b.getRelative(BlockFace.DOWN));
    }
  }
  return blocks;
}