Skip to content

Commit

Permalink
cleanup chunkload command and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 21, 2020
1 parent 6523edb commit 30b31a6
Showing 1 changed file with 3 additions and 12 deletions.
Expand Up @@ -84,7 +84,6 @@ private enum Action {ADD, REMOVE, REMOVEALL}

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

for (Argument arg : scriptEntry.getProcessedArgs()) {
if (arg.matchesEnum(Action.values())
&& !scriptEntry.hasObject("action")) {
Expand All @@ -109,15 +108,12 @@ else if (arg.matchesArgumentType(DurationTag.class)
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location argument!");
}

if (!scriptEntry.hasObject("action")) {
scriptEntry.addObject("action", new ElementTag("ADD"));
}

if (!scriptEntry.hasObject("duration")) {
scriptEntry.addObject("duration", new DurationTag(0));
}
Expand All @@ -128,16 +124,12 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag action = scriptEntry.getElement("action");
ListTag chunklocs = scriptEntry.getObjectTag("location");
DurationTag length = scriptEntry.getObjectTag("duration");

if (scriptEntry.dbCallShouldDebug()) {

Debug.report(scriptEntry, getName(),
action.debug()
+ chunklocs.debug()
+ length.debug());

}

for (String chunkText : chunklocs) {
Chunk chunk;
if (ChunkTag.matches(chunkText)) {
Expand All @@ -150,8 +142,7 @@ else if (LocationTag.matches(chunkText)) {
Debug.echoError("Chunk input '" + chunkText + "' is invalid.");
return;
}
String chunkString = chunk.getX() + ", " + chunk.getZ() + "," + chunk.getWorld().getName();

String chunkString = chunk.getX() + "," + chunk.getZ() + "," + chunk.getWorld().getName();
switch (Action.valueOf(action.asString())) {
case ADD:
if (length.getSeconds() != 0) {
Expand Down Expand Up @@ -207,7 +198,7 @@ public void stopUnload(ChunkUnloadEvent e) {
if (!(e instanceof Cancellable)) { // Not cancellable in 1.14
return;
}
String chunkString = e.getChunk().getX() + ", " + e.getChunk().getZ() + "," + e.getChunk().getWorld().getName();
String chunkString = e.getChunk().getX() + "," + e.getChunk().getZ() + "," + e.getChunk().getWorld().getName();
if (chunkDelays.containsKey(chunkString)) {
if (chunkDelays.get(chunkString) == 0) {
((Cancellable) e).setCancelled(true);
Expand All @@ -228,7 +219,7 @@ public void stopDespawn(NPCDespawnEvent e) {
return;
}
Chunk chnk = e.getNPC().getEntity().getLocation().getChunk();
String chunkString = chnk.getX() + ", " + chnk.getZ();
String chunkString = chnk.getX() + "," + chnk.getZ() + "," + chnk.getWorld().getName();
if (chunkDelays.containsKey(chunkString)) {
if (chunkDelays.get(chunkString) == 0) {
e.setCancelled(true);
Expand Down

0 comments on commit 30b31a6

Please sign in to comment.