Search in sources :

Example 6 with WorldTag

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

the class GroupCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    WorldTag world = scriptEntry.getObjectTag("world");
    ElementTag group = scriptEntry.getElement("group");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, world, group);
    }
    World bukkitWorld = null;
    if (world != null) {
        bukkitWorld = world.getWorld();
    }
    OfflinePlayer player = Utilities.getEntryPlayer(scriptEntry).getOfflinePlayer();
    boolean inGroup = Depends.permissions.playerInGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case ADD:
            if (inGroup) {
                Debug.echoDebug(scriptEntry, "Player " + player.getName() + " is already in group " + group);
            } else {
                Depends.permissions.playerAddGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
            }
            break;
        case REMOVE:
            if (!inGroup) {
                Debug.echoDebug(scriptEntry, "Player " + player.getName() + " is not in group " + group);
            } else {
                Depends.permissions.playerRemoveGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
            }
            break;
        case SET:
            for (String grp : Depends.permissions.getPlayerGroups((bukkitWorld == null ? null : bukkitWorld.getName()), player)) {
                Depends.permissions.playerRemoveGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, grp);
            }
            Depends.permissions.playerAddGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.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)

Example 7 with WorldTag

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

the class TimeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    DurationTag value = scriptEntry.getObjectTag("value");
    DurationTag resetAfter = scriptEntry.getObjectTag("reset_after");
    WorldTag world = scriptEntry.getObjectTag("world");
    ElementTag type_element = scriptEntry.getElement("type");
    ElementTag reset = scriptEntry.getElement("reset");
    ElementTag freeze = scriptEntry.getElement("freeze");
    Type type = Type.valueOf(type_element.asString().toUpperCase());
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), type_element, reset, value, freeze, resetAfter, world);
    }
    if (type.equals(Type.GLOBAL)) {
        world.getWorld().setTime(value.getTicks());
    } else {
        if (!Utilities.entryHasPlayer(scriptEntry)) {
            Debug.echoError("Must have a valid player link!");
        } else {
            Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
            if (reset != null && reset.asBoolean()) {
                player.resetPlayerTime();
            } else {
                Integer existingTask = resetTasks.get(player.getUniqueId());
                if (existingTask != null) {
                    Bukkit.getScheduler().cancelTask(existingTask);
                    resetTasks.remove(player.getUniqueId());
                }
                player.setPlayerTime(value.getTicks(), freeze == null || !freeze.asBoolean());
                if (resetAfter != null) {
                    int newTask = Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), player::resetPlayerTime, resetAfter.getTicks());
                    resetTasks.put(player.getUniqueId(), newTask);
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) WorldTag(com.denizenscript.denizen.objects.WorldTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 8 with WorldTag

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

the class WorldBorderCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    WorldTag world = scriptEntry.getObjectTag("world");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    LocationTag center = scriptEntry.getObjectTag("center");
    ElementTag size = scriptEntry.getElement("size");
    ElementTag currSize = scriptEntry.getElement("current_size");
    ElementTag damage = scriptEntry.getElement("damage");
    ElementTag damagebuffer = scriptEntry.getElement("damagebuffer");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag warningdistance = scriptEntry.getElement("warningdistance");
    DurationTag warningtime = scriptEntry.getObjectTag("warningtime");
    ElementTag reset = scriptEntry.getObjectTag("reset");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), world, db("players", players), center, size, currSize, damage, damagebuffer, warningdistance, warningtime, duration, reset);
    }
    if (players != null) {
        if (reset.asBoolean()) {
            for (PlayerTag player : players) {
                NMSHandler.getPacketHelper().resetWorldBorder(player.getPlayerEntity());
            }
            return;
        }
        WorldBorder wb;
        for (PlayerTag player : players) {
            wb = player.getWorld().getWorldBorder();
            NMSHandler.getPacketHelper().setWorldBorder(player.getPlayerEntity(), (center != null ? center : wb.getCenter()), (size != null ? size.asDouble() : wb.getSize()), (currSize != null ? currSize.asDouble() : wb.getSize()), duration.getMillis(), (warningdistance != null ? warningdistance.asInt() : wb.getWarningDistance()), (warningtime != null ? warningtime.getSecondsAsInt() : wb.getWarningTime()));
        }
        return;
    }
    WorldBorder worldborder = world.getWorld().getWorldBorder();
    if (reset.asBoolean()) {
        worldborder.reset();
        return;
    }
    if (center != null) {
        worldborder.setCenter(center);
    }
    if (size != null) {
        if (currSize != null) {
            worldborder.setSize(currSize.asDouble());
        }
        worldborder.setSize(size.asDouble(), duration.getSecondsAsInt());
    }
    if (damage != null) {
        worldborder.setDamageAmount(damage.asDouble());
    }
    if (damagebuffer != null) {
        worldborder.setDamageBuffer(damagebuffer.asDouble());
    }
    if (warningdistance != null) {
        worldborder.setWarningDistance(warningdistance.asInt());
    }
    if (warningtime != null) {
        worldborder.setWarningTime(warningtime.getSecondsAsInt());
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) WorldBorder(org.bukkit.WorldBorder) List(java.util.List) WorldTag(com.denizenscript.denizen.objects.WorldTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 9 with WorldTag

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

the class WeatherCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    Value value = Value.valueOf((scriptEntry.getElement("value")).asString().toUpperCase());
    WorldTag world = scriptEntry.getObjectTag("world");
    Type type = (Type) scriptEntry.getObject("type");
    DurationTag resetAfter = scriptEntry.getObjectTag("reset_after");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("type", type.name()), (type.name().equalsIgnoreCase("player") ? db("player", Utilities.getEntryPlayer(scriptEntry)) : ""), (type.name().equalsIgnoreCase("global") ? db("world", world) : ""), resetAfter, db("value", value));
    }
    if (type.equals(Type.GLOBAL)) {
        switch(value) {
            case SUNNY:
                world.getWorld().setStorm(false);
                world.getWorld().setThundering(false);
                break;
            case STORM:
                world.getWorld().setStorm(true);
                break;
            case THUNDER:
                world.getWorld().setStorm(true);
                world.getWorld().setThundering(true);
                break;
            case RESET:
                Debug.echoError("Cannot RESET global weather!");
                break;
        }
    } else {
        Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
        Integer existingTask = resetTasks.get(player.getUniqueId());
        if (existingTask != null) {
            Bukkit.getScheduler().cancelTask(existingTask);
            resetTasks.remove(player.getUniqueId());
        }
        if (value == Value.SUNNY) {
            player.setPlayerWeather(WeatherType.CLEAR);
        } else if (value == Value.STORM || value == Value.THUNDER) {
            player.setPlayerWeather(WeatherType.DOWNFALL);
        } else if (value == Value.RESET) {
            player.resetPlayerWeather();
        }
        if (resetAfter != null) {
            int newTask = Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), player::resetPlayerWeather, resetAfter.getTicks());
            resetTasks.put(player.getUniqueId(), newTask);
        }
    }
}
Also used : WeatherType(org.bukkit.WeatherType) Player(org.bukkit.entity.Player) WorldTag(com.denizenscript.denizen.objects.WorldTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 10 with WorldTag

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

the class WeatherChangesScriptEvent method onWeatherChanges.

@EventHandler
public void onWeatherChanges(WeatherChangeEvent event) {
    world = new WorldTag(event.getWorld());
    weather = new ElementTag(event.toWeatherState() ? "rains" : "clears");
    this.event = event;
    fire(event);
}
Also used : WorldTag(com.denizenscript.denizen.objects.WorldTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

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