Adds proper geyser checking
This commit is contained in:
10
pom.xml
10
pom.xml
@@ -43,6 +43,10 @@
|
|||||||
<id>minebench-repo</id>
|
<id>minebench-repo</id>
|
||||||
<url>https://repo.minebench.de/</url>
|
<url>https://repo.minebench.de/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>opencollab-snapshot</id>
|
||||||
|
<url>https://repo.opencollab.dev/main/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -112,6 +116,12 @@
|
|||||||
<version>1.7.1-SNAPSHOT</version>
|
<version>1.7.1-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geysermc.geyser</groupId>
|
||||||
|
<artifactId>api</artifactId>
|
||||||
|
<version>2.2.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@@ -36,10 +36,12 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
|||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.geysermc.geyser.api.GeyserApi;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -227,16 +229,41 @@ public class PlayerEventListener implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
|
||||||
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
|
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)) &&
|
// Get the real materials in the entrance, as END_GATEWAY or END_PORTAL may be available, but not chosen
|
||||||
(!entrancePortal.getOptions().isBungee() || !entranceMaterials.contains(Material.END_PORTAL))) {
|
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 null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return entrancePortal;
|
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
|
* This event handler detects if a player clicks a button or a sign
|
||||||
*
|
*
|
||||||
|
@@ -103,6 +103,9 @@ public class PortalEventListener implements Listener {
|
|||||||
public void onRespawn(@NotNull PlayerRespawnEvent event) {
|
public void onRespawn(@NotNull PlayerRespawnEvent event) {
|
||||||
Player respawningPlayer = event.getPlayer();
|
Player respawningPlayer = event.getPlayer();
|
||||||
FromTheEndTeleportation teleportation = playersFromTheEnd.remove(respawningPlayer);
|
FromTheEndTeleportation teleportation = playersFromTheEnd.remove(respawningPlayer);
|
||||||
|
if (teleportation == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Portal exitPortal = teleportation.exitPortal();
|
Portal exitPortal = teleportation.exitPortal();
|
||||||
|
|
||||||
//Overwrite respawn location to respawn in front of the portal
|
//Overwrite respawn location to respawn in front of the portal
|
||||||
|
Reference in New Issue
Block a user