From 63ecfedf71dd64d594f9dc3b7e707fead3e197e5 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 15 May 2020 01:55:58 -0500 Subject: [PATCH] Added better origin highlighting to highlight command. --- .../commands/runnables/HighlightCommand.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/commands/runnables/HighlightCommand.java b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/commands/runnables/HighlightCommand.java index f7021de..8b1a789 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/commands/runnables/HighlightCommand.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/commands/runnables/HighlightCommand.java @@ -12,14 +12,15 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import ca.recrown.islandsurvivalcraft.IslandSurvivalCraft; +import ca.recrown.islandsurvivalcraft.utilities.GeneralUtilities; import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2; import ca.recrown.islandsurvivalcraft.world.WorldInfo; import ca.recrown.islandsurvivalcraft.world.Information.IslandInformation; public class HighlightCommand implements CommandRunnable { - private boolean requiresInit = true; + private IslandSurvivalCraft islandSurvivalCraft; private final Particle.DustOptions EDGE_DUST_OPTIONS = new Particle.DustOptions(Color.RED, 1f); - private final Particle.DustOptions ORIGIN_DUST_OPTIONS = new Particle.DustOptions(Color.GREEN, 1f); + private final Particle.DustOptions ORIGIN_DUST_OPTIONS = new Particle.DustOptions(Color.LIME, 1.5f); private final int PARTICLE_AMOUNT = 1; private final double OFFSET_X = 0.0d, OFFSET_Y = 6.0d, OFFSET_Z = 0.0d; private final double EXTRA = 0d; @@ -52,6 +53,9 @@ public class HighlightCommand implements CommandRunnable { } else { sender.sendMessage("You weren't highlighting islands."); } + } else if (args[0].toLowerCase().equals("origin")) { + Point2 playerLoc = new Point2(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); + sender.sendMessage("Current island's origin point: " + islandSurvivalCraft.getWorldInfoManager().retrieve(player.getWorld().getName()).getIslandInfoManager().getIslandInformation(playerLoc).getIslandOrigin()); } else { return false; } @@ -60,7 +64,7 @@ public class HighlightCommand implements CommandRunnable { @Override public void initialize(IslandSurvivalCraft islandsurvivalcraft) { - requiresInit = false; + this.islandSurvivalCraft = islandsurvivalcraft; Bukkit.getScheduler().scheduleSyncRepeatingTask(islandsurvivalcraft, new Runnable() { @Override public void run() { @@ -79,9 +83,13 @@ public class HighlightCommand implements CommandRunnable { if (islandInfo != null) { Set islandBorder = islandInfo.getEdgeCoordinates(); for (Point2 current : islandBorder) { - spawnParticle(world, current.x, playerY, current.y, EDGE_DUST_OPTIONS); + spawnParticle(false, true, world, current.x, playerY, current.y, EDGE_DUST_OPTIONS); } - spawnParticle(world, islandInfo.getIslandOrigin().x, playerY, islandInfo.getIslandOrigin().y, ORIGIN_DUST_OPTIONS); + Point2 islandOrigin = islandInfo.getIslandOrigin(); + int xDirection = GeneralUtilities.addMagnitude(Math.max(Math.min(1, islandOrigin.x - playerX), -1), 1) + playerX; + int yDirection = GeneralUtilities.addMagnitude(Math.max(Math.min(1, islandOrigin.y - playerZ), -1), 1) + playerZ; + spawnParticle(false, false, world, xDirection, playerY, yDirection, ORIGIN_DUST_OPTIONS); + spawnParticle(true, true, world, islandOrigin.x, playerY, islandOrigin.y, ORIGIN_DUST_OPTIONS); } } } @@ -89,8 +97,8 @@ public class HighlightCommand implements CommandRunnable { } - private void spawnParticle(World world, double x, double y, double z, Particle.DustOptions dustOptions) { - world.spawnParticle(Particle.REDSTONE, x, y, z, PARTICLE_AMOUNT, OFFSET_X, OFFSET_Y, OFFSET_Z, EXTRA, dustOptions, false); + private void spawnParticle(boolean focus, boolean column, World world, double x, double y, double z, Particle.DustOptions dustOptions) { + world.spawnParticle(Particle.REDSTONE, x, y, z, focus ? PARTICLE_AMOUNT * 2 : PARTICLE_AMOUNT, OFFSET_X, column ? OFFSET_Y : 0.2, OFFSET_Z, EXTRA, dustOptions, false); } @Override @@ -102,6 +110,6 @@ public class HighlightCommand implements CommandRunnable { @Override public boolean requiresInitialization() { - return requiresInit; + return islandSurvivalCraft == null; } } \ No newline at end of file