Search in sources :

Example 1 with WorldTag

use of com.denizenscript.denizen.objects.WorldTag in project Denizen-For-Bukkit by DenizenScript.

the class WorldInitsScriptEvent method onWorldInits.

@EventHandler
public void onWorldInits(WorldInitEvent event) {
    world = new WorldTag(event.getWorld());
    this.event = event;
    fire(event);
}
Also used : WorldTag(com.denizenscript.denizen.objects.WorldTag) EventHandler(org.bukkit.event.EventHandler)

Example 2 with WorldTag

use of com.denizenscript.denizen.objects.WorldTag in project Denizen-For-Bukkit by DenizenScript.

the class WorldUnloadsScriptEvent method onWorldUnloads.

@EventHandler
public void onWorldUnloads(WorldUnloadEvent event) {
    world = new WorldTag(event.getWorld());
    this.event = event;
    fire(event);
}
Also used : WorldTag(com.denizenscript.denizen.objects.WorldTag) EventHandler(org.bukkit.event.EventHandler)

Example 3 with WorldTag

use of com.denizenscript.denizen.objects.WorldTag in project Denizen-For-Bukkit by DenizenScript.

the class MapCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag id = scriptEntry.getElement("map-id");
    WorldTag create = scriptEntry.getObjectTag("new");
    ElementTag reset = scriptEntry.getElement("reset");
    LocationTag resetLoc = scriptEntry.getObjectTag("reset-loc");
    ElementTag image = scriptEntry.getElement("image");
    ScriptTag script = scriptEntry.getObjectTag("script");
    ElementTag resize = scriptEntry.getElement("resize");
    ElementTag width = scriptEntry.getElement("width");
    ElementTag height = scriptEntry.getElement("height");
    ElementTag scale = scriptEntry.getElement("scale");
    ElementTag tracking = scriptEntry.getElement("tracking");
    ElementTag x = scriptEntry.getElement("x-value");
    ElementTag y = scriptEntry.getElement("y-value");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), id, create, reset, resetLoc, image, script, resize, width, height, x, y);
    }
    MapView map;
    if (create != null) {
        map = Bukkit.getServer().createMap(create.getWorld());
        scriptEntry.addObject("created_map", new ElementTag(map.getId()));
        Debug.echoDebug(scriptEntry, "Created map with id " + map.getId() + ".");
    } else if (id != null) {
        map = Bukkit.getServer().getMap((short) id.asInt());
        if (map == null) {
            Debug.echoError("No map found for ID '" + id.asInt() + "'!");
            return;
        }
    } else {
        // not possible
        return;
    }
    if (reset.asBoolean()) {
        if (tracking != null) {
            map.setTrackingPosition(true);
        }
        if (scale != null) {
            map.setScale(MapView.Scale.valueOf(scale.asString().toUpperCase()));
        }
        List<MapRenderer> oldRenderers = DenizenMapManager.removeDenizenRenderers(map);
        for (MapRenderer renderer : oldRenderers) {
            map.addRenderer(renderer);
        }
        if (resetLoc != null) {
            map.setCenterX(resetLoc.getBlockX());
            map.setCenterZ(resetLoc.getBlockZ());
            map.setWorld(resetLoc.getWorld());
        }
    }
    if (script != null) {
        DenizenMapManager.removeDenizenRenderers(map);
        ((MapScriptContainer) script.getContainer()).applyTo(map);
    }
    if (image != null) {
        DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
        int wide = width != null ? width.asInt() : resize.asBoolean() ? 128 : 0;
        int high = height != null ? height.asInt() : resize.asBoolean() ? 128 : 0;
        if (CoreUtilities.toLowerCase(image.asString()).endsWith(".gif")) {
            dmr.autoUpdate = true;
        }
        dmr.addObject(new MapImage(dmr, x.asString(), y.asString(), "true", false, image.asString(), wide, high));
        dmr.hasChanged = true;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MapImage(com.denizenscript.denizen.utilities.maps.MapImage) DenizenMapRenderer(com.denizenscript.denizen.utilities.maps.DenizenMapRenderer) MapRenderer(org.bukkit.map.MapRenderer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) MapView(org.bukkit.map.MapView) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) WorldTag(com.denizenscript.denizen.objects.WorldTag) DenizenMapRenderer(com.denizenscript.denizen.utilities.maps.DenizenMapRenderer) MapScriptContainer(com.denizenscript.denizen.scripts.containers.core.MapScriptContainer)

Example 4 with WorldTag

use of com.denizenscript.denizen.objects.WorldTag in project Denizen-For-Bukkit by DenizenScript.

the class RemoveCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    WorldTag world = scriptEntry.getObjectTag("world");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), world, db("entities", entities));
    }
    for (EntityTag entity : entities) {
        if (entity.isUnique()) {
            if (entity.isFake) {
                FakeEntity fakeEnt = FakeEntity.idsToEntities.get(entity.getUUID());
                if (fakeEnt != null) {
                    fakeEnt.cancelEntity();
                }
            } else if (entity.isCitizensNPC()) {
                entity.getDenizenNPC().getCitizen().destroy();
            } else if (entity.isSpawned()) {
                entity.remove();
            } else {
                Debug.echoError("Tried to remove already-removed entity.");
            }
        } else {
            int removed = 0;
            for (Entity worldEntity : world.getEntities()) {
                if (entity.getEntityType().equals(DenizenEntityType.getByEntity(worldEntity))) {
                    worldEntity.remove();
                    removed++;
                }
            }
            Debug.echoDebug(scriptEntry, "Removed " + removed + " entities from the world.");
            if (alwaysWarnOnMassRemove) {
                Debug.echoError("Remove command 'Always warn on mass delete' in Denizen config is enabled - mass removal of '" + entity.getEntityType() + "' performed, removing " + removed + " entities.");
            }
        }
    }
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) Entity(org.bukkit.entity.Entity) FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) WorldTag(com.denizenscript.denizen.objects.WorldTag)

Example 5 with WorldTag

use of com.denizenscript.denizen.objects.WorldTag in project Denizen-For-Bukkit by DenizenScript.

the class PermissionCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    ElementTag permission = scriptEntry.getElement("permission");
    ElementTag group = scriptEntry.getElement("group");
    WorldTag world = scriptEntry.getObjectTag("world");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, permission, group, world);
    }
    World bukkitWorld = null;
    if (world != null) {
        bukkitWorld = world.getWorld();
    }
    OfflinePlayer player = Utilities.entryHasPlayer(scriptEntry) ? Utilities.getEntryPlayer(scriptEntry).getOfflinePlayer() : null;
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case ADD:
            if (group != null) {
                if (Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
                    Debug.echoDebug(scriptEntry, "Group " + group + " already has permission " + permission);
                } else {
                    Depends.permissions.groupAdd(bukkitWorld, group.asString(), permission.asString());
                }
            } else {
                if (Depends.permissions.playerHas(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
                    Debug.echoDebug(scriptEntry, "Player " + player.getName() + " already has permission " + permission);
                } else {
                    Depends.permissions.playerAdd(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
                }
            }
            break;
        case REMOVE:
            if (group != null) {
                if (!Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
                    Debug.echoDebug(scriptEntry, "Group " + group + " does not have access to permission " + permission);
                } else {
                    Depends.permissions.groupRemove(bukkitWorld, group.asString(), permission.asString());
                }
            } else {
                if (!Depends.permissions.playerHas(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
                    Debug.echoDebug(scriptEntry, "Player " + player.getName() + " does not have access to permission " + permission);
                } else {
                    Depends.permissions.playerRemove(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
                }
            }
            break;
    }
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) WorldTag(com.denizenscript.denizen.objects.WorldTag) World(org.bukkit.World)

Aggregations

WorldTag (com.denizenscript.denizen.objects.WorldTag)14 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)7 EventHandler (org.bukkit.event.EventHandler)6 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)3 LocationTag (com.denizenscript.denizen.objects.LocationTag)2 List (java.util.List)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 World (org.bukkit.World)2 Player (org.bukkit.entity.Player)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 MapScriptContainer (com.denizenscript.denizen.scripts.containers.core.MapScriptContainer)1 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)1 DenizenMapRenderer (com.denizenscript.denizen.utilities.maps.DenizenMapRenderer)1 MapImage (com.denizenscript.denizen.utilities.maps.MapImage)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1 WeatherType (org.bukkit.WeatherType)1 WorldBorder (org.bukkit.WorldBorder)1 Entity (org.bukkit.entity.Entity)1 MapRenderer (org.bukkit.map.MapRenderer)1