Skip to content

Commit

Permalink
remove old 1.12 material stuff, cleanup meta/files, fix leaf decay event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 6, 2020
1 parent ab9f314 commit f7dba6d
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 84 deletions.
Expand Up @@ -724,9 +724,6 @@ else if (matcher.doesMatch(mat.identifyNoIdentifier())) {
else if (matcher.doesMatch(mat.identifySimpleNoIdentifier())) {
return true;
}
else if (matcher.doesMatch(mat.identifyFullNoIdentifier())) {
return true;
}
return false;
}

Expand Down
Expand Up @@ -45,7 +45,7 @@ public boolean couldMatch(ScriptPath path) {
if (!path.eventArgLowerAt(1).equals("decay")) {
return false;
}
if (!path.eventArgLowerAt(2).equals("leaves") && !couldMatchBlock(path.eventArgLowerAt(2))) {
if (!path.eventArgLowerAt(0).equals("leaves") && !couldMatchBlock(path.eventArgLowerAt(0))) {
return false;
}
return true;
Expand Down
Expand Up @@ -69,7 +69,7 @@ public boolean couldMatch(ScriptPath path) {
public boolean matches(ScriptPath path) {

String mat = path.eventArgLowerAt(2);
if (!mat.equals("sign") && (!mat.equals(material.identifyNoIdentifier()) && !mat.equals(material.identifyFullNoIdentifier()))) {
if (!mat.equals("sign") && (!tryMaterial(material, mat))) {
return false;
}

Expand Down
Expand Up @@ -43,7 +43,7 @@ public class CommandScriptEvent extends BukkitScriptEvent implements Listener {
//
// @Context
// <context.command> returns the command name as an ElementTag.
// <context.raw_args> returns any args used as a ListTag.
// <context.raw_args> returns any args used, unmodified as plaintext.
// <context.args> returns a ListTag of the arguments.
// <context.source_type> returns the source of the command. Can be: PLAYER, SERVER, COMMAND_BLOCK, or COMMAND_MINECART.
// <context.command_block_location> returns the command block's location (if the command was run from one).
Expand Down
Expand Up @@ -40,30 +40,6 @@ public class MaterialTag implements ObjectTag, Adjustable {
//
// -->

/**
* Legacy MaterialTag identities.
*/
private String forcedIdentity = null,
forcedIdentityLow = null;

/**
* Legacy MaterialTag identities. Do not use.
*/
public MaterialTag forceIdentifyAs(String string) {
forcedIdentity = string;
forcedIdentityLow = CoreUtilities.toLowerCase(string);
return this;
}

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

@Deprecated
public static MaterialTag valueOf(String string) {
return valueOf(string, null);
}

/**
* Gets a Material Object from a string form.
*
Expand Down Expand Up @@ -141,10 +117,6 @@ public boolean matchesBlock(Block b) {
return getMaterial() == b.getType();
}

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

public MaterialTag(Material material) {
this.material = material;
if (material.isBlock()) {
Expand All @@ -167,10 +139,6 @@ public MaterialTag(ModernBlockData data) {
this.material = data.getMaterial();
}

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

private Material material;
private ModernBlockData modernData;

Expand Down Expand Up @@ -223,52 +191,29 @@ public String identify() {
return "m@" + identifyNoIdentifier();
}

public String identifyFull() {
return "m@" + identifyFullNoIdentifier();
}

@Override
public String identifySimple() {
return "m@" + identifySimpleNoIdentifier();
}

public String identifyNoPropertiesNoIdentifier() {
if (forcedIdentity != null) {
return forcedIdentityLow;
}
return CoreUtilities.toLowerCase(material.name());
}

public String identifyNoIdentifier() {
if (forcedIdentity != null) {
return forcedIdentityLow;
}
return CoreUtilities.toLowerCase(material.name()) + PropertyParser.getPropertiesString(this);
}

public String identifySimpleNoIdentifier() {
if (forcedIdentity != null) {
return forcedIdentityLow;
}
return CoreUtilities.toLowerCase(material.name());
}

public String identifyFullNoIdentifier() {
if (forcedIdentity != null) {
return forcedIdentityLow;
}
return CoreUtilities.toLowerCase(material.name()) + PropertyParser.getPropertiesString(this);
}

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

public String realName() {
if (forcedIdentity != null) {
return forcedIdentityLow;
}
return CoreUtilities.toLowerCase(material.name());
}

Expand Down Expand Up @@ -686,7 +631,7 @@ public static void registerTags() {
// Returns the name of the material.
// -->
registerTag("name", (attribute, object) -> {
return new ElementTag(object.forcedIdentity != null ? object.forcedIdentityLow : CoreUtilities.toLowerCase(object.material.name()));
return new ElementTag(CoreUtilities.toLowerCase(object.material.name()));
});

// <--[tag]
Expand Down
Expand Up @@ -97,9 +97,7 @@ public WalkCommand() {

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

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

if (!scriptEntry.hasObject("lookat")
&& arg.matchesPrefix("lookat")
&& arg.matchesArgumentType(LocationTag.class)) {
Expand Down Expand Up @@ -135,37 +133,31 @@ else if (!scriptEntry.hasObject("entities")
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("location") && !scriptEntry.hasObject("stop")) {
throw new InvalidArgumentsException("Must specify a location!");
}

if (!scriptEntry.hasObject("entities")) {
if (Utilities.getEntryNPC(scriptEntry) == null
|| !Utilities.getEntryNPC(scriptEntry).isValid()
|| !Utilities.getEntryNPC(scriptEntry).isSpawned()) {
throw new InvalidArgumentsException("Must have a valid spawned NPC attached.");
}
else {
scriptEntry.addObject("entities",
Arrays.asList(Utilities.getEntryNPC(scriptEntry).getDenizenEntity()));
scriptEntry.addObject("entities", Arrays.asList(Utilities.getEntryNPC(scriptEntry).getDenizenEntity()));
}
}

scriptEntry.defaultObject("stop", new ElementTag(false));
}

@Override
public void execute(ScriptEntry scriptEntry) {

LocationTag loc = scriptEntry.getObjectTag("location");
ElementTag speed = scriptEntry.getElement("speed");
ElementTag auto_range = scriptEntry.getElement("auto_range");
ElementTag radius = scriptEntry.getElement("radius");
ElementTag stop = scriptEntry.getElement("stop");
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
final LocationTag lookat = scriptEntry.getObjectTag("lookat");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (loc != null ? loc.debug() : "")
+ (speed != null ? speed.debug() : "")
Expand All @@ -175,11 +167,7 @@ public void execute(ScriptEntry scriptEntry) {
+ stop.debug()
+ (ArgumentHelper.debugObj("entities", entities)));
}

// Do the execution

boolean shouldStop = stop.asBoolean();

List<NPCTag> npcs = new ArrayList<>();
final List<EntityTag> waitForEntities = new ArrayList<>();
for (final EntityTag entity : entities) {
Expand All @@ -190,22 +178,17 @@ public void execute(ScriptEntry scriptEntry) {
Debug.echoError(scriptEntry.getResidingQueue(), "NPC " + npc.identify() + " is not spawned!");
continue;
}

if (shouldStop) {
npc.getNavigator().cancelNavigation();
continue;
}

if (auto_range != null
&& auto_range.asBoolean()) {
if (auto_range != null && auto_range.asBoolean()) {
double distance = npc.getLocation().distance(loc);
if (npc.getNavigator().getLocalParameters().range() < distance + 10) {
npc.getNavigator().getLocalParameters().range((float) distance + 10);
}
}

npc.getNavigator().setTarget(loc);

if (lookat != null) {
npc.getNavigator().getLocalParameters().lookAtFunction(new Function<Navigator, Location>() {
@Override
Expand All @@ -214,11 +197,9 @@ public Location apply(Navigator nav) {
}
});
}

if (speed != null) {
npc.getNavigator().getLocalParameters().speedModifier(speed.asFloat());
}

if (radius != null) {
npc.getNavigator().getLocalParameters().addRunCallback(WalkCommandCitizensEvents
.generateNewFlocker(npc.getCitizen(), radius.asDouble()));
Expand All @@ -238,7 +219,6 @@ public void run() {
});
}
}

if (scriptEntry.shouldWaitFor()) {
held.add(scriptEntry);
if (!npcs.isEmpty()) {
Expand Down

0 comments on commit f7dba6d

Please sign in to comment.