Keep track of shuffle-positions teleportees.
Introduces a means of "tracking" both the players and the boss itself during the `shuffle-positions` ability for the sake of _not_ blocking the teleport event(s) that could potentially be blocked otherwise. Note that the change introduced in the PlayerTeleportEvent handler is not strictly necessary. The final block of code _should_ always yield the same result, as `shuffle-positions` _should_ be working solely on positions that are all inside the arena region, but the out-of-bounds check might be delayed, so we don't know for sure. It's just a safety precaution, but it really shouldn't be necessary. Fixes #792
This commit is contained in:
@@ -17,6 +17,7 @@ These changes will (most likely) be included in the next version.
|
||||
|
||||
### Fixed
|
||||
- MobArena no longer throws errors when handling block explosions on Minecraft 1.21.
|
||||
- The `shuffle-positions` ability now correctly shuffles the position of the boss as well if `monster-teleport` is set to `false`.
|
||||
|
||||
## [0.108] - 2024-01-01
|
||||
### Added
|
||||
|
||||
@@ -93,6 +93,7 @@ import org.bukkit.material.Attachable;
|
||||
import org.bukkit.material.Bed;
|
||||
import org.bukkit.material.Door;
|
||||
import org.bukkit.material.Redstone;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
@@ -928,6 +929,11 @@ public class ArenaListener
|
||||
}
|
||||
|
||||
if (isArenaMonster(event.getEntity())) {
|
||||
for (MetadataValue metadata : event.getEntity().getMetadata("teleporting")) {
|
||||
if (plugin.equals(metadata.getOwningPlugin())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!monsterTeleport || !region.contains(event.getTo())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -1328,6 +1334,13 @@ public class ArenaListener
|
||||
return TeleportResponse.ALLOW;
|
||||
}
|
||||
|
||||
// Same deal for players being teleported by shuffle-positions.
|
||||
for (MetadataValue metadata : p.getMetadata("teleporting")) {
|
||||
if (plugin.equals(metadata.getOwningPlugin())) {
|
||||
return TeleportResponse.ALLOW;
|
||||
}
|
||||
}
|
||||
|
||||
Location to = event.getTo();
|
||||
Location from = event.getFrom();
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.garbagemule.MobArena.waves.ability.Ability;
|
||||
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -30,6 +32,11 @@ public class ShufflePositions implements Ability
|
||||
locations.add(e.getLocation());
|
||||
}
|
||||
|
||||
// Keep track of teleportees
|
||||
MetadataValue metadata = new FixedMetadataValue(arena.getPlugin(), true);
|
||||
List<LivingEntity> teleportees = new ArrayList<>(entities);
|
||||
teleportees.forEach(e -> e.setMetadata("teleporting", metadata));
|
||||
|
||||
// Shuffle the entities list.
|
||||
Collections.shuffle(entities);
|
||||
|
||||
@@ -39,5 +46,8 @@ public class ShufflePositions implements Ability
|
||||
while (!entities.isEmpty() && !locations.isEmpty()) {
|
||||
entities.remove(0).teleport(locations.remove(0));
|
||||
}
|
||||
|
||||
// Remove teleportee metadata
|
||||
teleportees.forEach(e -> e.removeMetadata("teleporting", arena.getPlugin()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user