How to prevent mouse movement

Discussion in 'Spigot Plugin Development' started by Wixly, Mar 15, 2017.

  1. Did you even read the discussion. Yes or no?
    Even the first post by OP states that that is not what he wants.
     
    • Agree Agree x 1
  2. Yep, but didnt understand whats the point of blocking only the mouse.
     
    • Funny Funny x 1
    • Optimistic Optimistic x 1
  3. When in spectator mode, you're able to right click a mob to "spectate it" from it's view without being able to move your mouse or controls to move it. If it's possible to do this with an invisible armor stand, since it's an entity, that would be spectacular.

    I already stop them from being able to move by putting their walkspeed to 0.0F and a negative Jumpboost. There's no need to use the very resource intensive PlayerMoveEvent (the one I use is only temporary until I find another solution.)
     
  4. Guys the only solution to do that is not only cancelling the player movement. You have to cancel the player movement and also when a player tries to move or tries to move his mouse, teleport him in the location he is with the same looking coordinates. This is what you can only do.
     
  5. Strahan

    Benefactor

    Real answer: Get over it. The amount of effort you'd need to put in to make it work, judging from the suggestions, is totally not worth it. At least, not in my opinion.

    No, it doesn't make any sense, because that's a silly idea. The Bukkit/Spigot API is Java. Just because they make their own classes and methods and such doesn't mean it's not still Java.
     
  6. You might be right, the best solution might be to just live with that they can move their mouse slightly even if they're locked.

    Well what I meant from the beginning with the statement was that I could use Java's methods to solve this instead of using methods from Bukkit. That's why I meant "Java-code instead of Bukkit-code". The statement I made in your quotation was of course wrong, sorry! :p
     
  7. Strahan

    Benefactor

    Sadly this is one of those things where the ROI just doesn't seem worth it unfortunately.

    All good ;)
     
  8. PQE

    PQE

    Get the pitch/yaw of the location (e.getFrom().getPitch() and .getYaw()).

    If (I think) playermoveevent is done BEFORE the player moves at all, so you would have to wait one tick and then teleport them to their from location, and set their pitch to the pitch, and yaw to the yaw. Should work.

    EDIT: Location stores the pitch/yaw (derp) so you literally just have to teleport them to the location after 1 tick
     
    #28 PQE, Mar 15, 2017
    Last edited: Mar 15, 2017
  9. This is what i just said lol
     
  10. PQE

    PQE

    I stopped reading the responses after the first page lol
     
  11. Hahahah it's okay. But yes. This is the only solution to do that. Like the Login plugin for the unPremium users. The only way is to teleport them to their from location, and set their pitch to the pitch, and yaw to the yaw. It should work 100%
     
  12. I know it makes them unable to move, but what I was after was that they should not be able to even move the slightest with the mouse, which seems impossible. Because the "setYaw, setPitch" values in PlayerMoveEvent does still let the player to move the cursor sliiightly. Moving it too far puts it back to the set state. That's what I tried to avoid, but if it's impossible, it is :/

    If I find a solution I'll make sure to post it here! ;)
     
  13. The client already renders the movement before sending it to the server.
    The server then resets the camera to the position it should have which makes it look like the camera is shaking.

    The only way to stop this movement (which is only visible to the player that is trying to look around) is to (ab)use spectator mode to tell the client that it can't move.

    1. Send the player a packet that makes the client think it is in spectator mode (other players will still see the player)
    2. Send the player a packet that spawns a fake player with the players skin (otherwise the player would see him/herself as invisible when using third person camera)
    3. Send a packet to set the players camera to the fake player you just spawned
    Maybe I will post some example code later.
     
    • Winner Winner x 1
  14. If anyone still needs this, here is some example code.
    This example depends on Protocollib!

    WARNING:
    Blindly copy pasting this code will most likely result in a lot of trouble!
    Please read the code and try to understand what it does instead of just copy pasting!

    Freezing the player:
    Code (Text):
    /*
    Copyright (c) 2017 4a2e532e

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    package mousefreeze.mousefreeze;

    import com.comphenix.protocol.PacketType;
    import com.comphenix.protocol.ProtocolLibrary;
    import com.comphenix.protocol.ProtocolManager;
    import com.comphenix.protocol.events.PacketContainer;
    import com.comphenix.protocol.wrappers.*;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import java.lang.reflect.InvocationTargetException;
    import java.util.ArrayList;
    import java.util.UUID;

    public class FreezeCommand implements CommandExecutor {

        private ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();

        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(!(sender instanceof Player)){
                return false;
            }

            Player p = (Player) sender;

            /*
            Send PlayerListItem packet (http://wiki.vg/Protocol#Player_List_Item).
            This packet has to be sent before spawning the fake player.
             */
            PacketContainer fakeListItem = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
            UUID fakeUUID = UUID.fromString("00000000-0000-2000-0000-000000000000");
            WrappedGameProfile profile = new WrappedGameProfile(fakeUUID, p.getName());
            PlayerInfoData playerInfoData = new PlayerInfoData(profile, 0, EnumWrappers.NativeGameMode.NOT_SET, WrappedChatComponent.fromText(""));
            ArrayList<PlayerInfoData> dataList = new ArrayList<>();
            dataList.add(playerInfoData);
            fakeListItem.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
            fakeListItem.getPlayerInfoDataLists().write(0, dataList);
            try{
                protocolManager.sendServerPacket(p, fakeListItem);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            /*
            Send SpawnPlayer packet (http://wiki.vg/Protocol#Spawn_Player).
            The fake player will ONLY be visible for the player you want to freeze,
            other players will NOT see the fake player!
            The UUID used in this packet has to be the same UUID as the one used in the PlayerListItem packet!
             */
            PacketContainer fakePlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
            fakePlayer.getIntegers().write(0, 12345678);
            fakePlayer.getUUIDs().write(0, fakeUUID);
            fakePlayer.getDoubles()
                    .write(0, p.getLocation().getX())
                    .write(1, p.getLocation().getY())
                    .write(2, p.getLocation().getZ());
            fakePlayer.getBytes()
                    .write(0, (byte) (p.getLocation().getYaw() * 256 / 360))
                    .write(1, (byte) (p.getLocation().getPitch() * 256 / 360));
            fakePlayer.getDataWatcherModifier().write(0, new WrappedDataWatcher());
            try{
                protocolManager.sendServerPacket(p, fakePlayer);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            /*
            Send Camera packet (http://wiki.vg/Protocol#Camera).
            This packet sets the camera of the player you want to freeze to the fake player.
            The EntityID used in this packet has to be the same EntityID as the one used when spawning the fake player!
            The frozen player will NOT be able to move anymore.
            This also causes some weird visual glitches for the frozen player.
             */
            PacketContainer camera = new PacketContainer(PacketType.Play.Server.CAMERA);
            camera.getIntegers().write(0, 12345678);
            try{
                protocolManager.sendServerPacket(p, camera);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            return true;
        }
    }
     
    Unfreezing the player:
    Code (Text):
    /*
    Copyright (c) 2017 4a2e532e

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    package mousefreeze.mousefreeze;

    import com.comphenix.protocol.PacketType;
    import com.comphenix.protocol.ProtocolLibrary;
    import com.comphenix.protocol.ProtocolManager;
    import com.comphenix.protocol.events.PacketContainer;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import java.lang.reflect.InvocationTargetException;

    public class UnfreezeCommand implements CommandExecutor {

        ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();

        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(!(sender instanceof Player)){
                return false;
            }

            Player p = (Player) sender;

            /*
            Send DestroyEntities packet (http://wiki.vg/Protocol#Destroy_Entities).
            This packet removes the fake player.
            The EntityID used in this packet has to be the same as the EntityID used when spawning the fake player!
             */
            PacketContainer destroyFakePlayer = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
            int[] entityIDs = new int[1];
            entityIDs[0] = 12345678;
            destroyFakePlayer.getIntegerArrays().write(0, entityIDs);
            try{
                protocolManager.sendServerPacket(p, destroyFakePlayer);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            /*
            Send Camera packet (http://wiki.vg/Protocol#Camera).
            This packet resets the camera of the frozen player back to normal which unfreezes the player.
             */
            PacketContainer camera = new PacketContainer(PacketType.Play.Server.CAMERA);
            camera.getIntegers().write(0, p.getEntityId());
            try{
                protocolManager.sendServerPacket(p, camera);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            return true;
        }
    }
     

    This code is far from perfect and causes some weird visual glitches for the frozen player.

    The video shows the code in action and some weird visual glitches it causes for the frozen player.

     
    #34 4a2e532e, Mar 17, 2017
    Last edited: Mar 17, 2017
    • Winner Winner x 1

  15. Wow thanks alot for showing this. I will take some time to try to learn this and see what result I get. I will post here if I get it finished. Another thing I thought about, to get the visual glitches out of the way. Why not set an invisible effect on the player? Then it should solve most cases right, or is that not possible in this case?

    Once again, thank you :)
     
  16. I mean, like someone previously said, the amount of work you put into fixing such a subtle and not important thing won't be worth it.

    I don't think anyone will get on your case because your freeze plugin has a little bit of mouse movement when they are frozen lol

    I'm not saying its a bad idea, I would totally try to be like this as well everything needs to be perfect for me. But in this case might not be worth it
     
  17. Haha, if the solution above goes the way I want, then this is utterly perfect! If not, I'll just have to face the fact that I need to use the playermoveevent for the pitch and yaw :)
     
  18. I couldn't be bothered to read the previous responses, but I had this same issue a while back. The solution was rather simple. Remove all the code about setting the speed to 0 etc... on the playerMoveEvent, of a player is frozen, e.setTo(e.getFrom())
    Simple, cancels mouse movement completely as well as any type of movement. :)


    Sent from my iPhone using Tapatalk
     
  19. That way the player can still move a bit because the packet has to be sent to the server first and then a new packet has to be sent to the client. By the time that packet arrives the client probably already rendered the player. By setting the player's spectator target the cancelling is done by the client and thus it won't be able to move at all.
     
    • Agree Agree x 1
  20. If you want to avoid the visual glitches, you could tell the client that the player is in spectator mode instead of just setting the camera.
    You also have to cancel the kick event if a frozen player gets kicked for "Cannot interact with self!" because otherwise a frozen player would get kicked when rightclicking or leftclicking.

    To tell the client that the player is in spectator mode, you have to send a ChangeGameState packet (http://wiki.vg/Protocol#Change_Game_State):
    Code (Text):

            /*
            Send ChangeGameState packet (http://wiki.vg/Protocol#Change_Game_State).
            This packet tells the client that the player is in spectator mode which removes the arm.
             */
            PacketContainer fakeGm3 = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
            fakeGm3.getIntegers().write(0, 3);
            fakeGm3.getFloat().write(0, 3f);
            try{
                protocolManager.sendServerPacket(p, fakeGm3);
            }catch(InvocationTargetException e){
                e.printStackTrace();
            }
    and of course you have to undo this when unfreezing the player:
    Code (Text):

    /*
    Send ChangeGameState packet (http://wiki.vg/Protocol#Change_Game_State).
    This packet sets the clients GameMode back to the GameMode the player has on the server.
    */
    float gamemode = p.getGameMode().getValue();
    PacketContainer stopFakeGm3 = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
    stopFakeGm3.getIntegers().write(0, 3);
    stopFakeGm3.getFloat().write(0, gamemode);
    try{
        protocolManager.sendServerPacket(p, stopFakeGm3);
    }catch(InvocationTargetException e){
        e.printStackTrace();
    }
     
    Again: This is an example and should not be blindly copy pasted!
    The commands in this example only freeze/unfreeze the command sender because this is just example code.


    The freeze command from my previous post should now look like this:
    Code (Text):
    /*
    Copyright (c) 2017 4a2e532e

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    package mousefreeze.mousefreeze;

    import com.comphenix.protocol.PacketType;
    import com.comphenix.protocol.ProtocolLibrary;
    import com.comphenix.protocol.ProtocolManager;
    import com.comphenix.protocol.events.PacketContainer;
    import com.comphenix.protocol.wrappers.*;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import java.lang.reflect.InvocationTargetException;
    import java.util.ArrayList;
    import java.util.UUID;

    public class FreezeCommand implements CommandExecutor {

        private ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();

        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(!(sender instanceof Player)){
                return false;
            }

            Player p = (Player) sender;

            /*
            Send PlayerListItem packet (http://wiki.vg/Protocol#Player_List_Item).
            This packet has to be sent before spawning the fake player.
             */
            PacketContainer fakeListItem = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
            UUID fakeUUID = UUID.fromString("00000000-0000-2000-0000-000000000000");
            WrappedGameProfile profile = new WrappedGameProfile(fakeUUID, "");
            PlayerInfoData playerInfoData = new PlayerInfoData(profile, 0, EnumWrappers.NativeGameMode.NOT_SET, WrappedChatComponent.fromText(""));
            ArrayList<PlayerInfoData> dataList = new ArrayList<>();
            dataList.add(playerInfoData);
            fakeListItem.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
            fakeListItem.getPlayerInfoDataLists().write(0, dataList);
            try{
                protocolManager.sendServerPacket(p, fakeListItem);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            /*
            Send SpawnPlayer packet (http://wiki.vg/Protocol#Spawn_Player).
            The fake player will ONLY be visible for the player you want to freeze,
            other players will NOT see the fake player!
            The UUID used in this packet has to be the same UUID as the one used in the PlayerListItem packet!
             */
            PacketContainer fakePlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
            fakePlayer.getIntegers().write(0, 12345678);
            fakePlayer.getUUIDs().write(0, fakeUUID);
            fakePlayer.getDoubles()
                    .write(0, p.getLocation().getX())
                    .write(1, p.getLocation().getY())
                    .write(2, p.getLocation().getZ());
            fakePlayer.getBytes()
                    .write(0, (byte) (p.getLocation().getYaw() * 256 / 360))
                    .write(1, (byte) (p.getLocation().getPitch() * 256 / 360));
            fakePlayer.getDataWatcherModifier().write(0, new WrappedDataWatcher());
            try{
                protocolManager.sendServerPacket(p, fakePlayer);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            /*
            Send ChangeGameState packet (http://wiki.vg/Protocol#Change_Game_State).
            This packet tells the client that the player is in spectator mode which removes the arm.
             */
            PacketContainer fakeGm3 = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
            fakeGm3.getIntegers().write(0, 3);
            fakeGm3.getFloat().write(0, 3f);
            try{
                protocolManager.sendServerPacket(p, fakeGm3);
            }catch(InvocationTargetException e){
                e.printStackTrace();
            }

            /*
            Send Camera packet (http://wiki.vg/Protocol#Camera).
            This packet sets the camera of the player you want to freeze to the fake player.
            The EntityID used in this packet has to be the same EntityID as the one used when spawning the fake player!
            The frozen player will NOT be able to move anymore.
            This also causes some weird visual glitches for the frozen player.
             */
            PacketContainer camera = new PacketContainer(PacketType.Play.Server.CAMERA);
            camera.getIntegers().write(0, 12345678);
            try{
                protocolManager.sendServerPacket(p, camera);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            return true;
        }
    }
     
    The unfreeze command:
    Code (Text):
    /*
    Copyright (c) 2017 4a2e532e

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    package mousefreeze.mousefreeze;

    import com.comphenix.protocol.PacketType;
    import com.comphenix.protocol.ProtocolLibrary;
    import com.comphenix.protocol.ProtocolManager;
    import com.comphenix.protocol.events.PacketContainer;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import java.lang.reflect.InvocationTargetException;

    public class UnfreezeCommand implements CommandExecutor {

        ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();

        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(!(sender instanceof Player)){
                return false;
            }

            Player p = (Player) sender;

            /*
            Send DestroyEntities packet (http://wiki.vg/Protocol#Destroy_Entities).
            This packet removes the fake player.
            The EntityID used in this packet has to be the same as the EntityID used when spawning the fake player!
             */
            PacketContainer destroyFakePlayer = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
            int[] entityIDs = new int[1];
            entityIDs[0] = 12345678;
            destroyFakePlayer.getIntegerArrays().write(0, entityIDs);
            try{
                protocolManager.sendServerPacket(p, destroyFakePlayer);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            /*
            Send Camera packet (http://wiki.vg/Protocol#Camera).
            This packet resets the camera of the frozen player back to normal which unfreezes the player.
             */
            PacketContainer camera = new PacketContainer(PacketType.Play.Server.CAMERA);
            camera.getIntegers().write(0, p.getEntityId());
            try{
                protocolManager.sendServerPacket(p, camera);
            }catch(InvocationTargetException e){
                e.printStackTrace();
                return false;
            }

            /*
            Send ChangeGameState packet (http://wiki.vg/Protocol#Change_Game_State).
            This packet sets the clients GameMode back to the GameMode the player has on the server.
             */
            float gamemode = p.getGameMode().getValue();
            PacketContainer stopFakeGm3 = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
            stopFakeGm3.getIntegers().write(0, 3);
            stopFakeGm3.getFloat().write(0, gamemode);
            try{
                protocolManager.sendServerPacket(p, stopFakeGm3);
            }catch(InvocationTargetException e){
                e.printStackTrace();
            }

            return true;
        }
    }
     
    The kick listener:
    Code (Text):
    /*
    Copyright (c) 2017 4a2e532e

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    package mousefreeze.mousefreeze;

    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerKickEvent;

    public class KickListener implements Listener {

        @EventHandler
        public void onKickEvent(PlayerKickEvent event){
            /*
            If a frozen player leftclicks or rightclicks, the player gets kicked for "Cannot interact with self!"
            As we do not want frozen players to get kicked, we have to cancel the kick event if the player is frozen
            and the kick reason is "Cannot interact with self!"

            You should check if the player is frozen before cancelling the KickEvent
            Pseudo Code:
            if(Player not frozen){
                return;
            }
             */

            if(event.getReason().equals("Cannot interact with self!")){
                event.setCancelled(true);
            }
        }
    }
     
     
    #40 4a2e532e, Mar 18, 2017
    Last edited: Mar 18, 2017
    • Winner Winner x 1