Prevent players from joining 1.9+ games with 1.8 clients (#212)
This commit is contained in:
parent
9be26a92d1
commit
e15804fc15
@ -2,7 +2,24 @@ package mineplex.core.common;
|
|||||||
|
|
||||||
public enum MinecraftVersion
|
public enum MinecraftVersion
|
||||||
{
|
{
|
||||||
ALL,
|
ALL("Any"),
|
||||||
Version1_9,
|
Version1_9("1.9"),
|
||||||
Version1_8
|
Version1_8("1.8"),
|
||||||
|
;
|
||||||
|
private final String _friendlyName;
|
||||||
|
|
||||||
|
MinecraftVersion(String friendlyName)
|
||||||
|
{
|
||||||
|
_friendlyName = friendlyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String friendlyName()
|
||||||
|
{
|
||||||
|
return _friendlyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinecraftVersion fromInt(int version)
|
||||||
|
{
|
||||||
|
return version <= 47 ? Version1_8 : Version1_9;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,13 @@ package nautilus.game.arcade.game.modules;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
|
|
||||||
import mineplex.core.common.MinecraftVersion;
|
import mineplex.core.common.MinecraftVersion;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.portal.Portal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module functions as a checkpoint for any client connecting a game
|
* This module functions as a checkpoint for any client connecting a game
|
||||||
@ -33,25 +35,20 @@ public class VersionModule extends Module
|
|||||||
|
|
||||||
for (Player player : UtilServer.getPlayers())
|
for (Player player : UtilServer.getPlayers())
|
||||||
{
|
{
|
||||||
if (!hasVersion(player))
|
if (UtilPlayer.getVersion(player) != _minecraftVersion)
|
||||||
{
|
{
|
||||||
player.kickPlayer(kickMessage);
|
UtilPlayer.message(player, C.cGold + C.Bold + "Please use Minecraft " + _minecraftVersion.friendlyName() + " or newer to play this game!");
|
||||||
|
Portal.getInstance().sendPlayerToServer(player, "Lobby");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event)
|
||||||
{
|
{
|
||||||
if (!hasVersion(event.getPlayer()))
|
if (MinecraftVersion.fromInt(event.spigot().getVersion()) != _minecraftVersion)
|
||||||
{
|
{
|
||||||
event.getPlayer().kickPlayer(_kickMessage);
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, C.cGold + C.Bold + "Please use Minecraft " + _minecraftVersion.friendlyName() + " or newer to play this game!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasVersion(Player player)
|
|
||||||
{
|
|
||||||
return UtilPlayer.getVersion(player) == _minecraftVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user