Skip to content

Commit

Permalink
Parse item mech for dropped_item and item_projectile entities early
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Jun 24, 2015
1 parent 95d6152 commit e77cdca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static dInventory getInventory(Argument arg, ScriptEntry scriptEntry) {
if (dInventory.matches(string)) {
BukkitScriptEntryData data = (BukkitScriptEntryData) scriptEntry.getData();
if (data != null)
return dInventory.valueOf(string, ((BukkitScriptEntryData) scriptEntry.getData()).getTagContext());
return dInventory.valueOf(string, data.getTagContext());
else
return dInventory.valueOf(string);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package net.aufdemrand.denizen.utilities.entity;

import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizencore.objects.Mechanism;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.projectiles.ProjectileSource;

import java.util.ArrayList;
Expand All @@ -23,7 +26,14 @@ public CraftItemProjectile(CraftServer server, EntityItemProjectile entity) {
@CreateEntity
public static ItemProjectile createItemProjectile(Location location, ArrayList<Mechanism> mechanisms) {
CraftWorld world = (CraftWorld) location.getWorld();
EntityItemProjectile entity = new EntityItemProjectile(world, location);
ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(dItem.class)) {
itemStack = mechanism.getValue().asType(dItem.class).getItemStack();
break;
}
}
EntityItemProjectile entity = new EntityItemProjectile(world, location, itemStack);
return (ItemProjectile) entity.getBukkitEntity();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.utilities.entity;

import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Mechanism;
import org.bukkit.Location;
Expand Down Expand Up @@ -36,7 +37,7 @@ private DenizenEntityType(EntityType entityType) {
this.createMethod = null;
}

private DenizenEntityType(String name, Class<? extends DenizenCustomEntity> entityType) {
private DenizenEntityType(String name, Class<? extends DenizenCustomEntity> entityType) {
this(name, entityType, 0.115);
}

Expand Down Expand Up @@ -69,12 +70,22 @@ private DenizenEntityType(String name, Class<? extends DenizenCustomEntity> enti

public Entity spawnNewEntity(Location location, ArrayList<Mechanism> mechanisms) {
try {
if (name.equals("DROPPED_ITEM"))
return location.getWorld().dropItem(location, new ItemStack(Material.STONE));
else if (!isCustom())
if (name.equals("DROPPED_ITEM")) {
ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(dItem.class)) {
itemStack = mechanism.getValue().asType(dItem.class).getItemStack();
break;
}
}
return location.getWorld().dropItem(location, itemStack);
}
else if (!isCustom()) {
return location.getWorld().spawnEntity(location, bukkitEntityType);
else
}
else {
return (Entity) createMethod.invoke(null, location, mechanisms);
}
} catch (Exception e) {
dB.echoError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.inventory.*;

import java.util.List;

Expand All @@ -15,11 +17,12 @@ public class EntityItemProjectile extends EntityItem implements IProjectile {
public String shooterName;
private int age;

public EntityItemProjectile(CraftWorld craftWorld, Location location) {
public EntityItemProjectile(CraftWorld craftWorld, Location location, org.bukkit.inventory.ItemStack itemStack) {
super(craftWorld.getHandle());
this.pickupDelay = Integer.MAX_VALUE;
setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
//this.a(0.25F, 0.25F); // TODO: 1.8.3 update
this.setSize(0.25F, 0.25F);
this.setItemStack(CraftItemStack.asNMSCopy(itemStack));
world.addEntity(this);
bukkitEntity = new CraftItemProjectile((CraftServer) Bukkit.getServer(), this);
}
Expand Down

0 comments on commit e77cdca

Please sign in to comment.