Skip to content

Commit

Permalink
Make ChunkLoad tag a dChunk
Browse files Browse the repository at this point in the history
Yay for proper object type. Also document dChunks.
  • Loading branch information
mcmonkey4eva committed Nov 4, 2014
1 parent d254eaf commit b946dae
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dChunk.java
Expand Up @@ -87,6 +87,10 @@ public dChunk(Location location) {
this((CraftChunk) location.getChunk());
}

public dLocation getCenter() {
return new dLocation(getWorld(), getX() * 16 + 8, 128, getZ() * 16 + 8);
}

public int getX() {
return chunk.getX();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dObject.java
Expand Up @@ -94,6 +94,11 @@
// | cu@<position_1>|<position_2>|... - fetches a new cuboid encompassing a region from position 1 to 2, from 2 to 3, ...
// | cu@<notable_cuboid_name> - fetches the cuboid that has been 'noted' with the specified ID
//
// + ----- dChunk ------+
// | object notation: ch@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | ch@<x>,<y>,<world> - fetches a chunk at the given chunk location
//
// + ----- dInventory ---+
// | object notation: in@ can reference unique objects: yes can be notable: soon
// | constructors: ( <>'s represent non-static information and are not literal)
Expand Down
Expand Up @@ -539,7 +539,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name ChunkLoad
// @Syntax chunkload ({add}/remove/removeall) [<location>] (duration:<value>)
// @Syntax chunkload ({add}/remove/removeall) [<chunk>] (duration:<value>)
// @Required 1
// @Stable stable
// @Short Keeps a chunk actively loaded and allowing NPC activity.
Expand All @@ -550,10 +550,20 @@ public void registerCoreMembers() {
// @Tags
// TODO: Document Command Details
// @Usage
// TODO: Document Command Details
// Use to load a chunk.
// - chunkload ch@0,0,world
// @Usage
// Use to temporarily load a chunk.
// - chunkload ch@0,0,world duration:5m
// @Usage
// Use to stop loading a chunk.
// - chunkload remove ch@0,0,world
// @Usage
// Use to stop loading any chunks.
// - chunkload removeall
// -->
registerCoreMember(ChunkLoadCommand.class,
"CHUNKLOAD", "chunkload ({add}/remove/removeall) [<location>] (duration:<value>)", 1);
"CHUNKLOAD", "chunkload ({add}/remove/removeall) [<chunk>] (duration:<value>)", 1);


// <--[command]
Expand Down
Expand Up @@ -3,17 +3,15 @@
import java.util.HashMap;
import java.util.Map;

import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.Duration;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.citizensnpcs.api.event.NPCDespawnEvent;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -37,8 +35,15 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (arg.matchesEnum(Action.values())
&& !scriptEntry.hasObject("action"))
&& !scriptEntry.hasObject("action")) {
scriptEntry.addObject("action", new Element(arg.getValue().toUpperCase()));
if (arg.getValue().equalsIgnoreCase("removeall"))
scriptEntry.addObject("location", new dLocation(Bukkit.getWorlds().get(0), 0, 0, 0));
}

else if (arg.matchesArgumentType(dChunk.class)
&& !scriptEntry.hasObject("location"))
scriptEntry.addObject("location", arg.asType(dChunk.class).getCenter());

else if (arg.matchesArgumentType(dLocation.class)
&& !scriptEntry.hasObject("location"))
Expand Down

0 comments on commit b946dae

Please sign in to comment.