From de89244e0eb119d06e859d79c3a93fbde0fd22db Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 1 Apr 2016 18:21:05 +0200 Subject: [PATCH] #630 Disable collisions for unlogged players --- .../xephi/authme/process/join/AsynchronousJoin.java | 11 +++++++++++ .../authme/process/login/ProcessSyncPlayerLogin.java | 11 +++++++++++ src/main/java/fr/xephi/authme/settings/Settings.java | 4 ++-- .../authme/settings/properties/PluginSettings.java | 6 ++++++ src/main/resources/config.yml | 3 +++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index 838ac0e6d..900abd4c0 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -27,10 +27,14 @@ import fr.xephi.authme.util.Utils.GroupType; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.entity.LivingEntity; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitTask; +import com.comphenix.protocol.reflect.MethodUtils; + /** */ public class AsynchronousJoin implements Process { @@ -42,6 +46,9 @@ public class AsynchronousJoin implements Process { private final ProcessService service; private final PlayerCache playerCache; + private final boolean disableCollisions = MethodUtils + .getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null; + public AsynchronousJoin(Player player, AuthMe plugin, DataSource database, PlayerCache playerCache, ProcessService service) { this.player = player; @@ -89,6 +96,10 @@ public class AsynchronousJoin implements Process { }); return; } + // Prevent player collisions in 1.9 + if (disableCollisions) { + ((LivingEntity) player).setCollidable(false); + } final Location spawnLoc = service.getSpawnLoader().getSpawnLocation(player); final boolean isAuthAvailable = database.isAuthAvailable(name); if (isAuthAvailable) { diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index b454f3700..48b4eda45 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -4,12 +4,15 @@ import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; +import fr.xephi.authme.settings.properties.PluginSettings; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.potion.PotionEffectType; +import com.comphenix.protocol.reflect.MethodUtils; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; @@ -29,6 +32,7 @@ import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils.GroupType; import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; +import static fr.xephi.authme.settings.properties.PluginSettings.KEEP_COLLISIONS_DISABLED; public class ProcessSyncPlayerLogin implements Runnable { @@ -42,6 +46,9 @@ public class ProcessSyncPlayerLogin implements Runnable { private final JsonCache playerCache; private final NewSetting settings; + private final boolean restoreCollisions = MethodUtils + .getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null; + /** * Constructor for ProcessSyncPlayerLogin. * @@ -148,6 +155,10 @@ public class ProcessSyncPlayerLogin implements Runnable { } } + if (restoreCollisions && !settings.getProperty(KEEP_COLLISIONS_DISABLED)) { + player.setCollidable(true); + } + if (settings.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) { restoreInventory(); } diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 5989e2165..a35c6df84 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -59,7 +59,7 @@ public final class Settings { checkVeryGames, removeJoinMessage, removeLeaveMessage, delayJoinMessage, noTeleport, hideTablistBeforeLogin, denyTabcompleteBeforeLogin, kickPlayersBeforeStopping, allowAllCommandsIfRegIsOptional, - customAttributes, isRemoveSpeedEnabled, preventOtherCase; + customAttributes, isRemoveSpeedEnabled, preventOtherCase, keepCollisionsDisabled; public static String getNickRegex, getUnloggedinGroup, unRegisteredGroup, backupWindowsPath, getRegisteredGroup, @@ -195,7 +195,7 @@ public final class Settings { preventOtherCase = configFile.getBoolean("settings.preventOtherCase", false); kickPlayersBeforeStopping = configFile.getBoolean("Security.stop.kickPlayersBeforeStopping", true); sendPlayerTo = configFile.getString("Hooks.sendPlayerTo", ""); - + keepCollisionsDisabled = configFile.getBoolean("settings.keepCollisionsDisabled"); } /** diff --git a/src/main/java/fr/xephi/authme/settings/properties/PluginSettings.java b/src/main/java/fr/xephi/authme/settings/properties/PluginSettings.java index 6fea29fb0..de8582035 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/PluginSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/PluginSettings.java @@ -53,6 +53,12 @@ public class PluginSettings implements SettingsClass { public static final Property ENABLE_PERMISSION_CHECK = newProperty("permission.EnablePermissionCheck", false); + @Comment({ + "Keeps collisions disabled for logged players", + "Works only with MC 1.9" + }) + public static final Property KEEP_COLLISIONS_DISABLED = + newProperty("settings.KeepCollisionsDisabled", false); private PluginSettings() { } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index dc52379a2..5aa33aa7b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -159,6 +159,9 @@ settings: noTeleport: false # Regex syntax for allowed Chars in passwords. allowedPasswordCharacters: '[\x21-\x7E]*' + # Keeps collisions disabled for logged players + # Works only with MC 1.9 + keepCollisionsDisabled: false GameMode: # ForceSurvivalMode to player when join ? ForceSurvivalMode: false