Skip to content

Commit

Permalink
Fix mount typo, pause command parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 14, 2020
1 parent d195b8b commit 3691460
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 43 deletions.
Expand Up @@ -45,10 +45,6 @@ public class TradeTag implements ObjectTag, Adjustable {
//
// -->

//////////////////
// OBJECT FETCHER
////////////////

@Fetchable("trade")
public static TradeTag valueOf(String string, TagContext context) {
if (string == null) {
Expand All @@ -75,18 +71,11 @@ public static boolean matches(String str) {
return valueOf(str, CoreUtilities.noDebugContext) != null;
}

///////////////
// Constructors
/////////////

public TradeTag(MerchantRecipe recipe) {
this.recipe = recipe;
}

/////////////////////
// INSTANCE FIELDS/METHODS
/////////////////

@Override
public String toString() {
return identify();
}
Expand All @@ -101,44 +90,49 @@ public void setRecipe(MerchantRecipe recipe) {
this.recipe = recipe;
}

//////////////////////////////
// DSCRIPT ARGUMENT METHODS
/////////////////////////

@Override
public String getPrefix() {
return "trade";
}

@Override
public TradeTag setPrefix(String prefix) {
return this;
}

@Override
public boolean isUnique() {
return false;
}

@Override
public String getObjectType() {
return "Trade";
}

@Override
public String identify() {
return getPrefix() + "@trade" + PropertyParser.getPropertiesString(this);
return "trade@trade" + PropertyParser.getPropertiesString(this);
}

@Override
public String identifySimple() {
return identify();
}

public static ObjectTagProcessor<TradeTag> tagProcessor = new ObjectTagProcessor<>();

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
return tagProcessor.getObjectAttribute(this, attribute);
}

@Override
public void applyProperty(Mechanism mechanism) {
adjust(mechanism);
}

@Override
public void adjust(Mechanism mechanism) {
CoreUtilities.autoPropertyMechanism(this, mechanism);
}
Expand Down
Expand Up @@ -71,9 +71,7 @@ public HurtCommand() {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("amount")
&& (arg.matchesFloat()
|| arg.matchesInteger())) {
Expand All @@ -100,11 +98,9 @@ else if (!scriptEntry.hasObject("source_once")
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("amount")) {
scriptEntry.addObject("amount", new ElementTag(1.0d));
}

if (!scriptEntry.hasObject("entities")) {
List<EntityTag> entities = new ArrayList<>();
if (Utilities.getEntryPlayer(scriptEntry) != null) {
Expand All @@ -124,23 +120,18 @@ else if (Utilities.getEntryNPC(scriptEntry) != null) {
@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) {

List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
EntityTag source = scriptEntry.getObjectTag("source");
ElementTag amountElement = scriptEntry.getElement("amount");
ElementTag cause = scriptEntry.getElement("cause");
ElementTag source_once = scriptEntry.getElement("source_once");

if (scriptEntry.dbCallShouldDebug()) {

Debug.report(scriptEntry, getName(), amountElement.debug()
+ ArgumentHelper.debugList("entities", entities)
+ (source_once == null ? "" : source_once.debug())
+ (cause == null ? "" : cause.debug())
+ (source == null ? "" : source.debug()));

}

double amount = amountElement.asDouble();
for (EntityTag entity : entities) {
if (entity.getLivingEntity() == null) {
Expand Down
Expand Up @@ -96,46 +96,37 @@ enum PauseType {ACTIVITY, WAYPOINTS, NAVIGATION}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (arg.matchesArgumentType(DurationTag.class)
&& !scriptEntry.hasObject("duration")) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
}
if (!scriptEntry.hasObject("pause_type")
else if (!scriptEntry.hasObject("pause_type")
&& arg.matchesEnum(PauseType.values())) {
scriptEntry.addObject("pause_type", arg.asElement());
}
else {
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("pause_type")) {
throw new InvalidArgumentsException("Must specify a pause type!");
}
}

@Override
public void execute(ScriptEntry scriptEntry) {

DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag pauseTypeElement = scriptEntry.getElement("pause_type");

PauseType pauseType = PauseType.valueOf(pauseTypeElement.asString().toUpperCase());

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (duration == null ? "" : duration.debug()) + pauseTypeElement.debug());
}

NPCTag npc = null;
if (Utilities.getEntryNPC(scriptEntry) != null) {
npc = Utilities.getEntryNPC(scriptEntry);
}
pause(npc, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));

// If duration...
if (duration != null) {
if (durations.containsKey(npc.getCitizen().getId() + pauseType.name())) {
try {
Expand All @@ -145,10 +136,8 @@ public void execute(ScriptEntry scriptEntry) {
Debug.echoError(scriptEntry.getResidingQueue(), "There was an error pausing that!");
Debug.echoError(scriptEntry.getResidingQueue(), e);
}

}
Debug.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());

final NPCTag theNpc = npc;
final ScriptEntry se = scriptEntry;
durations.put(npc.getId() + pauseType.name(), DenizenAPI.getCurrentInstance()
Expand All @@ -166,21 +155,17 @@ public void run() {

public void pause(NPCTag denizen, PauseType pauseType, boolean pause) {
switch (pauseType) {

case WAYPOINTS:
denizen.getCitizen().getTrait(Waypoints.class).getCurrentProvider().setPaused(pause);
if (pause) {
denizen.getNavigator().cancelNavigation();
}
return;

case ACTIVITY:
denizen.getCitizen().getDefaultGoalController().setPaused(pause);
return;

case NAVIGATION:
// TODO: Finish this
}

}
}
Expand Up @@ -11,7 +11,7 @@ public static void mount(List<Entity> entities) {
for (Entity entity : entities) {
if (entity != null) {
if (lastEntity != null && entity != lastEntity) {
if (entity.getPassengers().contains(lastEntity)) {
if (!entity.getPassengers().contains(lastEntity)) {
lastEntity.teleport(entity.getLocation());
entity.addPassenger(lastEntity);
}
Expand Down

0 comments on commit 3691460

Please sign in to comment.