From 36e60475460ae6c513cbc17d0718c0e08370f1ba Mon Sep 17 00:00:00 2001 From: Shinare Date: Sat, 4 May 2024 17:22:05 +0300 Subject: [PATCH] Initializing repository --- pom.xml | 24 ++++++++ .../java/com/zivilon/abilities/Abilities.java | 35 +++++++++++ .../abilities/command/ArrowSwarmCommand.java | 45 ++++++++++++++ .../abilities/command/surge_command.java | 58 +++++++++++++++++++ src/main/resources/plugin.yml | 9 +++ 5 files changed, 171 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/zivilon/abilities/Abilities.java create mode 100644 src/main/java/com/zivilon/abilities/command/ArrowSwarmCommand.java create mode 100644 src/main/java/com/zivilon/abilities/command/surge_command.java create mode 100644 src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2629a63 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + com.zivilon + Abilities + 1.1 + + + + org.bukkit + bukkit + 1.7.10-R0.1-SNAPSHOT + provided + + + com.github.flinbein + PowerNBT + 0.8.9.2 + + + diff --git a/src/main/java/com/zivilon/abilities/Abilities.java b/src/main/java/com/zivilon/abilities/Abilities.java new file mode 100644 index 0000000..d961e45 --- /dev/null +++ b/src/main/java/com/zivilon/abilities/Abilities.java @@ -0,0 +1,35 @@ +package com.zivilon.abilities; + +import com.zivilon.abilities.command.surge_command; +import com.zivilon.abilities.command.ArrowSwarmCommand; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +public class Abilities extends JavaPlugin { + private static Abilities plugin; + + PluginDescriptionFile pdfFile; // plugin.yml + + public void onDisable() { + plugin = getPlugin(Abilities.class); + this.pdfFile = getDescription(); + } + + public static Abilities getPlugin() { // getter for the static plugin instance + return plugin; + } + + public PluginDescriptionFile getPdfFile() { + return pdfFile; + } + + public void onEnable() { + PluginManager pm = getServer().getPluginManager(); + this.pdfFile = getDescription(); + this.getCommand("surge").setExecutor(new surge_command()); + this.getCommand("arrowswarm").setExecutor(new ArrowSwarmCommand()); + this.getLogger() + .info(this.pdfFile.getName() + " - Version " + this.pdfFile.getVersion() + " - has been enabled!"); + } +} diff --git a/src/main/java/com/zivilon/abilities/command/ArrowSwarmCommand.java b/src/main/java/com/zivilon/abilities/command/ArrowSwarmCommand.java new file mode 100644 index 0000000..0a7661f --- /dev/null +++ b/src/main/java/com/zivilon/abilities/command/ArrowSwarmCommand.java @@ -0,0 +1,45 @@ +package com.zivilon.abilities.command; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +public class ArrowSwarmCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage("This command can only be run by a player."); + return true; + } + + Player player = (Player) sender; + String perms = "abilities.arrowswarm"; + + if (!player.hasPermission(perms)) { + player.sendMessage("You do not have permission to use this command"); + return true; + } + + Location playerLocation = player.getLocation(); + Vector direction = playerLocation.getDirection().normalize(); + + for (int i = 0; i < 5; i++) { + Arrow arrow = player.getWorld().spawnArrow( + playerLocation.add(direction.multiply(2)), + direction, + 1.0f, // Projectile speed + 1.0f); // Spread + arrow.setShooter(player); + } + + return true; + } +} diff --git a/src/main/java/com/zivilon/abilities/command/surge_command.java b/src/main/java/com/zivilon/abilities/command/surge_command.java new file mode 100644 index 0000000..2a2f6f6 --- /dev/null +++ b/src/main/java/com/zivilon/abilities/command/surge_command.java @@ -0,0 +1,58 @@ +package com.zivilon.abilities.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.Location; +import org.bukkit.util.Vector; + +public class surge_command implements CommandExecutor { + @Override + public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) { + Player player = (Player) sender; + String perms = "abilities.surge"; + if (!sender.hasPermission(perms)) { + player.sendMessage("You do not have permission to use this command"); + return true; + } + if (sender instanceof ConsoleCommandSender) { + sender.sendMessage(" > " + "You cannot run this command from the console!"); + return true; + } + Location pos = player.getPlayer().getLocation(); + Float yaw = pos.getYaw(); + if (yaw < 0) { + yaw += 360; + } + Float pitch = pos.getPitch(); + Float pitch_multi = 0.0f; + Float x_multi = 0.0f; + Float z_multi = 0.0f; + + // The math from here on could have been compressed a lot but I found it easier to understand when done step by step + + if (pitch >= 0.0) { + pitch_multi = 1.0f; + } else { + pitch_multi = 1.0f+(Math.abs(pitch)/90*2.5f); + } + if (yaw > 180 && yaw < 360) { //Mids 90 and 270 + x_multi = (-180.0f+yaw); //Returns value 0-180 + x_multi = 1-(Math.abs((90.0f-x_multi)/90)); //Returns negative value 0-1, higher is closer to 90 + } else if (yaw > 0 && yaw < 180) { + x_multi = -1+(Math.abs((90.0f-yaw)/90)); //Returns positive value 0.1, higher is closer to 90 + } + if (yaw > 90 && yaw < 270) { //Mids 0 and 180 + z_multi = (-90.0f+yaw); //Returns value 0-180 + z_multi = -1+(Math.abs(90.0f-z_multi)/90); //Returns negative value 0-1, higher is closer to 90 + } else if (yaw < 90) { + z_multi = 1-yaw/90; //Returns positive value 0.1, higher is closer to 90 + } else if (yaw > 270) { + z_multi = 1-Math.abs(yaw-360)/90; //Returns positive value 0.1, higher is closer to 90 + } + player.setVelocity(new Vector((3*x_multi/pitch_multi), (0.25f*pitch_multi), (3*z_multi/pitch_multi))); + return false; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..4eb0816 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,9 @@ +main: com.zivilon.abilities.Abilities +name: Abilities +author: Shinare +version: 1.0 +commands: + surge: + description: Throws the player forward + arrowswarm: + description: Shoots arrows