Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a65727
commit d48efe4
Showing
5 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityFlags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.denizenscript.denizen.objects.properties.entity; | ||
|
||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.utilities.flags.DataPersistenceFlagTracker; | ||
import com.denizenscript.denizencore.flags.MapTagFlagTracker; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.MapTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.tags.Attribute; | ||
|
||
import java.util.Collection; | ||
|
||
public class EntityFlags implements Property { | ||
|
||
public static boolean describes(ObjectTag entity) { | ||
return entity instanceof EntityTag; | ||
} | ||
|
||
public static EntityFlags getFrom(ObjectTag entity) { | ||
if (!describes(entity)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityFlags((EntityTag) entity); | ||
} | ||
} | ||
|
||
public static final String[] handledTags = new String[] { | ||
}; | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"flag_map" | ||
}; | ||
|
||
private EntityFlags(EntityTag ent) { | ||
entity = ent; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
@Override | ||
public String getPropertyString() { | ||
DataPersistenceFlagTracker tracker = (DataPersistenceFlagTracker) entity.getFlagTracker(); | ||
Collection<String> flagNames = tracker.listAllFlags(); | ||
if (flagNames.isEmpty()) { | ||
return null; | ||
} | ||
MapTag flags = new MapTag(); | ||
for (String name : flagNames) { | ||
flags.putObject(name, tracker.getRootMap(name)); | ||
} | ||
return flags.toString(); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "flag_map"; | ||
} | ||
|
||
@Override | ||
public ObjectTag getObjectAttribute(Attribute attribute) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name flag_map | ||
// @input MapTag | ||
// @description | ||
// Internal setter for the EntityTag flag map. | ||
// --> | ||
if (mechanism.matches("flag_map") && mechanism.requireObject(MapTag.class)) { | ||
MapTagFlagTracker flags = new MapTagFlagTracker(mechanism.valueAsType(MapTag.class)); | ||
DataPersistenceFlagTracker tracker = (DataPersistenceFlagTracker) entity.getFlagTracker(); | ||
for (String flagName : flags.map.keys()) { | ||
tracker.setRootMap(flagName, flags.getRootMap(flagName)); | ||
} | ||
entity.reapplyTracker(tracker); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters