From c9e9cbbcdb58bcaf712611f98bdce4e7223fbbad Mon Sep 17 00:00:00 2001 From: Idrees Hassan Date: Fri, 24 Jul 2020 14:27:06 -0400 Subject: [PATCH] Adds player targeting commands Adds player targeting summon commands, customizable summon messages, changes the shooting star summon to now appear directly above the player's head, and now adds the config by default upon installation --- README.md | 10 ++++--- pom.xml | 2 +- .../java/com/idreesinc/celeste/Celeste.java | 6 ++--- .../idreesinc/celeste/CelestialSphere.java | 26 ++++++++++++------- .../celeste/commands/CommandFallingStar.java | 25 +++++++++++++----- .../celeste/commands/CommandShootingStar.java | 25 +++++++++++++----- src/main/resources/config.yml | 4 ++- src/main/resources/plugin.yml | 12 ++++----- 8 files changed, 74 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index ab669e3..efb5239 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Additionally, the worlds that shooting and falling stars can spawn in must meet - Will not spawn in the nether or end ## Configuration -Installation is as simple as copying the newest build jar to your plugins folder. **A configuration file is not added by default**, but can be easily created by making a "Celeste" directory in your plugins folder and creating a "config.yml" within that directory. It is not necessary (nor recommended) to copy everything from the default config shown below, instead copy only the lines you wish to change. +Installation is as simple as copying the newest build jar to your plugins folder. A configuration file is created by default, but if the file was created previously it may not include default values that were added in later updates. These values can be added easily by just copying and pasting the particular lines from the defaults below. ### Defaults ``` yaml # The average number of shooting stars to create per minute for each world @@ -51,6 +51,10 @@ new-moon-meteor-shower: true shooting-stars-per-minute-during-meteor-showers: 15 # The number of falling stars to create per minute during meteor showers falling-stars-per-minute-during-meteor-showers: 0.3 +# The message to send in response to summoning a shooting star +shooting-stars-summon-text: "Make a wish!" +# The message to send in response to summoning a falling star +falling-stars-summon-text: "Make a wish!" ``` ### Falling Star Loot Falling stars drop loot wherever they fall, and spark for 10 seconds (200 ticks) by default to show their location. The loot they drop is randomly selected from the loot table in the config, with each material being given a weight. For instance, in the default config, there is a 60% chance for a diamond, 20% of an emerald, and 20% chance of a fire_charge. Experience also drops from falling stars, 100 points (not levels) by default. @@ -68,7 +72,7 @@ falling-stars-loot: ``` ## Commands -**/shootingstar** summons a shooting star in the sky around the player, however because the area a shooting star can spawn is quite large, it is easy to miss just a single one. I am currently working on making it appear exactly above the player for easy testing +**/shootingstar [player]** summons a shooting star in the sky directly above the player. If no player is given, spawns one above the summoner. -**/fallingstar** summons a falling star at the exact location of the player +**/fallingstar [player]** summons a falling star directly above the player. If no player is given, spawns one above the summoner. diff --git a/pom.xml b/pom.xml index 2827dab..356e6a0 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.idreesinc Celeste - 1.2 + 1.3 UTF-8 diff --git a/src/main/java/com/idreesinc/celeste/Celeste.java b/src/main/java/com/idreesinc/celeste/Celeste.java index 0f70dac..f0c1234 100644 --- a/src/main/java/com/idreesinc/celeste/Celeste.java +++ b/src/main/java/com/idreesinc/celeste/Celeste.java @@ -16,6 +16,7 @@ public class Celeste extends JavaPlugin { @Override public void onEnable() { + this.saveDefaultConfig(); Metrics metrics = new Metrics(this, 81862); this.getCommand("shootingstar").setExecutor(new CommandShootingStar(this)); @@ -44,11 +45,10 @@ public void onEnable() { stargazingTask.runTaskTimer(this, 0, 10); new UpdateChecker(this, 81862).getVersion(version -> { -// System.out.println(version); if (this.getDescription().getVersion().equalsIgnoreCase(version)) { -// this.getLogger().info("Celeste is up to date!"); + this.getLogger().info("Celeste is up to date!"); } else { - this.getLogger().info("There is a new update available for Celeste!"); + this.getLogger().info("There is an update available for Celeste (" + this.getDescription().getVersion() + " -> " + version + ")"); } }); } diff --git a/src/main/java/com/idreesinc/celeste/CelestialSphere.java b/src/main/java/com/idreesinc/celeste/CelestialSphere.java index fd0a48a..d9832ac 100644 --- a/src/main/java/com/idreesinc/celeste/CelestialSphere.java +++ b/src/main/java/com/idreesinc/celeste/CelestialSphere.java @@ -9,25 +9,31 @@ import java.util.Random; public class CelestialSphere { + public static void createShootingStar(Player player) { - createShootingStar(player.getLocation()); + createShootingStar(player, true); + } + + public static void createShootingStar(Player player, boolean approximate) { + createShootingStar(player.getLocation(), approximate); } public static void createShootingStar(Location location) { -// double radius = 100 + new Random().nextDouble() * 30; -// Vector locationMod = new Vector(new Random().nextDouble() * 2 - 1, new Random().nextDouble(), new Random().nextDouble() * 2 - 1); -// locationMod.normalize(); -// locationMod.multiply(radius); -// Location starLocation = new Location(location.getWorld(), locationMod.getX() + location.getX(), Math.min(256, -// Math.max(150, locationMod.getY() + location.getY() + 10)), locationMod.getZ() + location.getZ()); -// Vector direction = new Vector(new Random().nextDouble() * 2 - 1, new Random().nextDouble() * -1 * Math.cos(locationMod.getY() / radius * (Math.PI / 2)), new Random().nextDouble() * 2 - 1); -// direction.normalize(); + createShootingStar(location, true); + } + + public static void createShootingStar(Location location, boolean approximate) { + Location starLocation; double w = 100 * Math.sqrt(new Random().nextDouble()); double t = 2d * Math.PI * new Random().nextDouble(); double x = w * Math.cos(t); double y = Math.max(new Random().nextDouble() * 50 + 100, location.getY() + 50); double z = w * Math.sin(t); - Location starLocation = new Location(location.getWorld(), location.getX() + x, y, location.getZ() + z); + if (approximate) { + starLocation = new Location(location.getWorld(), location.getX() + x, y, location.getZ() + z); + } else { + starLocation = new Location(location.getWorld(), location.getX(), y, location.getZ()); + } Vector direction = new Vector(new Random().nextDouble() * 2 - 1, new Random().nextDouble() * -0.75d, new Random().nextDouble() * 2 - 1); direction.normalize(); double speed = new Random().nextDouble() * 2 + 0.75; diff --git a/src/main/java/com/idreesinc/celeste/commands/CommandFallingStar.java b/src/main/java/com/idreesinc/celeste/commands/CommandFallingStar.java index 86b3ab1..590e3a2 100644 --- a/src/main/java/com/idreesinc/celeste/commands/CommandFallingStar.java +++ b/src/main/java/com/idreesinc/celeste/commands/CommandFallingStar.java @@ -2,6 +2,7 @@ import com.idreesinc.celeste.Celeste; import com.idreesinc.celeste.CelestialSphere; +import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -16,13 +17,25 @@ public CommandFallingStar(Celeste celeste) { } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - player.sendMessage("Make a wish!"); - CelestialSphere.createFallingStar(celeste, player, false); - return true; + if (args.length > 0) { + if (Bukkit.getPlayer(args[0]) == null) { + sender.sendMessage("\u00a7cError: Player not found."); + return true; + } + CelestialSphere.createFallingStar(celeste, Bukkit.getPlayer(args[0]), false); + } else { + if (sender instanceof Player) { + Player player = (Player) sender; + CelestialSphere.createFallingStar(celeste, player, false); + } else { + return false; + } } - return false; + String message = this.celeste.getConfig().getString("falling-stars-summon-text"); + if (message != null) { + sender.sendMessage(message); + } + return true; } } diff --git a/src/main/java/com/idreesinc/celeste/commands/CommandShootingStar.java b/src/main/java/com/idreesinc/celeste/commands/CommandShootingStar.java index 23e0cba..2fbec3e 100644 --- a/src/main/java/com/idreesinc/celeste/commands/CommandShootingStar.java +++ b/src/main/java/com/idreesinc/celeste/commands/CommandShootingStar.java @@ -2,6 +2,7 @@ import com.idreesinc.celeste.Celeste; import com.idreesinc.celeste.CelestialSphere; +import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -16,13 +17,25 @@ public CommandShootingStar(Celeste celeste) { } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - player.sendMessage("Make a wish!"); - CelestialSphere.createShootingStar(player); - return true; + if (args.length > 0) { + if (Bukkit.getPlayer(args[0]) == null) { + sender.sendMessage("\u00a7cError: Player not found."); + return true; + } + CelestialSphere.createShootingStar(Bukkit.getPlayer(args[0]), false); + } else { + if (sender instanceof Player) { + Player player = (Player) sender; + CelestialSphere.createShootingStar(player, false); + } else { + return false; + } } - return false; + String message = this.celeste.getConfig().getString("shooting-stars-summon-text"); + if (message != null) { + sender.sendMessage(message); + } + return true; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a589368..14df88a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,4 +10,6 @@ falling-stars-loot: fire_charge: 20 new-moon-meteor-shower: true shooting-stars-per-minute-during-meteor-showers: 15 -falling-stars-per-minute-during-meteor-showers: 0.3 \ No newline at end of file +falling-stars-per-minute-during-meteor-showers: 0.3 +shooting-stars-summon-text: "Make a wish!" +falling-stars-summon-text: "Make a wish!" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 470dea9..de15f33 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,15 +1,15 @@ name: Celeste -version: 1.2 +version: 1.3 api-version: 1.14 author: Idrees main: com.idreesinc.celeste.Celeste commands: shootingstar: - description: Creates a shooting star near the player that summons it - usage: / + description: Creates a shooting star near the player that summons it, or optionally near another player + usage: / [player] permission: celeste.shootingstar fallingstar: - description: Creates a falling star near the player that summons it - usage: / - permission: celeste.fallingstar \ No newline at end of file + description: Creates a falling star near the player that summons it, or optionally near another player + usage: / [player] + permission: celeste.fallingstar