Skip to content

Commit

Permalink
Work towards making replaceabletagevent core-ready
Browse files Browse the repository at this point in the history
Core power!
Also deprecate some junk.
  • Loading branch information
mcmonkey4eva committed Dec 13, 2014
1 parent e7429db commit d8da233
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/main/java/net/aufdemrand/denizen/tags/ReplaceableTagEvent.java
Expand Up @@ -5,14 +5,14 @@
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.ScriptEntry;

import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;

import java.util.List;

public class ReplaceableTagEvent {

private final dPlayer player;
private final dNPC npc;
private final TagContext context;

private boolean instant = false;
private boolean wasReplaced = false;
Expand All @@ -33,19 +33,25 @@ public class ReplaceableTagEvent {
////////////
// Constructors

@Deprecated
public ReplaceableTagEvent(dPlayer player, dNPC npc, String tag) {
this(player, npc, tag, null, null);
}

@Deprecated
public ReplaceableTagEvent(dPlayer player, dNPC npc, String tag, ScriptEntry scriptEntry, dScript script) {
this(tag, new BukkitTagContext(player, npc, false, scriptEntry,
scriptEntry != null ? scriptEntry.shouldDebug(): true, script));
}

public ReplaceableTagEvent(String tag, TagContext context) {

// Reference ScriptEntry if available
this.scriptEntry = scriptEntry;
this.script = script;
this.scriptEntry = ((BukkitTagContext)context).entry;
this.script = ((BukkitTagContext)context).script;

// Reference player/npc
this.player = player;
this.npc = npc;
// Reference context
this.context = context;

// If tag is not replaced, return the tag
// TODO: Possibly make this return "null" ... might break some
Expand Down Expand Up @@ -185,54 +191,66 @@ public boolean hasNameContext() {

// Type

@Deprecated
public String getType() {
return StripContext(core_attributes.getAttribute(2));
}

@Deprecated
public boolean hasType() {
return core_attributes.getAttribute(2).length() > 0;
}

@Deprecated
public String getTypeContext() {
return core_attributes.getContext(2);
}

@Deprecated
public boolean hasTypeContext() {
return core_attributes.hasContext(2);
}

// Subtype

@Deprecated
public String getSubType() {
return StripContext(core_attributes.getAttribute(3));
}

@Deprecated
public boolean hasSubType() {
return core_attributes.getAttribute(3).length() > 0;
}

@Deprecated
public String getSubTypeContext() {
return core_attributes.getContext(3);
}

@Deprecated
public boolean hasSubTypeContext() {
return core_attributes.hasContext(3);
}

// Specifier

@Deprecated
public String getSpecifier() {
return StripContext(core_attributes.getAttribute(4));
}

@Deprecated
public boolean hasSpecifier() {
return core_attributes.getAttribute(4).length() > 0;
}

@Deprecated
public String getSpecifierContext() {
return core_attributes.getContext(4);
}

@Deprecated
public boolean hasSpecifierContext() {
return core_attributes.hasContext(4);
}
Expand All @@ -243,10 +261,7 @@ public String getValue() {
if (value_tagged)
return value;
value_tagged = true;
value = TagManager.cleanOutputFully(TagManager.tag(value,
new BukkitTagContext(getPlayer(), getNPC(), false, getScriptEntry(),
getScriptEntry() != null ? getScriptEntry().shouldDebug() : true,
getScript())));
value = TagManager.cleanOutputFully(TagManager.tag(value, context));
return value;
}

Expand All @@ -260,10 +275,7 @@ public String getAlternative() {
if (alternative_tagged)
return alternative;
alternative_tagged = true;
alternative = TagManager.cleanOutputFully(TagManager.tag(alternative,
new BukkitTagContext(getPlayer(), getNPC(), false, getScriptEntry(),
getScriptEntry() != null ? getScriptEntry().shouldDebug(): true,
getScript())));
alternative = TagManager.cleanOutputFully(TagManager.tag(alternative, context));
return alternative;
}

Expand All @@ -273,12 +285,14 @@ public boolean hasAlternative() {

// Other internal mechanics

@Deprecated
public dNPC getNPC() {
return npc;
return ((BukkitTagContext)context).npc;
}

@Deprecated
public dPlayer getPlayer() {
return player;
return ((BukkitTagContext)context).player;
}

public String getReplaced() {
Expand Down

0 comments on commit d8da233

Please sign in to comment.