From c2b285539ba6e8d2fb62ba54c01fa63ec9dc6552 Mon Sep 17 00:00:00 2001 From: Wolfieheart Date: Sat, 4 Jan 2025 13:46:58 +0100 Subject: [PATCH] [CORE] Ground Work for PlayerEditor and PlayerEditorManager. Make sure that MetricsHandler uses the ASE Instance. Signed-off-by: Wolfieheart --- .../ArmorStandEditorPlugin.java | 4 +- .../armorstandeditor/PlayerEditor.java | 50 +++++++++++++++++++ .../armorstandeditor/PlayerEditorManager.java | 43 ++++++++++++++++ .../metricshandler/MetricsHandler.java | 3 +- 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditor.java create mode 100644 src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditorManager.java diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java b/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java index c23e17b7..e7a860b4 100644 --- a/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java +++ b/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java @@ -25,6 +25,7 @@ public final class ArmorStandEditorPlugin extends JavaPlugin { private static ArmorStandEditorPlugin instance; private Debug debug = new Debug(this); MetricsHandler metricsHandler; + protected PlayerEditorManager editorManager; // Server Software Check True/False boolean isFolia; @@ -145,7 +146,8 @@ public void onEnable() { getLogger().log(Level.INFO, SEPARATOR_FIELD); // Do all the Metrics for BStats - metricsHandler = new MetricsHandler(); + metricsHandler = new MetricsHandler(this); + editorManager = new PlayerEditorManager(this); } diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditor.java b/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditor.java new file mode 100644 index 00000000..9dd54ae8 --- /dev/null +++ b/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditor.java @@ -0,0 +1,50 @@ +package io.github.rypofalem.armorstandeditor; + +import io.github.rypofalem.armorstandeditor.devtools.Debug; +import io.github.rypofalem.armorstandeditor.modes.AdjustmentMode; +import io.github.rypofalem.armorstandeditor.modes.Axis; +import io.github.rypofalem.armorstandeditor.modes.CopySlots; +import io.github.rypofalem.armorstandeditor.modes.EditMode; +import lombok.Getter; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.UUID; + +public class PlayerEditor { + public ArmorStandEditorPlugin plugin; + private Debug debug; + private UUID uuid; + private long lastOpened = Integer.MIN_VALUE; + + @Getter EditMode eMode; + @Getter AdjustmentMode adjMode; + CopySlots copySlots; + @Getter Axis axis; + double eulerAngleChange; + double degreeAngleChange; + double movChange; + //TODO: Add Menu Here once that is reimplemented + ArmorStand targeted; + ArrayList targetList = null; + int targetIndex = 0; + long lastCancelled = 0; + + public PlayerEditor(UUID uuid, ArmorStandEditorPlugin plugin){ + this.uuid = uuid; + this.plugin = plugin; + eMode = EditMode.NONE; + adjMode = AdjustmentMode.COARSE; + axis = Axis.X; + copySlots = new CopySlots(); + eulerAngleChange = getManager().coarseAdj; + degreeAngleChange = eulerAngleChange / Math.PI * 180; + movChange = getManager().coarseMov; + } + + public PlayerEditorManager getManager() { + return plugin.editorManager; + } + +} diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditorManager.java b/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditorManager.java new file mode 100644 index 00000000..e1c9aee9 --- /dev/null +++ b/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditorManager.java @@ -0,0 +1,43 @@ +package io.github.rypofalem.armorstandeditor; + +import org.bukkit.Bukkit; +import org.bukkit.event.Listener; +import io.github.rypofalem.armorstandeditor.util.Util; + +import java.util.HashMap; +import java.util.UUID; + +public class PlayerEditorManager implements Listener { + private ArmorStandEditorPlugin plugin; + private HashMap players; + double coarseAdj; + double fineAdj; + double coarseMov; + double fineMov; + private boolean ignoreNextInteract = false; + private TickCounter counter; + + PlayerEditorManager(final ArmorStandEditorPlugin plugin) { + this.plugin = plugin; + players = new HashMap<>(); + coarseAdj = Util.FULL_CIRCLE / plugin.getCoarseConfig(); + fineAdj = Util.FULL_CIRCLE / plugin.getFineConfig(); + coarseMov = 1; + fineMov = .03125; // 1/32 + counter = new TickCounter(); + Bukkit.getServer().getScheduler().runTaskTimer(plugin, counter, 0, 1); + } + + class TickCounter implements Runnable { + long ticks = 0; //I am optimistic + + @Override + public void run() { + ticks++; + } + + public long getTime() { + return ticks; + } + } +} diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/metricshandler/MetricsHandler.java b/src/main/java/io/github/rypofalem/armorstandeditor/metricshandler/MetricsHandler.java index ed64ad0f..e828e3ec 100644 --- a/src/main/java/io/github/rypofalem/armorstandeditor/metricshandler/MetricsHandler.java +++ b/src/main/java/io/github/rypofalem/armorstandeditor/metricshandler/MetricsHandler.java @@ -9,7 +9,8 @@ public class MetricsHandler { private static final int PLUGIN_ID = 12668; public ArmorStandEditorPlugin plugin; - public MetricsHandler(){ + public MetricsHandler(ArmorStandEditorPlugin plugin){ + this.plugin = plugin; Metrics metrics = new Metrics(plugin, PLUGIN_ID); metrics.addCustomChart(new Metrics.SimplePie("dev_flag_enabled", () -> valueOf(plugin.isDebug()))); metrics.addCustomChart(new Metrics.SimplePie("require_sneaking", () -> valueOf(plugin.getRequireSneakingConfig())));