Merge pull request #40 from TBMCPlugins/Feature

Adjusted and created settings for Cannon Bow <@114932850507120641>
This commit is contained in:
alisolarflare 2016-12-21 23:17:36 -05:00 committed by GitHub
commit 28629dc054
7 changed files with 175 additions and 29 deletions

View file

@ -1 +1,5 @@
UHCMatchState: "IDLE"
UHCMatchState: "IDLE"
magic:
cannonbow:
speedmultiplier: 1.5
minforce: 0.2

View file

@ -5,16 +5,12 @@ version: 2.0.2
commands:
alilink:
description: creates wireless redstone
cashmob:
description: creates mobs
cb:
description: creates creative boundaries
debug:
description: debug commands
flaircolour:
description: flaaairs
fruit:
description: fruits
gpower:
description: powerssss
insurance:

View file

@ -85,14 +85,14 @@
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<artifactId>spigot</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>

View file

@ -7,11 +7,14 @@ import buttondevteam.alipresents.components.magic.tricks.AliArrowListener;
import buttondevteam.alipresents.components.magic.tricks.BoomBowDeathListener;
import buttondevteam.alipresents.components.magic.tricks.BoomBowListener;
import buttondevteam.alipresents.components.magic.tricks.CannonBowListener;
import buttondevteam.alipresents.components.magic.tricks.CannonBowSettings;
public class MagicComponent extends Component{
@Override
public void register(JavaPlugin plugin) {
registerCommand(plugin, new CannonBowSettings());
registerListener(plugin, new AliArrowListener(plugin));
registerListener(plugin, new BoomBowDeathListener());
registerListener(plugin, new BoomBowListener(plugin));

View file

@ -8,6 +8,7 @@ public class AliArrowTask extends BukkitRunnable {
static String[] permittedUsers = {"alisolarflare", "Zanthr", "NorbiPeti"};
String name;
Arrow arrow;
int count = 0;
public AliArrowTask(Arrow arrow, String name) {
this.name = name;
@ -16,7 +17,8 @@ public class AliArrowTask extends BukkitRunnable {
@Override
public void run() {
if (arrow.isOnGround() || arrow.isDead()) {
count++;
if (count > 400 ||arrow.isOnGround() || arrow.isDead()) {
this.cancel();
}
@ -33,6 +35,10 @@ public class AliArrowTask extends BukkitRunnable {
case "norbipeti":
arrow.getWorld().spawnParticle(Particle.LAVA, arrow.getLocation(), 1);
break;
case "mayskam1995":
arrow.getWorld().spawnParticle(Particle.DRIP_WATER, arrow.getLocation(), 2);
break;
}
}

View file

@ -1,9 +1,14 @@
package buttondevteam.alipresents.components.magic.tricks;
import java.lang.reflect.Field;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftTNTPrimed;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
@ -12,47 +17,93 @@ import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import net.minecraft.server.v1_11_R1.EntityLiving;
import net.minecraft.server.v1_11_R1.EntityTNTPrimed;
public class CannonBowListener implements Listener {
private static double SpeedMultiplier = 1.5;
private static double minforce = 0.2;
private static int fuseticks = 40;
private static double recoil = 1;
public final static String launchedTNTName = "CANNON BOW TNT:42170";
JavaPlugin plugin;
public CannonBowListener(JavaPlugin plugin){
this.plugin = plugin;
FileConfiguration config = plugin.getConfig();
if (config.isDouble("magic.cannonbow.speedmultiplier"))
setSpeedMultiplier(config.getDouble("magic.cannonbow.speedmultiplier"));
if (config.isDouble("magic.cannonbow.minforce"))
setMinforce(config.getDouble("magic.cannonbow.minforce"));
if (config.isInt("magic.cannonbow.fuseticks"))
setFuseticks(config.getInt("magic.cannonbow.fuseticks"));
if (config.isDouble("magic.cannonbow.recoil"))
setRecoil(config.getDouble("magic.cannonbow.recoil"));
}
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event){
//ENTITY SANITATION
if(event.getEntity().getType() != EntityType.ARROW)return;
public void onProjectileLaunch(EntityShootBowEvent event){
//Entity Sanitation
if(event.getProjectile().getType() != EntityType.ARROW)return;
//ARROW SANITATION
Arrow arrow = (Arrow) event.getEntity();
if (!(arrow.isCritical()) || !(arrow.getShooter() instanceof Player))return;
//Arrow Sanitation
Arrow arrow = (Arrow) event.getProjectile();
if (!(arrow.getShooter() instanceof Player))return;
//PLAYER SANITATION
//Player Sanitation
Player player = (Player) arrow.getShooter();
if (!player.getInventory().contains(Material.TNT))return;
//BOW SANITATION
//Bow Sanitation
ItemStack bow;
if (!((bow = player.getInventory().getItemInMainHand()).getType() == Material.BOW))return;
if (!(bow.containsEnchantment(Enchantment.PROTECTION_EXPLOSIONS)))return;
if (!(bow.getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS) == 10))return;
if (!(bow.getItemMeta().getDisplayName().toUpperCase().contains("CANNON BOW")))return;
//TNT Spawning
Vector playerVector = player.getEyeLocation().getDirection().normalize();
if (event.getForce() < getMinforce()){
TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT);
tnt.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(1.0));
tnt.setCustomName(launchedTNTName);
tnt.setFuseTicks(40);
player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1));
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2.0F, 0);
player.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, player.getLocation(), 2);
//Smoke cloud if draw is too low
arrow.getWorld().spawnParticle(Particle.SMOKE_NORMAL, player.getLocation(), 30);
arrow.getWorld().playSound(player.getLocation(), Sound.BLOCK_LADDER_BREAK, 1.0F, -7);
}else{
//Spawn TNT
TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT);
// Change via NMS the source of the TNT by the player
EntityLiving nmsPlayer = (EntityLiving) (((CraftLivingEntity) player).getHandle());
EntityTNTPrimed nmsTNT = (EntityTNTPrimed) (((CraftTNTPrimed) tnt).getHandle());
try {
Field sourceField = EntityTNTPrimed.class.getDeclaredField("source");
sourceField.setAccessible(true);
sourceField.set(nmsTNT, nmsPlayer);
} catch (Exception ex) {
ex.printStackTrace();
}
//
tnt.setVelocity(playerVector.multiply(getSpeedMultiplier()).multiply(event.getForce()));
tnt.setCustomName(launchedTNTName);
tnt.setFuseTicks(getFuseticks());
//Player Recoil
player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1).multiply(getRecoil()));
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 0);
player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 2);
}
arrow.remove();
return;
}
@ -68,4 +119,44 @@ public class CannonBowListener implements Listener {
}
public static double getSpeedMultiplier() {
return SpeedMultiplier;
}
public static void setSpeedMultiplier(double speedMultiplier) {
if (speedMultiplier > 4) speedMultiplier = 4;
if (speedMultiplier < 0) speedMultiplier = 0;
SpeedMultiplier = speedMultiplier;
}
public static double getMinforce() {
return minforce;
}
public static void setMinforce(double minforce) {
if (minforce > 1) minforce = 1;
if (minforce < 0) minforce = 0;
CannonBowListener.minforce = minforce;
}
public static int getFuseticks() {
return fuseticks;
}
public static void setFuseticks(int fuseticks) {
if (fuseticks > 400) fuseticks = 400;
if (fuseticks < 0) fuseticks = 0;
CannonBowListener.fuseticks = fuseticks;
}
public static double getRecoil() {
return recoil;
}
public static void setRecoil(double recoil) {
if (recoil > 20) recoil = 20;
if (recoil < 0) recoil = 0;
CannonBowListener.recoil = recoil;
}
}

View file

@ -0,0 +1,46 @@
package buttondevteam.alipresents.components.magic.tricks;
import org.apache.commons.lang3.math.NumberUtils;
import org.bukkit.entity.Player;
import buttondevteam.alipresents.architecture.commands.ModCommand;
public class CannonBowSettings extends ModCommand {
@Override
public boolean OnCommand(Player player, String alias, String[] args) {
if (args.length > 1){
switch(args[0].toLowerCase()){
case "speedmultiplier":
CannonBowListener.setSpeedMultiplier(NumberUtils.toDouble(args[1], CannonBowListener.getSpeedMultiplier()));
break;
case "minforce":
CannonBowListener.setMinforce(NumberUtils.toDouble(args[1], CannonBowListener.getMinforce()));
break;
case "fuseticks":
CannonBowListener.setFuseticks(NumberUtils.toInt(args[1], CannonBowListener.getFuseticks()));
break;
case "recoil":
CannonBowListener.setRecoil(NumberUtils.toDouble((args[1]), CannonBowListener.getRecoil()));
break;
case "display":
player.sendMessage("Speed Multiplier: "+CannonBowListener.getSpeedMultiplier());
player.sendMessage("Minimum Force: "+CannonBowListener.getMinforce());
player.sendMessage("Fuseticks: " + CannonBowListener.getFuseticks());
player.sendMessage("Recoil: " + CannonBowListener.getRecoil());
break;
default:
player.sendMessage("That isn't a valid setting!");
player.sendMessage("Valid Settings are: ");
return false;
}
}
return true;
}
@Override
public String GetCommandPath(){
return "magic cannonbow settings";
}
}