use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class SneakCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag fake = scriptEntry.getElement("fake");
ElementTag stopfake = scriptEntry.getElement("stopfake");
ElementTag mode = scriptEntry.getElement("mode");
List<PlayerTag> forPlayers = (List<PlayerTag>) scriptEntry.getObject("for_players");
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), mode, db("entities", entities), db("for_players", forPlayers), fake, stopfake);
}
boolean shouldSneak = mode.asString().equalsIgnoreCase("start");
boolean shouldFake = fake != null && fake.asBoolean();
boolean shouldStopFake = stopfake != null && stopfake.asBoolean();
for (EntityTag entity : entities) {
if (shouldFake || shouldStopFake) {
if (forPlayers == null) {
updateFakeSneak(entity.getUUID(), null, shouldSneak, shouldFake);
for (Player player : NMSHandler.getEntityHelper().getPlayersThatSee(entity.getBukkitEntity())) {
NMSHandler.getPacketHelper().sendEntityMetadataFlagsUpdate(player, entity.getBukkitEntity());
}
} else {
for (PlayerTag player : forPlayers) {
updateFakeSneak(entity.getUUID(), player.getUUID(), shouldSneak, shouldFake);
NMSHandler.getPacketHelper().sendEntityMetadataFlagsUpdate(player.getPlayerEntity(), entity.getBukkitEntity());
}
}
} else if (entity.isCitizensNPC()) {
SneakingTrait trait = entity.getDenizenNPC().getCitizen().getOrAddTrait(SneakingTrait.class);
if (shouldSneak) {
trait.sneak();
} else {
trait.stand();
}
} else if (entity.isSpawned()) {
NMSHandler.getEntityHelper().setSneaking(entity.getBukkitEntity(), shouldSneak);
} else {
Debug.echoError("Cannot make unspawned entity sneak.");
}
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class ResetCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
// We allow players to be a single player or multiple players
ObjectTag player = scriptEntry.getObjectTag("players");
ListTag players;
if (player instanceof PlayerTag) {
players = new ListTag(player);
} else {
players = scriptEntry.getObjectTag("players");
}
Type type = (Type) scriptEntry.getObject("type");
ScriptTag script = scriptEntry.getObjectTag("script");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), players, db("type", type), script);
}
// Deal with GLOBAL_COOLDOWN reset first, since there's no player/players involved
if (type == Type.GLOBAL_COOLDOWN) {
CooldownCommand.setCooldown(null, new DurationTag(0), script.getName(), true);
return;
}
// Now deal with the rest
for (String object : players) {
PlayerTag resettable = PlayerTag.valueOf(object, scriptEntry.context);
if (resettable.isValid()) {
switch(type) {
case PLAYER_COOLDOWN:
CooldownCommand.setCooldown(resettable, new DurationTag(0), script.getName(), false);
return;
}
}
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class FeedCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
PlayerTag player = scriptEntry.getObjectTag("targetplayer");
NPCTag npc = scriptEntry.getObjectTag("targetnpc");
ElementTag amount = scriptEntry.getElement("amount");
ElementTag saturation = scriptEntry.getElement("saturation");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), player, npc, amount, saturation);
}
if (npc != null) {
if (!npc.getCitizen().hasTrait(HungerTrait.class)) {
Debug.echoError(scriptEntry, "This NPC does not have the HungerTrait enabled! Use /trait hunger");
return;
}
npc.getCitizen().getOrAddTrait(HungerTrait.class).feed(amount.asInt());
} else {
int result = Math.max(0, Math.min(20, player.getPlayerEntity().getFoodLevel() + amount.asInt()));
player.getPlayerEntity().setFoodLevel(result);
float satResult = Math.max(0, Math.min(20, player.getPlayerEntity().getSaturation() + saturation.asFloat()));
player.getPlayerEntity().setSaturation(satResult);
Debug.echoDebug(scriptEntry, "Player food level updated to " + result + " food and " + satResult + " saturation.");
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class ActionBarCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
String text = scriptEntry.getElement("text").asString();
ScriptTag formatObj = scriptEntry.getObjectTag("format");
ElementTag perPlayerObj = scriptEntry.getElement("per_player");
boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
if (!perPlayer) {
text = TagManager.tag(text, context);
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("message", text), db("targets", targets), formatObj, perPlayerObj);
}
FormatScriptContainer format = formatObj == null ? null : (FormatScriptContainer) formatObj.getContainer();
for (PlayerTag player : targets) {
if (player != null) {
if (!player.isOnline()) {
Debug.echoDebug(scriptEntry, "Player is offline, can't send actionbar to them. Skipping.");
continue;
}
String personalText = text;
if (perPlayer) {
context.player = player;
personalText = TagManager.tag(personalText, context);
}
player.getPlayerEntity().spigot().sendMessage(ChatMessageType.ACTION_BAR, FormattedTextHelper.parse(format != null ? format.getFormattedText(personalText, scriptEntry) : personalText, ChatColor.WHITE));
} else {
Debug.echoError("Sent actionbar to non-existent player!?");
}
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class BlockCrackCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
ElementTag progress = scriptEntry.getElement("progress");
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag stack = scriptEntry.getElement("stack");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("players", players), progress, location, stack);
}
Location loc = location.getBlock().getLocation();
if (!progressTracker.containsKey(loc)) {
progressTracker.put(loc, new HashMap<>());
lastBase += 10;
}
Map<UUID, IntHolder> uuidInt = progressTracker.get(loc);
boolean stackVal = stack.asBoolean();
PacketHelper packetHelper = NMSHandler.getPacketHelper();
for (PlayerTag player : players) {
if (!player.isOnline()) {
Debug.echoError("Players must be online!");
continue;
}
Player playerEnt = player.getPlayerEntity();
UUID uuid = playerEnt.getUniqueId();
if (!uuidInt.containsKey(uuid)) {
IntHolder newIntHolder = new IntHolder();
newIntHolder.theInt = lastBase;
newIntHolder.base = lastBase;
uuidInt.put(uuid, newIntHolder);
}
IntHolder intHolder = uuidInt.get(uuid);
if (!stackVal && intHolder.theInt > intHolder.base) {
for (int i = intHolder.base; i <= intHolder.theInt; i++) {
packetHelper.showBlockCrack(playerEnt, i, loc, -1);
}
intHolder.theInt = intHolder.base;
} else if (stackVal && intHolder.theInt - intHolder.base > 10) {
continue;
}
int id = stackVal ? intHolder.theInt++ : intHolder.theInt;
packetHelper.showBlockCrack(player.getPlayerEntity(), id, loc, progress.asInt() - 1);
}
}
Aggregations