Creating a realistic timeout?

Discussion in 'Spigot Plugin Development' started by Tr3xEmpire, May 28, 2016.

  1. I'm trying to create a plugin that allows me to /timeout <player> with protocollib maybe? I want it to be as realistic as possible without effecting the server performance. Is this possible?
     
  2. Yes, it's possible.
    A: For ProtocolLib, you can listen to all packets which send to specific player. Store them in a list. Wait for certain times and send them.
    But I think this may bring lag problem (When too much packets stored in the list?) (I didn't try that and I may wrong)
    Another way, listen packets, cancel all packets which send to specific player, and only allows KeepAlive packet. Wait for certain times and... stop cancelling
    -------
    I think reduce entities on server or set the config appropriately is better than make a player lag. In my opinion: Player gaming experience first.
     
  3. Simply cancel all the packets to and from the player, the server and client will do the rest.
    This is 100% realistic, it's like someone cut the cable.
     
    • Agree Agree x 2
  4. If you don't want to implement ProtocolLib you could use a Netty-injection
    http://bit.ly/NettyInjection_independent and http://bit.ly/IReflect

    Code (Text):
        private List<Player> timeout = new ArrayList<Player>();

        @Override
        public void onEnable() {
            this.injection = new NettyInjection(this, this.getName());
            this.injection.addHandler("TIMEOUT", new PacketHandler() {
               
                @Override
                public Object onPacketIn(Player sender, Channel channel, Object packet) {
                    if(timeout.contains(sender))
                        return null;
                    return packet;
                }
            });
        }
     
    • Informative Informative x 1
    • Useful Useful x 1
  5. and if I wanted to use this in command form, I simply add the player to the player array?
     
  6. Yes that's it