Skip to content

Commit 4fa7e96

Browse files
committed
refactor: reorganize package structure and enhance class documentation
1 parent 99d0beb commit 4fa7e96

36 files changed

Lines changed: 1526 additions & 33 deletions

src/main/java/com/github/pinont/singularitylib/api/annotation/AutoRegister.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package com.github.pinont.singularitylib.api.annotation;
22

3+
/**
4+
* Annotation to mark classes for automatic registration by the plugin.
5+
* This annotation is used to mark classes that need to be registered during the plugin's startup process.
6+
* <p>
7+
* Classes annotated with this will be processed by the plugin's registration system.
8+
* <p>
9+
* <b>Hint:</b> Use this annotation to register commands, events, or custom items.
10+
* It should only be used when the class extends {@code CustomItem}, {@code SimpleCommand}, or {@code Listener}.
11+
*/
312
public @interface AutoRegister {
413
/**
514
* Indicates that the annotated class should be automatically registered by the plugin.
@@ -9,6 +18,8 @@
918
* <p>
1019
* <b>Hint:</b> Use this annotation to register commands, events, or custom items.
1120
* It should only be used when the class extends {@code CustomItem}, {@code SimpleCommand}, or {@code Listener}.
21+
*
22+
* @return the registration value, defaults to empty string
1223
*/
1324
String value() default "";
1425
}

src/main/java/com/github/pinont/singularitylib/api/command/SimpleCommand.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,35 @@
22

33
import io.papermc.paper.command.brigadier.BasicCommand;
44

5+
/**
6+
* Interface for creating simple commands that extend Paper's BasicCommand.
7+
* This interface provides a simplified way to create commands with automatic registration.
8+
*/
59
public interface SimpleCommand extends BasicCommand {
610

11+
/**
12+
* Gets the name of the command.
13+
* This is used for command registration and execution.
14+
*
15+
* @return the command name
16+
*/
717
String getName();
818

19+
/**
20+
* Gets the usage string for this command.
21+
*
22+
* @param bool unused parameter for compatibility
23+
* @return the usage string for this command
24+
*/
925
default String usage(Boolean bool) {
1026
return "/" + getName();
1127
}
1228

29+
/**
30+
* Gets the description of the command.
31+
* This description is used in help messages and command documentation.
32+
*
33+
* @return the command description
34+
*/
1335
String description();
1436
}

src/main/java/com/github/pinont/singularitylib/api/entity/EntityCreator.java

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
import static com.github.pinont.singularitylib.plugin.CorePlugin.sendDebugMessage;
1414

15+
/**
16+
* Builder class for creating and configuring entities before spawning them.
17+
* Provides a fluent API for setting various entity properties and spawning entities at specific locations.
18+
*/
1519
public class EntityCreator {
1620

1721
private final EntityType entityType;
@@ -69,116 +73,236 @@ public class EntityCreator {
6973
private boolean isSetMaxHealth = false;
7074
private double maxHealth;
7175

76+
/**
77+
* Creates a new EntityCreator for the specified entity type.
78+
*
79+
* @param entityType the type of entity to create
80+
*/
7281
public EntityCreator(EntityType entityType) {
7382
this.entityType = entityType;
7483
}
7584

85+
/**
86+
* Adds a passenger entity to this entity.
87+
*
88+
* @param passenger the entity to add as a passenger
89+
* @return this EntityCreator for method chaining
90+
*/
7691
public EntityCreator addPassenger(Entity passenger) {
7792
this.passenger = passenger;
7893
return this;
7994
}
8095

96+
/**
97+
* Adds scoreboard tags to the entity.
98+
*
99+
* @param ScoreboardTag the scoreboard tags to add
100+
* @return this EntityCreator for method chaining
101+
*/
81102
public EntityCreator addScoreboardTag(String... ScoreboardTag) {
82103
this.ScoreboardTag.addAll(List.of(ScoreboardTag));
83104
return this;
84105
}
85106

107+
/**
108+
* Sets the maximum health for the entity (only applies to LivingEntity).
109+
*
110+
* @param maxHealth the maximum health value
111+
* @return this EntityCreator for method chaining
112+
*/
86113
public EntityCreator setMaxHealth(double maxHealth) {
87114
this.isSetMaxHealth = true;
88115
this.maxHealth = maxHealth;
89116
return this;
90117
}
91118

119+
/**
120+
* Sets the number of fire ticks for the entity.
121+
*
122+
* @param ticks the number of fire ticks
123+
* @return this EntityCreator for method chaining
124+
*/
92125
public EntityCreator setFireTicks(int ticks) {
93126
this.isSetFireTicks = true;
94127
this.fireTicks = ticks;
95128
return this;
96129
}
97130

131+
/**
132+
* Sets whether the entity should glow.
133+
*
134+
* @param glowing true if the entity should glow, false otherwise
135+
* @return this EntityCreator for method chaining
136+
*/
98137
public EntityCreator setGlowing(boolean glowing) {
99138
this.isSetGlowing = true;
100139
this.glowing = glowing;
101140
return this;
102141
}
103142

143+
/**
144+
* Sets whether the entity is invulnerable to damage.
145+
*
146+
* @param invulnerable true if the entity should be invulnerable, false otherwise
147+
* @return this EntityCreator for method chaining
148+
*/
104149
public EntityCreator setInvulnerable(boolean invulnerable) {
105150
this.isSetInvulnerable = true;
106151
this.invulnerable = invulnerable;
107152
return this;
108153
}
109154

155+
/**
156+
* Sets whether the entity makes sounds.
157+
*
158+
* @param silent true if the entity should be silent, false otherwise
159+
* @return this EntityCreator for method chaining
160+
*/
110161
public EntityCreator setSilent(boolean silent) {
111162
this.isSetSilient = true;
112163
this.silent = silent;
113164
return this;
114165
}
115166

167+
/**
168+
* Sets whether the entity is affected by gravity.
169+
*
170+
* @param gravity true if the entity should have gravity, false otherwise
171+
* @return this EntityCreator for method chaining
172+
*/
116173
public EntityCreator hasGravity(boolean gravity) {
117174
this.isSetGravity = true;
118175
this.gravity = gravity;
119176
return this;
120177
}
121178

179+
/**
180+
* Sets the velocity vector for the entity.
181+
*
182+
* @param vector the velocity vector
183+
* @return this EntityCreator for method chaining
184+
*/
122185
public EntityCreator setVelocity(Vector vector) {
123186
this.isSetVector = true;
124187
this.vector = vector;
125188
return this;
126189
}
127190

191+
/**
192+
* Sets whether the entity is persistent (won't despawn).
193+
*
194+
* @param persistent true if the entity should be persistent, false otherwise
195+
* @return this EntityCreator for method chaining
196+
*/
128197
public EntityCreator setPersistent(Boolean persistent) {
129198
this.isSetSilentGravity = true;
130199
this.persistent = persistent;
131200
return this;
132201
}
133202

203+
/**
204+
* Sets the number of freeze ticks for the entity.
205+
*
206+
* @param ticks the number of freeze ticks
207+
* @return this EntityCreator for method chaining
208+
*/
134209
public EntityCreator setFreezeTicks(int ticks) {
135210
this.isSetFreezeTicks = true;
136211
this.freezeTicks = ticks;
137212
return this;
138213
}
139214

215+
/**
216+
* Sets whether the entity's custom name is visible.
217+
*
218+
* @param visible true if the custom name should be visible, false otherwise
219+
* @return this EntityCreator for method chaining
220+
*/
140221
public EntityCreator setCustomNameVisible(Boolean visible) {
141222
this.isSetCustomNameVisible = true;
142223
this.customNameVisible = visible;
143224
return this;
144225
}
145226

227+
/**
228+
* Sets the portal cooldown for the entity.
229+
*
230+
* @param ticks the portal cooldown in ticks
231+
* @return this EntityCreator for method chaining
232+
*/
146233
public EntityCreator setPortalCooldown(int ticks) {
147234
this.isSetProtalCooldown = true;
148235
this.portalCooldown = ticks;
149236
return this;
150237
}
151238

239+
/**
240+
* Sets the falling distance for the entity.
241+
*
242+
* @param distance the falling distance
243+
* @return this EntityCreator for method chaining
244+
*/
152245
public EntityCreator setFallingDistance(float distance) {
153246
this.isSetFallingDistance = true;
154247
this.fallingDistance = distance;
155248
return this;
156249
}
157250

251+
/**
252+
* Sets the rotation (yaw and pitch) for the entity.
253+
*
254+
* @param yaw the yaw rotation
255+
* @param pitch the pitch rotation
256+
* @return this EntityCreator for method chaining
257+
*/
158258
public EntityCreator setRotation(float yaw, float pitch) {
159259
this.isSetRotation = true;
160260
this.rotation = new float[]{yaw, pitch};
161261
return this;
162262
}
163263

264+
/**
265+
* Sets the number of ticks the entity has been alive.
266+
*
267+
* @param ticks the number of ticks lived
268+
* @return this EntityCreator for method chaining
269+
*/
164270
public EntityCreator setTicksLived(int ticks) {
165271
this.isSetTicksLived = true;
166272
this.ticksLived = ticks;
167273
return this;
168274
}
169275

276+
/**
277+
* Sets whether the entity is visible by default.
278+
*
279+
* @param visible true if the entity should be visible by default, false otherwise
280+
* @return this EntityCreator for method chaining
281+
*/
170282
public EntityCreator setVisibleByDefault(boolean visible) {
171283
this.isSetVisibleByDefault = true;
172284
this.visibleByDefault = visible;
173285
return this;
174286
}
175287

288+
/**
289+
* Sets whether the entity has visual fire effect.
290+
*
291+
* @param fire true if the entity should have visual fire, false otherwise
292+
* @return this EntityCreator for method chaining
293+
*/
176294
public EntityCreator setVisualFire(boolean fire) {
177295
this.isSetVisualFire = true;
178296
this.visualFire = fire;
179297
return this;
180298
}
181299

300+
/**
301+
* Spawns the entity at the specified location with all configured properties.
302+
*
303+
* @param location the location to spawn the entity at
304+
* @return the spawned entity
305+
*/
182306
public Entity spawn(Location location) {
183307
Entity entity = Objects.requireNonNull(location.getWorld()).spawnEntity(location, entityType);
184308
sendDebugMessage("Spawned " + entityType + " at " + location);
@@ -222,14 +346,33 @@ public Entity spawn(Location location) {
222346
return entity;
223347
}
224348

349+
/**
350+
* Spawns the entity at the specified coordinates in the given world.
351+
*
352+
* @param world the world to spawn the entity in
353+
* @param x the x coordinate
354+
* @param y the y coordinate
355+
* @param z the z coordinate
356+
* @return the spawned entity
357+
*/
225358
public Entity spawn(World world, double x, double y, double z) {
226359
return spawn(new Location(world, x, y, z));
227360
}
228361

362+
/**
363+
* Gets the entity type this creator will spawn.
364+
*
365+
* @return the entity type
366+
*/
229367
public EntityType getType() {
230368
return entityType;
231369
}
232370

371+
/**
372+
* Gets the entity class for the entity type this creator will spawn.
373+
*
374+
* @return the entity class
375+
*/
233376
public Class<? extends Entity> getEntity() {
234377
return this.entityType.getEntityClass();
235378
}

0 commit comments

Comments
 (0)