Skip to content

Commit

Permalink
modernize more properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 29, 2019
1 parent 6173615 commit 251c69d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 75 deletions.
Expand Up @@ -5,7 +5,6 @@
import com.denizenscript.denizen.scripts.containers.core.ItemScriptHelper;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.tags.BukkitTagContext;
Expand Down Expand Up @@ -40,9 +39,6 @@ private BukkitElementProperties(ElementTag element) {
this.element = element;
}

public static final String[] handledTags = new String[] {
}; // Modernized.

public static final String[] handledMechs = new String[] {
}; // None

Expand Down Expand Up @@ -431,11 +427,6 @@ public static void registerTags() {
});
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
throw new UnsupportedOperationException("Invalid property getObjectAttribute call (old-style).");
}

@Override
public String getPropertyString() {
return null;
Expand Down
Expand Up @@ -7,7 +7,7 @@
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.objects.properties.PropertyParser;

public class BukkitListProperties implements Property {
public static boolean describes(ObjectTag list) {
Expand All @@ -28,16 +28,12 @@ private BukkitListProperties(ListTag list) {
this.list = list;
}

public static final String[] handledTags = new String[] {
"expiration", "formatted"
};

public static final String[] handledMechs = new String[] {
}; // None

ListTag list;

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
public static void registerTags() {

// <--[tag]
// @attribute <ListTag.formatted>
Expand All @@ -46,9 +42,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns the list in a human-readable format.
// EG, a list of "n@3|p@bob|potato" will return "GuardNPC, bob, and potato".
// -->
if (attribute.startsWith("formatted")) {
PropertyParser.<ListTag>registerTag("formatted", (attribute, list) -> {
if (list.isEmpty()) {
return new ElementTag("").getObjectAttribute(attribute.fulfill(1));
return new ElementTag("");
}
StringBuilder dScriptArg = new StringBuilder();

Expand Down Expand Up @@ -83,11 +79,8 @@ else if (list.get(n).startsWith("e@") || list.get(n).startsWith("n@")) {
}
}

return new ElementTag(dScriptArg.toString().substring(0, dScriptArg.length() - 2))
.getObjectAttribute(attribute.fulfill(1));
}

return null;
return new ElementTag(dScriptArg.toString().substring(0, dScriptArg.length() - 2));
});
}

@Override
Expand Down
Expand Up @@ -8,9 +8,9 @@
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.QueueTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.queues.ScriptQueue;
import com.denizenscript.denizencore.tags.Attribute;

public class BukkitQueueProperties implements Property {

Expand All @@ -27,10 +27,6 @@ public static BukkitQueueProperties getFrom(ObjectTag queue) {
}
}

public static final String[] handledTags = new String[] {
"player", "npc"
};

public static final String[] handledMechs = new String[] {
"linked_player", "linked_npc"
};
Expand All @@ -41,8 +37,7 @@ private BukkitQueueProperties(QueueTag queue) {

ScriptQueue queue;

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
public static void registerTags() {

// <--[tag]
// @attribute <QueueTag.npc>
Expand All @@ -51,24 +46,24 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns the NPCTag linked to a queue.
// -->
if (attribute.startsWith("npc")) {
PropertyParser.<QueueTag>registerTag("npc", (attribute, object) -> {
NPCTag npc = null;
if (queue.getLastEntryExecuted() != null) {
npc = ((BukkitScriptEntryData) queue.getLastEntryExecuted().entryData).getNPC();
if (object.queue.getLastEntryExecuted() != null) {
npc = ((BukkitScriptEntryData) object.queue.getLastEntryExecuted().entryData).getNPC();
}
else if (queue.getEntries().size() > 0) {
npc = ((BukkitScriptEntryData) queue.getEntries().get(0).entryData).getNPC();
else if (object.queue.getEntries().size() > 0) {
npc = ((BukkitScriptEntryData) object.queue.getEntries().get(0).entryData).getNPC();
}
else {
Debug.echoError(queue, "Can't determine a linked NPC.");
else if (!attribute.hasAlternative()) {
Debug.echoError(object.queue, "Can't determine a linked NPC.");
}
if (npc == null) {
return null;
}
else {
return npc.getObjectAttribute(attribute.fulfill(1));
return npc;
}
}
});

// <--[tag]
// @attribute <QueueTag.player>
Expand All @@ -77,25 +72,24 @@ else if (queue.getEntries().size() > 0) {
// @description
// Returns the PlayerTag linked to a queue.
// -->
if (attribute.startsWith("player")) {
PropertyParser.<QueueTag>registerTag("player", (attribute, object) -> {
PlayerTag player = null;
if (queue.getLastEntryExecuted() != null) {
player = ((BukkitScriptEntryData) queue.getLastEntryExecuted().entryData).getPlayer();
if (object.queue.getLastEntryExecuted() != null) {
player = ((BukkitScriptEntryData) object.queue.getLastEntryExecuted().entryData).getPlayer();
}
else if (queue.getEntries().size() > 0) {
player = ((BukkitScriptEntryData) queue.getEntries().get(0).entryData).getPlayer();
else if (object.queue.getEntries().size() > 0) {
player = ((BukkitScriptEntryData) object.queue.getEntries().get(0).entryData).getPlayer();
}
else {
Debug.echoError(queue, "Can't determine a linked player.");
Debug.echoError(object.queue, "Can't determine a linked player.");
}
if (player == null) {
return null;
}
else {
return player.getObjectAttribute(attribute.fulfill(1));
return player;
}
}
return null;
});
}

@Override
Expand Down
Expand Up @@ -9,7 +9,7 @@
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.objects.properties.PropertyParser;

public class BukkitScriptProperties implements Property {

Expand All @@ -26,10 +26,6 @@ public static BukkitScriptProperties getFrom(ObjectTag script) {
}
}

public static final String[] handledTags = new String[] {
"cooled_down", "cooldown", "step"
};

public static final String[] handledMechs = new String[] {
}; // None

Expand All @@ -39,12 +35,7 @@ private BukkitScriptProperties(ScriptTag script) {

ScriptTag script;

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

if (attribute == null) {
return null;
}
public static void registerTags() {

// <--[tag]
// @attribute <ScriptTag.cooled_down[<player>]>
Expand All @@ -54,32 +45,28 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// cooldown present on the script will also be taken into account. Not specifying a player will result in
// using the attached player available in the script entry. Not having a valid player will result in 'null'.
// -->
if (attribute.startsWith("cooled_down")) {
PropertyParser.<ScriptTag>registerTag("cooled_down", (attribute, script) -> {
PlayerTag player = (attribute.hasContext(1) ? PlayerTag.valueOf(attribute.getContext(1))
: ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
if (player != null && player.isValid()) {
return new ElementTag(CooldownCommand.checkCooldown(player, script.getContainer().getName()))
.getObjectAttribute(attribute.fulfill(1));
return new ElementTag(CooldownCommand.checkCooldown(player, script.getContainer().getName()));
}
else {
return null;
}
}
});

// <--[tag]
// @attribute <ScriptTag.cooldown[<player>]>
// @returns DurationTag
// @description
// Returns the time left for the player to cooldown for the script.
// -->
if (attribute.startsWith("cooldown")) {
PropertyParser.<ScriptTag>registerTag("cooldown", (attribute, script) -> {
PlayerTag player = (attribute.hasContext(1) ? PlayerTag.valueOf(attribute.getContext(1))
: ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
return CooldownCommand.getCooldownDuration(player, script.getName())
.getObjectAttribute(attribute.fulfill(1));

}

return CooldownCommand.getCooldownDuration(player, script.getName());
});

// <--[tag]
// @attribute <ScriptTag.step[<player>]>
Expand All @@ -88,16 +75,16 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns the name of a script step that the player is currently on.
// Must be an INTERACT script.
// -->
if (attribute.startsWith("step")) {
PropertyParser.<ScriptTag>registerTag("step", (attribute, script) -> {
PlayerTag player = (attribute.hasContext(1) ? PlayerTag.valueOf(attribute.getContext(1))
: ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());

if (player != null && player.isValid()) {
return new ElementTag(InteractScriptHelper.getCurrentStep(player, script.getContainer().getName()))
.getObjectAttribute(attribute.fulfill(1));
return new ElementTag(InteractScriptHelper.getCurrentStep(player, script.getContainer().getName()));
}
}
return null;
else {
return null;
}
});
}


Expand Down

0 comments on commit 251c69d

Please sign in to comment.