Permalink
Browse files

Update for latest changes to projectiles.

Recent additions to Bukkit included distinction of ProjectileSource,
which can be an entity or a dispenser (or through modding, other
blocks). The previous behavior was CH treated projectile sources as
either an entity or null. This commit accommodates the new handling.
  • Loading branch information...
1 parent 3e391d4 commit 671f4784eb95b4a246c1985f9ab4a6112a8a614c @jb-aero jb-aero committed Feb 11, 2014
Showing with 364 additions and 159 deletions.
  1. +3 −2 nb-configuration.xml
  2. +3 −3 pom.xml
  3. +0 −57 src/main/java/com/laytonsmith/abstraction/MCEntity.java
  4. +1 −3 src/main/java/com/laytonsmith/abstraction/MCLivingEntity.java
  5. +1 −1 src/main/java/com/laytonsmith/abstraction/MCLocation.java
  6. +2 −2 src/main/java/com/laytonsmith/abstraction/MCProjectile.java
  7. +14 −0 src/main/java/com/laytonsmith/abstraction/MCProjectileSource.java
  8. +63 −0 src/main/java/com/laytonsmith/abstraction/Velocity.java
  9. +12 −0 src/main/java/com/laytonsmith/abstraction/blocks/MCBlockProjectileSource.java
  10. +24 −8 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java
  11. +1 −0 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCFireball.java
  12. +2 −21 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCLivingEntity.java
  13. +1 −1 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCLocation.java
  14. +21 −9 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCProjectile.java
  15. +67 −0 src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCBlockProjectileSource.java
  16. +63 −0 src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEntityProjectileSource.java
  17. +2 −2 src/main/java/com/laytonsmith/abstraction/bukkit/events/BukkitBlockEvents.java
  18. +1 −1 src/main/java/com/laytonsmith/abstraction/events/MCBlockDispenseEvent.java
  19. +4 −3 src/main/java/com/laytonsmith/core/ObjectGenerator.java
  20. +57 −36 src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java
  21. +19 −7 src/main/java/com/laytonsmith/core/functions/EntityManagement.java
  22. +2 −2 src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
  23. +1 −1 src/main/java/com/laytonsmith/core/functions/World.java
View
@@ -13,14 +13,14 @@ You can copy and paste the single properties, into the pom.xml file and the IDE
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
- <netbeans.compile.on.save>none</netbeans.compile.on.save>
+ <netbeans.compile.on.save>all</netbeans.compile.on.save>
<netbeans.checkstyle.format>true</netbeans.checkstyle.format>
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
<org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab>4</org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab>
<org-netbeans-modules-editor-indent.CodeStyle.project.tab-size>4</org-netbeans-modules-editor-indent.CodeStyle.project.tab-size>
<org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>
<org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs>false</org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs>
- <org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width>80</org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width>
+ <org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width>120</org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width>
<org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap>none</org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap>
<com-junichi11-netbeans-changelf.use-project>true</com-junichi11-netbeans-changelf.use-project>
<com-junichi11-netbeans-changelf.enable>true</com-junichi11-netbeans-changelf.enable>
@@ -34,5 +34,6 @@ Any value defined here will override the pom.xml file value but is only applicab
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs>false</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width>80</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-line-wrap>none</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-line-wrap>
+ <netbeans.hint.licensePath>LICENSE.txt</netbeans.hint.licensePath>
</properties>
</project-shared-configuration>
View
@@ -95,8 +95,8 @@
</contributor>
</contributors>
<issueManagement>
- <system>sk89q's Redmine</system>
- <url>http://redmine.sk89q.com/projects/commandhelper/</url>
+ <system>sk89q's Youtrack</system>
+ <url>http://youtrack.sk89q.com/issues/CMDHELPER</url>
</issueManagement>
<ciManagement>
<system>TeamCity</system>
@@ -177,7 +177,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
- <version>1.7.2-R0.1-SNAPSHOT</version>
+ <version>1.7.2-R0.3-SNAPSHOT</version>
</dependency>
<!-- CraftBukkit Dependency for experimental features
@@ -13,63 +13,6 @@
* @author layton
*/
public interface MCEntity extends MCMetadatable {
- public static class Velocity {
- public double magnitude;
- public double x;
- public double y;
- public double z;
-
- public Velocity(double x, double y, double z){
- this(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)), x, y, z);
- }
- public Velocity(double magnitude, double x, double y, double z) {
- this.magnitude = magnitude;
- this.x = x;
- this.y = y;
- this.z = z;
- }
-
- public Velocity add(Velocity vec) {
- this.x += vec.x;
- this.y += vec.y;
- this.z += vec.z;
- return this;
- }
-
- public Velocity multiply(Velocity vec) {
- this.x *= vec.x;
- this.y *= vec.y;
- this.z *= vec.z;
- return this;
- }
-
- public Velocity multiply(double m) {
- this.x *= m;
- this.y *= m;
- this.z *= m;
- return this;
- }
-
- public Velocity normalize() {
- double length = length();
-
- this.x /= length;
- this.y /= length;
- this.z /= length;
- return this;
- }
-
- public Velocity subtract(Velocity vec) {
- this.x -= vec.x;
- this.y -= vec.y;
- this.z -= vec.z;
- return this;
- }
-
- public double length() {
- return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2));
- }
- }
public boolean eject();
@@ -2,7 +2,6 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.blocks.MCBlock;
-import com.laytonsmith.abstraction.enums.MCProjectileType;
import com.laytonsmith.core.constructs.Target;
import java.util.HashSet;
import java.util.List;
@@ -11,7 +10,7 @@
*
* @author layton
*/
-public interface MCLivingEntity extends MCEntity {
+public interface MCLivingEntity extends MCEntity, MCProjectileSource {
public void addEffect(int potionID, int strength, int seconds, boolean ambient, Target t);
public boolean removeEffect(int potionID);
@@ -47,7 +46,6 @@
public int getRemainingAir();
public boolean isCustomNameVisible();
public boolean isLeashed();
- public MCProjectile launchProjectile(MCProjectileType projectile);
public void resetMaxHealth();
public void setCanPickupItems(boolean pickup);
public void setRemoveWhenFarAway(boolean remove);
@@ -1,7 +1,7 @@
package com.laytonsmith.abstraction;
-import com.laytonsmith.abstraction.MCEntity.Velocity;
+import com.laytonsmith.abstraction.Velocity;
import com.laytonsmith.abstraction.blocks.MCBlock;
/**
@@ -7,7 +7,7 @@
*/
public interface MCProjectile extends MCEntity, MCMetadatable {
public boolean doesBounce();
- public MCLivingEntity getShooter();
+ public MCProjectileSource getShooter();
public void setBounce(boolean doesBounce);
- public void setShooter(MCLivingEntity shooter);
+ public void setShooter(MCProjectileSource shooter);
}
@@ -0,0 +1,14 @@
+package com.laytonsmith.abstraction;
+
+import com.laytonsmith.abstraction.Velocity;
+import com.laytonsmith.abstraction.enums.MCProjectileType;
+
+/**
+ *
+ * @author jb_aero
+ */
+public interface MCProjectileSource extends AbstractionObject {
+
+ public MCProjectile launchProjectile(MCProjectileType projectile);
+ public MCProjectile launchProjectile(MCProjectileType projectile, Velocity init);
+}
@@ -0,0 +1,63 @@
+package com.laytonsmith.abstraction;
+
+/**
+ *
+ * @author layton
+ */
+public class Velocity {
+ public double magnitude;
+ public double x;
+ public double y;
+ public double z;
+
+ public Velocity(double x, double y, double z) {
+ this(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)), x, y, z);
+ }
+
+ public Velocity(double magnitude, double x, double y, double z) {
+ this.magnitude = magnitude;
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ public Velocity add(Velocity vec) {
+ this.x += vec.x;
+ this.y += vec.y;
+ this.z += vec.z;
+ return this;
+ }
+
+ public Velocity multiply(Velocity vec) {
+ this.x *= vec.x;
+ this.y *= vec.y;
+ this.z *= vec.z;
+ return this;
+ }
+
+ public Velocity multiply(double m) {
+ this.x *= m;
+ this.y *= m;
+ this.z *= m;
+ return this;
+ }
+
+ public Velocity normalize() {
+ double length = length();
+ this.x /= length;
+ this.y /= length;
+ this.z /= length;
+ return this;
+ }
+
+ public Velocity subtract(Velocity vec) {
+ this.x -= vec.x;
+ this.y -= vec.y;
+ this.z -= vec.z;
+ return this;
+ }
+
+ public double length() {
+ return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2));
+ }
+}
@@ -0,0 +1,12 @@
+package com.laytonsmith.abstraction.blocks;
+
+import com.laytonsmith.abstraction.MCProjectileSource;
+
+/**
+ *
+ * @author jb_aero
+ */
+public interface MCBlockProjectileSource extends MCProjectileSource {
+
+ public MCBlock getBlock();
+}
@@ -32,6 +32,7 @@
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCEnderDragonPart;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCEnderSignal;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCEnderman;
+import com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntityProjectileSource;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCFirework;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCFishHook;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCHorse;
@@ -62,7 +63,10 @@
import com.laytonsmith.abstraction.enums.MCTone;
import com.laytonsmith.annotations.convert;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
+import com.laytonsmith.core.CHLog;
+import com.laytonsmith.core.LogLevel;
import com.laytonsmith.core.Static;
+import com.laytonsmith.core.constructs.Target;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -139,6 +143,7 @@
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.MaterialData;
+import org.bukkit.projectiles.ProjectileSource;
/**
*
@@ -480,17 +485,28 @@ public static MCEntity BukkitGetCorrectEntity(Entity be){
if(be instanceof LivingEntity){
return new BukkitMCLivingEntity(((LivingEntity)be));
}
-
- throw new Error("While trying to find the correct entity type for " + be.getClass().getName() + ", was unable"
- + " to find the appropriate implementation. Please alert the developers of this stack trace.");
- }
+
+ if (be instanceof ProjectileSource) {
+ return new BukkitMCEntityProjectileSource(be);
+ }
+
+ throw new IllegalArgumentException("While trying to find the correct entity type for " + be.getClass().getName()
+ + ", was unable to find the appropriate implementation. If the named entity is not provided by mods,"
+ + " please alert the developers of this stack trace. This is not necessarily an error,"
+ + " we just don't have any special handling for this entity yet, and will treat it generically.");
+ }
@Override
- public MCEntity GetCorrectEntity(MCEntity e) {
+ public MCEntity GetCorrectEntity(MCEntity e) {
- Entity be = ((BukkitMCEntity)e).asEntity();
- return BukkitConvertor.BukkitGetCorrectEntity(be);
- }
+ Entity be = ((BukkitMCEntity)e).asEntity();
+ try {
+ return BukkitConvertor.BukkitGetCorrectEntity(be);
+ } catch (IllegalArgumentException iae) {
+ CHLog.GetLogger().Log(CHLog.Tags.RUNTIME, LogLevel.INFO, iae.getMessage(), Target.UNKNOWN);
+ return e;
+ }
+ }
@Override
public MCItemMeta GetCorrectMeta(MCItemMeta im) {
@@ -1,6 +1,7 @@
package com.laytonsmith.abstraction.bukkit;
import com.laytonsmith.abstraction.MCFireball;
+import com.laytonsmith.abstraction.Velocity;
import org.bukkit.entity.Fireball;
import org.bukkit.util.Vector;
@@ -6,10 +6,9 @@
import com.laytonsmith.abstraction.MCLivingEntity;
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.MCPlayer;
-import com.laytonsmith.abstraction.MCProjectile;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlock;
-import com.laytonsmith.abstraction.enums.MCProjectileType;
+import com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntityProjectileSource;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
@@ -22,10 +21,7 @@
import java.util.logging.Logger;
import org.bukkit.block.Block;
import org.bukkit.entity.Creature;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
-import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -35,7 +31,7 @@
*
* @author layton
*/
-public class BukkitMCLivingEntity extends BukkitMCEntity implements MCLivingEntity {
+public class BukkitMCLivingEntity extends BukkitMCEntityProjectileSource implements MCLivingEntity {
LivingEntity le;
@@ -279,21 +275,6 @@ public boolean removeEffect(int potionID) {
}
@Override
- public MCProjectile launchProjectile(MCProjectileType projectile) {
- EntityType et = EntityType.valueOf(projectile.name());
- Class<? extends Entity> c = et.getEntityClass();
- Projectile proj = le.launchProjectile(c.asSubclass(Projectile.class));
-
- MCEntity e = BukkitConvertor.BukkitGetCorrectEntity(proj);
-
- if (e instanceof MCProjectile) {
- return (MCProjectile) e;
- } else {
- return null;
- }
- }
-
- @Override
public void setLastDamage(double damage) {
le.setLastDamage(damage);
}
@@ -2,7 +2,7 @@
import com.laytonsmith.abstraction.AbstractionObject;
import com.laytonsmith.abstraction.MCChunk;
-import com.laytonsmith.abstraction.MCEntity.Velocity;
+import com.laytonsmith.abstraction.Velocity;
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.MCWorld;
import com.laytonsmith.abstraction.blocks.MCBlock;
Oops, something went wrong.

0 comments on commit 671f478

Please sign in to comment.