parent
4be130b71b
commit
81cf14fbc1
@ -27,6 +27,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -48,10 +49,12 @@ class InventoryPacketAdapter extends PacketAdapter {
|
|||||||
private static final int HOTBAR_SIZE = 9;
|
private static final int HOTBAR_SIZE = 9;
|
||||||
|
|
||||||
private final PlayerCache playerCache;
|
private final PlayerCache playerCache;
|
||||||
|
private final DataSource dataSource;
|
||||||
|
|
||||||
InventoryPacketAdapter(AuthMe plugin, PlayerCache playerCache) {
|
InventoryPacketAdapter(AuthMe plugin, PlayerCache playerCache, DataSource dataSource) {
|
||||||
super(plugin, PacketType.Play.Server.SET_SLOT, PacketType.Play.Server.WINDOW_ITEMS);
|
super(plugin, PacketType.Play.Server.SET_SLOT, PacketType.Play.Server.WINDOW_ITEMS);
|
||||||
this.playerCache = playerCache;
|
this.playerCache = playerCache;
|
||||||
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,20 +62,22 @@ class InventoryPacketAdapter extends PacketAdapter {
|
|||||||
Player player = packetEvent.getPlayer();
|
Player player = packetEvent.getPlayer();
|
||||||
PacketContainer packet = packetEvent.getPacket();
|
PacketContainer packet = packetEvent.getPacket();
|
||||||
|
|
||||||
byte windowId = packet.getIntegers().read(0).byteValue();
|
int windowId = packet.getIntegers().read(0);
|
||||||
if (windowId == PLAYER_INVENTORY && !playerCache.isAuthenticated(player.getName())) {
|
if (windowId == PLAYER_INVENTORY && shouldHideInventory(player.getName())) {
|
||||||
packetEvent.setCancelled(true);
|
packetEvent.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(BukkitService bukkitService, boolean hideNow) {
|
public void register(BukkitService bukkitService) {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
||||||
|
|
||||||
if (hideNow) {
|
bukkitService.getOnlinePlayers().stream()
|
||||||
bukkitService.getOnlinePlayers().stream()
|
.filter(player -> shouldHideInventory(player.getName()))
|
||||||
.filter(player -> playerCache.isAuthenticated(player.getName()))
|
.forEach(this::sendBlankInventoryPacket);
|
||||||
.forEach(this::sendBlankInventoryPacket);
|
}
|
||||||
}
|
|
||||||
|
private boolean shouldHideInventory(String playerName) {
|
||||||
|
return !playerCache.isAuthenticated(playerName) && dataSource.isAuthAvailable(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregister() {
|
public void unregister() {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import ch.jalu.injector.annotations.NoFieldScan;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
@ -28,12 +29,15 @@ public class ProtocolLibService implements SettingsDependent {
|
|||||||
private AuthMe plugin;
|
private AuthMe plugin;
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ProtocolLibService(AuthMe plugin, Settings settings, BukkitService bukkitService, PlayerCache playerCache) {
|
ProtocolLibService(AuthMe plugin, Settings settings, BukkitService bukkitService, PlayerCache playerCache,
|
||||||
|
DataSource dataSource) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.bukkitService = bukkitService;
|
this.bukkitService = bukkitService;
|
||||||
this.playerCache = playerCache;
|
this.playerCache = playerCache;
|
||||||
|
this.dataSource = dataSource;
|
||||||
reload(settings);
|
reload(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,8 +63,8 @@ public class ProtocolLibService implements SettingsDependent {
|
|||||||
if (protectInvBeforeLogin) {
|
if (protectInvBeforeLogin) {
|
||||||
if (inventoryPacketAdapter == null) {
|
if (inventoryPacketAdapter == null) {
|
||||||
// register the packet listener and start hiding it for all already online players (reload)
|
// register the packet listener and start hiding it for all already online players (reload)
|
||||||
inventoryPacketAdapter = new InventoryPacketAdapter(plugin, playerCache);
|
inventoryPacketAdapter = new InventoryPacketAdapter(plugin, playerCache, dataSource);
|
||||||
inventoryPacketAdapter.register(bukkitService, true);
|
inventoryPacketAdapter.register(bukkitService);
|
||||||
}
|
}
|
||||||
} else if (inventoryPacketAdapter != null) {
|
} else if (inventoryPacketAdapter != null) {
|
||||||
inventoryPacketAdapter.unregister();
|
inventoryPacketAdapter.unregister();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user