Skip to content

Commit

Permalink
Added the "RAINY" requirement, changed "STORMY" requirement to also r…
Browse files Browse the repository at this point in the history
…ecognize the thunder.

Changed the "REMOVE" command to use the default server world instead of "world", also added an entity null check
  • Loading branch information
spaceemotion committed Aug 3, 2013
1 parent d3005c1 commit ba44c80
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
@@ -1,8 +1,5 @@
package net.aufdemrand.denizen.scripts.commands.entity;

import java.util.List;
import org.bukkit.entity.Entity;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Element;
Expand All @@ -15,6 +12,10 @@
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.aufdemrand.denizen.utilities.depends.WorldGuardUtilities;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;

import java.util.List;

/**
* Delete certain entities or all entities of a type.
Expand Down Expand Up @@ -55,12 +56,12 @@ else if (!scriptEntry.hasObject("world")
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES");

// If the world has not been specified, try to use the NPC's or player's
// world, or default to "world" if necessary
// world, or default to the specified world in the server properties if necessary

scriptEntry.defaultObject("world",
scriptEntry.hasNPC() ? new dWorld(scriptEntry.getNPC().getWorld()) : null,
scriptEntry.hasPlayer() ? new dWorld(scriptEntry.getPlayer().getWorld()) : null,
dWorld.valueOf("world"));
new dWorld(Bukkit.getWorlds().get(0)));
}

@SuppressWarnings("unchecked")
Expand All @@ -81,21 +82,25 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
// Go through all of our entities and remove them

for (dEntity entity : entities) {
// NP check to prevent errors from happening
if(entity == null) {
continue;
}

conditionsMet = true;

// If this is a specific spawned entity, and all
// other applicable conditions are met, remove it

if (entity.isGeneric() == false) {
if (entity.isGeneric()) {

if (region != null) {
conditionsMet = WorldGuardUtilities.inRegion
(entity.getBukkitEntity().getLocation(),
region.asString());
}

if (conditionsMet == true) {
if (conditionsMet) {

if (entity.isNPC()) {
entity.getNPC().destroy();
Expand Down
Expand Up @@ -107,6 +107,9 @@ public void registerCoreMembers() {

registerCoreMember(SunnyRequirement.class,
"SUNNY", "sunny", 0);

registerCoreMember(RainyRequirement.class,
"RAINY", "rainy", 0);

registerCoreMember(TimeRequirement.class,
"TIME", "time [dawn/day/dusk/night]", 1);
Expand Down
@@ -0,0 +1,22 @@
package net.aufdemrand.denizen.scripts.requirements.core;

import net.aufdemrand.denizen.exceptions.RequirementCheckException;
import net.aufdemrand.denizen.scripts.requirements.AbstractRequirement;
import net.aufdemrand.denizen.scripts.requirements.RequirementsContext;
import org.bukkit.World;

import java.util.List;

/**
* Returns whether or not it's raining in the world where the player is.
*/
public class RainyRequirement extends AbstractRequirement {

@Override
public boolean check(RequirementsContext context, List<String> args) throws RequirementCheckException {
World world = context.getPlayer().getPlayerEntity().getWorld();

return world.hasStorm() && !world.isThundering();
}

}
Expand Up @@ -3,6 +3,7 @@
import net.aufdemrand.denizen.exceptions.RequirementCheckException;
import net.aufdemrand.denizen.scripts.requirements.AbstractRequirement;
import net.aufdemrand.denizen.scripts.requirements.RequirementsContext;
import org.bukkit.World;

import java.util.List;

Expand All @@ -13,6 +14,8 @@ public class StormRequirement extends AbstractRequirement {

@Override
public boolean check(RequirementsContext context, List<String> args) throws RequirementCheckException {
return context.getPlayer().getPlayerEntity().getWorld().hasStorm();
World world = context.getPlayer().getPlayerEntity().getWorld();

return world.hasStorm() && world.isThundering();
}
}

2 comments on commit ba44c80

@spaceemotion
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops seems like I messed up my IDE settings "a bit" - sorry :(

@davidcernat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, the null check in Remove is unnecessary, because this line:

((dList) arg.asType(dList.class)).filter(dEntity.class));

Already handles that.

Secondly, you completely reversed the logic in Remove, thus breaking the command. You changed this:

if (entity.isGeneric() == false) { 

Into:

if (entity.isGeneric()) { 

Instead of what was correct:

if (!entity.isGeneric()) { 

Better luck next time. :P

Please sign in to comment.