Search in sources :

Example 26 with World

use of org.bukkit.World in project Bukkit by Bukkit.

the class ToggleDownfallCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender))
        return true;
    World world = null;
    if (args.length == 1) {
        world = Bukkit.getWorld(args[0]);
        if (world == null) {
            sender.sendMessage(ChatColor.RED + "No world exists with the name '" + args[0] + "'");
            return true;
        }
    } else if (sender instanceof Player) {
        world = ((Player) sender).getWorld();
    } else {
        world = Bukkit.getWorlds().get(0);
    }
    Command.broadcastCommandMessage(sender, "Toggling downfall " + (world.hasStorm() ? "off" : "on") + " for world '" + world.getName() + "'");
    world.setStorm(!world.hasStorm());
    return true;
}
Also used : Player(org.bukkit.entity.Player) World(org.bukkit.World)

Example 27 with World

use of org.bukkit.World in project Denizen-For-Bukkit by DenizenScript.

the class BukkitWorldScriptHelper method timeEvent.

// <--[event]
// @Events
// time changes (in <world>)
// time <0-23> in <world>
//
// @Regex ^on time [^\s]+( in [^\s]+)$
//
// @Triggers when the current time changes in a world (once per mine-hour).
//
// @Context
// <context.time> returns the current time.
// <context.world> returns the world.
//
// -->
public void timeEvent() {
    for (World world : Bukkit.getWorlds()) {
        // TODO: What is this conversion math
        int hour = Double.valueOf(world.getTime() / 1000).intValue();
        hour = hour + 6;
        // Get the hour
        if (hour >= 24) {
            hour = hour - 24;
        }
        dWorld currentWorld = new dWorld(world);
        if (!current_time.containsKey(currentWorld.identifySimple()) || current_time.get(currentWorld.identifySimple()) != hour) {
            Map<String, dObject> context = new HashMap<String, dObject>();
            context.put("time", new Element(hour));
            context.put("world", currentWorld);
            doEvents(Arrays.asList("time changes", "time changes in " + currentWorld.identifySimple(), // NOTE: Deprecated
            String.valueOf(hour) + ":00 in " + currentWorld.identifySimple(), "time " + String.valueOf(hour) + " in " + currentWorld.identifySimple()), null, null, context, true);
            current_time.put(currentWorld.identifySimple(), hour);
        }
    }
}
Also used : HashMap(java.util.HashMap) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) Element(net.aufdemrand.denizencore.objects.Element) World(org.bukkit.World)

Example 28 with World

use of org.bukkit.World in project Denizen-For-Bukkit by DenizenScript.

the class CreateWorldCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element worldName = scriptEntry.getElement("world_name");
    Element generator = scriptEntry.getElement("generator");
    Element worldType = scriptEntry.getElement("worldtype");
    Element environment = scriptEntry.getElement("environment");
    Element copy_from = scriptEntry.getElement("copy_from");
    Element seed = scriptEntry.getElement("seed");
    dB.report(scriptEntry, getName(), worldName.debug() + (generator != null ? generator.debug() : "") + environment.debug() + (copy_from != null ? copy_from.debug() : "") + worldType.debug() + (seed != null ? seed.debug() : ""));
    if (copy_from != null) {
        try {
            if (copy_from.asString().contains("..")) {
                dB.echoError(scriptEntry.getResidingQueue(), "Invalid copy from world name!");
                return;
            }
            File newFolder = new File(worldName.asString());
            File folder = new File(copy_from.asString().replace("w@", ""));
            if (!folder.exists() || !folder.isDirectory()) {
                dB.echoError(scriptEntry.getResidingQueue(), "Invalid copy from world folder - does not exist!");
                return;
            }
            FileUtils.copyDirectory(folder, newFolder);
            File file = new File(worldName.asString() + "/uid.dat");
            if (file.exists()) {
                file.delete();
            }
            File file2 = new File(worldName.asString() + "/session.lock");
            if (file2.exists()) {
                file2.delete();
            }
        } catch (Exception ex) {
            dB.echoError(ex);
            return;
        }
    }
    World world;
    WorldCreator worldCreator = WorldCreator.name(worldName.asString()).environment(World.Environment.valueOf(environment.asString().toUpperCase())).type(WorldType.valueOf(worldType.asString().toUpperCase()));
    if (generator != null) {
        worldCreator.generator(generator.asString());
    }
    if (seed != null) {
        worldCreator.seed(seed.asLong());
    }
    world = Bukkit.getServer().createWorld(worldCreator);
    if (world == null) {
        dB.echoDebug(scriptEntry, "World is null, something went wrong in creation!");
    }
}
Also used : WorldCreator(org.bukkit.WorldCreator) Element(net.aufdemrand.denizencore.objects.Element) World(org.bukkit.World) File(java.io.File) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Example 29 with World

use of org.bukkit.World in project Denizen-For-Bukkit by DenizenScript.

the class ModifyBlockCommand method handleLocation.

void handleLocation(dLocation location, int index, List<dMaterial> materialList, boolean doPhysics, boolean isNatural, int radius, int height, int depth, List<Float> percents) {
    dMaterial material;
    if (percents == null) {
        material = materialList.get(index % materialList.size());
    } else {
        material = null;
        for (int i = 0; i < materialList.size(); i++) {
            float perc = percents.get(i) / 100f;
            if (CoreUtilities.getRandom().nextDouble() <= perc) {
                material = materialList.get(i);
                break;
            }
        }
        if (material == null) {
            return;
        }
    }
    World world = location.getWorld();
    location.setX(location.getBlockX());
    location.setY(location.getBlockY());
    location.setZ(location.getBlockZ());
    setBlock(location, material, doPhysics, isNatural);
    if (radius != 0) {
        for (int x = 0; x < 2 * radius + 1; x++) {
            for (int z = 0; z < 2 * radius + 1; z++) {
                setBlock(new Location(world, location.getX() + x - radius, location.getY(), location.getZ() + z - radius), material, doPhysics, isNatural);
            }
        }
    }
    if (height != 0) {
        for (int x = 0; x < 2 * radius + 1; x++) {
            for (int z = 0; z < 2 * radius + 1; z++) {
                for (int y = 1; y < height + 1; y++) {
                    setBlock(new Location(world, location.getX() + x - radius, location.getY() + y, location.getZ() + z - radius), material, doPhysics, isNatural);
                }
            }
        }
    }
    if (depth != 0) {
        for (int x = 0; x < 2 * radius + 1; x++) {
            for (int z = 0; z < 2 * radius + 1; z++) {
                for (int y = 1; y < depth + 1; y++) {
                    setBlock(new Location(world, location.getX() + x - radius, location.getY() - y, location.getZ() + z - radius), material, doPhysics, isNatural);
                }
            }
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) World(org.bukkit.World) Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 30 with World

use of org.bukkit.World in project Denizen-For-Bukkit by DenizenScript.

the class SwitchCommand method switchBlock.

// Break off this portion of the code from execute() so it can be used in both execute and the delayed runnable
public void switchBlock(ScriptEntry scriptEntry, Location interactLocation, SwitchState switchState, Player player) {
    World world = interactLocation.getWorld();
    boolean currentState = (interactLocation.getBlock().getData() & 0x8) > 0;
    String state = switchState.toString();
    // Try for a linked player
    if (player == null && Bukkit.getOnlinePlayers().size() > 0) {
        // If there's none, link any player
        if (Bukkit.getOnlinePlayers().size() > 0) {
            player = (Player) Bukkit.getOnlinePlayers().toArray()[0];
        } else if (Depends.citizens != null) {
            // If there are no players, link any Human NPC
            for (NPC npc : CitizensAPI.getNPCRegistry()) {
                if (npc.isSpawned() && npc.getEntity() instanceof Player) {
                    player = (Player) npc.getEntity();
                    break;
                }
            }
        // TODO: backup if no human NPC available? (Fake EntityPlayer instance?)
        }
    }
    if ((state.equals("ON") && !currentState) || (state.equals("OFF") && currentState) || state.equals("TOGGLE")) {
        try {
            if (interactLocation.getBlock().getType() == Material.IRON_DOOR_BLOCK) {
                Location block;
                if (interactLocation.clone().add(0, -1, 0).getBlock().getType() == Material.IRON_DOOR_BLOCK) {
                    block = interactLocation.clone().add(0, -1, 0);
                } else {
                    block = interactLocation;
                }
                block.getBlock().setData((byte) (block.getBlock().getData() ^ 4));
            } else {
                NMSHandler.getInstance().getEntityHelper().forceInteraction(player, interactLocation);
            }
            dB.echoDebug(scriptEntry, "Switched " + interactLocation.getBlock().getType().toString() + "! Current state now: " + ((interactLocation.getBlock().getData() & 0x8) > 0 ? "ON" : "OFF"));
        } catch (NullPointerException e) {
            dB.echoError("Cannot switch " + interactLocation.getBlock().getType().toString() + "!");
        }
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Player(org.bukkit.entity.Player) World(org.bukkit.World) Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

World (org.bukkit.World)124 Location (org.bukkit.Location)56 Player (org.bukkit.entity.Player)37 Test (org.junit.Test)20 Block (org.bukkit.block.Block)11 User (com.earth2me.essentials.User)9 IOException (java.io.IOException)9 File (java.io.File)8 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)6 BlockState (org.bukkit.block.BlockState)5 PluginManager (org.bukkit.plugin.PluginManager)5 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)4 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)4 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)4 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)4 Entity (org.bukkit.entity.Entity)4 LivingEntity (org.bukkit.entity.LivingEntity)4