diff --git a/java/noppes/npcs/api/AbstractNpcAPI.java b/java/noppes/npcs/api/AbstractNpcAPI.java index 488b3a1..f5dab48 100644 --- a/java/noppes/npcs/api/AbstractNpcAPI.java +++ b/java/noppes/npcs/api/AbstractNpcAPI.java @@ -30,6 +30,7 @@ import noppes.npcs.api.handler.IProfileHandler; import noppes.npcs.api.handler.IQuestHandler; import noppes.npcs.api.handler.IRecipeHandler; import noppes.npcs.api.handler.IScriptHookHandler; +import noppes.npcs.api.handler.ITelegraphHandler; import noppes.npcs.api.handler.ITransportHandler; import noppes.npcs.api.handler.data.IAnimation; import noppes.npcs.api.handler.data.IFrame; @@ -177,6 +178,17 @@ public abstract class AbstractNpcAPI { public abstract IAbilityHandler getAbilities(); + public abstract ITelegraphHandler getTelegraphs(); + + /** + * Create a telegraph directly. + * Convenience method equivalent to getTelegraphs().create(type). + * + * @param type Type name: "circle", "ring", "line", "cone", "point" + * @return A new telegraph configuration + */ + public abstract ITelegraph createTelegraph(String type); + public abstract String[] getAllBiomeNames(); public abstract ICustomNpc> createNPC(IWorld var1); diff --git a/java/noppes/npcs/api/ITelegraph.java b/java/noppes/npcs/api/ITelegraph.java new file mode 100644 index 0000000..389cddc --- /dev/null +++ b/java/noppes/npcs/api/ITelegraph.java @@ -0,0 +1,224 @@ +package noppes.npcs.api; + +import noppes.npcs.api.entity.IEntity; + +/** + * A telegraph is a visual warning indicator that displays on the ground. + * Telegraphs are commonly used to warn players of incoming attacks or mark areas of effect. + *
+ * To create a telegraph: + *
+ * var telegraph = API.getTelegraphs().createCircle(5.0); + * telegraph.setDuration(60); // 3 seconds + * telegraph.setColor(0x80FF0000); // Semi-transparent red + * var instance = telegraph.spawn(world, x, y, z); + *+ *
+ * Telegraph types: + *
+ * Instances are created when you call spawn() on an ITelegraph: + *
+ * var telegraph = API.getTelegraphs().createCircle(5.0); + * var instance = telegraph.spawn(world, x, y, z); + * + * // Later... + * instance.remove(); // Remove the telegraph early + *+ */ +public interface ITelegraphInstance { + + /** + * Get the unique instance ID. + */ + String getInstanceId(); + + // ═══════════════════════════════════════════════════════════════════════════ + // POSITION + // ═══════════════════════════════════════════════════════════════════════════ + + /** + * Get the current X position. + */ + double getX(); + + /** + * Get the current Y position. + */ + double getY(); + + /** + * Get the current Z position. + */ + double getZ(); + + /** + * Get the rotation yaw. + */ + float getYaw(); + + /** + * Set the position. + * Note: Only works for static telegraphs (not following an entity). + */ + void setPosition(double x, double y, double z); + + // ═══════════════════════════════════════════════════════════════════════════ + // ENTITY FOLLOWING + // ═══════════════════════════════════════════════════════════════════════════ + + /** + * Make this telegraph follow an entity. + * The telegraph position will update each tick to match the entity. + */ + void followEntity(IEntity entity); + + /** + * Stop following any entity and fix the current position. + */ + void stopFollowing(); + + /** + * Check if this telegraph is following an entity. + */ + boolean isFollowing(); + + // ═══════════════════════════════════════════════════════════════════════════ + // TIMING + // ═══════════════════════════════════════════════════════════════════════════ + + /** + * Get the remaining ticks before the telegraph expires. + */ + int getRemainingTicks(); + + /** + * Get the total duration ticks. + */ + int getTotalTicks(); + + /** + * Get the progress from 0.0 (just started) to 1.0 (finished). + */ + float getProgress(); + + /** + * Check if the telegraph is in the warning phase. + */ + boolean isWarning(); + + // ═══════════════════════════════════════════════════════════════════════════ + // CONTROL + // ═══════════════════════════════════════════════════════════════════════════ + + /** + * Remove this telegraph immediately. + * Sends a removal packet to all clients tracking it. + */ + void remove(); + + /** + * Lock the telegraph at its current position. + * Equivalent to calling stopFollowing(). + */ + void lockPosition(); +} diff --git a/java/noppes/npcs/api/handler/ITelegraphHandler.java b/java/noppes/npcs/api/handler/ITelegraphHandler.java new file mode 100644 index 0000000..c73b2c6 --- /dev/null +++ b/java/noppes/npcs/api/handler/ITelegraphHandler.java @@ -0,0 +1,193 @@ +package noppes.npcs.api.handler; + +import noppes.npcs.api.ITelegraph; +import noppes.npcs.api.ITelegraphInstance; +import noppes.npcs.api.IWorld; +import noppes.npcs.api.entity.IEntity; + +/** + * Handler for creating and managing telegraphs. + * Access via API.getTelegraphs() + *
+ * Example usage: + *
+ * // Create a telegraph
+ * var telegraph = API.getTelegraphs().createCircle(5.0);
+ * telegraph.setDuration(60); // 3 seconds
+ * telegraph.setColor(0x80FF0000); // Semi-transparent red
+ *
+ * // Spawn it
+ * var instance = telegraph.spawn(world, x, y, z);
+ *
+ * // Or save as a preset for reuse
+ * API.getTelegraphs().save("myCircle", telegraph);
+ *
+ * // Load preset later
+ * var loaded = API.getTelegraphs().get("myCircle");
+ * loaded.spawn(world, x, y, z);
+ *
+ */
+public interface ITelegraphHandler {
+
+ // ═══════════════════════════════════════════════════════════════════════════
+ // FACTORY METHODS
+ // ═══════════════════════════════════════════════════════════════════════════
+
+ /**
+ * Create a circle telegraph.
+ *
+ * @param radius The radius of the circle
+ * @return A new telegraph configuration
+ */
+ ITelegraph createCircle(float radius);
+
+ /**
+ * Create a ring telegraph.
+ *
+ * @param outerRadius The outer radius
+ * @param innerRadius The inner radius
+ * @return A new telegraph configuration
+ */
+ ITelegraph createRing(float outerRadius, float innerRadius);
+
+ /**
+ * Create a line telegraph.
+ *
+ * @param length The length of the line
+ * @param width The width of the line
+ * @return A new telegraph configuration
+ */
+ ITelegraph createLine(float length, float width);
+
+ /**
+ * Create a cone telegraph.
+ *
+ * @param length The length of the cone
+ * @param angle The angle of the cone in degrees
+ * @return A new telegraph configuration
+ */
+ ITelegraph createCone(float length, float angle);
+
+ /**
+ * Create a point telegraph.
+ *
+ * @return A new telegraph configuration
+ */
+ ITelegraph createPoint();
+
+ /**
+ * Create a telegraph by type name.
+ *
+ * @param type Type name: "circle", "ring", "line", "cone", "point" (case insensitive)
+ * @return A new telegraph configuration, or null if type is invalid
+ */
+ ITelegraph create(String type);
+
+ // ═══════════════════════════════════════════════════════════════════════════
+ // SPAWN METHODS
+ // ═══════════════════════════════════════════════════════════════════════════
+
+ /**
+ * Spawn a telegraph at a position.
+ *
+ * @param telegraph The telegraph configuration
+ * @param world The world
+ * @param x X position
+ * @param y Y position
+ * @param z Z position
+ * @return The spawned instance
+ */
+ ITelegraphInstance spawn(ITelegraph telegraph, IWorld world, double x, double y, double z);
+
+ /**
+ * Spawn a telegraph at a position with rotation.
+ *
+ * @param telegraph The telegraph configuration
+ * @param world The world
+ * @param x X position
+ * @param y Y position
+ * @param z Z position
+ * @param yaw Rotation yaw
+ * @return The spawned instance
+ */
+ ITelegraphInstance spawn(ITelegraph telegraph, IWorld world, double x, double y, double z, float yaw);
+
+ /**
+ * Spawn a telegraph following an entity.
+ *
+ * @param telegraph The telegraph configuration
+ * @param entity The entity to follow
+ * @return The spawned instance
+ */
+ ITelegraphInstance spawn(ITelegraph telegraph, IEntity entity);
+
+ /**
+ * Spawn a telegraph following an entity with rotation.
+ *
+ * @param telegraph The telegraph configuration
+ * @param entity The entity to follow
+ * @param yaw Rotation yaw
+ * @return The spawned instance
+ */
+ ITelegraphInstance spawn(ITelegraph telegraph, IEntity entity, float yaw);
+
+ // ═══════════════════════════════════════════════════════════════════════════
+ // PRESET MANAGEMENT
+ // ═══════════════════════════════════════════════════════════════════════════
+
+ /**
+ * Get a saved telegraph preset by name.
+ *
+ * @param name The preset name
+ * @return The telegraph configuration, or null if not found
+ */
+ ITelegraph get(String name);
+
+ /**
+ * Save a telegraph as a preset.
+ *
+ * @param name The name for the preset
+ * @param telegraph The telegraph configuration to save
+ */
+ void save(String name, ITelegraph telegraph);
+
+ /**
+ * Delete a saved preset.
+ *
+ * @param name The preset name
+ */
+ void delete(String name);
+
+ /**
+ * Check if a preset exists.
+ *
+ * @param name The preset name
+ * @return True if the preset exists
+ */
+ boolean has(String name);
+
+ /**
+ * Get all saved preset names.
+ *
+ * @return Array of preset names
+ */
+ String[] getSavedNames();
+
+ // ═══════════════════════════════════════════════════════════════════════════
+ // REMOVAL
+ // ═══════════════════════════════════════════════════════════════════════════
+
+ /**
+ * Remove an active telegraph by instance ID.
+ *
+ * @param instanceId The instance ID to remove
+ */
+ void remove(String instanceId);
+
+ /**
+ * Remove an active telegraph instance.
+ *
+ * @param instance The instance to remove
+ */
+ void remove(ITelegraphInstance instance);
+}