Search in sources :

Example 81 with World

use of org.bukkit.World in project Towny by ElgarL.

the class TownyRegenAPI method regenUndo.

/**
	 * Restore the relevant chunk using the snapshot data stored in the resident
	 * object.
	 * 
	 * @param snapshot
	 * @param resident
	 */
public static void regenUndo(Object[][][] snapshot, Resident resident) {
    BlockObject key = ((BlockObject) snapshot[0][0][0]);
    World world = key.getLocation().getWorld();
    Chunk chunk = key.getLocation().getChunk();
    int maxHeight = world.getMaxHeight();
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            for (int y = 0; y < maxHeight; y++) {
                // Snapshot data we need to update the world.
                Object state = snapshot[x][y][z];
                // The block we will be updating
                Block block = chunk.getBlock(x, y, z);
                if (state instanceof BlockSign) {
                    BlockSign signData = (BlockSign) state;
                    BukkitTools.setTypeIdAndData(block, signData.getTypeId(), signData.getData(), false);
                    Sign sign = (Sign) block.getState();
                    int i = 0;
                    for (String line : signData.getLines()) sign.setLine(i++, line);
                    sign.update(true);
                } else if (state instanceof BlockMobSpawner) {
                    BlockMobSpawner spawnerData = (BlockMobSpawner) state;
                    BukkitTools.setTypeIdAndData(block, spawnerData.getTypeId(), spawnerData.getData(), false);
                    ((CreatureSpawner) block.getState()).setSpawnedType(spawnerData.getSpawnedType());
                    ((CreatureSpawner) block.getState()).setDelay(spawnerData.getDelay());
                } else if ((state instanceof BlockInventoryHolder) && !(state instanceof Player)) {
                    BlockInventoryHolder containerData = (BlockInventoryHolder) state;
                    BukkitTools.setTypeIdAndData(block, containerData.getTypeId(), containerData.getData(), false);
                    // Container to receive the inventory
                    InventoryHolder container = (InventoryHolder) block.getState();
                    // Contents we are respawning.						
                    if (containerData.getItems().length > 0)
                        container.getInventory().setContents(containerData.getItems());
                } else {
                    BlockObject blockData = (BlockObject) state;
                    BukkitTools.setTypeIdAndData(block, blockData.getTypeId(), blockData.getData(), false);
                }
            }
        }
    }
    TownyMessaging.sendMessage(BukkitTools.getPlayerExact(resident.getName()), TownySettings.getLangString("msg_undo_complete"));
}
Also used : BlockInventoryHolder(com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder) Player(org.bukkit.entity.Player) World(org.bukkit.World) Chunk(org.bukkit.Chunk) BlockMobSpawner(com.palmergames.bukkit.towny.regen.block.BlockMobSpawner) BlockSign(com.palmergames.bukkit.towny.regen.block.BlockSign) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) BlockObject(com.palmergames.bukkit.towny.regen.block.BlockObject) Sign(org.bukkit.block.Sign) BlockSign(com.palmergames.bukkit.towny.regen.block.BlockSign) InventoryHolder(org.bukkit.inventory.InventoryHolder) BlockInventoryHolder(com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder) BlockObject(com.palmergames.bukkit.towny.regen.block.BlockObject)

Example 82 with World

use of org.bukkit.World in project Towny by ElgarL.

the class TownyRegenAPI method doDeleteTownBlockIds.

/**
	 * Deletes all of a specified block type from a TownBlock
	 * 
	 * @param worldCoord
	 */
public static void doDeleteTownBlockIds(WorldCoord worldCoord) {
    //Block block = null;
    World world = null;
    int plotSize = TownySettings.getTownBlockSize();
    TownyMessaging.sendDebugMsg("Processing deleteTownBlockIds");
    world = worldCoord.getBukkitWorld();
    if (world != null) {
        /*
			 * if
			 * (!world.isChunkLoaded(MinecraftTools.calcChunk(townBlock.getX()),
			 * MinecraftTools.calcChunk(townBlock.getZ())))
			 * return;
			 */
        int height = world.getMaxHeight() - 1;
        int worldx = worldCoord.getX() * plotSize, worldz = worldCoord.getZ() * plotSize;
        for (int z = 0; z < plotSize; z++) for (int x = 0; x < plotSize; x++) for (int y = height; y > 0; y--) {
            //Check from bottom up else minecraft won't remove doors
            Block block = world.getBlockAt(worldx + x, y, worldz + z);
            try {
                if (worldCoord.getTownyWorld().isPlotManagementDeleteIds(block.getType().name())) {
                    block.setType(Material.AIR);
                }
            } catch (NotRegisteredException e) {
            // Not a registered world
            }
            block = null;
        }
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) World(org.bukkit.World)

Example 83 with World

use of org.bukkit.World in project Towny by ElgarL.

the class MobRemovalTimerTask method run.

@Override
public void run() {
    // Build a list of mobs to be removed
    List<LivingEntity> livingEntitiesToRemove = new ArrayList<LivingEntity>();
    for (World world : server.getWorlds()) {
        TownyWorld townyWorld;
        // Filter worlds not registered
        try {
            townyWorld = TownyUniverse.getDataSource().getWorld(world.getName());
        } catch (NotRegisteredException e) {
            // World was not registered by Towny, so we skip all mobs in it.
            continue;
        } catch (NullPointerException ex) {
            // Spigot has unloaded this world.
            continue;
        }
        // Filter worlds not using towny.
        if (!townyWorld.isUsingTowny())
            continue;
        // Filter worlds that will always pass all checks in a world, regardless of possible conditions.
        if (townyWorld.isForceTownMobs() && townyWorld.hasWorldMobs())
            continue;
        //
        for (LivingEntity livingEntity : world.getLivingEntities()) {
            Location livingEntityLoc = livingEntity.getLocation();
            if (!livingEntityLoc.getChunk().isLoaded())
                continue;
            Coord coord = Coord.parseCoord(livingEntityLoc);
            try {
                TownBlock townBlock = townyWorld.getTownBlock(coord);
                // Check if mobs are always allowed inside towns in this world.
                if (townyWorld.isForceTownMobs())
                    continue;
                // Check if plot allows mobs.
                if (townBlock.getPermissions().mobs)
                    continue;
                // Check if the plot is registered to a town.
                Town town = townBlock.getTown();
                // Check if the town this plot is registered to allows mobs.
                if (town.hasMobs())
                    continue;
                // Check that Towny is removing this type of entity inside towns.
                if (!isRemovingTownEntity(livingEntity))
                    continue;
            } catch (NotRegisteredException x) {
                // Check if we're allowing mobs in unregistered plots in this world.
                if (townyWorld.hasWorldMobs())
                    continue;
                // Check that Towny is removing this type of entity in unregistered plots.
                if (!isRemovingWorldEntity(livingEntity))
                    continue;
            }
            // Check if entity is a Citizens NPC
            if (plugin.isCitizens2()) {
                if (CitizensAPI.getNPCRegistry().isNPC(livingEntity))
                    continue;
            }
            livingEntitiesToRemove.add(livingEntity);
        }
    }
    MobRemovalEvent mobRemovalEvent;
    for (LivingEntity livingEntity : livingEntitiesToRemove) {
        mobRemovalEvent = new MobRemovalEvent(livingEntity);
        plugin.getServer().getPluginManager().callEvent(mobRemovalEvent);
        if (!mobRemovalEvent.isCancelled()) {
            TownyMessaging.sendDebugMsg("MobRemoval Removed: " + livingEntity.toString());
            livingEntity.remove();
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) MobRemovalEvent(com.palmergames.bukkit.towny.event.MobRemovalEvent) ArrayList(java.util.ArrayList) World(org.bukkit.World) Location(org.bukkit.Location)

Example 84 with World

use of org.bukkit.World in project Towny by ElgarL.

the class CellBorder method runBorderedOnSurface.

public void runBorderedOnSurface(int wallHeight, int cornerHeight, LocationRunnable runnable) {
    int x = getBlockX();
    int z = getBlockZ();
    int w = Coord.getCellSize() - 1;
    World world = getBukkitWorld();
    for (Section section : Section.values()) {
        if (border[section.ordinal()]) {
            if ((section.getType() == Section.Type.WALL && wallHeight > 0) || section.getType() == Section.Type.CORNER && cornerHeight > 0) {
                switch(section) {
                    case N:
                        DrawUtil.runOnSurface(world, x, z, x, z + w, wallHeight, runnable);
                        break;
                    case NE:
                        DrawUtil.runOnSurface(world, x, z, x, z, cornerHeight, runnable);
                        break;
                    case E:
                        DrawUtil.runOnSurface(world, x, z, x + w, z, wallHeight, runnable);
                        break;
                    case SE:
                        DrawUtil.runOnSurface(world, x + w, z, x + w, z, cornerHeight, runnable);
                        break;
                    case S:
                        DrawUtil.runOnSurface(world, x + w, z, x + w, z + w, wallHeight, runnable);
                        break;
                    case SW:
                        DrawUtil.runOnSurface(world, x + w, z + w, x + w, z + w, cornerHeight, runnable);
                        break;
                    case W:
                        DrawUtil.runOnSurface(world, x, z + w, x + w, z + w, wallHeight, runnable);
                        break;
                    case NW:
                        DrawUtil.runOnSurface(world, x, z + w, x, z + w, cornerHeight, runnable);
                        break;
                }
            }
        }
    }
}
Also used : World(org.bukkit.World)

Example 85 with World

use of org.bukkit.World in project Jobs by GamingMesh.

the class JobsConfiguration method loadRestrictedAreaSettings.

/**
     * Method to load the restricted areas configuration
     * 
     * loads from Jobs/restrictedAreas.yml
     */
private synchronized void loadRestrictedAreaSettings() {
    this.restrictedAreas.clear();
    File f = new File(plugin.getDataFolder(), "restrictedAreas.yml");
    YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
    conf.options().indent(2);
    conf.options().copyDefaults(true);
    StringBuilder header = new StringBuilder();
    header.append("Restricted area configuration").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Configures restricted areas where you cannot get experience or money").append(System.getProperty("line.separator")).append("when performing a job.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("The multiplier changes the experience/money gains in an area.").append(System.getProperty("line.separator")).append("A multiplier of 0.0 means no money or xp, while 0.5 means you will get half the normal money/exp").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("restrictedareas:").append(System.getProperty("line.separator")).append("  area1:").append(System.getProperty("line.separator")).append("    world: 'world'").append(System.getProperty("line.separator")).append("    multiplier: 0.0").append(System.getProperty("line.separator")).append("    point1:").append(System.getProperty("line.separator")).append("      x: 125").append(System.getProperty("line.separator")).append("      y: 0").append(System.getProperty("line.separator")).append("      z: 125").append(System.getProperty("line.separator")).append("    point2:").append(System.getProperty("line.separator")).append("      x: 150").append(System.getProperty("line.separator")).append("      y: 100").append(System.getProperty("line.separator")).append("      z: 150").append(System.getProperty("line.separator")).append("  area2:").append(System.getProperty("line.separator")).append("    world: 'world_nether'").append(System.getProperty("line.separator")).append("    multiplier: 0.0").append(System.getProperty("line.separator")).append("    point1:").append(System.getProperty("line.separator")).append("      x: -100").append(System.getProperty("line.separator")).append("      y: 0").append(System.getProperty("line.separator")).append("      z: -100").append(System.getProperty("line.separator")).append("    point2:").append(System.getProperty("line.separator")).append("      x: -150").append(System.getProperty("line.separator")).append("      y: 100").append(System.getProperty("line.separator")).append("      z: -150");
    conf.options().header(header.toString());
    ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas");
    if (areaSection != null) {
        for (String areaKey : areaSection.getKeys(false)) {
            String worldName = conf.getString("restrictedareas." + areaKey + ".world");
            double multiplier = conf.getDouble("restrictedareas." + areaKey + ".multiplier", 0.0);
            World world = Bukkit.getServer().getWorld(worldName);
            if (world == null)
                continue;
            Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point1.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point1.z", 0.0));
            Location point2 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point2.x", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.z", 0.0));
            this.restrictedAreas.add(new RestrictedArea(point1, point2, multiplier));
        }
    }
    try {
        conf.save(f);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : RestrictedArea(com.gamingmesh.jobs.container.RestrictedArea) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) World(org.bukkit.World) File(java.io.File) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Location(org.bukkit.Location)

Aggregations

World (org.bukkit.World)139 Location (org.bukkit.Location)63 Player (org.bukkit.entity.Player)41 Test (org.junit.Test)20 Block (org.bukkit.block.Block)14 IOException (java.io.IOException)10 Entity (org.bukkit.entity.Entity)10 User (com.earth2me.essentials.User)9 File (java.io.File)9 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)7 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)7 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)7 ArrayList (java.util.ArrayList)7 Material (org.bukkit.Material)6 LivingEntity (org.bukkit.entity.LivingEntity)6 EventHandler (org.bukkit.event.EventHandler)6 UUID (java.util.UUID)5 PluginManager (org.bukkit.plugin.PluginManager)5 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)4 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)4