Adds proper geyser checking

This commit is contained in:
2024-03-06 14:59:09 +01:00
parent 184cb38cbb
commit dfeeaf6999
3 changed files with 42 additions and 2 deletions

10
pom.xml
View File

@@ -43,6 +43,10 @@
<id>minebench-repo</id>
<url>https://repo.minebench.de/</url>
</repository>
<repository>
<id>opencollab-snapshot</id>
<url>https://repo.opencollab.dev/main/</url>
</repository>
</repositories>
<dependencies>
@@ -112,6 +116,12 @@
<version>1.7.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.geysermc.geyser</groupId>
<artifactId>api</artifactId>
<version>2.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@@ -36,10 +36,12 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.geysermc.geyser.api.GeyserApi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -227,16 +229,41 @@ public class PlayerEventListener implements Listener {
return null;
}
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {
return null;
}
if ((player.getName().matches("^[a-zA-Z0-9_]{2,16}$") || !entranceMaterials.contains(Material.END_GATEWAY)) &&
(!entrancePortal.getOptions().isBungee() || !entranceMaterials.contains(Material.END_PORTAL))) {
// Get the real materials in the entrance, as END_GATEWAY or END_PORTAL may be available, but not chosen
Set<Material> materialsInEntrance = new HashSet<>();
for (BlockLocation location : entrancePortal.getStructure().getEntrances()) {
materialsInEntrance.add(location.getType());
}
// Abort if not a special case
if ((!materialsInEntrance.contains(Material.END_GATEWAY) || !isGeyserPlayer(player)) &&
(!entrancePortal.getOptions().isBungee() || !materialsInEntrance.contains(Material.END_PORTAL))) {
return null;
}
return entrancePortal;
}
/**
* Checks whether the given player is connected through Geyser
*
* @param player <p>The player to check</p>
* @return <p>True if the player is connected through Geyser</p>
*/
private boolean isGeyserPlayer(@NotNull Player player) {
try {
return GeyserApi.api().connectionByUuid(player.getUniqueId()) != null;
} catch (NoClassDefFoundError error) {
return false;
}
}
/**
* This event handler detects if a player clicks a button or a sign
*

View File

@@ -103,6 +103,9 @@ public class PortalEventListener implements Listener {
public void onRespawn(@NotNull PlayerRespawnEvent event) {
Player respawningPlayer = event.getPlayer();
FromTheEndTeleportation teleportation = playersFromTheEnd.remove(respawningPlayer);
if (teleportation == null) {
return;
}
Portal exitPortal = teleportation.exitPortal();
//Overwrite respawn location to respawn in front of the portal