Added isDestructive setting

This commit is contained in:
alisolarflare 2016-12-24 02:15:02 -05:00
parent b9219413f6
commit 7d012bb9ec
2 changed files with 164 additions and 61 deletions

View file

@ -4,6 +4,7 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
@ -19,25 +20,56 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class CannonBowListener implements Listener { public class CannonBowListener implements Listener {
private static double SpeedMultiplier = 1.5;
private static double minforce = 0.2; private static double maxSpeedMultiplier = 4;
private static int fuseticks = 40; private static double minSpeedMultiplier = 0;
private static double recoil = 1; private static double defaultSpeedMultiplier = 1;
private static String speedMultiplierPath = "magic.cannonbow.speedmultiplier";
private static int maxFuseTicks = 400;
private static int minFuseTicks = 0;
private static int defaultFuseTicks = 30;
private static String fuseTicksPath = "magic.cannonbow.fuseticks";
private static double maxMinForce = 1;
private static double minMinForce = 0;
private static double defaultMinForce = 0.2;
private static String minForcePath = "magic.cannonbow.minforce";
private static double maxRecoil = 20;
private static double minRecoil = -5;
private static double defaultRecoil = 1;
private static String recoilPath = "magic.cannonbow.recoil";
private static boolean defaultIsDestructive = false;
private static String isDestructivePath = "magic.cannonbow.isdestructive";
private static double speedMultiplier = defaultSpeedMultiplier;
private static double minForce = defaultMinForce;
private static int fuseTicks = defaultFuseTicks;
private static double recoil = defaultRecoil;
private static boolean isDestructive = defaultIsDestructive;
public final static String launchedTNTName = "CANNON BOW TNT:42170"; public final static String launchedTNTName = "CANNON BOW TNT:42170";
static FileConfiguration config;
public CannonBowListener(JavaPlugin plugin){ public CannonBowListener(JavaPlugin plugin){
FileConfiguration config = plugin.getConfig(); config = plugin.getConfig();
if (config.isDouble("magic.cannonbow.speedmultiplier")) if (config.isDouble(speedMultiplierPath))
setSpeedMultiplier(config.getDouble("magic.cannonbow.speedmultiplier")); setSpeedMultiplier(config.getDouble(speedMultiplierPath));
if (config.isDouble("magic.cannonbow.minforce")) if (config.isDouble(minForcePath))
setMinforce(config.getDouble("magic.cannonbow.minforce")); setMinforce(config.getDouble(minForcePath));
if (config.isInt("magic.cannonbow.fuseticks")) if (config.isInt(fuseTicksPath))
setFuseticks(config.getInt("magic.cannonbow.fuseticks")); setFuseticks(config.getInt(fuseTicksPath));
if (config.isDouble("magic.cannonbow.recoil")) if (config.isDouble(recoilPath))
setRecoil(config.getDouble("magic.cannonbow.recoil")); setRecoil(config.getDouble(recoilPath));
if (config.isBoolean(isDestructivePath))
setIsDestructive(config.getBoolean(isDestructivePath));
} }
@EventHandler @EventHandler
@ -62,11 +94,12 @@ public class CannonBowListener implements Listener {
//TNT Spawning //TNT Spawning
Vector playerVector = player.getEyeLocation().getDirection().normalize(); Vector playerVector = player.getEyeLocation().getDirection().normalize();
Location playerLocation = player.getLocation();
if (event.getForce() < getMinforce()){ if (event.getForce() < getMinforce()){
//Smoke cloud if draw is too low //Smoke cloud if draw is too low
arrow.getWorld().spawnParticle(Particle.SMOKE_NORMAL, player.getLocation(), 30); arrow.getWorld().spawnParticle(Particle.SMOKE_NORMAL, playerLocation, 30);
arrow.getWorld().playSound(player.getLocation(), Sound.BLOCK_LADDER_BREAK, 1.0F, -7); arrow.getWorld().playSound(playerLocation, Sound.BLOCK_LADDER_BREAK, 1.0F, -7);
}else{ }else{
//Spawn TNT //Spawn TNT
@ -89,9 +122,9 @@ public class CannonBowListener implements Listener {
tnt.setFuseTicks(getFuseticks()); tnt.setFuseTicks(getFuseticks());
//Player Recoil //Player Recoil
player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1).multiply(getRecoil())); player.setVelocity(playerVector.multiply(-1).multiply(getRecoil()));
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 0); player.getWorld().playSound(playerLocation, Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 0);
player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 2); player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, playerLocation, 2);
} }
arrow.remove(); arrow.remove();
@ -106,50 +139,111 @@ public class CannonBowListener implements Listener {
if (event.getEntityType() != EntityType.PRIMED_TNT) return; if (event.getEntityType() != EntityType.PRIMED_TNT) return;
if (event.getEntity().getCustomName() != "CANNON BOW TNT:42170") return; if (event.getEntity().getCustomName() != "CANNON BOW TNT:42170") return;
if (isDestructive == true){
Location loc = event.getEntity().getLocation(); Location loc = event.getEntity().getLocation();
event.getEntity().getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 3, false, false); event.getEntity().getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 3, false, false);
event.setCancelled(true); event.setCancelled(true);
}
} }
public static double getSpeedMultiplier() { public static double getSpeedMultiplier() {
return SpeedMultiplier; return speedMultiplier;
} }
public static void setSpeedMultiplier(double speedMultiplier) { public static void setSpeedMultiplier(double multiplier, CommandSender sender){
if (speedMultiplier > 4) speedMultiplier = 4;
if (speedMultiplier < 0) speedMultiplier = 0; if (multiplier > maxSpeedMultiplier) sender.sendMessage("SpeedMultiplier is too Large! Setting multiplier to "+ maxSpeedMultiplier);
SpeedMultiplier = speedMultiplier; if (multiplier < maxSpeedMultiplier) sender.sendMessage("SpeedMultiplier is too Small! Setting multiplier to "+ minSpeedMultiplier);
setSpeedMultiplier(multiplier, sender);
sender.sendMessage("SpeedMultiplier set to " + getSpeedMultiplier());
} }
public static void setSpeedMultiplier(double multiplier) {
if (multiplier > maxSpeedMultiplier) multiplier = maxSpeedMultiplier;
if (multiplier < minSpeedMultiplier) multiplier = minSpeedMultiplier;
config.set(speedMultiplierPath, multiplier);
speedMultiplier = multiplier;
}
public static double getMinforce() { public static double getMinforce() {
return minforce; return minForce;
}
public static void setMinForce(double minforce, CommandSender sender){
if (minforce > maxMinForce) sender.sendMessage("MinForce is too large! Setting it to " + maxMinForce);
if (minforce < minMinForce) sender.sendMessage("MinForce is too small! Setting it to " + minMinForce);
setMinforce(minforce);
sender.sendMessage("MinForce set to " + getMinforce());
}
public static void setMinforce(double minforce) {
if (minforce > maxMinForce) minforce = maxMinForce;
if (minforce < minMinForce) minforce = minMinForce;
config.set(minForcePath, minforce);
CannonBowListener.minForce = minforce;
} }
public static void setMinforce(double minforce) {
if (minforce > 1) minforce = 1;
if (minforce < 0) minforce = 0;
CannonBowListener.minforce = minforce;
}
public static int getFuseticks() { public static int getFuseticks() {
return fuseticks; return fuseTicks;
}
public static void setFuseticks(int fuseticks, CommandSender sender){
if (fuseticks > maxFuseTicks) sender.sendMessage("Fuseticks is too large! Setting it to " + maxFuseTicks);
if (fuseticks < minFuseTicks) sender.sendMessage("Fuseticks is too small! Setting it to " + minFuseTicks);
setFuseticks(fuseticks);
sender.sendMessage("FuseTicks set to " + getFuseticks());
}
public static void setFuseticks(int fuseticks) {
if (fuseticks > maxFuseTicks) fuseticks = maxFuseTicks;
if (fuseticks < minFuseTicks) fuseticks = minFuseTicks;
config.set(fuseTicksPath, fuseticks);
CannonBowListener.fuseTicks = fuseticks;
} }
public static void setFuseticks(int fuseticks) {
if (fuseticks > 400) fuseticks = 400;
if (fuseticks < 0) fuseticks = 0;
CannonBowListener.fuseticks = fuseticks;
}
public static double getRecoil() { public static double getRecoil() {
return recoil; return recoil;
} }
public static void setRecoil(double recoil, CommandSender sender){
if (recoil > maxRecoil) sender.sendMessage("Recoil is too large! Setting it to " + maxRecoil);
if (recoil < maxRecoil) sender.sendMessage("Recoil is too small! Setting it to " + minRecoil);
setRecoil(recoil);
sender.sendMessage("Recoil set to " + getRecoil());
}
public static void setRecoil(double recoil) { public static void setRecoil(double recoil) {
if (recoil > 20) recoil = 20;
if (recoil < 0) recoil = 0; if (recoil > maxRecoil) recoil = maxRecoil;
if (recoil < minRecoil) recoil = minRecoil;
config.set(recoilPath, recoil);
CannonBowListener.recoil = recoil; CannonBowListener.recoil = recoil;
}
public static boolean getIsDestructive(){
return isDestructive;
}
public static void setIsDestructive(String input){
if(input.startsWith("T") || input.startsWith("t")) setIsDestructive(true);
if(input.startsWith("F") || input.startsWith("f")) setIsDestructive(false);
}
public static void setIsDestructive(boolean isDestructive){
CannonBowListener.isDestructive = isDestructive;
config.set(speedMultiplierPath, isDestructive);
} }
} }

View file

@ -9,25 +9,34 @@ public class CannonBowSettings extends ModCommand {
@Override @Override
public boolean OnCommand(Player player, String alias, String[] args) { public boolean OnCommand(Player player, String alias, String[] args) {
if (args.length > 1){ if (args.length > 1 && args[0] == "display"){
switch(args[0].toLowerCase()){ switch(args[0].toLowerCase()){
case "force":
case "speedmultiplier": case "speedmultiplier":
CannonBowListener.setSpeedMultiplier(NumberUtils.toDouble(args[1], CannonBowListener.getSpeedMultiplier())); CannonBowListener.setSpeedMultiplier(NumberUtils.toDouble(args[1], CannonBowListener.getSpeedMultiplier()));
break; break;
case "minimumforce":
case "minforce": case "minforce":
case "minimumdraw":
case "mindraw":
CannonBowListener.setMinforce(NumberUtils.toDouble(args[1], CannonBowListener.getMinforce())); CannonBowListener.setMinforce(NumberUtils.toDouble(args[1], CannonBowListener.getMinforce()));
break; break;
case "fuse":
case "fusetick":
case "fuseticks": case "fuseticks":
CannonBowListener.setFuseticks(NumberUtils.toInt(args[1], CannonBowListener.getFuseticks())); CannonBowListener.setFuseticks(NumberUtils.toInt(args[1], CannonBowListener.getFuseticks()));
break; break;
case "recoil": case "recoil":
CannonBowListener.setRecoil(NumberUtils.toDouble((args[1]), CannonBowListener.getRecoil())); CannonBowListener.setRecoil(NumberUtils.toDouble((args[1]), CannonBowListener.getRecoil()));
break; break;
case "isDestructive":
CannonBowListener.setIsDestructive(args[1]);
case "display": case "display":
player.sendMessage("Speed Multiplier: "+CannonBowListener.getSpeedMultiplier()); player.sendMessage("Speed Multiplier: "+CannonBowListener.getSpeedMultiplier());
player.sendMessage("Minimum Force: "+CannonBowListener.getMinforce()); player.sendMessage("Minimum Force: "+CannonBowListener.getMinforce());
player.sendMessage("Fuseticks: " + CannonBowListener.getFuseticks()); player.sendMessage("Fuseticks: " + CannonBowListener.getFuseticks());
player.sendMessage("Recoil: " + CannonBowListener.getRecoil()); player.sendMessage("Recoil: " + CannonBowListener.getRecoil());
player.sendMessage("isDestructive: " + CannonBowListener.getIsDestructive());
break; break;
default: default:
player.sendMessage("That isn't a valid setting!"); player.sendMessage("That isn't a valid setting!");