Removing player from protected players if afk protection is disabled after applying effects and when the grace period runs out. Sending player state packet to player when it gets updated.
This commit is contained in:
@ -1,10 +1,13 @@
|
|||||||
package dev.micle.loginprotection.data;
|
package dev.micle.loginprotection.data;
|
||||||
|
|
||||||
import dev.micle.loginprotection.LoginProtection;
|
import dev.micle.loginprotection.LoginProtection;
|
||||||
|
import dev.micle.loginprotection.network.NetworkManager;
|
||||||
|
import dev.micle.loginprotection.network.ServerPlayerStatePacket;
|
||||||
import dev.micle.loginprotection.setup.Config;
|
import dev.micle.loginprotection.setup.Config;
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.world.effect.MobEffects;
|
import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.network.NetworkDirection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -84,10 +87,18 @@ public class ProtectedPlayerManager {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ACTIVE -> AFK
|
// ACTIVE -> AFK
|
||||||
if (Config.Server.AFK_PROTECTION_ENABLED.get()) {
|
player.setState(ProtectedPlayer.State.AFK);
|
||||||
player.setState(ProtectedPlayer.State.AFK);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send state packet to player
|
||||||
|
try {
|
||||||
|
NetworkManager.getChannel().sendTo(new ServerPlayerStatePacket(player.getState()),
|
||||||
|
LoginProtection.getProxy().getServer().getPlayerList().getPlayer(playerUUID).connection.getConnection(),
|
||||||
|
NetworkDirection.PLAY_TO_CLIENT);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
removePlayer(playerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +121,9 @@ public class ProtectedPlayerManager {
|
|||||||
if (player.getGracePeriodTimeRemaining() == 0) {
|
if (player.getGracePeriodTimeRemaining() == 0) {
|
||||||
applyPostEffects(playerUUID);
|
applyPostEffects(playerUUID);
|
||||||
player.getGracePeriodTimer().cancel();
|
player.getGracePeriodTimer().cancel();
|
||||||
|
if (!Config.Server.AFK_PROTECTION_ENABLED.get()) {
|
||||||
|
ProtectedPlayerManager.removePlayer(playerUUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1000, 1000);
|
}, 1000, 1000);
|
||||||
@ -149,5 +163,10 @@ public class ProtectedPlayerManager {
|
|||||||
Config.Server.POST_FIRE_DURATION.get()*20, 0));
|
Config.Server.POST_FIRE_DURATION.get()*20, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove player if afk protection is disabled
|
||||||
|
if (!Config.Server.AFK_PROTECTION_ENABLED.get()) {
|
||||||
|
ProtectedPlayerManager.removePlayer(playerUUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user