Skip to content

Commit

Permalink
More conversion to dObjects.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed May 28, 2013
1 parent ab83400 commit 4c2f5ab
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 77 deletions.
Expand Up @@ -91,16 +91,16 @@ public class ReplaceableTagEvent extends Event {

public String raw_tag;

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

public ReplaceableTagEvent(OfflinePlayer player, dNPC npc, String tag, ScriptEntry scriptEntry) {
public ReplaceableTagEvent(dPlayer player, dNPC npc, String tag, ScriptEntry scriptEntry) {

// Add ScriptEntry if available
this.scriptEntry = scriptEntry;

this.player = new dPlayer(player);
this.player = player;

this.replaced = tag;
this.npc = npc;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aufdemrand/denizen/flags/FlagManager.java
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
Expand All @@ -17,7 +18,7 @@ public FlagManager(Denizen denizen) {
this.denizen = denizen;
}

public static boolean playerHasFlag(Player player, String flagName) {
public static boolean playerHasFlag(dPlayer player, String flagName) {
if (player == null || flagName == null) return false;
if (DenizenAPI.getCurrentInstance().flagManager()
.getPlayerFlag(player.getName(), flagName).size() > 0)
Expand Down
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.ScriptQueue;
import net.aufdemrand.denizen.scripts.containers.core.AssignmentScriptContainer;
Expand All @@ -20,7 +21,7 @@ public ActionHandler(Denizen denizen) {
this.denizen = denizen;
}

public boolean doAction(String actionName, dNPC npc, Player player, AssignmentScriptContainer assignment) {
public boolean doAction(String actionName, dNPC npc, dPlayer player, AssignmentScriptContainer assignment) {

if (assignment == null) return false;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -40,7 +40,7 @@ public static dList valueOf(String string) {
return new dList(flag_manager.getGlobalFlag(m.group(4)));

} else if (m.group(2).toLowerCase().startsWith("p@")) {
if (FlagManager.playerHasFlag(aH.getPlayerFrom(m.group(3)), m.group(4)))
if (FlagManager.playerHasFlag(dPlayer.valueOf(m.group(3)), m.group(4)))
return new dList(flag_manager.getPlayerFlag(m.group(3), m.group(4)));

} else if (m.group(2).toLowerCase().startsWith("n@")) {
Expand Down
38 changes: 34 additions & 4 deletions src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -25,6 +25,36 @@

public class dNPC implements dScriptArgument {

@ObjectFetcher("n")
public static dNPC valueOf(String string) {
if (string == null) return null;

////////
// Match NPC id

string = string.replace("n@", "");
NPC npc;
if (aH.matchesInteger(string)) {
npc = CitizensAPI.getNPCRegistry().getById(aH.getIntegerFrom(string));
if (npc != null) return new dNPC(npc);
}

return null;
}


public static boolean matches(String string) {

string = string.replace("n@", "");
NPC npc;
if (aH.matchesInteger(string)) {
npc = CitizensAPI.getNPCRegistry().getById(aH.getIntegerFrom(string));
if (npc != null) return true;
}

return false;
}

private int npcid;
private final org.bukkit.Location locationCache = new org.bukkit.Location(null, 0, 0, 0);

Expand Down Expand Up @@ -68,11 +98,11 @@ public String getName() {
return getCitizen().getName();
}

public InteractScriptContainer getInteractScript(Player player, Class<? extends AbstractTrigger> triggerType) {
public InteractScriptContainer getInteractScript(dPlayer player, Class<? extends AbstractTrigger> triggerType) {
return InteractScriptHelper.getInteractScript(this, player, triggerType);
}

public InteractScriptContainer getInteractScriptQuietly(Player player, Class<? extends AbstractTrigger> triggerType) {
public InteractScriptContainer getInteractScriptQuietly(dPlayer player, Class<? extends AbstractTrigger> triggerType) {
boolean db = dB.debugMode;
dB.debugMode = false;
InteractScriptContainer script = InteractScriptHelper.getInteractScript(this, player, triggerType);
Expand Down Expand Up @@ -142,7 +172,7 @@ public TriggerTrait getTriggerTrait() {
return getCitizen().getTrait(TriggerTrait.class);
}

public void action(String actionName, Player player) {
public void action(String actionName, dPlayer player) {
if (getCitizen() != null)
{
if (getCitizen().hasTrait(AssignmentTrait.class))
Expand All @@ -166,7 +196,7 @@ public String getPrefix() {

@Override
public String debug() {
return null;
return (prefix + "='<A>" + identify() + "<G>' ");
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -48,6 +48,11 @@ public Player getPlayerEntity() {
}


public String getName() {
return getPlayerEntity() != null ? getPlayerEntity().getName() : getOfflinePlayer().getName();
}


public OfflinePlayer getOfflinePlayer() {
return Bukkit.getOfflinePlayer(player);
}
Expand Down
Expand Up @@ -3,6 +3,7 @@
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.events.ScriptEntryExecuteEvent;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.tags.TagManager;
Expand Down Expand Up @@ -32,7 +33,7 @@ public CommandExecuter(Denizen denizen) {
public boolean execute(ScriptEntry scriptEntry) {
if (plugin.getCommandRegistry().get(scriptEntry.getCommandName()) == null) {
dB.echoDebug(DebugElement.Header, "Executing command: " + scriptEntry.getCommandName());
dB.echoError(scriptEntry.getCommandName() + " is an invalid dScript command! Are you sure the command loaded?");
dB.echoError(scriptEntry.getCommandName() + " is an invalid dCommand! Are you sure it loaded?");
dB.echoDebug(DebugElement.Footer);
return false;
}
Expand All @@ -42,8 +43,8 @@ public boolean execute(ScriptEntry scriptEntry) {

// Debugger information
if (scriptEntry.getPlayer() != null)
dB.echoDebug(DebugElement.Header, "Executing command: " + scriptEntry.getCommandName() + "/" + scriptEntry.getPlayer().getName());
else dB.echoDebug(DebugElement.Header, "Executing command: " + scriptEntry.getCommandName() + (scriptEntry.getNPC() != null ? "/" + scriptEntry.getNPC().getName() : ""));
dB.echoDebug(DebugElement.Header, "Executing dCommand: " + scriptEntry.getCommandName() + "/" + scriptEntry.getPlayer().getName());
else dB.echoDebug(DebugElement.Header, "Executing dCommand: " + scriptEntry.getCommandName() + (scriptEntry.getNPC() != null ? "/" + scriptEntry.getNPC().getName() : ""));

// Don't execute() if problems arise in parseArgs()
boolean keepGoing = true;
Expand All @@ -54,7 +55,7 @@ public boolean execute(ScriptEntry scriptEntry) {
if (command.getOptions().REQUIRED_ARGS > scriptEntry.getArguments().size()) throw new InvalidArgumentsException("");

if (scriptEntry.has_tags)
scriptEntry.setArguments(plugin.tagManager().fillArguments(scriptEntry.getArguments(), scriptEntry, true)); // Replace tags
scriptEntry.setArguments(TagManager.fillArguments(scriptEntry.getArguments(), scriptEntry, true)); // Replace tags

/* If using NPCID:# or PLAYER:Name arguments, these need to be changed out immediately because...
* 1) Denizen/Player flags need the desired NPC/PLAYER before parseArgs's getFilledArguments() so that
Expand All @@ -64,28 +65,14 @@ public boolean execute(ScriptEntry scriptEntry) {
* here, instead of requiring each command to take care of the argument.
*/



List<String> newArgs = new ArrayList<String>();

for (String arg : scriptEntry.getArguments()) {
String[] split = arg.split(":");

// Fill player/off-line player
if (aH.matchesValueArg("PLAYER", arg, aH.ArgumentType.String)) {
boolean foundNewPlayer = false;
dB.echoDebug("...replacing the linked Player.");

for (OfflinePlayer playa : Bukkit.getServer().getOfflinePlayers())
if (playa.getName().equalsIgnoreCase(split[1])) {
scriptEntry.setPlayer(playa);
foundNewPlayer = true;
}

if (foundNewPlayer) dB.echoDebug("Found an offline player.. linking.");
else { dB.echoError("Could not find a valid player!"); scriptEntry.setPlayer(null); }

}
if (aH.matchesValueArg("PLAYER", arg, aH.ArgumentType.String))
scriptEntry.setPlayer(dPlayer.valueOf(split[1]));

// Fill Denizen with NPCID
else if (aH.matchesValueArg("NPCID", arg, aH.ArgumentType.String)) {
Expand All @@ -99,10 +86,10 @@ else if (aH.matchesValueArg("NPCID", arg, aH.ArgumentType.String)) {
scriptEntry.setNPC(null);
}
}
else {
newArgs.add(arg);
}

else newArgs.add(arg);
}

// Add the arguments back to the scriptEntry.
scriptEntry.setArguments(newArgs);

Expand Down
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.scripts.containers;

import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.ScriptBuilder;
import net.aufdemrand.denizen.scripts.ScriptEntry;
Expand Down Expand Up @@ -71,11 +72,11 @@ public String getName() {
return name;
}

public boolean checkBaseRequirements(Player player, dNPC npc) {
public boolean checkBaseRequirements(dPlayer player, dNPC npc) {
return checkRequirements(player, npc, "");
}

public boolean checkRequirements(Player player, dNPC npc, String path) {
public boolean checkRequirements(dPlayer player, dNPC npc, String path) {
if (path == null) path = "";
if (path.length() > 0) path = path + ".";
// Get requirements
Expand All @@ -90,11 +91,11 @@ public boolean checkRequirements(Player player, dNPC npc, String path) {
return DenizenAPI.getCurrentInstance().getScriptEngine().getRequirementChecker().check(context);
}

public List<ScriptEntry> getBaseEntries(Player player, dNPC npc) {
public List<ScriptEntry> getBaseEntries(dPlayer player, dNPC npc) {
return getEntries(player, npc, null);
}

public List<ScriptEntry> getEntries(Player player, dNPC npc, String path) {
public List<ScriptEntry> getEntries(dPlayer player, dNPC npc, String path) {
List<ScriptEntry> list = new ArrayList<ScriptEntry>();
if (path == null) path = "script";
List<String> stringEntries = contents.getStringList(path.toUpperCase());
Expand All @@ -103,7 +104,7 @@ public List<ScriptEntry> getEntries(Player player, dNPC npc, String path) {
return list;
}

public boolean checkCooldown(Player player) {
public boolean checkCooldown(dPlayer player) {
return DenizenAPI._commandRegistry().get(CooldownCommand.class).checkCooldown(player.getName(), name);
}

Expand Down
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.scripts.containers.core;

import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.objects.dItem;
Expand All @@ -18,12 +19,12 @@ public BookScriptContainer(ConfigurationSection configurationSection, String scr
super(configurationSection, scriptContainerName);
}

public dItem getBookFrom(Player player, dNPC npc) {
public dItem getBookFrom(dPlayer player, dNPC npc) {
dItem stack = new dItem(Material.BOOK);
return writeBookTo(stack, player, npc);
}

public dItem writeBookTo(dItem book, Player player, dNPC npc) {
public dItem writeBookTo(dItem book, dPlayer player, dNPC npc) {
// Get current ItemMeta from the book
BookMeta bookInfo = (BookMeta) book.getItemStack().getItemMeta();

Expand Down
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.scripts.containers.core;

import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.scripts.triggers.AbstractTrigger;
Expand Down Expand Up @@ -138,7 +139,7 @@ public boolean containsTriggerInStep(String step, Class<? extends AbstractTrigge
*
*/
public List<ScriptEntry> getEntriesFor(Class<? extends AbstractTrigger> trigger,
Player player, dNPC npc, String id) {
dPlayer player, dNPC npc, String id) {
// Get the trigger name
String triggerName = DenizenAPI.getCurrentInstance()
.getTriggerRegistry().get(trigger).getName().toUpperCase();
Expand Down Expand Up @@ -190,7 +191,7 @@ public List<ScriptEntry> getEntriesFor(Class<? extends AbstractTrigger> trigger,
*/

public Map<String, String> getIdMapFor(Class<? extends AbstractTrigger> trigger,
Player player) {
dPlayer player) {
// Get the trigger name
String triggerName = DenizenAPI.getCurrentInstance()
.getTriggerRegistry().get(trigger).getName().toUpperCase();
Expand All @@ -213,7 +214,7 @@ public Map<String, String> getIdMapFor(Class<? extends AbstractTrigger> trigger,
}

public boolean checkSpecificTriggerScriptRequirementsFor(Class<? extends AbstractTrigger> trigger,
Player player, dNPC npc, String id) {
dPlayer player, dNPC npc, String id) {
// Get the trigger name
String triggerName = DenizenAPI.getCurrentInstance()
.getTriggerRegistry().get(trigger).getName().toUpperCase();
Expand All @@ -224,7 +225,7 @@ public boolean checkSpecificTriggerScriptRequirementsFor(Class<? extends Abstrac
}

public String getTriggerOptionFor(Class<? extends AbstractTrigger> trigger,
Player player, String id, String option) {
dPlayer player, String id, String option) {
// Get the trigger name
String triggerName = DenizenAPI.getCurrentInstance()
.getTriggerRegistry().get(trigger).getName().toUpperCase();
Expand All @@ -235,7 +236,7 @@ public String getTriggerOptionFor(Class<? extends AbstractTrigger> trigger,
}

public boolean hasTriggerOptionFor(Class<? extends AbstractTrigger> trigger,
Player player, String id, String option) {
dPlayer player, String id, String option) {
// Get the trigger name
String triggerName = DenizenAPI.getCurrentInstance()
.getTriggerRegistry().get(trigger).getName().toUpperCase();
Expand Down
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.scripts.containers.core;

import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.triggers.AbstractTrigger;
import net.aufdemrand.denizen.utilities.DenizenAPI;
Expand All @@ -25,7 +26,7 @@ public class InteractScriptHelper {
* @return the highest priority InteractScriptContainer that meets requirements, if any.
*
*/
public static InteractScriptContainer getInteractScript(dNPC npc, Player player,
public static InteractScriptContainer getInteractScript(dNPC npc, dPlayer player,
Class<? extends AbstractTrigger> trigger) {
// If no trigger, npc or player specified, return null.
// These objects are required to progress any further.
Expand Down Expand Up @@ -189,7 +190,7 @@ else if (interactableScripts.isEmpty()) {
* @return the current, or default, step name
*
*/
public static String getCurrentStep(Player player, String scriptName) {
public static String getCurrentStep(dPlayer player, String scriptName) {
if (scriptName == null) return null;
// Probe 'saves.yml' for the current step
if (DenizenAPI._saves().contains("Players." + player.getName()
Expand Down
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.tags.TagManager;
Expand All @@ -29,7 +30,7 @@ public dItem getItemFrom() {
return getItemFrom(null, null);
}

public dItem getItemFrom(Player player, dNPC npc) {
public dItem getItemFrom(dPlayer player, dNPC npc) {
// Try to use this script to make an item.
dItem stack = null;
try {
Expand Down

0 comments on commit 4c2f5ab

Please sign in to comment.