|
12 | 12 |
|
13 | 13 | import static com.github.pinont.singularitylib.plugin.CorePlugin.sendDebugMessage; |
14 | 14 |
|
| 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 | + */ |
15 | 19 | public class EntityCreator { |
16 | 20 |
|
17 | 21 | private final EntityType entityType; |
@@ -69,116 +73,236 @@ public class EntityCreator { |
69 | 73 | private boolean isSetMaxHealth = false; |
70 | 74 | private double maxHealth; |
71 | 75 |
|
| 76 | + /** |
| 77 | + * Creates a new EntityCreator for the specified entity type. |
| 78 | + * |
| 79 | + * @param entityType the type of entity to create |
| 80 | + */ |
72 | 81 | public EntityCreator(EntityType entityType) { |
73 | 82 | this.entityType = entityType; |
74 | 83 | } |
75 | 84 |
|
| 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 | + */ |
76 | 91 | public EntityCreator addPassenger(Entity passenger) { |
77 | 92 | this.passenger = passenger; |
78 | 93 | return this; |
79 | 94 | } |
80 | 95 |
|
| 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 | + */ |
81 | 102 | public EntityCreator addScoreboardTag(String... ScoreboardTag) { |
82 | 103 | this.ScoreboardTag.addAll(List.of(ScoreboardTag)); |
83 | 104 | return this; |
84 | 105 | } |
85 | 106 |
|
| 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 | + */ |
86 | 113 | public EntityCreator setMaxHealth(double maxHealth) { |
87 | 114 | this.isSetMaxHealth = true; |
88 | 115 | this.maxHealth = maxHealth; |
89 | 116 | return this; |
90 | 117 | } |
91 | 118 |
|
| 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 | + */ |
92 | 125 | public EntityCreator setFireTicks(int ticks) { |
93 | 126 | this.isSetFireTicks = true; |
94 | 127 | this.fireTicks = ticks; |
95 | 128 | return this; |
96 | 129 | } |
97 | 130 |
|
| 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 | + */ |
98 | 137 | public EntityCreator setGlowing(boolean glowing) { |
99 | 138 | this.isSetGlowing = true; |
100 | 139 | this.glowing = glowing; |
101 | 140 | return this; |
102 | 141 | } |
103 | 142 |
|
| 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 | + */ |
104 | 149 | public EntityCreator setInvulnerable(boolean invulnerable) { |
105 | 150 | this.isSetInvulnerable = true; |
106 | 151 | this.invulnerable = invulnerable; |
107 | 152 | return this; |
108 | 153 | } |
109 | 154 |
|
| 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 | + */ |
110 | 161 | public EntityCreator setSilent(boolean silent) { |
111 | 162 | this.isSetSilient = true; |
112 | 163 | this.silent = silent; |
113 | 164 | return this; |
114 | 165 | } |
115 | 166 |
|
| 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 | + */ |
116 | 173 | public EntityCreator hasGravity(boolean gravity) { |
117 | 174 | this.isSetGravity = true; |
118 | 175 | this.gravity = gravity; |
119 | 176 | return this; |
120 | 177 | } |
121 | 178 |
|
| 179 | + /** |
| 180 | + * Sets the velocity vector for the entity. |
| 181 | + * |
| 182 | + * @param vector the velocity vector |
| 183 | + * @return this EntityCreator for method chaining |
| 184 | + */ |
122 | 185 | public EntityCreator setVelocity(Vector vector) { |
123 | 186 | this.isSetVector = true; |
124 | 187 | this.vector = vector; |
125 | 188 | return this; |
126 | 189 | } |
127 | 190 |
|
| 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 | + */ |
128 | 197 | public EntityCreator setPersistent(Boolean persistent) { |
129 | 198 | this.isSetSilentGravity = true; |
130 | 199 | this.persistent = persistent; |
131 | 200 | return this; |
132 | 201 | } |
133 | 202 |
|
| 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 | + */ |
134 | 209 | public EntityCreator setFreezeTicks(int ticks) { |
135 | 210 | this.isSetFreezeTicks = true; |
136 | 211 | this.freezeTicks = ticks; |
137 | 212 | return this; |
138 | 213 | } |
139 | 214 |
|
| 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 | + */ |
140 | 221 | public EntityCreator setCustomNameVisible(Boolean visible) { |
141 | 222 | this.isSetCustomNameVisible = true; |
142 | 223 | this.customNameVisible = visible; |
143 | 224 | return this; |
144 | 225 | } |
145 | 226 |
|
| 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 | + */ |
146 | 233 | public EntityCreator setPortalCooldown(int ticks) { |
147 | 234 | this.isSetProtalCooldown = true; |
148 | 235 | this.portalCooldown = ticks; |
149 | 236 | return this; |
150 | 237 | } |
151 | 238 |
|
| 239 | + /** |
| 240 | + * Sets the falling distance for the entity. |
| 241 | + * |
| 242 | + * @param distance the falling distance |
| 243 | + * @return this EntityCreator for method chaining |
| 244 | + */ |
152 | 245 | public EntityCreator setFallingDistance(float distance) { |
153 | 246 | this.isSetFallingDistance = true; |
154 | 247 | this.fallingDistance = distance; |
155 | 248 | return this; |
156 | 249 | } |
157 | 250 |
|
| 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 | + */ |
158 | 258 | public EntityCreator setRotation(float yaw, float pitch) { |
159 | 259 | this.isSetRotation = true; |
160 | 260 | this.rotation = new float[]{yaw, pitch}; |
161 | 261 | return this; |
162 | 262 | } |
163 | 263 |
|
| 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 | + */ |
164 | 270 | public EntityCreator setTicksLived(int ticks) { |
165 | 271 | this.isSetTicksLived = true; |
166 | 272 | this.ticksLived = ticks; |
167 | 273 | return this; |
168 | 274 | } |
169 | 275 |
|
| 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 | + */ |
170 | 282 | public EntityCreator setVisibleByDefault(boolean visible) { |
171 | 283 | this.isSetVisibleByDefault = true; |
172 | 284 | this.visibleByDefault = visible; |
173 | 285 | return this; |
174 | 286 | } |
175 | 287 |
|
| 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 | + */ |
176 | 294 | public EntityCreator setVisualFire(boolean fire) { |
177 | 295 | this.isSetVisualFire = true; |
178 | 296 | this.visualFire = fire; |
179 | 297 | return this; |
180 | 298 | } |
181 | 299 |
|
| 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 | + */ |
182 | 306 | public Entity spawn(Location location) { |
183 | 307 | Entity entity = Objects.requireNonNull(location.getWorld()).spawnEntity(location, entityType); |
184 | 308 | sendDebugMessage("Spawned " + entityType + " at " + location); |
@@ -222,14 +346,33 @@ public Entity spawn(Location location) { |
222 | 346 | return entity; |
223 | 347 | } |
224 | 348 |
|
| 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 | + */ |
225 | 358 | public Entity spawn(World world, double x, double y, double z) { |
226 | 359 | return spawn(new Location(world, x, y, z)); |
227 | 360 | } |
228 | 361 |
|
| 362 | + /** |
| 363 | + * Gets the entity type this creator will spawn. |
| 364 | + * |
| 365 | + * @return the entity type |
| 366 | + */ |
229 | 367 | public EntityType getType() { |
230 | 368 | return entityType; |
231 | 369 | } |
232 | 370 |
|
| 371 | + /** |
| 372 | + * Gets the entity class for the entity type this creator will spawn. |
| 373 | + * |
| 374 | + * @return the entity class |
| 375 | + */ |
233 | 376 | public Class<? extends Entity> getEntity() { |
234 | 377 | return this.entityType.getEntityClass(); |
235 | 378 | } |
|
0 commit comments