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;
}
}
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);
}
}
}
}
}
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());
}
}
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);
}
}
}
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);
}
Aggregations