shell class now handles explosion
parent
8b5e847b1b
commit
edd34d3d11
|
@ -54,27 +54,20 @@ public class MortarInteract implements Listener {
|
||||||
if(event.getEntity() instanceof Arrow
|
if(event.getEntity() instanceof Arrow
|
||||||
&& event.getEntity().getCustomName() != null
|
&& event.getEntity().getCustomName() != null
|
||||||
&& event.getEntity().getCustomName().equals("shell")){
|
&& event.getEntity().getCustomName().equals("shell")){
|
||||||
|
Shell shell = new Shell(event.getEntity());
|
||||||
if(event.getHitBlock() != null){
|
if(event.getHitBlock() != null){
|
||||||
/* TODO: This needs to have another accompanying explosion that does more player damage than physical damage.
|
shell.explodeShell(
|
||||||
* Maybe make this a function of arty.item.Shell?
|
|
||||||
*/
|
|
||||||
event.getHitBlock().getWorld().createExplosion(
|
|
||||||
event.getHitBlock()
|
event.getHitBlock()
|
||||||
.getLocation()
|
.getLocation()
|
||||||
.add(.5, 0, .5)
|
.add(.5,0,.5)
|
||||||
.add(event.getHitBlockFace()
|
.add(event.getHitBlockFace()
|
||||||
.getDirection()),
|
.getDirection()
|
||||||
2.5F,
|
)
|
||||||
false,
|
);
|
||||||
true);
|
|
||||||
event.getEntity().remove();
|
event.getEntity().remove();
|
||||||
}
|
}
|
||||||
else if(event.getHitEntity() != null){
|
else if(event.getHitEntity() != null){
|
||||||
event.getHitEntity().getWorld().createExplosion(
|
shell.explodeShell(event.getHitEntity().getLocation());
|
||||||
event.getHitEntity().getLocation(),
|
|
||||||
2.5F,
|
|
||||||
false,
|
|
||||||
true);
|
|
||||||
event.getEntity().remove();
|
event.getEntity().remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package xyz.soper.arty.item;
|
package xyz.soper.arty.item;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Nameable;
|
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
@ -69,7 +67,38 @@ public class Shell {
|
||||||
*/
|
*/
|
||||||
public Shell(Projectile shell){
|
public Shell(Projectile shell){
|
||||||
isFired = true;
|
isFired = true;
|
||||||
|
String shellName = shell.getCustomName();
|
||||||
|
if(shellName != null && shellName.startsWith("shell-")){
|
||||||
|
String shellStats = shellName.substring(6);
|
||||||
|
//PARSING NAME DATA
|
||||||
|
int commaCount = 0;
|
||||||
|
while(commaCount < 5){
|
||||||
|
int lastCommaIndex = -1;
|
||||||
|
for(int i = 0; i < shellStats.length(); i++){
|
||||||
|
if(shellStats.charAt(i) == ','){
|
||||||
|
commaCount++;
|
||||||
|
switch(commaCount) {
|
||||||
|
case 1: //Parsing explosive power
|
||||||
|
explosivePower = Float.parseFloat(shellStats.substring(0, i));
|
||||||
|
lastCommaIndex = i;
|
||||||
|
break;
|
||||||
|
case 2: //Parsing penetration value
|
||||||
|
penetration = Integer.parseInt(shellStats.substring(lastCommaIndex+1, i));
|
||||||
|
lastCommaIndex = i;
|
||||||
|
break;
|
||||||
|
case 3: //Parsing incendiary type
|
||||||
|
incendiaryType = Boolean.parseBoolean(shellStats.substring(lastCommaIndex+1, i));
|
||||||
|
lastCommaIndex = i;
|
||||||
|
break;
|
||||||
|
case 4: //Parsing base velocity and fail chance
|
||||||
|
baseVelocity = Double.parseDouble(shellStats.substring(lastCommaIndex+1, i));
|
||||||
|
failChance = Double.parseDouble(shellStats.substring(i+1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} //FINISHED NAME PARSING
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,11 +107,20 @@ public class Shell {
|
||||||
* @return True if item is an arrow with a gray name "Shell"
|
* @return True if item is an arrow with a gray name "Shell"
|
||||||
*/
|
*/
|
||||||
public static boolean isShell(ItemStack item){
|
public static boolean isShell(ItemStack item){
|
||||||
if(item.getType() == Material.ARROW
|
return item.getType() == Material.ARROW
|
||||||
&& item.hasItemMeta()
|
&& item.hasItemMeta()
|
||||||
&& item.getItemMeta().hasDisplayName()
|
&& item.getItemMeta().hasDisplayName()
|
||||||
&& item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell")) return true;
|
&& item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell");
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the projectile is a shell
|
||||||
|
* @param projectile Projectile to check against
|
||||||
|
* @return True if projectile has a name that starts with "shell"
|
||||||
|
*/
|
||||||
|
public static boolean isShell(Projectile projectile){
|
||||||
|
return projectile.getCustomName() != null
|
||||||
|
&& projectile.getCustomName().startsWith("shell");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,7 +157,17 @@ public class Shell {
|
||||||
// return null;
|
// return null;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void explodeShell(){
|
/**
|
||||||
|
* Creates an explosion at the specified location using this shell's parameters.
|
||||||
|
* @param location The location where the explosion will occur
|
||||||
|
*/
|
||||||
|
public void explodeShell(Location location){
|
||||||
|
location.getWorld().createExplosion(location, explosivePower, incendiaryType, true);
|
||||||
|
float explosiveDamagePower = explosivePower;
|
||||||
|
if(explosivePower < 4.5){
|
||||||
|
explosiveDamagePower = (float)((1/((-0.5*4.5)+4.5))*explosivePower*((-.5*explosivePower)+4.5));
|
||||||
|
}
|
||||||
|
location.getWorld().createExplosion(location, explosiveDamagePower, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue