Skip to content

Commit

Permalink
update inventorytags to new property system
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 29, 2019
1 parent fbf1b2e commit a22f9ae
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 95 deletions.
Expand Up @@ -6,7 +6,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;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand All @@ -25,10 +25,6 @@ public static InventoryContents getFrom(ObjectTag inventory) {
return new InventoryContents((InventoryTag) inventory);
}

public static final String[] handledTags = new String[] {
"list_contents"
};

public static final String[] handledMechs = new String[] {
"contents"
};
Expand Down Expand Up @@ -127,12 +123,8 @@ public String getPropertyId() {
return "contents";
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <InventoryTag.list_contents>
Expand All @@ -142,8 +134,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns a list of all items in the inventory.
// -->
if (attribute.startsWith("list_contents")) {
attribute.fulfill(1);
PropertyParser.<InventoryTag>registerTag("list_contents", (attribute, object) -> {

InventoryContents contents = getFrom(object);

// <--[tag]
// @attribute <InventoryTag.list_contents.simple>
Expand All @@ -153,8 +146,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns a list of all items in the inventory, without item properties.
// -->
if (attribute.startsWith("simple")) {
return getContents(1).getObjectAttribute(attribute.fulfill(1));
if (attribute.startsWith("simple", 2)) {
attribute.fulfill(1);
return contents.getContents(1);
}

// <--[tag]
Expand All @@ -166,8 +160,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns a list of all items in the inventory, with the tag item.full used.
// Irrelevant on modern (1.13+) servers.
// -->
if (attribute.startsWith("full")) {
return getContents(2).getObjectAttribute(attribute.fulfill(1));
if (attribute.startsWith("full", 2)) {
attribute.fulfill(1);
return contents.getContents(2);
}

// <--[tag]
Expand All @@ -179,13 +174,15 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns a list of all items in the inventory with the specified
// lore. Color codes are ignored.
// -->
if (attribute.startsWith("with_lore")) {
if (attribute.startsWith("with_lore", 2)) {
attribute.fulfill(1);
// Must specify lore to check
if (!attribute.hasContext(1)) {
return null;
}
String lore = attribute.getContext(1);
attribute.fulfill(1);

// <--[tag]
// @attribute <InventoryTag.list_contents.with_lore[<element>].simple>
// @returns ListTag(ItemTag)
Expand All @@ -195,20 +192,16 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns a list of all items in the inventory with the specified
// lore, without item properties. Color codes are ignored.
// -->
if (attribute.startsWith("simple")) {
return getContentsWithLore(lore, true)
.getObjectAttribute(attribute.fulfill(1));
if (attribute.startsWith("simple", 2)) {
attribute.fulfill(1);
return contents.getContentsWithLore(lore, true);
}

return getContentsWithLore(lore, false)
.getObjectAttribute(attribute);
return contents.getContentsWithLore(lore, false);
}

return getContents(0).getObjectAttribute(attribute);
}

return null;

return contents.getContents(0);
});
}

@Override
Expand Down
Expand Up @@ -7,7 +7,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;
import net.citizensnpcs.api.CitizensAPI;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
Expand All @@ -32,10 +32,6 @@ public static InventoryHolder getFrom(ObjectTag inventory) {
return new InventoryHolder((InventoryTag) inventory);
}

public static final String[] handledTags = new String[] {
"id_holder"
};

public static final String[] handledMechs = new String[] {
"holder"
};
Expand Down Expand Up @@ -163,12 +159,7 @@ public String getPropertyId() {
// ObjectTag Attributes
////////

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <InventoryTag.id_holder>
Expand All @@ -178,15 +169,13 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns Denizen's holder ID for this inventory. (p@aufdemrand, l@123,321,123, etc.)
// -->
if (attribute.startsWith("id_holder")) {
PropertyParser.<InventoryTag>registerTag("id_holder", (attribute, object) -> {
ObjectTag holder = getFrom(object).holder;
if (holder == null) {
return null;
}
return holder.getObjectAttribute(attribute.fulfill(1));
}

return null;

return holder;
});
}

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

public class InventoryScriptName implements Property {

Expand All @@ -21,10 +21,6 @@ public static InventoryScriptName getFrom(ObjectTag inventory) {
return new InventoryScriptName((InventoryTag) inventory);
}

public static final String[] handledTags = new String[] {
"script_name"
};

public static final String[] handledMechs = new String[] {
"script_name"
};
Expand Down Expand Up @@ -53,12 +49,7 @@ public String getPropertyId() {
return "contents";
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <InventoryTag.script_name>
Expand All @@ -67,12 +58,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns the name of the script that this inventory came from (if any).
// -->
if (attribute.startsWith("script_name")) {
return new ElementTag(inventory.scriptName)
.getObjectAttribute(attribute.fulfill(1));
}

return null;
PropertyParser.<InventoryTag>registerTag("script_name", (attribute, inventory) -> {
return new ElementTag(inventory.scriptName);
});
}

@Override
Expand Down
Expand Up @@ -5,7 +5,7 @@
import com.denizenscript.denizencore.objects.Mechanism;
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 InventorySize implements Property {

Expand All @@ -21,10 +21,6 @@ public static InventorySize getFrom(ObjectTag inventory) {
return new InventorySize((InventoryTag) inventory);
}

public static final String[] handledTags = new String[] {
"size"
};

public static final String[] handledMechs = new String[] {
"size"
};
Expand Down Expand Up @@ -76,12 +72,7 @@ public String getPropertyId() {
// ObjectTag Attributes
////////

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <InventoryTag.size>
Expand All @@ -91,13 +82,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Return the number of slots in the inventory.
// -->
if (attribute.startsWith("size")) {
return new ElementTag(getSize())
.getObjectAttribute(attribute.fulfill(1));
}

return null;

PropertyParser.<InventoryTag>registerTag("script_name", (attribute, inventory) -> {
return new ElementTag(getFrom(inventory).getSize());
});
}

@Override
Expand Down
Expand Up @@ -6,7 +6,7 @@
import com.denizenscript.denizencore.objects.Mechanism;
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 InventoryTitle implements Property {

Expand All @@ -22,10 +22,6 @@ public static InventoryTitle getFrom(ObjectTag inventory) {
return new InventoryTitle((InventoryTag) inventory);
}

public static final String[] handledTags = new String[] {
"title"
};

public static final String[] handledMechs = new String[] {
"title"
};
Expand Down Expand Up @@ -78,12 +74,7 @@ public String getPropertyId() {
return "title";
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <InventoryTag.title>
Expand All @@ -93,11 +84,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns the title of the inventory.
// -->
if (attribute.startsWith("title")) {
return new ElementTag(getTitle()).getObjectAttribute(attribute.fulfill(1));
}

return null;
PropertyParser.<InventoryTag>registerTag("title", (attribute, inventory) -> {
return new ElementTag(getFrom(inventory).getTitle());
});
}

@Override
Expand Down

0 comments on commit a22f9ae

Please sign in to comment.