Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
'dead flags' tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 13, 2017
1 parent b052765 commit fef6ac5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Expand Up @@ -9,13 +9,17 @@
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.tags.objects.*;
import com.denizenscript.denizen2sponge.utilities.Utilities;
import com.denizenscript.denizen2sponge.utilities.flags.FlagHelper;
import com.denizenscript.denizen2sponge.utilities.flags.FlagMap;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.world.World;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class ServerTagBase extends AbstractTagBase {

Expand Down Expand Up @@ -157,7 +161,7 @@ public String getName() {
});
// <--[tag]
// @Name ServerBaseTag.has_flag[<TextTag>]
// @Updated 2017/09/15
// @Updated 2017/10/13
// @Group Flag Data
// @ReturnType BooleanTag
// @Returns whether the entity has a flag with the specified key.
Expand All @@ -168,8 +172,25 @@ public String getName() {
return new BooleanTag(Utilities.flagIsValidAndNotExpired(dat.error, flags, flagName));
});
// <--[tag]
// @Name ServerBaseTag.dead_flags
// @Updated 2017/10/13
// @Group Flag Data
// @ReturnType ListTag
// @Returns the list of invalid (expired) flags on the server.
// -->
handlers.put("dead_flags", (dat, obj) -> {
MapTag flags = Denizen2Sponge.instance.serverFlagMap;
ListTag invalid = new ListTag();
for (Map.Entry<String, AbstractTagObject> flag : flags.getInternal().entrySet()) {
if (!Utilities.flagIsValidAndNotExpired(dat.error, flags, flag.getKey())) {
invalid.getInternal().add(new TextTag(flag.getKey()));
}
}
return invalid;
});
// <--[tag]
// @Name ServerBaseTag.flag[<TextTag>]
// @Updated 2017/09/15
// @Updated 2017/10/13
// @Group Flag Data
// @ReturnType Dynamic
// @Returns the flag of the specified key from the entity. May become TextTag regardless of input original type.
Expand Down
Expand Up @@ -234,7 +234,7 @@ public String friendlyName() {
});
// <--[tag]
// @Name EntityTag.has_flag[<TextTag>]
// @Updated 2016/10/26
// @Updated 2017/10/13
// @Group Flag Data
// @ReturnType BooleanTag
// @Returns whether the entity has a flag with the specified key. (And it is not expired).
Expand All @@ -253,13 +253,37 @@ public String friendlyName() {
return new BooleanTag(Utilities.flagIsValidAndNotExpired(dat.error, flags, flagName));
});
// <--[tag]
// @Name EntityTag.dead_flags
// @Updated 2017/10/13
// @Group Flag Data
// @ReturnType ListTag
// @Returns the list of invalid (expired) flags on this entity.
// -->
handlers.put("dead_flags", (dat, obj) -> {
MapTag flags;
Entity e = ((EntityTag) obj).internal;
Optional<FlagMap> fm = e.get(FlagHelper.FLAGMAP);
if (fm.isPresent()) {
flags = fm.get().flags;
}
else {
flags = new MapTag();
}
ListTag invalid = new ListTag();
for (Map.Entry<String, AbstractTagObject> flag : flags.getInternal().entrySet()) {
if (!Utilities.flagIsValidAndNotExpired(dat.error, flags, flag.getKey())) {
invalid.getInternal().add(new TextTag(flag.getKey()));
}
}
return invalid;
});
// <--[tag]
// @Name EntityTag.flag[<TextTag>]
// @Updated 2016/10/26
// @Updated 2017/10/13
// @Group Flag Data
// @ReturnType Dynamic
// @Returns the flag of the specified key from the entity. (And it is not expired).
// Optionally don't specify anything to get the entire flag map.
// Note that flag map uses a s
// -->
handlers.put("flag", (dat, obj) -> {
MapTag flags;
Expand Down

0 comments on commit fef6ac5

Please sign in to comment.