Skip to content

Commit 95908e3

Browse files
committed
Fix Commandremove when radius == 0
1 parent b1ea1d5 commit 95908e3

1 file changed

Lines changed: 124 additions & 121 deletions

File tree

patches/0013-Fix-command-remove.patch

Lines changed: 124 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Subject: [PATCH] Fix command remove
55

66

77
diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandremove.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandremove.java
8-
index 65e7ad9a69329a71ce56d5bbe331f3ae35b37c34..61afdde5a27fba797d851e5a4d42d8a4672b2b41 100644
8+
index 65e7ad9a69329a71ce56d5bbe331f3ae35b37c34..7a34420edca735d03161f6dcd5184ac0bc70a530 100644
99
--- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandremove.java
1010
+++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandremove.java
1111
@@ -106,10 +106,11 @@ public class Commandremove extends EssentialsCommand {
@@ -21,7 +21,7 @@ index 65e7ad9a69329a71ce56d5bbe331f3ae35b37c34..61afdde5a27fba797d851e5a4d42d8a4
2121

2222
final ArrayList<ToRemove> removeTypes = new ArrayList<>();
2323
final ArrayList<Mob> customRemoveTypes = new ArrayList<>();
24-
@@ -133,134 +134,170 @@ public class Commandremove extends EssentialsCommand {
24+
@@ -133,134 +134,172 @@ public class Commandremove extends EssentialsCommand {
2525
sender.sendTl("invalidMob");
2626
}
2727

@@ -30,25 +30,25 @@ index 65e7ad9a69329a71ce56d5bbe331f3ae35b37c34..61afdde5a27fba797d851e5a4d42d8a4
3030
- if (radius > 0) {
3131
- if (sender.getPlayer().getLocation().distanceSquared(e.getLocation()) > radius) {
3232
- continue;
33-
+ org.bukkit.Location playerLocation;
33+
+ final org.bukkit.Location playerLocation;
3434
+ if (radiusFinal > 0 && sender.getPlayer() != null) {
3535
+ playerLocation = sender.getPlayer().getLocation().clone();
3636
+ } else {
3737
+ playerLocation = null;
3838
+ }
3939
+
40-
+ Chunk[] chunks = world.getLoadedChunks();
40+
+ final Chunk[] chunks = world.getLoadedChunks();
4141
+
4242
+ if (chunks.length == 0) {
4343
+ sender.sendTl("removed", removed.get());
4444
+ return;
4545
+ }
4646
+
47-
+ java.util.concurrent.CompletableFuture<Integer> future = new java.util.concurrent.CompletableFuture<>();
48-
+ java.util.concurrent.atomic.AtomicInteger remaining = new java.util.concurrent.atomic.AtomicInteger(chunks.length);
47+
+ final java.util.concurrent.CompletableFuture<Integer> future = new java.util.concurrent.CompletableFuture<>();
48+
+ final java.util.concurrent.atomic.AtomicInteger remaining = new java.util.concurrent.atomic.AtomicInteger(chunks.length);
4949
+
5050
+ for (final Chunk chunk : chunks) {
51-
+ ess.getRegionScheduler().run(ess, world, chunk.getX(), chunk.getZ(), (scheduledTask) -> {
51+
+ ess.getRegionScheduler().run(ess, world, chunk.getX(), chunk.getZ(), scheduledTask -> {
5252
+ try {
5353
+ for (final Entity e : chunk.getEntities()) {
5454
+ if (shouldBeRemovable(e, playerLocation, radiusFinal, customRemoveTypes, removeTypes)) {
@@ -78,25 +78,21 @@ index 65e7ad9a69329a71ce56d5bbe331f3ae35b37c34..61afdde5a27fba797d851e5a4d42d8a4
7878
- }
7979
+ private boolean shouldBeRemovable(final Entity e, org.bukkit.Location playerLocation, int radius, ArrayList<Mob> customRemoveTypes, ArrayList<ToRemove> removeTypes) {
8080
+ if (radius > 0 && playerLocation != null) {
81-
+ double dx = playerLocation.getX() - e.getX();
82-
+ double dy = playerLocation.getY() - e.getY();
83-
+ double dz = playerLocation.getZ() - e.getZ();
81+
+ final double dx = playerLocation.getX() - e.getX();
82+
+ final double dy = playerLocation.getY() - e.getY();
83+
+ final double dz = playerLocation.getZ() - e.getZ();
8484
+ if (dx * dx + dy * dy + dz * dz > radius) {
8585
+ return false;
8686
+ }
87-
+ if (e instanceof HumanEntity) {
88-
+ return false;
89-
+ }
87+
+ }
9088

9189
- // We should skip any NAMED animals unless we are specifially targetting them.
9290
- if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
9391
- continue;
9492
- }
95-
+ for (final ToRemove toRemove : removeTypes) {
96-
+// We should skip any animals tamed by players unless we are specifially targetting them.
97-
+ if (e instanceof Tameable && ((Tameable) e).isTamed() && (((Tameable) e).getOwner() instanceof Player || ((Tameable) e).getOwner() instanceof OfflinePlayer) && !removeTypes.contains(ToRemove.TAMED)) {
98-
+ return false;
99-
+ }
93+
+ if (e instanceof HumanEntity) {
94+
+ return false;
95+
+ }
10096

10197
- switch (toRemove) {
10298
- case TAMED:
@@ -187,14 +183,112 @@ index 65e7ad9a69329a71ce56d5bbe331f3ae35b37c34..61afdde5a27fba797d851e5a4d42d8a4
187183
- break;
188184
- case ENTITIES:
189185
- case ALL:
190-
+ // We should skip any NAMED animals unless we are specifially targetting them.
191-
+ if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
192-
+ return false;
193-
+ }
186+
+ for (final ToRemove toRemove : removeTypes) {
194187
+
195-
+ switch (toRemove) {
196-
+ case TAMED:
197-
+ if (e instanceof Tameable && ((Tameable) e).isTamed()) {
188+
+ // We should skip any animals tamed by players unless we are specifially targetting them.
189+
+ if (e instanceof Tameable && ((Tameable) e).isTamed() && (((Tameable) e).getOwner() instanceof Player || ((Tameable) e).getOwner() instanceof OfflinePlayer) && !removeTypes.contains(ToRemove.TAMED)) {
190+
+ return false;
191+
+ }
192+
+
193+
+ // We should skip any NAMED animals unless we are specifially targetting them.
194+
+ if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
195+
+ return false;
196+
+ }
197+
+
198+
+ switch (toRemove) {
199+
+ case TAMED:
200+
+ if (e instanceof Tameable && ((Tameable) e).isTamed()) {
201+
+ e.remove();
202+
+ return true;
203+
+ }
204+
+ break;
205+
+ case NAMED:
206+
+ if (e instanceof LivingEntity && e.getCustomName() != null) {
207+
+ e.remove();
208+
+ return true;
209+
+ }
210+
+ break;
211+
+ case DROPS:
212+
+ if (e instanceof Item) {
213+
+ e.remove();
214+
+ return true;
215+
+ }
216+
+ break;
217+
+ case ARROWS:
218+
+ if (e instanceof Projectile) {
219+
+ e.remove();
220+
+ return true;
221+
+ }
222+
+ break;
223+
+ case BOATS:
224+
+ if (e instanceof Boat) {
225+
+ e.remove();
226+
+ return true;
227+
+ }
228+
+ break;
229+
+ case MINECARTS:
230+
+ if (e instanceof Minecart) {
231+
+ e.remove();
232+
+ return true;
233+
+ }
234+
+ break;
235+
+ case XP:
236+
+ if (e instanceof ExperienceOrb) {
237+
+ e.remove();
238+
+ return true;
239+
+ }
240+
+ break;
241+
+ case PAINTINGS:
242+
+ if (e instanceof Painting) {
243+
+ e.remove();
244+
+ return true;
245+
+ }
246+
+ break;
247+
+ case ITEMFRAMES:
248+
+ if (e instanceof ItemFrame) {
249+
+ e.remove();
250+
+ return true;
251+
+ }
252+
+ break;
253+
+ case ENDERCRYSTALS:
254+
+ if (e instanceof EnderCrystal) {
255+
+ e.remove();
256+
+ return true;
257+
+ }
258+
+ break;
259+
+ case AMBIENT:
260+
+ if (e instanceof Flying) {
261+
+ e.remove();
262+
+ return true;
263+
+ }
264+
+ break;
265+
+ case HOSTILE:
266+
+ case MONSTERS:
267+
+ if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
268+
+ e.remove();
269+
+ return true;
270+
+ }
271+
+ break;
272+
+ case PASSIVE:
273+
+ case ANIMALS:
274+
+ if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
275+
+ e.remove();
276+
+ return true;
277+
+ }
278+
+ break;
279+
+ case MOBS:
280+
+ if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
281+
+ e.remove();
282+
+ return true;
283+
+ }
284+
+ break;
285+
+ case ENTITIES:
286+
+ case ALL:
287+
+ e.remove();
288+
+ return true;
289+
+ case CUSTOM:
290+
+ for (final Mob type : customRemoveTypes) {
291+
+ if (e.getType() == type.getType()) {
198292
e.remove();
199293
- removed++;
200294
- break;
@@ -204,104 +298,13 @@ index 65e7ad9a69329a71ce56d5bbe331f3ae35b37c34..61afdde5a27fba797d851e5a4d42d8a4
204298
- e.remove();
205299
- removed++;
206300
- }
207-
+ return true;
208-
+ }
209-
+ break;
210-
+ case NAMED:
211-
+ if (e instanceof LivingEntity && e.getCustomName() != null) {
212-
+ e.remove();
213-
+ return true;
214-
+ }
215-
+ break;
216-
+ case DROPS:
217-
+ if (e instanceof Item) {
218-
+ e.remove();
219-
+ return true;
220-
+ }
221-
+ break;
222-
+ case ARROWS:
223-
+ if (e instanceof Projectile) {
224-
+ e.remove();
225-
+ return true;
226-
+ }
227-
+ break;
228-
+ case BOATS:
229-
+ if (e instanceof Boat) {
230-
+ e.remove();
231-
+ return true;
232-
+ }
233-
+ break;
234-
+ case MINECARTS:
235-
+ if (e instanceof Minecart) {
236-
+ e.remove();
237-
+ return true;
238-
+ }
239-
+ break;
240-
+ case XP:
241-
+ if (e instanceof ExperienceOrb) {
242-
+ e.remove();
243-
+ return true;
244-
+ }
245-
+ break;
246-
+ case PAINTINGS:
247-
+ if (e instanceof Painting) {
248-
+ e.remove();
249-
+ return true;
250-
+ }
251-
+ break;
252-
+ case ITEMFRAMES:
253-
+ if (e instanceof ItemFrame) {
254-
+ e.remove();
255-
+ return true;
256-
+ }
257-
+ break;
258-
+ case ENDERCRYSTALS:
259-
+ if (e instanceof EnderCrystal) {
260-
+ e.remove();
261-
+ return true;
262-
+ }
263-
+ break;
264-
+ case AMBIENT:
265-
+ if (e instanceof Flying) {
266-
+ e.remove();
267-
+ return true;
268-
+ }
269-
+ break;
270-
+ case HOSTILE:
271-
+ case MONSTERS:
272-
+ if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
273-
+ e.remove();
274-
+ return true;
275-
+ }
276-
+ break;
277-
+ case PASSIVE:
278-
+ case ANIMALS:
279-
+ if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
280-
+ e.remove();
281-
+ return true;
282-
+ }
283-
+ break;
284-
+ case MOBS:
285-
+ if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
286-
+ e.remove();
287-
+ return true;
288-
+ }
289-
+ break;
290-
+ case ENTITIES:
291-
+ case ALL:
292-
+ e.remove();
293-
+ return true;
294-
+ case CUSTOM:
295-
+ for (final Mob type : customRemoveTypes) {
296-
+ if (e.getType() == type.getType()) {
297-
+ e.remove();
298-
+ return true;
299-
}
301+
- }
300302
- break;
301-
- }
303+
+ return true;
302304
+ }
303-
+ break;
304-
}
305+
}
306+
- }
307+
+ break;
305308
}
306309
}
307310
- sender.sendTl("removed", removed);

0 commit comments

Comments
 (0)