Skip to content

Commit

Permalink
Merge pull request #553 from mcmonkey4eva/master
Browse files Browse the repository at this point in the history
Request pull
  • Loading branch information
aufdemrand committed Dec 10, 2013
2 parents 261e4b2 + f337ad0 commit cd548f2
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 40 deletions.
17 changes: 14 additions & 3 deletions src/main/java/net/aufdemrand/denizen/events/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ public void scanWorldEvents(ScriptReloadEvent event) {

}

// Register any custom commands found with Bukkit
// TODO:
// TODO: Register any custom commands found with Bukkit

}

private Plugin plugin = DenizenAPI.getCurrentInstance();
private Plugin plugin = DenizenAPI.getCurrentInstance();

public void registerCommand(String... aliases) {
PluginCommand command = getCommand(aliases[0], plugin);
Expand Down Expand Up @@ -153,6 +152,18 @@ public static List<String> trimEvents(List<String> event) {

if (dB.showEventsTrimming) dB.echoApproval("Trimming world events '" + event.toString() + '\'');

// Remove any duplicate event names
for (int i = 0; i < event.size(); i++) {
for (int x = 0; x < event.size(); x++) {
if (i != x && event.get(i).equalsIgnoreCase(event.get(x))) {
event.remove(i);
i--;
break;
}
}
}

// Create a new list, only containing events that have existing scripts
for (String e : event)
if (events.containsKey("ON " + e.toUpperCase()))
parsed.add(e);
Expand Down
48 changes: 41 additions & 7 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,22 @@ public String getAttribute(Attribute attribute) {

// Operator is the value of the .is[] context. Valid are Comparable.Operators, same
// as used by the IF command.
com.setOperator(Comparable.Operator.valueOf(operator
.replace("==", "EQUALS").replace(">=", "OR_MORE").replace("<=", "OR_LESS")
.replace("<", "LESS").replace(">", "MORE").replace("=", "EQUALS")));
Comparable.Operator comparableOperator = null;
try {
comparableOperator = Comparable.Operator.valueOf(operator.replace("==", "EQUALS")
.replace(">=", "OR_MORE").replace("<=", "OR_LESS").replace("<", "LESS")
.replace(">", "MORE").replace("=", "EQUALS").toUpperCase());
}
catch (IllegalArgumentException e) { }

return new Element(com.determineOutcome()).getAttribute(attribute.fulfill(2));
if (comparableOperator != null) {
com.setOperator(comparableOperator);

return new Element(com.determineOutcome()).getAttribute(attribute.fulfill(2));
}
else {
dB.echoError("Unknown operator '" + operator + "'.");
}
}


Expand Down Expand Up @@ -651,7 +662,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
return new Element(ChatColor.stripColor(element)).getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <e@element.trim>
// @attribute <el@element.trim>
// @returns Element
// @description
// Returns the value of an element minus any leading or trailing whitespace.
Expand All @@ -660,7 +671,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
return new Element(element.trim()).getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <e@element.upper>
// @attribute <el@element.upper>
// @returns Element
// @description
// Returns the value of an element in all uppercase letters.
Expand All @@ -669,14 +680,37 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
return new Element(element.toUpperCase()).getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <e@element.lower>
// @attribute <el@element.lower>
// @returns Element
// @description
// Returns the value of an element in all lowercase letters.
// -->
if (attribute.startsWith("lower"))
return new Element(element.toLowerCase()).getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <el@element.totitlecase>
// @returns Element
// @description
// Returns The Value Of An Element In Title Case.
// -->
if (attribute.startsWith("totitlecase")) {
if (element.length() == 0) {
return new Element("").getAttribute(attribute.fulfill(1));
}
StringBuilder TitleCase = new StringBuilder(element.length());
String Upper = element.toUpperCase();
String Lower = element.toLowerCase();
TitleCase.append(Upper.charAt(0));
for (int i = 1; i < element.length(); i++) {
if (element.charAt(i - 1) == ' ')
TitleCase.append(Upper.charAt(i));
else
TitleCase.append(Lower.charAt(i));
}
return new Element(TitleCase.toString()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <el@element.substring[<#>(,<#>)]>
// @returns Element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("equipment")) {
return getEquipment().getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <in@inventory.title>
// @returns Element
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,30 @@ else if (dEntity.matches(attribute.getContext(1))) {
return loc.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <l@location.yaw.simple>
// @returns Element
// @description
// Returns the yaw as 'North', 'South', 'East', or 'West'.
// -->
if (attribute.startsWith("yaw.simple")) {
if (getYaw() < 45)
return new Element("South")
.getAttribute(attribute.fulfill(2));
else if (getYaw() < 135)
return new Element("West")
.getAttribute(attribute.fulfill(2));
else if (getYaw() < 225)
return new Element("North")
.getAttribute(attribute.fulfill(2));
else if (getYaw() < 315)
return new Element("East")
.getAttribute(attribute.fulfill(2));
else
return new Element("South")
.getAttribute(attribute.fulfill(2));
}

// <--[tag]
// @attribute <l@location.yaw.raw>
// @returns Element(Decimal)
Expand Down Expand Up @@ -751,7 +775,7 @@ else if (attribute.startsWith("entities")
dList ent_list = new dList();
if (attribute.hasContext(1)) {
for (String ent : attribute.getContext(1).split("\\|")) {
if (dEntity.matches(ent))
if (dEntity.matches(ent))
ent_list.add(ent.toUpperCase());
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,15 @@ public String getAttribute(Attribute attribute) {
/////////////////////
// ENTITY LIST ATTRIBUTES
/////////////////

// <--[tag]
// @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")) {
int range = 50;
int attribs = 1;
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 All @@ -443,27 +445,27 @@ public String getAttribute(Attribute attribute) {
possibleTargets.add((LivingEntity) entity);
}
}

// Find the valid target
BlockIterator bi;
try {
bi = new BlockIterator(getPlayerEntity(), range);
}
catch (IllegalStateException e) {
return null;
return Element.NULL.getAttribute(attribute.fulfill(attribs));
}
Block b;
Location l;
int bx, by, bz;
double ex, ey, ez;

// Loop through player's line of sight
while (bi.hasNext()) {
b = bi.next();
bx = b.getX();
by = b.getY();
bz = b.getZ();

if (b.getType() != Material.AIR) {
// Line of sight is broken
break;
Expand All @@ -475,7 +477,7 @@ public String getAttribute(Attribute attribute) {
ex = l.getX();
ey = l.getY();
ez = l.getZ();

if ((bx - .75 <= ex && ex <= bx + 1.75) &&
(bz - .75 <= ez && ez <= bz + 1.75) &&
(by - 1 <= ey && ey <= by + 2.5)) {
Expand All @@ -487,7 +489,7 @@ public String getAttribute(Attribute attribute) {
}
return Element.NULL.getAttribute(attribute.fulfill(attribs));
}

// <--[tag]
// @attribute <p@player.list>
// @returns dList(dPlayer)
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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));
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ public static void setValues(Object obj, FieldEntry... entrys) throws Exception
for (FieldEntry f : entrys)
setValue(obj, f);
}
}
}

0 comments on commit cd548f2

Please sign in to comment.