Adjusted and created settings for Cannon Bow <@114932850507120641> #40
5 changed files with 38 additions and 9 deletions
|
@ -1 +1,5 @@
|
||||||
UHCMatchState: "IDLE"
|
UHCMatchState: "IDLE"
|
||||||
|
magic:
|
||||||
|
cannonbow:
|
||||||
|
speedmultiplier: 1.5
|
||||||
|
minforce: 0.2
|
2
pom.xml
2
pom.xml
|
@ -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 -->
|
||||||
|
|
|
@ -10,7 +10,7 @@ import buttondevteam.alipresents.components.magic.tricks.CannonBowListener;
|
||||||
import buttondevteam.alipresents.components.magic.tricks.CannonBowSettings;
|
import buttondevteam.alipresents.components.magic.tricks.CannonBowSettings;
|
||||||
|
|
||||||
public class MagicComponent extends Component{
|
public class MagicComponent extends Component{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(JavaPlugin plugin) {
|
public void register(JavaPlugin plugin) {
|
||||||
registerCommand(plugin, new CannonBowSettings());
|
registerCommand(plugin, new CannonBowSettings());
|
||||||
|
|
|
@ -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
|
||||||
|
@ -55,6 +62,18 @@ 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);
|
||||||
|
@ -62,7 +81,7 @@ public class CannonBowListener implements Listener {
|
||||||
|
|
||||||
//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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,21 @@ import org.bukkit.entity.Player;
|
||||||
import buttondevteam.alipresents.architecture.commands.ModCommand;
|
import buttondevteam.alipresents.architecture.commands.ModCommand;
|
||||||
|
|
||||||
public class CannonBowSettings extends ModCommand {
|
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) {
|
||||||
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!");
|
||||||
|
|
Loading…
Reference in a new issue