shell class now handles explosion

master
Soper Aylamo 2021-05-18 14:39:34 -04:00
parent 8b5e847b1b
commit edd34d3d11
Signed by: Soper
GPG Key ID: A27AC885ACC3BEAE
2 changed files with 63 additions and 22 deletions

View File

@ -54,27 +54,20 @@ public class MortarInteract implements Listener {
if(event.getEntity() instanceof Arrow
&& event.getEntity().getCustomName() != null
&& event.getEntity().getCustomName().equals("shell")){
Shell shell = new Shell(event.getEntity());
if(event.getHitBlock() != null){
/* TODO: This needs to have another accompanying explosion that does more player damage than physical damage.
* Maybe make this a function of arty.item.Shell?
*/
event.getHitBlock().getWorld().createExplosion(
shell.explodeShell(
event.getHitBlock()
.getLocation()
.add(.5,0,.5)
.add(event.getHitBlockFace()
.getDirection()),
2.5F,
false,
true);
.getDirection()
)
);
event.getEntity().remove();
}
else if(event.getHitEntity() != null){
event.getHitEntity().getWorld().createExplosion(
event.getHitEntity().getLocation(),
2.5F,
false,
true);
shell.explodeShell(event.getHitEntity().getLocation());
event.getEntity().remove();
}
}

View File

@ -1,8 +1,6 @@
package xyz.soper.arty.item;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Nameable;
import org.bukkit.*;
import org.bukkit.entity.Projectile;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -69,7 +67,38 @@ public class Shell {
*/
public Shell(Projectile shell){
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"
*/
public static boolean isShell(ItemStack item){
if(item.getType() == Material.ARROW
return item.getType() == Material.ARROW
&& item.hasItemMeta()
&& item.getItemMeta().hasDisplayName()
&& item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell")) return true;
return false;
&& item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell");
}
/**
* 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;
// }
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);
}
/**