Skip to content

Commit

Permalink
implement contextAsType
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 12, 2020
1 parent 1481768 commit b324838
Show file tree
Hide file tree
Showing 27 changed files with 39 additions and 37 deletions.
Expand Up @@ -42,7 +42,7 @@ public void tagEvent(ReplaceableTagEvent event) {
if (attribute.hasContext(1)) {
// Documented below.
if (JobsJobTag.matches(attribute.getContext(1))) {
j = JobsJobTag.valueOf(attribute.getContext(1));
j = attribute.contextAsType(1, JobsJobTag.class);
}
else {
Debug.echoError("Could not match '" + attribute.getContext(1) + "' to a valid job!");
Expand Down
Expand Up @@ -59,7 +59,7 @@ public void tagEvent(ReplaceableTagEvent event) {
// -->
if (attribute.startsWith("track")) {
if (attribute.hasContext(1)) {
event.setReplacedObject(LuckPermsTrackTag.valueOf(attribute.getContext(1)).getObjectAttribute(attribute.fulfill(1)));
event.setReplacedObject(attribute.contextAsType(1, LuckPermsTrackTag.class).getObjectAttribute(attribute.fulfill(1)));
}
}
}
Expand Down
Expand Up @@ -47,7 +47,7 @@ public void tagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes();

if (attribute.startsWith("party") && attribute.hasContext(1)) {
PartyTag party = PartyTag.valueOf(attribute.getContext(1));
PartyTag party = attribute.contextAsType(1, PartyTag.class);
if (party != null) {
event.setReplacedObject(party.getObjectAttribute(attribute.fulfill(1)));
}
Expand Down
Expand Up @@ -53,7 +53,7 @@ public void tagEvent(ReplaceableTagEvent event) {
// Returns the mob arena for the input name.
// -->
if (attribute.hasContext(1)) {
MobArenaArenaTag arena = MobArenaArenaTag.valueOf(attribute.getContext(1));
MobArenaArenaTag arena = attribute.contextAsType(1, MobArenaArenaTag.class);
if (arena != null) {
event.setReplacedObject(arena.getObjectAttribute(attribute.fulfill(1)));
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ public void tagEvent(ReplaceableTagEvent event) {
// Returns the PVPArena by the input name.
// -->
if (attribute.hasContext(1)) {
PVPArenaArenaTag arena = PVPArenaArenaTag.valueOf(attribute.getContext(1));
PVPArenaArenaTag arena = attribute.contextAsType(1, PVPArenaArenaTag.class);
if (arena != null) {
event.setReplacedObject(arena.getObjectAttribute(attribute.fulfill(1)));
}
Expand Down
Expand Up @@ -57,7 +57,7 @@ public void tagEvent(ReplaceableTagEvent event) {
// Returns the value of the placeholder for the specified player.
// -->
if (attribute.matches("player") && attribute.hasContext(1) && PlayerTag.matches(attribute.getContext(1))) {
player = PlayerTag.valueOf(attribute.getContext(1)).getPlayerEntity();
player = attribute.contextAsType(1, PlayerTag.class).getPlayerEntity();
}
event.setReplacedObject(new ElementTag(PlaceholderAPI.setPlaceholders(player, "%" + placeholder + "%"))
.getObjectAttribute(attribute.fulfill(1)));
Expand Down
Expand Up @@ -62,7 +62,7 @@ public boolean isTarget(LivingEntity ent, String prefix, String value) {
context = value.substring(colon + 1);
value = value.substring(0, colon);
}
ScriptTag script = ScriptTag.valueOf(value);
ScriptTag script = ScriptTag.valueOf(value, CoreUtilities.basicContext);
if (script == null) {
Debug.echoError("Invalid procedure script name '" + value + "' (non-existent) in a Sentinel NPC target.");
return false;
Expand Down
Expand Up @@ -100,7 +100,7 @@ public void townTagEvent(ReplaceableTagEvent event) {
if (attribute.hasContext(1)) {
TownTag town;
if (TownTag.matches(attribute.getContext(1))) {
town = TownTag.valueOf(attribute.getContext(1));
town = attribute.contextAsType(1, TownTag.class);
}
else {
Debug.echoError("Could not match '" + attribute.getContext(1) + "' to a valid town!");
Expand Down Expand Up @@ -128,7 +128,7 @@ public void nationTagEvent(ReplaceableTagEvent event) {
if (attribute.hasContext(1)) {
NationTag nation;
if (NationTag.matches(attribute.getContext(1))) {
nation = NationTag.valueOf(attribute.getContext(1));
nation = attribute.contextAsType(1, NationTag.class);
}
else {
Debug.echoError("Could not match '" + attribute.getContext(1) + "' to a valid nation!");
Expand Down
Expand Up @@ -44,7 +44,7 @@ public void run(ReplaceableTagEvent event) {
public void tagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes();
if (attribute.startsWith("region") && attribute.hasContext(1)) {
WorldGuardRegionTag region = WorldGuardRegionTag.valueOf(attribute.getContext(1));
WorldGuardRegionTag region = attribute.contextAsType(1, WorldGuardRegionTag.class);
if (region != null) {
event.setReplacedObject(region.getObjectAttribute(attribute.fulfill(1)));
}
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.denizenscript.denizen.tags.BukkitTagContext;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.depenizen.bukkit.Depenizen;
import com.denizenscript.depenizen.bukkit.bungee.BungeeBridge;
import com.denizenscript.depenizen.bukkit.bungee.PacketIn;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void run() {
// Ignore
}
}
ScriptTag script = ScriptTag.valueOf(scriptName);
ScriptTag script = ScriptTag.valueOf(scriptName, CoreUtilities.basicContext);
List<ScriptEntry> entries = script.getContainer().getBaseEntries(new BukkitScriptEntryData(linkedPlayer, null));
if (entries.isEmpty()) {
return;
Expand Down
Expand Up @@ -68,6 +68,7 @@ public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
}
new_mana = mana.asInt();
event.setNewAmount(new_mana);
return true;
}
return super.applyDetermination(path, determinationObj);
}
Expand Down
Expand Up @@ -226,7 +226,7 @@ else if (attribute.startsWith("ispermanent") || attribute.startsWith("is_permane
// -->
else if (attribute.startsWith("leader")) {
if (faction.getLeader() != null) {
return PlayerTag.valueOf(faction.getLeader().getName())
return PlayerTag.valueOf(faction.getLeader().getName(), attribute.context)
.getAttribute(attribute.fulfill(1));
}
}
Expand Down Expand Up @@ -334,7 +334,7 @@ else if (attribute.startsWith("size")) {
Set<PS> chunks = BoardColl.get().getChunks(faction);
ListTag players = new ListTag();
for (MPlayer ps : faction.getMPlayers()) {
players.addObject(PlayerTag.valueOf(faction.getLeader().getUuid().toString()));
players.addObject(PlayerTag.valueOf(faction.getLeader().getUuid().toString(), attribute.context));
}
return players.getAttribute(attribute.fulfill(1));
}
Expand Down
Expand Up @@ -152,7 +152,7 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("assistants")) {
ListTag list = new ListTag();
for (Resident resident : nation.getAssistants()) {
list.addObject(PlayerTag.valueOf(resident.getName()));
list.addObject(PlayerTag.valueOf(resident.getName(), attribute.context));
}
return list.getAttribute(attribute.fulfill(1));
}
Expand Down Expand Up @@ -224,7 +224,7 @@ else if (attribute.startsWith("isneutral") || attribute.startsWith("is_neutral")
// Returns the king of the nation.
// -->
else if (attribute.startsWith("king")) {
return PlayerTag.valueOf(nation.getCapital().getMayor().getName())
return PlayerTag.valueOf(nation.getCapital().getMayor().getName(), attribute.context)
.getAttribute(attribute.fulfill(1));
}

Expand Down Expand Up @@ -290,7 +290,7 @@ else if (nation.hasEnemy(to.nation)) {
if (attribute.startsWith("residents")) {
ListTag list = new ListTag();
for (Resident resident : nation.getResidents()) {
list.addObject(PlayerTag.valueOf(resident.getName()));
list.addObject(PlayerTag.valueOf(resident.getName(), attribute.context));
}
return list.getAttribute(attribute.fulfill(1));
}
Expand Down
Expand Up @@ -281,7 +281,7 @@ else if (attribute.startsWith("chunks")) {
// Returns whether the GriefPreventionClaim can siege the player.
// -->
else if (attribute.startsWith("can_siege") && attribute.hasContext(1)) {
PlayerTag defender = PlayerTag.valueOf(attribute.getContext(1));
PlayerTag defender = attribute.contextAsType(1, PlayerTag.class);
if (defender == null || defender.getPlayerEntity() == null) {
return null;
}
Expand Down Expand Up @@ -317,7 +317,7 @@ public void adjust(Mechanism mechanism) {
if (mechanism.matches("owner")) {
try {
if (PlayerTag.matches(mechanism.getValue().asString())) {
PlayerTag player = PlayerTag.valueOf(mechanism.getValue().asString());
PlayerTag player = mechanism.valueAsType(PlayerTag.class);
dataStore.changeClaimOwner(claim, player.getOfflinePlayer().getUniqueId());
}
else if (CoreUtilities.toLowerCase(mechanism.getValue().asString()).equals("admin")) {
Expand Down
Expand Up @@ -163,7 +163,7 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("groups")) {
ListTag groups = new ListTag();
if (attribute.hasContext(1)) {
PlayerTag player = PlayerTag.valueOf(attribute.getContext(1));
PlayerTag player = attribute.contextAsType(1, PlayerTag.class);
if (player == null) {
attribute.echoError("Invalid player input for 'group' tag.");
return null;
Expand Down
Expand Up @@ -160,7 +160,7 @@ else if (attribute.startsWith("leader")) {
else if (attribute.startsWith("members")) {
ListTag players = new ListTag();
for (UUID uuid : party.getMembers().keySet()) {
players.addObject(PlayerTag.valueOf(uuid.toString()));
players.addObject(PlayerTag.valueOf(uuid.toString(), attribute.context));
}
return players.getAttribute(attribute.fulfill(1));
}
Expand Down
Expand Up @@ -336,7 +336,7 @@ else if (mechanism.matches("reset_target")) {
// <MythicMobsMobTag.target>
// -->
else if (mechanism.matches("target") && mechanism.requireObject(EntityTag.class)) {
EntityTag mTarget = EntityTag.valueOf(mechanism.getValue().asString());
EntityTag mTarget = mechanism.valueAsType(EntityTag.class);
if (mTarget == null || !mTarget.isValid() || mTarget.getLivingEntity() == null) {
return;
}
Expand Down
Expand Up @@ -201,7 +201,7 @@ public String getAttribute(Attribute attribute) {
// Returns the plot's world.
// -->
if (attribute.startsWith("world")) {
return WorldTag.valueOf(plot.getArea().worldname).getAttribute(attribute.fulfill(1));
return WorldTag.valueOf(plot.getArea().worldname, attribute.context).getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down Expand Up @@ -272,7 +272,7 @@ public String getAttribute(Attribute attribute) {
// Returns the plot's cuboid.
// -->
if (attribute.startsWith("cuboid")) {
WorldTag world = WorldTag.valueOf(plot.getArea().worldname);
WorldTag world = WorldTag.valueOf(plot.getArea().worldname, attribute.context);
Location l1 = new Location(world.getWorld(), plot.getBottomAbs().getX(), 0, plot.getBottomAbs().getZ());
Location l2 = new Location(world.getWorld(), plot.getTopAbs().getX(), 255, plot.getTopAbs().getZ());
return new CuboidTag(l1, l2).getAttribute(attribute.fulfill(1));
Expand All @@ -287,7 +287,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("all_cuboids")) {
ListTag cuboids = new ListTag();
WorldTag world = WorldTag.valueOf(plot.getArea().worldname);
WorldTag world = WorldTag.valueOf(plot.getArea().worldname, attribute.context);
for (RegionWrapper region : plot.getRegions()) {
Location l1 = new Location(world.getWorld(), region.minX, region.minY, region.minZ);
Location l2 = new Location(world.getWorld(), region.maxX, region.maxY, region.maxZ);
Expand Down
Expand Up @@ -151,7 +151,7 @@ else if (attribute.startsWith("owner")) {
// Returns whether the specified location is within this Residence.
// -->
else if (attribute.startsWith("is_within") && attribute.hasContext(1)) {
LocationTag location = LocationTag.valueOf(attribute.getContext(1));
LocationTag location = attribute.contextAsType(1, LocationTag.class);
return new ElementTag(residence.containsLoc(location)).getAttribute(attribute.fulfill(1));
}

Expand Down
Expand Up @@ -157,7 +157,7 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("assistants")) {
ListTag list = new ListTag();
for (Resident resident : town.getAssistants()) {
PlayerTag player = PlayerTag.valueOf(resident.getName());
PlayerTag player = PlayerTag.valueOf(resident.getName(), attribute.context);
if (player != null) {
list.addObject(player);
}
Expand Down Expand Up @@ -230,7 +230,7 @@ else if (attribute.startsWith("ispublic") || attribute.startsWith("is_public"))
// Returns the mayor of the town.
// -->
else if (attribute.startsWith("mayor")) {
return PlayerTag.valueOf(town.getMayor().getName())
return PlayerTag.valueOf(town.getMayor().getName(), attribute.context)
.getAttribute(attribute.fulfill(1));
}

Expand Down Expand Up @@ -284,7 +284,7 @@ else if (attribute.startsWith("playercount") || attribute.startsWith("player_cou
else if (attribute.startsWith("residents")) {
ListTag list = new ListTag();
for (Resident resident : town.getResidents()) {
PlayerTag player = PlayerTag.valueOf(resident.getName());
PlayerTag player = PlayerTag.valueOf(resident.getName(), attribute.context);
if (player != null) {
list.addObject(player);
}
Expand Down
Expand Up @@ -112,7 +112,7 @@ else if (attribute.startsWith("class")) {
}

else if (attribute.startsWith("stats") && attribute.hasContext(1)) {
MobArenaArenaTag a = MobArenaArenaTag.valueOf(attribute.getContext(1));
MobArenaArenaTag a = attribute.contextAsType(1, MobArenaArenaTag.class);
if (a == null) {
return null;
}
Expand Down
Expand Up @@ -61,7 +61,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("plotsquared_plots")) {
if (attribute.hasContext(1)) {
WorldTag world = WorldTag.valueOf(attribute.getContext(1));
WorldTag world = attribute.contextAsType(1, WorldTag.class);
if (world == null) {
return null;
}
Expand Down
Expand Up @@ -73,7 +73,7 @@ public String getAttribute(Attribute attribute) {
return new ElementTag(false).getAttribute(attribute.fulfill(1));
}
if (attribute.hasContext(1)) {
PVPArenaArenaTag a = PVPArenaArenaTag.valueOf(attribute.getContext(1));
PVPArenaArenaTag a = attribute.contextAsType(1, PVPArenaArenaTag.class);
if (a == null) {
return null;
}
Expand Down
Expand Up @@ -89,7 +89,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("in_class")) {
if (attribute.hasContext(1)) {
SkillAPIClassTag testClass = SkillAPIClassTag.valueOf(attribute.getContext(1));
SkillAPIClassTag testClass = attribute.contextAsType(1, SkillAPIClassTag.class);
if (testClass == null) {
return null;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public String getAttribute(Attribute attribute) {
if (attribute.getAttribute(1).startsWith("class_") && attribute.hasContext(1)) {

PlayerClass playerClass = null;
SkillAPIClassTag skillAPIClass = SkillAPIClassTag.valueOf(attribute.getContext(1));
SkillAPIClassTag skillAPIClass = attribute.contextAsType(1, SkillAPIClassTag.class);
if (skillAPIClass != null) {
String name = skillAPIClass.getRPGClass().getName();
for (PlayerClass plClass : data.getClasses()) {
Expand Down
Expand Up @@ -96,7 +96,7 @@ public String getAttribute(Attribute attribute) {
WorldEditPlugin worldEdit = (WorldEditPlugin) WorldEditBridge.instance.plugin;
ItemType itemType;
if (attribute.hasContext(1)) {
itemType = BukkitAdapter.asItemType(deLegacy(ItemTag.valueOf(attribute.getContext(1), attribute.context).getMaterial().getMaterial()));
itemType = BukkitAdapter.asItemType(deLegacy(attribute.contextAsType(1, ItemTag.class).getMaterial().getMaterial()));
}
else {
ItemStack itm = player.getEquipment().getItemInMainHand();
Expand Down
Expand Up @@ -98,7 +98,7 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("in_region")) {
// Check if the location is in the specified region
if (attribute.hasContext(1)) {
ListTag region_list = ListTag.valueOf(attribute.getContext(1), attribute.context);
ListTag region_list = attribute.contextAsType(1, ListTag.class);
for (String region : region_list) {
if (inRegion(region)) {
return new ElementTag(true).getAttribute(attribute.fulfill(1));
Expand Down
Expand Up @@ -82,7 +82,7 @@ public String getAttribute(Attribute attribute) {
// Whether WorldGuard allows to build at a location.
// -->
if (attribute.startsWith("can_build") && attribute.hasContext(1)) {
LocationTag location = LocationTag.valueOf(attribute.getContext(1));
LocationTag location = attribute.contextAsType(1, LocationTag.class);
if (location == null) {
return null;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ public String getAttribute(Attribute attribute) {
// Returns the state of a flag for that player at the specified location.
// -->
if (attribute.getAttribute(2).startsWith("at") && attribute.hasContext(2)) {
loc = LocationTag.valueOf(attribute.getContext(2));
loc = attribute.contextAsType(2, LocationTag.class);
args = 2;
if (loc == null) {
return null;
Expand Down

0 comments on commit b324838

Please sign in to comment.