Skip to content

Commit

Permalink
Prevent ParticleEffect errors + clean meta
Browse files Browse the repository at this point in the history
This will prevent the ParticleEffect from throwing errors when
accidentally sending Effect packets to NPCs.
Also cleaning up some meta and error messages for English readability.
  • Loading branch information
mcmonkey4eva committed Dec 10, 2013
1 parent c4d0fc0 commit b025421
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -417,7 +417,8 @@ public String getAttribute(Attribute attribute) {
// @attribute <p@player.target>
// @returns dEntity
// @description
// Returns Entity that the player is looking at in 50 range.
// Returns the entity that the player is looking at, within a maximum range of 50 blocks,
// or null if the player is not looking at an entity.
// -->

if (attribute.startsWith("target")) {
Expand All @@ -428,7 +429,8 @@ public String getAttribute(Attribute attribute) {
// @attribute <p@player.target.within[#]>
// @returns dEntity
// @description
// Returns Entity that the player is looking at in the specified range.
// Returns the entity that the player is looking at within the specified range limit,
// or null if the player is not looking at an entity.
if (attribute.getAttribute(2).startsWith("within") &&
attribute.hasContext(2) &&
aH.matchesInteger(attribute.getContext(2))) {
Expand Down
Expand Up @@ -13,6 +13,8 @@ public class Comparable {
// @group Comparables
// @description
// A Comparable is a method that the IF command and Element dObject uses to compare objects.
// (This lang is TODO! )
// See <@link language operator>
// -->

// <--[language]
Expand Down
Expand Up @@ -73,7 +73,7 @@ public boolean check(RequirementsContext context) {
//
// Evaluate the requirement
//

// <--[requirement]
// @Name ValueOf
// @Syntax valueof [<tag>]
Expand All @@ -82,14 +82,14 @@ public boolean check(RequirementsContext context) {
// @Short Checks if the tag is true.
//
// @Description
// Checks if a specified tag or value of some sort returns "true".
// Checks if a specified tag or value returns 'true'.
//
// @Usage
// Check if a simple tag is true.
// - valueof <player.is_player>
//
// @Usage
// Check a comparator (See <@link language operator> for more information...)
// Check a comparable (See <@link language comparable> for more information.)
// - valueof <player.health.is[LESS].than[10]>
// -->
if (reqString.equalsIgnoreCase("valueof")) {
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/net/aufdemrand/denizen/utilities/ParticleEffect.java
Expand Up @@ -10,6 +10,7 @@
import java.util.Map.Entry;

import net.aufdemrand.denizen.utilities.ReflectionUtil;
import net.citizensnpcs.api.CitizensAPI;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -75,7 +76,7 @@ public enum ParticleEffect {

private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<String, ParticleEffect>();
private static final Map<Integer, ParticleEffect> ID_MAP = new HashMap<Integer, ParticleEffect>();
private static final double MAX_RANGE = 100.0D; // When auf updated, it was 20.0 max range
private static final double MAX_RANGE = 100.0D; // Denizen: Modified from original range of 20.0D
private static Constructor<?> PARTICLE_PACKET_CONSTRUCTOR;

static {
Expand Down Expand Up @@ -158,7 +159,8 @@ private static Object createBlockDustPacket(int id, byte data, Location loc, flo
}

private static void sendPacket(Player p, Object packet) {
if (packet != null)
// Denizen: Check player against NPC registry to prevent errors
if (packet != null && !CitizensAPI.getNPCRegistry().isNPC(p))
try {
Object entityPlayer = ReflectionUtil.invokeMethod("getHandle", p.getClass(), p);
Object playerConnection = ReflectionUtil.getValue("playerConnection", entityPlayer);
Expand Down Expand Up @@ -188,11 +190,12 @@ public void display(Location loc, float offsetX, float offsetY, float offsetZ, f
}

/**
* Displays a particle effect which is visible for all players whitin a certain range in the the world of @param loc
* Displays a particle effect which is visible for all players within a certain range in the the world of @param loc
*/
public void display(Location loc, double range, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
// Denizen: Clean invalid range message (Also on following matching messages)
if (range > MAX_RANGE)
throw new IllegalArgumentException("Radius effect has to be lower/equal the maximum of 100");
throw new IllegalArgumentException("Effect radius must be less than or equal to the maximum range of 100 blocks");
sendPacket(getPlayersInRange(loc, range), createPacket(loc, offsetX, offsetY, offsetZ, speed, amount));
}

Expand All @@ -204,18 +207,18 @@ public static void displayIconCrack(Location loc, int id, float offsetX, float o
}

/**
* Displays an icon crack (item break) effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
* Displays an icon crack (item break) effect which is visible for all players within the maximum range of 20 blocks in the world of @param loc
*/
public static void displayIconCrack(Location loc, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
displayIconCrack(loc, MAX_RANGE, id, offsetX, offsetY, offsetZ, speed, amount);
}

/**
* Displays an icon crack (item break) effect which is visible for all players whitin a certain range in the the world of @param loc
* Displays an icon crack (item break) effect which is visible for all players within a certain range in the the world of @param loc
*/
public static void displayIconCrack(Location loc, double range, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
if (range > MAX_RANGE)
throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
throw new IllegalArgumentException("Effect radius must be less than or equal to the maximum range of 100 blocks");
sendPacket(getPlayersInRange(loc, range), createIconCrackPacket(id, loc, offsetX, offsetY, offsetZ, speed, amount));
}

Expand All @@ -227,18 +230,18 @@ public static void displayBlockCrack(Location loc, int id, byte data, float offs
}

/**
* Displays a block crack (block break) effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
* Displays a block crack (block break) effect which is visible for all players within the maximum range of 20 blocks in the world of @param loc
*/
public static void displayBlockCrack(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
displayBlockCrack(loc, MAX_RANGE, id, data, offsetX, offsetY, offsetZ, speed, amount);
}

/**
* Displays a block crack (block break) effect which is visible for all players whitin a certain range in the the world of @param loc
* Displays a block crack (block break) effect which is visible for all players within a certain range in the the world of @param loc
*/
public static void displayBlockCrack(Location loc, double range, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
if (range > MAX_RANGE)
throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
throw new IllegalArgumentException("Effect radius must be less than or equal to the maximum range of 100 blocks");
sendPacket(getPlayersInRange(loc, range), createBlockCrackPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
}

Expand All @@ -250,20 +253,20 @@ public static void displayBlockDust(Location loc, int id, byte data, float offse
}

/**
* Displays a block dust effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
* Displays a block dust effect which is visible for all players within the maximum range of 20 blocks in the world of @param loc
*/
public static void displayBlockDust(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
displayBlockDust(loc, MAX_RANGE, id, data, offsetX, offsetY, offsetZ, speed, amount);
}

/**
* Displays a block dust effect which is visible for all players whitin a certain range in the the world of @param loc
* Displays a block dust effect which is visible for all players within a certain range in the the world of @param loc
*/
public static void displayBlockDust(Location loc, double range, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
if (range > MAX_RANGE)
throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
throw new IllegalArgumentException("Effect radius must be less than or equal to the maximum range of 100 blocks");
sendPacket(getPlayersInRange(loc, range), createBlockDustPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
}


}
}

0 comments on commit b025421

Please sign in to comment.