Skip to content

Commit

Permalink
Fix <location.direction[location]> tag. Add contextless <location.dir…
Browse files Browse the repository at this point in the history
…ection> tag.
  • Loading branch information
davidcernat committed Jul 12, 2013
1 parent ebe4c72 commit 6acc505
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 31 deletions.
20 changes: 16 additions & 4 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static dEntity valueOf(String string) {

// When selecting a random entity type, ignore invalid or inappropriate ones
while (randomType == null ||
randomType.name().matches("^(COMPLEX_PART|DROPPED_ITEM|ENDER_CRYSTAL|ENDER_DRAGON|FISHING_HOOK|ITEM_FRAME|LIGHTNING|PAINTING|PLAYER|UNKNOWN|WEATHER|WITHER|WITHER_SKULL)$") == true) {
randomType.name().matches("^(COMPLEX_PART|DROPPED_ITEM|ENDER_CRYSTAL|ENDER_DRAGON|FISHING_HOOK|ITEM_FRAME|LIGHTNING|PAINTING|PLAYER|UNKNOWN|WEATHER|WITHER|WITHER_SKULL)$") == true) {

randomType = EntityType.values()[Utilities.getRandom().nextInt(EntityType.values().length)];
}
Expand Down Expand Up @@ -647,9 +647,21 @@ public String getAttribute(Attribute attribute) {
return new dLocation(entity.getLocation().add(0, -1, 0))
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("location"))
return new dLocation(entity.getLocation())
if (attribute.startsWith("location")) {

if (entity instanceof Player) {
// Important for player yaw and direction!
//
// A player's true yaw is always 90 less than the one given by
// Bukkit's location.getYaw(), so correct it here

dLocation location = new dLocation(entity.getLocation());
location.setYaw(location.getYaw() - 90);
return location.getAttribute(attribute.fulfill(1));
}
else return new dLocation(entity.getLocation())
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("health.formatted")) {
double maxHealth = getLivingEntity().getMaxHealth();
Expand Down Expand Up @@ -711,7 +723,7 @@ else if ((float) getLivingEntity().getHealth() / maxHealth < 1)
return new Element(String.valueOf(getLivingEntity().getCanPickupItems()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("id"))
if (attribute.startsWith("entity_id"))
return new Element(String.valueOf(entity.getEntityId()))
.getAttribute(attribute.fulfill(1));

Expand Down
22 changes: 19 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,20 @@ else if (attribute.startsWith("surface_blocks")
if (attribute.startsWith("block.material"))
return new Element(getBlock().getType().toString()).getAttribute(attribute.fulfill(2));

if (attribute.startsWith("direction"))
if (attribute.hasContext(1) && dLocation.matches(attribute.getContext(1)))
if (attribute.startsWith("direction")) {
if (attribute.hasContext(1) && dLocation.matches(attribute.getContext(1))) {
// Subtract this location's vector from the other location's vector,
// not the other way around
return new Element(Rotation.getCardinal(Rotation.getYaw
(this.toVector().subtract(dLocation.valueOf(attribute.getContext(1)).toVector())
(dLocation.valueOf(attribute.getContext(1)).toVector().subtract(this.toVector())
.normalize())))
.getAttribute(attribute.fulfill(1));
}
else {
return new Element(Rotation.getCardinal(getYaw()))
.getAttribute(attribute.fulfill(1));
}
}

if (attribute.startsWith("distance")) {
if (attribute.hasContext(1) && dLocation.matches(attribute.getContext(1))) {
Expand Down Expand Up @@ -492,6 +500,14 @@ else return new Element(String.valueOf(this.distance(toLocation)))
return new Element(String.valueOf((int) getBlock().getLightLevel()))
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("pitch")) {
return new Element(String.valueOf(getPitch())).getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("yaw")) {
return new Element(String.valueOf(getYaw())).getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("power"))
return new Element(String.valueOf(getBlock().getBlockPower()))
.getAttribute(attribute.fulfill(1));
Expand Down
41 changes: 31 additions & 10 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.entity.Rotation;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -256,7 +257,7 @@ else if (attribute.startsWith("list.offline")) {
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("location.bed_spawn"))
if (attribute.startsWith("bed_spawn"))
return new dLocation(getOfflinePlayer().getBedSpawnLocation())
.getAttribute(attribute.fulfill(2));

Expand Down Expand Up @@ -302,20 +303,24 @@ else if (attribute.startsWith("list.offline")) {
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("equipment.boots"))
return new dItem(getPlayerEntity().getInventory().getBoots())
.getAttribute(attribute.fulfill(2));
if (getPlayerEntity().getInventory().getBoots() != null)
return new dItem(getPlayerEntity().getInventory().getBoots())
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("equipment.chestplate"))
return new dItem(getPlayerEntity().getInventory().getChestplate())
.getAttribute(attribute.fulfill(2));
if (getPlayerEntity().getInventory().getChestplate() != null)
return new dItem(getPlayerEntity().getInventory().getChestplate())
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("equipment.helmet"))
return new dItem(getPlayerEntity().getInventory().getHelmet())
.getAttribute(attribute.fulfill(2));
if (getPlayerEntity().getInventory().getHelmet() != null)
return new dItem(getPlayerEntity().getInventory().getHelmet())
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("equipment.leggings"))
return new dItem(getPlayerEntity().getInventory().getLeggings())
.getAttribute(attribute.fulfill(2));
if (getPlayerEntity().getInventory().getLeggings() != null)
return new dItem(getPlayerEntity().getInventory().getLeggings())
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("equipment"))
// The only way to return correct size for dInventory
Expand All @@ -328,6 +333,18 @@ else if (attribute.startsWith("list.offline")) {
return new dInventory(getPlayerEntity().getInventory())
.getAttribute(attribute.fulfill(1));

// Estimate the location of the item the player is holding
if (attribute.startsWith("item_in_hand.location")) {

dLocation location = new dLocation(getPlayerEntity().getLocation());
//location.setYaw((float) Rotation.normalizeYaw(Rotation.getYaw(location.getDirection())));
location.setYaw(location.getYaw() + 30);
//location.add(location.getDirection().multiply(1.2));
getPlayerEntity().teleport(location);

return location.getAttribute(attribute.fulfill(2));
}

if (attribute.startsWith("item_in_hand"))
return new dItem(getPlayerEntity().getItemInHand())
.getAttribute(attribute.fulfill(1));
Expand All @@ -343,7 +360,11 @@ else if (attribute.startsWith("list.offline")) {
if (attribute.startsWith("name"))
return new Element(player_name).getAttribute(attribute.fulfill(1));

if (attribute.startsWith("location.compass_target"))
if (attribute.startsWith("eyes"))
return new dLocation(getPlayerEntity().getEyeLocation())
.getAttribute(attribute.fulfill(1));

if (attribute.startsWith("compass_target"))
return new dLocation(getPlayerEntity().getCompassTarget())
.getAttribute(attribute.fulfill(2));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@
import net.aufdemrand.denizen.objects.aH.ArgumentType;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Builds new objects for use with in scripts.
* Builds new objects for use within scripts.
*
* @author Jeremy Schroeder
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
if (aH.matchesArg("MONEY, COINS", arg))
takeType = TakeType.MONEY;

else if (aH.matchesArg("ITEM_IN_HAND", arg))
else if (aH.matchesArg("ITEM_IN_HAND, ITEMINHAND", arg))
takeType = TakeType.ITEMINHAND;

else if (aH.matchesArg("INVENTORY", arg))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,10 +1174,12 @@ public void serverCommandEvent(ServerCommandEvent event) {

@EventHandler
public void vehicleDamage(VehicleDamageEvent event) {

Map<String, Object> context = new HashMap<String, Object>();

Entity entity = event.getAttacker();

if (entity == null) return;

Entity entity = event.getAttacker();
Map<String, Object> context = new HashMap<String, Object>();
Vehicle vehicle = event.getVehicle();

String entityType = entity.getType().name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum ParticleEffect {
RED_DUST("reddust", 24),
SNOWBALL_POOF("snowballpoof", 25),
DRIP_WATER("dripWater", 26),
RIP_LAVA("dripLava", 27),
DRIP_LAVA("dripLava", 27),
SNOW_SHOVEL("snowshovel", 28),
SLIME("slime", 29),
HEART("heart", 30),
Expand Down Expand Up @@ -187,8 +187,13 @@ public static void playIconCrack(Location loc, double range, int id, float offse
private Object createNormalPacket(ParticleEffect effect, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {

// Get another effect if "RANDOM" is used
while (effect.equals(ParticleEffect.RANDOM)){
effect = ParticleEffect.values()[Utilities.getRandom().nextInt(ParticleEffect.values().length)];
if (effect.equals(ParticleEffect.RANDOM)) {

// Make sure the new effect is not "RANDOM" or an invisible effect
while (effect.toString().matches("^(RANDOM|BUBBLE|SUSPEND|DEPTH_SUSPEND)$")) {

effect = ParticleEffect.values()[Utilities.getRandom().nextInt(ParticleEffect.values().length)];
}
}

return createPacket(effect.getName(), loc, offsetX, offsetY, offsetZ, speed, amount);
Expand Down

0 comments on commit 6acc505

Please sign in to comment.