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
ac9b3f7
commit 9f3b6a5
Showing
4 changed files
with
220 additions
and
1 deletion.
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
116 changes: 116 additions & 0 deletions
116
...rc/main/java/com/denizenscript/denizen/objects/properties/item/ItemLodestoneLocation.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,116 @@ | ||
package com.denizenscript.denizen.objects.properties.item; | ||
|
||
import com.denizenscript.denizen.objects.ItemTag; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
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 org.bukkit.Material; | ||
import org.bukkit.inventory.meta.CompassMeta; | ||
|
||
public class ItemLodestoneLocation implements Property { | ||
|
||
public static boolean describes(ObjectTag item) { | ||
return item instanceof ItemTag | ||
&& (((ItemTag) item).getBukkitMaterial() == Material.COMPASS); | ||
} | ||
|
||
public static ItemLodestoneLocation getFrom(ObjectTag _item) { | ||
if (!describes(_item)) { | ||
return null; | ||
} | ||
else { | ||
return new ItemLodestoneLocation((ItemTag) _item); | ||
} | ||
} | ||
|
||
public static final String[] handledTags = new String[] { | ||
"lodestone_location" | ||
}; | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"lodestone_location" | ||
}; | ||
|
||
private ItemLodestoneLocation(ItemTag _item) { | ||
item = _item; | ||
} | ||
|
||
ItemTag item; | ||
|
||
@Override | ||
public ObjectTag getObjectAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) { | ||
return null; | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <ItemTag.lodestone_location> | ||
// @returns LocationTag | ||
// @group properties | ||
// @mechanism ItemTag.lodestone_location | ||
// @description | ||
// Returns the lodestone location this compass is pointing at (if any). | ||
// See also <@link tag ItemTag.lodestone_tracked> | ||
// --> | ||
if (attribute.startsWith("lodestone_location")) { | ||
LocationTag target = getTarget(); | ||
if (target == null) { | ||
return null; | ||
} | ||
return target.getObjectAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public LocationTag getTarget() { | ||
CompassMeta meta = (CompassMeta) item.getItemMeta(); | ||
if (meta.getLodestone() == null) { | ||
return null; | ||
} | ||
return new LocationTag(meta.getLodestone()); | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
LocationTag target = getTarget(); | ||
if (target == null) { | ||
return null; | ||
} | ||
return target.identify(); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "lodestone_location"; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object ItemTag | ||
// @name lodestone_location | ||
// @input LocationTag | ||
// @description | ||
// Changes the lodestone location this compass is pointing at. | ||
// See also <@link mechanism ItemTag.lodestone_tracked> | ||
// Give no input to unset. | ||
// @tags | ||
// <ItemTag.lodestone_location> | ||
// --> | ||
if (mechanism.matches("lodestone_location")) { | ||
CompassMeta meta = (CompassMeta) item.getItemMeta(); | ||
if (mechanism.hasValue() && mechanism.requireObject(LocationTag.class)) { | ||
meta.setLodestone(mechanism.valueAsType(LocationTag.class).clone()); | ||
} | ||
else { | ||
meta.setLodestone(null); | ||
} | ||
item.setItemMeta(meta); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...src/main/java/com/denizenscript/denizen/objects/properties/item/ItemLodestoneTracked.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,97 @@ | ||
package com.denizenscript.denizen.objects.properties.item; | ||
|
||
import com.denizenscript.denizen.objects.ItemTag; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
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 org.bukkit.Material; | ||
import org.bukkit.inventory.meta.CompassMeta; | ||
|
||
public class ItemLodestoneTracked implements Property { | ||
|
||
public static boolean describes(ObjectTag item) { | ||
return item instanceof ItemTag | ||
&& (((ItemTag) item).getBukkitMaterial() == Material.COMPASS); | ||
} | ||
|
||
public static ItemLodestoneTracked getFrom(ObjectTag _item) { | ||
if (!describes(_item)) { | ||
return null; | ||
} | ||
else { | ||
return new ItemLodestoneTracked((ItemTag) _item); | ||
} | ||
} | ||
|
||
public static final String[] handledTags = new String[] { | ||
"lodestone_tracked" | ||
}; | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"lodestone_tracked" | ||
}; | ||
|
||
private ItemLodestoneTracked(ItemTag _item) { | ||
item = _item; | ||
} | ||
|
||
ItemTag item; | ||
|
||
@Override | ||
public ObjectTag getObjectAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) { | ||
return null; | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <ItemTag.lodestone_tracked> | ||
// @returns ElementTag(Boolean) | ||
// @group properties | ||
// @mechanism ItemTag.lodestone_tracked | ||
// @description | ||
// Returns whether the compass will track a lodestone. If "true", the compass will only work if there's a lodestone at the target location. | ||
// See also <@link tag ItemTag.lodestone_location> | ||
// --> | ||
if (attribute.startsWith("lodestone_tracked")) { | ||
CompassMeta meta = (CompassMeta) item.getItemMeta(); | ||
return new ElementTag(meta.isLodestoneTracked()).getObjectAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
CompassMeta meta = (CompassMeta) item.getItemMeta(); | ||
return meta.isLodestoneTracked() ? "true" : "false"; | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "lodestone_tracked"; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object ItemTag | ||
// @name lodestone_tracked | ||
// @input ElementTag(Boolean) | ||
// @description | ||
// Changes whether the compass will track a lodestone. If "true", the compass will only work if there's a lodestone at the target location. | ||
// See also <@link mechanism ItemTag.lodestone_location> | ||
// @tags | ||
// <ItemTag.lodestone_tracked> | ||
// --> | ||
if (mechanism.matches("lodestone_tracked") && mechanism.requireBoolean()) { | ||
CompassMeta meta = (CompassMeta) item.getItemMeta(); | ||
meta.setLodestoneTracked(mechanism.getValue().asBoolean()); | ||
item.setItemMeta(meta); | ||
} | ||
} | ||
} |
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