EssentialsX

EssentialsX

2M Downloads

Add an option to allow/disallow gamemode change of jailed players

EXtremeExploit opened this issue ยท 0 comments

commented

Feature description

This wasn't a problem until #2875 got merged.
Basically the feature would be to have an option like "jail-block-gamemode-change" that when set to true would cancel the onJailPlayerGameModeChange event when the user is jailed.
But when set to false the isJailed check wouldn't matter and allow the user's gamemode to be changed.

The implementation could be easily be done by just doing something like this:

diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java
index e725f8fa9..87a441e59 100644
--- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java
+++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java
@@ -377,6 +377,8 @@ public interface ISettings extends IConf {
 
     TeleportWhenFreePolicy getTeleportWhenFreePolicy();
 
+    boolean jailBlockGamemodeChange();
+
     boolean isJailOnlineTime();
 
     boolean isCompassTowardsHomePerm();
diff --git a/Essentials/src/main/java/com/earth2me/essentials/Jails.java b/Essentials/src/main/java/com/earth2me/essentials/Jails.java
index c29521923..610305cf9 100644
--- a/Essentials/src/main/java/com/earth2me/essentials/Jails.java
+++ b/Essentials/src/main/java/com/earth2me/essentials/Jails.java
@@ -275,7 +275,7 @@ public class Jails implements net.ess3.api.IJails {
             }
 
             final User user = ess.getUser(event.getPlayer());
-            if (user.isJailed()) {
+            if (user.isJailed() && ess.getSettings().jailBlockGamemodeChange()) {
                 event.setCancelled(true);
             }
         }
diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java
index bd8d64b4f..dd8e56853 100644
--- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java
@@ -1827,6 +1827,10 @@ public class Settings implements net.ess3.api.ISettings {
         return teleportWhenFreePolicy;
     }
 
+    @Override public boolean jailBlockGamemodeChange() {
+        return config.getBoolean("jail-block-gamemode-change", true);
+    }
+
     @Override
     public boolean isJailOnlineTime() {
         return config.getBoolean("jail-online-time", false);
diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml
index e477f037b..1c8f276f3 100644
--- a/Essentials/src/main/resources/config.yml
+++ b/Essentials/src/main/resources/config.yml
@@ -713,6 +713,9 @@ default-enabled-confirm-commands:
 # teleport to spawn, or "off" to not have them teleport.
 teleport-when-freed: back
 
+# Should essentials block the gamemode change event for jailed players?
+# Mainly useful to allow/disallow other plugins/players to change the gamemode of the jailed user
+jail-block-gamemode-change: true

 # Whether or not jail time should only be counted while the user is online.
 # If true, a jailed player's time will only decrement when they are online.
 jail-online-time: false

Im not directly PRing these changes as i dont know if this deserves to go into essentialsx, so thats why im making this issue in place

How the feature is useful

This is useful for the case where the user can have multiple game modes over the course of its gameplay, like having a survival and a creative world with multiverse or an adventure map that changes the player's gamemode, it also doesn't break with the initial report (#1996) of plugins unwillingly changing user's gamemode. This will still be disabled by default and enabled by manual configuration.
Having to always keep in mind and remember to change the user's gamemode before jailing is REALLY annoying and you could sometimes forget and have an user jailed in creative mode.
It too allows to use multiple worlds for jails and have different gamemodes for different jails and have all of the gamemode's be handled by a plugin such as multiverse instead of raw brainpower which is prone to mistakes (fixes #3685)