Packet based movement freeze (#1879)
* Remove unused files * Remove walk/fly speed from limbo player * Implement packet based movement freeze
This commit is contained in:
@@ -68,9 +68,7 @@ class LimboPlayerViewer implements DebugSection {
|
||||
sender.sendMessage(ChatColor.BLUE + "Player / limbo / disk limbo info for '" + arguments.get(0) + "'");
|
||||
new InfoDisplayer(sender, player, memoryLimbo, diskLimbo)
|
||||
.sendEntry("Is op", Player::isOp, LimboPlayer::isOperator)
|
||||
.sendEntry("Walk speed", Player::getWalkSpeed, LimboPlayer::getWalkSpeed)
|
||||
.sendEntry("Can fly", Player::getAllowFlight, LimboPlayer::isCanFly)
|
||||
.sendEntry("Fly speed", Player::getFlySpeed, LimboPlayer::getFlySpeed)
|
||||
.sendEntry("Location", p -> formatLocation(p.getLocation()), l -> formatLocation(l.getLocation()))
|
||||
.sendEntry("Prim. group",
|
||||
p -> permissionsManager.hasGroupSupport() ? permissionsManager.getPrimaryGroup(p) : "N/A",
|
||||
|
||||
@@ -12,27 +12,19 @@ import java.util.Collection;
|
||||
*/
|
||||
public class LimboPlayer {
|
||||
|
||||
public static final float DEFAULT_WALK_SPEED = 0.2f;
|
||||
public static final float DEFAULT_FLY_SPEED = 0.1f;
|
||||
|
||||
private final boolean canFly;
|
||||
private final boolean operator;
|
||||
private final Collection<String> groups;
|
||||
private final Location loc;
|
||||
private final float walkSpeed;
|
||||
private final float flySpeed;
|
||||
private BukkitTask timeoutTask = null;
|
||||
private MessageTask messageTask = null;
|
||||
private LimboPlayerState state = LimboPlayerState.PASSWORD_REQUIRED;
|
||||
|
||||
public LimboPlayer(Location loc, boolean operator, Collection<String> groups, boolean fly, float walkSpeed,
|
||||
float flySpeed) {
|
||||
public LimboPlayer(Location loc, boolean operator, Collection<String> groups, boolean fly) {
|
||||
this.loc = loc;
|
||||
this.operator = operator;
|
||||
this.groups = groups;
|
||||
this.canFly = fly;
|
||||
this.walkSpeed = walkSpeed;
|
||||
this.flySpeed = flySpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,14 +58,6 @@ public class LimboPlayer {
|
||||
return canFly;
|
||||
}
|
||||
|
||||
public float getWalkSpeed() {
|
||||
return walkSpeed;
|
||||
}
|
||||
|
||||
public float getFlySpeed() {
|
||||
return flySpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the timeout task, which kicks the player if he hasn't registered or logged in
|
||||
* after a configurable amount of time.
|
||||
|
||||
@@ -14,8 +14,6 @@ import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.LimboSettings.RESTORE_ALLOW_FLIGHT;
|
||||
import static fr.xephi.authme.settings.properties.LimboSettings.RESTORE_FLY_SPEED;
|
||||
import static fr.xephi.authme.settings.properties.LimboSettings.RESTORE_WALK_SPEED;
|
||||
|
||||
/**
|
||||
* Service for managing players that are in "limbo," a temporary state players are
|
||||
@@ -119,8 +117,6 @@ public class LimboService {
|
||||
} else {
|
||||
player.setOp(limbo.isOperator());
|
||||
settings.getProperty(RESTORE_ALLOW_FLIGHT).restoreAllowFlight(player, limbo);
|
||||
settings.getProperty(RESTORE_FLY_SPEED).restoreFlySpeed(player, limbo);
|
||||
settings.getProperty(RESTORE_WALK_SPEED).restoreWalkSpeed(player, limbo);
|
||||
limbo.clearTasks();
|
||||
logger.debug("Restored LimboPlayer stats for `{0}`", lowerName);
|
||||
persistence.removeLimboPlayer(player);
|
||||
|
||||
@@ -5,7 +5,6 @@ import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.LimboSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -40,13 +39,11 @@ class LimboServiceHelper {
|
||||
// For safety reasons an unregistered player should not have OP status after registration
|
||||
boolean isOperator = isRegistered && player.isOp();
|
||||
boolean flyEnabled = player.getAllowFlight();
|
||||
float walkSpeed = player.getWalkSpeed();
|
||||
float flySpeed = player.getFlySpeed();
|
||||
Collection<String> playerGroups = permissionsManager.hasGroupSupport()
|
||||
? permissionsManager.getGroups(player) : Collections.emptyList();
|
||||
logger.debug("Player `{0}` has groups `{1}`", player.getName(), String.join(", ", playerGroups));
|
||||
|
||||
return new LimboPlayer(location, isOperator, playerGroups, flyEnabled, walkSpeed, flySpeed);
|
||||
return new LimboPlayer(location, isOperator, playerGroups, flyEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,18 +58,12 @@ class LimboServiceHelper {
|
||||
player.setOp(false);
|
||||
settings.getProperty(LimboSettings.RESTORE_ALLOW_FLIGHT)
|
||||
.processPlayer(player);
|
||||
|
||||
if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) {
|
||||
player.setFlySpeed(0.0f);
|
||||
player.setWalkSpeed(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two existing LimboPlayer instances of a player. Merging is done the following way:
|
||||
* <ul>
|
||||
* <li><code>isOperator, allowFlight</code>: true if either limbo has true</li>
|
||||
* <li><code>flySpeed, walkSpeed</code>: maximum value of either limbo player</li>
|
||||
* <li><code>groups, location</code>: from old limbo if not empty/null, otherwise from new limbo</li>
|
||||
* </ul>
|
||||
*
|
||||
@@ -89,12 +80,10 @@ class LimboServiceHelper {
|
||||
|
||||
boolean isOperator = newLimbo.isOperator() || oldLimbo.isOperator();
|
||||
boolean canFly = newLimbo.isCanFly() || oldLimbo.isCanFly();
|
||||
float flySpeed = Math.max(newLimbo.getFlySpeed(), oldLimbo.getFlySpeed());
|
||||
float walkSpeed = Math.max(newLimbo.getWalkSpeed(), oldLimbo.getWalkSpeed());
|
||||
Collection<String> groups = getLimboGroups(oldLimbo.getGroups(), newLimbo.getGroups());
|
||||
Location location = firstNotNull(oldLimbo.getLocation(), newLimbo.getLocation());
|
||||
|
||||
return new LimboPlayer(location, isOperator, groups, canFly, walkSpeed, flySpeed);
|
||||
return new LimboPlayer(location, isOperator, groups, canFly);
|
||||
}
|
||||
|
||||
private static Location firstNotNull(Location first, Location second) {
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
package fr.xephi.authme.data.limbo;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Possible types to restore the walk and fly speed from LimboPlayer
|
||||
* back to Bukkit Player.
|
||||
*/
|
||||
public enum WalkFlySpeedRestoreType {
|
||||
|
||||
/**
|
||||
* Restores from LimboPlayer to Player.
|
||||
*/
|
||||
RESTORE {
|
||||
@Override
|
||||
public void restoreFlySpeed(Player player, LimboPlayer limbo) {
|
||||
logger.debug(() -> "Restoring fly speed for LimboPlayer " + player.getName() + " to "
|
||||
+ limbo.getFlySpeed() + " (RESTORE mode)");
|
||||
player.setFlySpeed(limbo.getFlySpeed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWalkSpeed(Player player, LimboPlayer limbo) {
|
||||
logger.debug(() -> "Restoring walk speed for LimboPlayer " + player.getName() + " to "
|
||||
+ limbo.getWalkSpeed() + " (RESTORE mode)");
|
||||
player.setWalkSpeed(limbo.getWalkSpeed());
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Restores from LimboPlayer, using the default speed if the speed on LimboPlayer is 0.
|
||||
*/
|
||||
RESTORE_NO_ZERO {
|
||||
@Override
|
||||
public void restoreFlySpeed(Player player, LimboPlayer limbo) {
|
||||
float limboFlySpeed = limbo.getFlySpeed();
|
||||
if (limboFlySpeed > 0.01f) {
|
||||
logger.debug(() -> "Restoring fly speed for LimboPlayer " + player.getName() + " to "
|
||||
+ limboFlySpeed + " (RESTORE_NO_ZERO mode)");
|
||||
player.setFlySpeed(limboFlySpeed);
|
||||
} else {
|
||||
logger.debug(() -> "Restoring fly speed for LimboPlayer " + player.getName()
|
||||
+ " to DEFAULT, it was 0! (RESTORE_NO_ZERO mode)");
|
||||
player.setFlySpeed(LimboPlayer.DEFAULT_FLY_SPEED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWalkSpeed(Player player, LimboPlayer limbo) {
|
||||
float limboWalkSpeed = limbo.getWalkSpeed();
|
||||
if (limboWalkSpeed > 0.01f) {
|
||||
logger.debug(() -> "Restoring walk speed for LimboPlayer " + player.getName() + " to "
|
||||
+ limboWalkSpeed + " (RESTORE_NO_ZERO mode)");
|
||||
player.setWalkSpeed(limboWalkSpeed);
|
||||
} else {
|
||||
logger.debug(() -> "Restoring walk speed for LimboPlayer " + player.getName() + ""
|
||||
+ " to DEFAULT, it was 0! (RESTORE_NO_ZERO mode)");
|
||||
player.setWalkSpeed(LimboPlayer.DEFAULT_WALK_SPEED);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Uses the max speed of Player (current speed) and the LimboPlayer.
|
||||
*/
|
||||
MAX_RESTORE {
|
||||
@Override
|
||||
public void restoreFlySpeed(Player player, LimboPlayer limbo) {
|
||||
float newSpeed = Math.max(player.getFlySpeed(), limbo.getFlySpeed());
|
||||
logger.debug(() -> "Restoring fly speed for LimboPlayer " + player.getName() + " to " + newSpeed
|
||||
+ " (Current: " + player.getFlySpeed() + ", Limbo: " + limbo.getFlySpeed() + ") (MAX_RESTORE mode)");
|
||||
player.setFlySpeed(newSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWalkSpeed(Player player, LimboPlayer limbo) {
|
||||
float newSpeed = Math.max(player.getWalkSpeed(), limbo.getWalkSpeed());
|
||||
logger.debug(() -> "Restoring walk speed for LimboPlayer " + player.getName() + " to " + newSpeed
|
||||
+ " (Current: " + player.getWalkSpeed() + ", Limbo: " + limbo.getWalkSpeed() + ") (MAX_RESTORE mode)");
|
||||
player.setWalkSpeed(newSpeed);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Always sets the default speed to the player.
|
||||
*/
|
||||
DEFAULT {
|
||||
@Override
|
||||
public void restoreFlySpeed(Player player, LimboPlayer limbo) {
|
||||
logger.debug(() -> "Restoring fly speed for LimboPlayer " + player.getName()
|
||||
+ " to DEFAULT (DEFAULT mode)");
|
||||
player.setFlySpeed(LimboPlayer.DEFAULT_FLY_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWalkSpeed(Player player, LimboPlayer limbo) {
|
||||
logger.debug(() -> "Restoring walk speed for LimboPlayer " + player.getName()
|
||||
+ " to DEFAULT (DEFAULT mode)");
|
||||
player.setWalkSpeed(LimboPlayer.DEFAULT_WALK_SPEED);
|
||||
}
|
||||
};
|
||||
|
||||
private static final ConsoleLogger logger = ConsoleLoggerFactory.get(WalkFlySpeedRestoreType.class);
|
||||
|
||||
/**
|
||||
* Restores the fly speed from Limbo to Player according to the restoration type.
|
||||
*
|
||||
* @param player the player to modify
|
||||
* @param limbo the limbo player to read from
|
||||
*/
|
||||
public abstract void restoreFlySpeed(Player player, LimboPlayer limbo);
|
||||
|
||||
/**
|
||||
* Restores the walk speed from Limbo to Player according to the restoration type.
|
||||
*
|
||||
* @param player the player to modify
|
||||
* @param limbo the limbo player to read from
|
||||
*/
|
||||
public abstract void restoreWalkSpeed(Player player, LimboPlayer limbo);
|
||||
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.CAN_FLY;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.FLY_SPEED;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.GROUPS;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.IS_OP;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.LOCATION;
|
||||
@@ -28,7 +27,6 @@ import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.LOC_X
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.LOC_Y;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.LOC_YAW;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.LOC_Z;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.WALK_SPEED;
|
||||
import static java.util.Optional.ofNullable;
|
||||
|
||||
/**
|
||||
@@ -56,10 +54,8 @@ class LimboPlayerDeserializer implements JsonDeserializer<LimboPlayer> {
|
||||
|
||||
Collection<String> groups = getLimboGroups(jsonObject);
|
||||
boolean canFly = getBoolean(jsonObject, CAN_FLY);
|
||||
float walkSpeed = getFloat(jsonObject, WALK_SPEED, LimboPlayer.DEFAULT_WALK_SPEED);
|
||||
float flySpeed = getFloat(jsonObject, FLY_SPEED, LimboPlayer.DEFAULT_FLY_SPEED);
|
||||
|
||||
return new LimboPlayer(loc, operator, groups, canFly, walkSpeed, flySpeed);
|
||||
return new LimboPlayer(loc, operator, groups, canFly);
|
||||
}
|
||||
|
||||
private Location deserializeLocation(JsonObject jsonObject) {
|
||||
|
||||
@@ -26,8 +26,6 @@ class LimboPlayerSerializer implements JsonSerializer<LimboPlayer> {
|
||||
static final String GROUPS = "groups";
|
||||
static final String IS_OP = "operator";
|
||||
static final String CAN_FLY = "can-fly";
|
||||
static final String WALK_SPEED = "walk-speed";
|
||||
static final String FLY_SPEED = "fly-speed";
|
||||
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
@@ -49,8 +47,6 @@ class LimboPlayerSerializer implements JsonSerializer<LimboPlayer> {
|
||||
|
||||
obj.addProperty(IS_OP, limboPlayer.isOperator());
|
||||
obj.addProperty(CAN_FLY, limboPlayer.isCanFly());
|
||||
obj.addProperty(WALK_SPEED, limboPlayer.getWalkSpeed());
|
||||
obj.addProperty(FLY_SPEED, limboPlayer.getFlySpeed());
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2015 AuthMe-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package fr.xephi.authme.listener.protocollib;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.WrappedAttribute;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
class FreezePacketAdapter extends PacketAdapter {
|
||||
|
||||
private static final String ATTRIBUTE_MOVEMENT_SPEED = "generic.movementSpeed";
|
||||
private static final String ATTRIBUTE_FLYING_SPEED = "generic.flyingSpeed";
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(FreezePacketAdapter.class);
|
||||
private final PlayerCache playerCache;
|
||||
private final DataSource dataSource;
|
||||
|
||||
FreezePacketAdapter(AuthMe plugin, PlayerCache playerCache, DataSource dataSource) {
|
||||
super(plugin, PacketType.Play.Server.UPDATE_ATTRIBUTES);
|
||||
this.playerCache = playerCache;
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent packetEvent) {
|
||||
Player player = packetEvent.getPlayer();
|
||||
PacketContainer packet = packetEvent.getPacket();
|
||||
|
||||
int entityId = packet.getIntegers().read(0);
|
||||
if (entityId != player.getEntityId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldFreeze(player.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<WrappedAttribute> newAttributes = new ArrayList<>();
|
||||
for (WrappedAttribute attribute : packet.getAttributeCollectionModifier().read(0)) {
|
||||
if (ATTRIBUTE_MOVEMENT_SPEED.equals(attribute.getAttributeKey())
|
||||
|| ATTRIBUTE_FLYING_SPEED.equals(attribute.getAttributeKey())) {
|
||||
newAttributes.add(WrappedAttribute.newBuilder(attribute)
|
||||
.baseValue(0.0f).modifiers(Collections.emptyList()).build());
|
||||
} else {
|
||||
newAttributes.add(attribute);
|
||||
}
|
||||
}
|
||||
packet.getAttributeCollectionModifier().write(0, newAttributes);
|
||||
}
|
||||
|
||||
protected void register(BukkitService bukkitService) {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
||||
|
||||
bukkitService.getOnlinePlayers().stream()
|
||||
.filter(player -> shouldFreeze(player.getName()))
|
||||
.forEach(this::sendFreezePacket);
|
||||
}
|
||||
|
||||
private boolean shouldFreeze(String playerName) {
|
||||
return !playerCache.isAuthenticated(playerName) && dataSource.isAuthAvailable(playerName);
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(this);
|
||||
}
|
||||
|
||||
protected void sendFreezePacket(Player player) {
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
PacketContainer attributesPacket = protocolManager.createPacket(PacketType.Play.Server.UPDATE_ATTRIBUTES);
|
||||
|
||||
attributesPacket.getIntegers().write(0, player.getEntityId());
|
||||
attributesPacket.getAttributeCollectionModifier().write(0, Arrays.asList(
|
||||
WrappedAttribute.newBuilder()
|
||||
.packet(attributesPacket)
|
||||
.attributeKey(ATTRIBUTE_MOVEMENT_SPEED)
|
||||
.baseValue(0.0f)
|
||||
.build(),
|
||||
WrappedAttribute.newBuilder()
|
||||
.packet(attributesPacket)
|
||||
.attributeKey(ATTRIBUTE_FLYING_SPEED)
|
||||
.baseValue(0.0f)
|
||||
.build()
|
||||
));
|
||||
|
||||
try {
|
||||
protocolManager.sendServerPacket(player, attributesPacket, false);
|
||||
} catch (InvocationTargetException invocationExc) {
|
||||
logger.logException("Error during sending freeze packet", invocationExc);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendUnFreezePacket(Player player) {
|
||||
player.setWalkSpeed(player.getWalkSpeed());
|
||||
player.setFlySpeed(player.getFlySpeed());
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,12 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
/* Packet Adapters */
|
||||
private InventoryPacketAdapter inventoryPacketAdapter;
|
||||
private TabCompletePacketAdapter tabCompletePacketAdapter;
|
||||
private FreezePacketAdapter freezePacketAdapter;
|
||||
|
||||
/* Settings */
|
||||
private boolean protectInvBeforeLogin;
|
||||
private boolean denyTabCompleteBeforeLogin;
|
||||
private boolean freezePlayerBeforeLogin;
|
||||
|
||||
/* Service */
|
||||
private boolean isEnabled;
|
||||
@@ -58,6 +60,11 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
logger.warning("WARNING! The denyTabComplete feature requires ProtocolLib! Disabling it...");
|
||||
}
|
||||
|
||||
if (freezePlayerBeforeLogin) {
|
||||
logger.warning("WARNING! In oder to prevent player movements in a nicer way consider"
|
||||
+ " installing ProtocolLib!");
|
||||
}
|
||||
|
||||
this.isEnabled = false;
|
||||
return;
|
||||
}
|
||||
@@ -84,6 +91,16 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
tabCompletePacketAdapter = null;
|
||||
}
|
||||
|
||||
if (freezePlayerBeforeLogin) {
|
||||
if (freezePacketAdapter == null) {
|
||||
freezePacketAdapter = new FreezePacketAdapter(plugin, playerCache, dataSource);
|
||||
freezePacketAdapter.register(bukkitService);
|
||||
}
|
||||
} else if (freezePacketAdapter != null) {
|
||||
freezePacketAdapter.unregister();
|
||||
freezePacketAdapter = null;
|
||||
}
|
||||
|
||||
this.isEnabled = true;
|
||||
}
|
||||
|
||||
@@ -101,6 +118,10 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
tabCompletePacketAdapter.unregister();
|
||||
tabCompletePacketAdapter = null;
|
||||
}
|
||||
if (freezePacketAdapter != null) {
|
||||
freezePacketAdapter.unregister();
|
||||
freezePacketAdapter = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,12 +135,36 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the player to freeze any movement.
|
||||
*
|
||||
* @param player The player to send the packet to.
|
||||
*/
|
||||
public void sendFreezePacket(Player player) {
|
||||
if (isEnabled && freezePacketAdapter != null) {
|
||||
freezePacketAdapter.sendFreezePacket(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the player to unfreeze movements.
|
||||
*
|
||||
* @param player The player to send the packet to.
|
||||
*/
|
||||
public void sendUnFreezePacket(Player player) {
|
||||
if (isEnabled && freezePacketAdapter != null) {
|
||||
freezePacketAdapter.sendUnFreezePacket(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(Settings settings) {
|
||||
boolean oldProtectInventory = this.protectInvBeforeLogin;
|
||||
final boolean oldProtectInventory = this.protectInvBeforeLogin;
|
||||
final boolean oldFreezePlayer = this.freezePlayerBeforeLogin;
|
||||
|
||||
this.protectInvBeforeLogin = settings.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN);
|
||||
this.denyTabCompleteBeforeLogin = settings.getProperty(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN);
|
||||
this.freezePlayerBeforeLogin = !settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT);
|
||||
|
||||
//it was true and will be deactivated now, so we need to restore the inventory for every player
|
||||
if (oldProtectInventory && !protectInvBeforeLogin && inventoryPacketAdapter != null) {
|
||||
@@ -130,6 +175,14 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oldFreezePlayer && !freezePlayerBeforeLogin && freezePacketAdapter != null) {
|
||||
freezePacketAdapter.unregister();
|
||||
for (Player onlinePlayer : bukkitService.getOnlinePlayers()) {
|
||||
if (!playerCache.isAuthenticated(onlinePlayer.getName())) {
|
||||
freezePacketAdapter.sendUnFreezePacket(onlinePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
setup();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import fr.xephi.authme.data.limbo.LimboService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.LoginEvent;
|
||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.SynchronousProcess;
|
||||
@@ -23,6 +24,7 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
|
||||
|
||||
public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
@@ -57,6 +59,9 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Inject
|
||||
private ProtocolLibService protocolLibService;
|
||||
|
||||
ProcessSyncPlayerLogin() {
|
||||
}
|
||||
|
||||
@@ -87,6 +92,9 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||
if (commonService.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||
restoreInventory(player);
|
||||
}
|
||||
if (!commonService.getProperty(ALLOW_UNAUTHED_MOVEMENT)) {
|
||||
protocolLibService.sendUnFreezePacket(player);
|
||||
}
|
||||
|
||||
final PlayerAuth auth = dataSource.getAuth(name);
|
||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||
|
||||
@@ -56,6 +56,9 @@ public class ProcessSyncPlayerLogout implements SynchronousProcess {
|
||||
if (service.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||
protocolLibService.sendBlankInventoryPacket(player);
|
||||
}
|
||||
if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)){
|
||||
protocolLibService.sendFreezePacket(player);
|
||||
}
|
||||
|
||||
applyLogoutEffect(player);
|
||||
commandManager.runCommandsOnLogout(player);
|
||||
|
||||
@@ -5,7 +5,6 @@ import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.configurationdata.CommentsConfiguration;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import fr.xephi.authme.data.limbo.AllowFlightRestoreType;
|
||||
import fr.xephi.authme.data.limbo.WalkFlySpeedRestoreType;
|
||||
import fr.xephi.authme.data.limbo.persistence.LimboPersistenceType;
|
||||
import fr.xephi.authme.data.limbo.persistence.SegmentSize;
|
||||
|
||||
@@ -19,7 +18,7 @@ public final class LimboSettings implements SettingsHolder {
|
||||
@Comment({
|
||||
"Besides storing the data in memory, you can define if/how the data should be persisted",
|
||||
"on disk. This is useful in case of a server crash, so next time the server starts we can",
|
||||
"properly restore things like OP status, ability to fly, and walk/fly speed.",
|
||||
"properly restore things like OP status and the ability to fly",
|
||||
"DISABLED: no disk storage,",
|
||||
"INDIVIDUAL_FILES: each player data in its own file,",
|
||||
"DISTRIBUTED_FILES: distributes players into different files based on their UUID, see below"
|
||||
@@ -49,23 +48,6 @@ public final class LimboSettings implements SettingsHolder {
|
||||
public static final Property<AllowFlightRestoreType> RESTORE_ALLOW_FLIGHT =
|
||||
newProperty(AllowFlightRestoreType.class, "limbo.restoreAllowFlight", AllowFlightRestoreType.RESTORE);
|
||||
|
||||
@Comment({
|
||||
"Restore fly speed: RESTORE, DEFAULT, MAX_RESTORE, RESTORE_NO_ZERO.",
|
||||
"RESTORE: restore the speed the player had;",
|
||||
"DEFAULT: always set to default speed;",
|
||||
"MAX_RESTORE: take the maximum of the player's current speed and the previous one",
|
||||
"RESTORE_NO_ZERO: Like 'restore' but sets speed to default if the player's speed was 0"
|
||||
})
|
||||
public static final Property<WalkFlySpeedRestoreType> RESTORE_FLY_SPEED =
|
||||
newProperty(WalkFlySpeedRestoreType.class, "limbo.restoreFlySpeed", WalkFlySpeedRestoreType.RESTORE_NO_ZERO);
|
||||
|
||||
@Comment({
|
||||
"Restore walk speed: RESTORE, DEFAULT, MAX_RESTORE, RESTORE_NO_ZERO.",
|
||||
"See above for a description of the values."
|
||||
})
|
||||
public static final Property<WalkFlySpeedRestoreType> RESTORE_WALK_SPEED =
|
||||
newProperty(WalkFlySpeedRestoreType.class, "limbo.restoreWalkSpeed", WalkFlySpeedRestoreType.RESTORE_NO_ZERO);
|
||||
|
||||
private LimboSettings() {
|
||||
}
|
||||
|
||||
@@ -73,7 +55,7 @@ public final class LimboSettings implements SettingsHolder {
|
||||
public void registerComments(CommentsConfiguration conf) {
|
||||
String[] limboExplanation = {
|
||||
"Before a user logs in, various properties are temporarily removed from the player,",
|
||||
"such as OP status, ability to fly, and walk/fly speed.",
|
||||
"such as OP status and the ability to fly.",
|
||||
"Once the user is logged in, we add back the properties we previously saved.",
|
||||
"In this section, you may define how these properties should be handled.",
|
||||
"Read more at https://github.com/AuthMe/AuthMeReloaded/wiki/Limbo-players"
|
||||
|
||||
Reference in New Issue
Block a user