Skip to content

Commit

Permalink
More updates to OO tag system
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed May 17, 2013
1 parent 8bb8097 commit 07287f5
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 212 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/aufdemrand/denizen/flags/FlagManager.java
Expand Up @@ -354,6 +354,8 @@ public void save() {
@Override
public String toString() {
checkExpired();
// Possibly use reflection to check whether dList or dElement is calling this?
// If dList, return fl@..., if dElement, return f@...
return (flagOwner == null ? "fl@" + flagName : "fl[" + flagOwner + "]@" + flagName);
}

Expand Down
Expand Up @@ -11,6 +11,7 @@ public interface dScriptArgument {
*/
public String getPrefix();


/**
* <p>Gets a standard dB representation of this argument.</p>
*
Expand All @@ -25,10 +26,26 @@ public interface dScriptArgument {
*/
public String debug();


/**
* Determines if this argument object is unique. This typically stipulates
* that this object has been named, or has some unique identifier that
* Denizen can use to recall it.
*
* @return true if this object is unique, false if it is a 'singleton generic argument/object'
*/
public boolean isUnique();


/**
* Returns the string type of the object. This is fairly verbose and crude, but used with
* a basic dScriptArg attribute.
*
* @return a straight-up string description of the type of dScriptArg. ie. dList, dLocation
*/
public String getType();


/**
* Gets an ugly, but exact, string representation of this dScriptArgument.
* While not specified in the dScriptArgument Interface, this value should be
Expand All @@ -38,19 +55,22 @@ public interface dScriptArgument {
*/
public String identify();


/**
* Sets the prefix for this argument, otherwise uses the default.
*
* @return the dScriptArgument
*/
public dScriptArgument setPrefix(String prefix);


/**
* Gets a string-friendly specific attribute of this object.
* Gets a specific attribute using this object to fetch the necessary data.
*
* @param attribute the name of the attribute
* @return a string attribute
* @return a string result of the fetched attribute
*/
public String getAttribute(Attribute attribute);


}
Expand Up @@ -3,7 +3,7 @@
import java.util.HashMap;
import java.util.Map;

import net.aufdemrand.denizen.utilities.nbt.NBTItem;
import net.aufdemrand.denizen.utilities.nbt.CustomNBT;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemDespawnEvent;
Expand Down Expand Up @@ -77,13 +77,13 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
switch (action) {
case ADD:
dB.echoDebug("Engraving '" + item.getType() + "' with an inscription of '" + target + "'.");
NBTItem.addCustomNBT(item, "owner", target);
dB.echoDebug(NBTItem.getCustomNBT(item, "owner"));
CustomNBT.addCustomNBT(item, "owner", target);
dB.echoDebug(CustomNBT.getCustomNBT(item, "owner"));

return;
case REMOVE:
dB.echoDebug("Removing engraving on '" + item.getType() + "'.");
NBTItem.removeCustomNBT(item, "owner");
CustomNBT.removeCustomNBT(item, "owner");
return;
}
}
Expand All @@ -103,9 +103,9 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
@EventHandler
public void checkOwner(PlayerPickupItemEvent event) {
ItemStack item = event.getItem().getItemStack();
if (NBTItem.hasCustomNBT(item, "owner")
&& !NBTItem.getCustomNBT(item, "owner").equalsIgnoreCase(event.getPlayer().getName())) {
dB.echoDebug(NBTItem.getCustomNBT(item, "owner"));
if (CustomNBT.hasCustomNBT(item, "owner")
&& !CustomNBT.getCustomNBT(item, "owner").equalsIgnoreCase(event.getPlayer().getName())) {
dB.echoDebug(CustomNBT.getCustomNBT(item, "owner"));

// See why item isn't being picked up if sneaking.
if (event.getPlayer().isSneaking()) {
Expand Down Expand Up @@ -140,8 +140,8 @@ public void checkOwner(PlayerPickupItemEvent event) {
public void stopDespawn(ItemDespawnEvent event) {
ItemStack item = event.getEntity().getItemStack();
// Check if the item has an engraving, otherwise carry on.
if (NBTItem.hasCustomNBT(item, "owner")) {
dB.echoDebug(NBTItem.getCustomNBT(item, "owner"));
if (CustomNBT.hasCustomNBT(item, "owner")) {
dB.echoDebug(CustomNBT.getCustomNBT(item, "owner"));

// If in the delay map
if (despawnDelay.containsKey(event.getEntity().getEntityId())) {
Expand All @@ -150,12 +150,12 @@ public void stopDespawn(ItemDespawnEvent event) {
event.setCancelled(true);
else
// If cooled, remove from map.
dB.echoDebug("Removed an ENGRAVED '" + item.getType().name() + "' which belonged to '" + NBTItem.getCustomNBT(item, "owner") + "'.");
dB.echoDebug("Removed an ENGRAVED '" + item.getType().name() + "' which belonged to '" + CustomNBT.getCustomNBT(item, "owner") + "'.");
despawnDelay.remove(event.getEntity().getEntityId());
} else {
// If not in delay map, add to delay map and cancel despawn.
event.setCancelled(true);
dB.echoDebug("Stopped despawn of an ENGRAVED '" + item + "' which belonged to '" + NBTItem.getCustomNBT(item, "owner") + "'. Will remove from world in 10 minutes.");
dB.echoDebug("Stopped despawn of an ENGRAVED '" + item + "' which belonged to '" + CustomNBT.getCustomNBT(item, "owner") + "'. Will remove from world in 10 minutes.");
despawnDelay.put(event.getEntity().getEntityId(), System.currentTimeMillis() + (1000 * 60 * 10));
}
}
Expand Down
Expand Up @@ -8,7 +8,7 @@
import net.aufdemrand.denizen.utilities.arguments.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.nbt.NBTItem;
import net.aufdemrand.denizen.utilities.nbt.CustomNBT;

import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -108,7 +108,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
case ITEM:
ItemStack is = item.getItemStack();
is.setAmount(amt.intValue());
if(engrave) is = NBTItem.addCustomNBT(item.getItemStack(), "owner", scriptEntry.getPlayer().getName());
if(engrave) is = CustomNBT.addCustomNBT(item.getItemStack(), "owner", scriptEntry.getPlayer().getName());

HashMap<Integer, ItemStack> leftovers = scriptEntry.getPlayer().getInventory().addItem(is);

Expand Down
Expand Up @@ -25,7 +25,11 @@ public dEntity getEntityFrom(Player player, dNPC npc) {
dEntity entity = null;
try {
// Check validity of material
if (contains("TYPE")){ }
if (contains("TYPE")){

// TODO:

}

// Set Id of the stack

Expand Down
Expand Up @@ -9,8 +9,8 @@
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.arguments.dItem;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.nbt.CustomNBT;
import net.aufdemrand.denizen.utilities.nbt.LeatherColorer;
import net.aufdemrand.denizen.utilities.nbt.NBTItem;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -100,7 +100,7 @@ public dItem getItemFrom(Player player, dNPC npc) {
}

// Set Id of the stack
stack.setItemStack(NBTItem.addCustomNBT(stack.getItemStack(), "denizen-script-id", getName()));
stack.setItemStack(CustomNBT.addCustomNBT(stack.getItemStack(), "denizen-script-id", getName()));

} catch (Exception e) {
dB.echoError("Woah! An exception has been called with this item script!");
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/aufdemrand/denizen/tags/core/PlayerTags.java
Expand Up @@ -8,7 +8,7 @@
import net.aufdemrand.denizen.utilities.arguments.*;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.nbt.NBTItem;
import net.aufdemrand.denizen.utilities.nbt.CustomNBT;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
Expand Down Expand Up @@ -185,19 +185,19 @@ else if (subType.equalsIgnoreCase("DATA"))
else if (subType.equalsIgnoreCase("MAX_STACK"))
event.setReplaced(String.valueOf(p.getItemInHand().getMaxStackSize()));
else if (subType.equalsIgnoreCase("OWNER")) {
if (NBTItem.hasCustomNBT(p.getItemInHand(), "owner"))
event.setReplaced(NBTItem.getCustomNBT(p.getItemInHand(), "owner"));
if (CustomNBT.hasCustomNBT(p.getItemInHand(), "owner"))
event.setReplaced(CustomNBT.getCustomNBT(p.getItemInHand(), "owner"));
}
else if (subType.equalsIgnoreCase("ENCHANTMENTS"))
{
String enchantments = null;

if (specifier.equalsIgnoreCase("LEVELS"))
enchantments = NBTItem.getEnchantments(p.getItemInHand()).asDScriptListWithLevels();
enchantments = CustomNBT.getEnchantments(p.getItemInHand()).asDScriptListWithLevels();
else if (specifier.equalsIgnoreCase("LEVELS_ONLY"))
enchantments = NBTItem.getEnchantments(p.getItemInHand()).asDScriptListLevelsOnly();
enchantments = CustomNBT.getEnchantments(p.getItemInHand()).asDScriptListLevelsOnly();
else
enchantments = NBTItem.getEnchantments(p.getItemInHand()).asDScriptList();
enchantments = CustomNBT.getEnchantments(p.getItemInHand()).asDScriptList();

if (enchantments != null && enchantments.length() > 0)
event.setReplaced(enchantments);
Expand Down

0 comments on commit 07287f5

Please sign in to comment.