Adjusted and created settings for Cannon Bow <@114932850507120641> #40

Merged
alisolarflare merged 5 commits from Feature into master 2016-12-22 04:17:37 +00:00
5 changed files with 38 additions and 9 deletions
Showing only changes of commit d48d145111 - Show all commits

View file

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

View file

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

View file

@ -1,9 +1,13 @@
package buttondevteam.alipresents.components.magic.tricks; package buttondevteam.alipresents.components.magic.tricks;
import java.lang.reflect.Field;
import org.bukkit.Location; 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.craftbukkit.v1_11_R1.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftTNTPrimed;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -17,13 +21,16 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; 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 { public class CannonBowListener implements Listener {
public static double SpeedMultiplier = 1.5; public static double SpeedMultiplier = 1.5;
public static double minforce = 0.2; public static double minforce = 0.2;
public final static String launchedTNTName = "CANNON BOW TNT:42170"; public final static String launchedTNTName = "CANNON BOW TNT:42170";
JavaPlugin plugin;
public CannonBowListener(JavaPlugin plugin){ public CannonBowListener(JavaPlugin plugin){
this.plugin = plugin; SpeedMultiplier = plugin.getConfig().getDouble("magic.cannonbow.speedmultiplier");
minforce = plugin.getConfig().getDouble("magic.cannonbow.minforce");
} }
@EventHandler @EventHandler
@ -56,13 +63,25 @@ public class CannonBowListener implements Listener {
}else{ }else{
TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_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(SpeedMultiplier).multiply(event.getForce())); tnt.setVelocity(playerVector.multiply(SpeedMultiplier).multiply(event.getForce()));
tnt.setCustomName(launchedTNTName); tnt.setCustomName(launchedTNTName);
tnt.setFuseTicks(40); tnt.setFuseTicks(40);
//Player Recoil //Player Recoil
player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1)); player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1));
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2.0F, 0); player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 0);
player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 2); player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 2);
} }

View file

@ -11,10 +11,16 @@ public class CannonBowSettings extends ModCommand {
public boolean OnCommand(Player player, String alias, String[] args) { public boolean OnCommand(Player player, String alias, String[] args) {
switch(args[0].toLowerCase()){ switch(args[0].toLowerCase()){
case "speedmultiplier": case "speedmultiplier":
CannonBowListener.SpeedMultiplier = NumberUtils.toDouble(args[1], CannonBowListener.SpeedMultiplier); double speedMultiplier = NumberUtils.toDouble(args[1], CannonBowListener.SpeedMultiplier);
CannonBowListener.SpeedMultiplier = speedMultiplier;
this.getPlugin().getConfig().set("magic.cannonbow.speedmultiplier", speedMultiplier);
this.getPlugin().saveConfig();
break; break;
case "minforce": case "minforce":
CannonBowListener.minforce = NumberUtils.toDouble(args[1], CannonBowListener.SpeedMultiplier); double minforce = NumberUtils.toDouble(args[1], CannonBowListener.minforce);
CannonBowListener.minforce = minforce;
this.getPlugin().getConfig().set("magic.cannonbow.minforce", minforce);
this.getPlugin().saveConfig();
break; break;
default: default:
player.sendMessage("That isn't a valid setting!"); player.sendMessage("That isn't a valid setting!");