Changed grace period time from 200 to 400 (5s to 10s). Added function to ProtectedPlayers.java to remove a player from the list, updated the updateGracePeriods method. Updated C2SKeyPress.java. Made OnKeyPressEventHandler.java check for mouse clicks as well, also made sure it only fires on client-side. Added an event for when a player leaves the server to remove them from the list.
This commit is contained in:
@ -1,5 +1,13 @@
|
||||
package com.micle.loginprotection.data;
|
||||
|
||||
import net.minecraft.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -29,18 +37,25 @@ public class ProtectedPlayers {
|
||||
}
|
||||
|
||||
public void removePlayer(UUID player_uuid) {
|
||||
ProtectedPlayer player = getPlayer(player_uuid);
|
||||
ProtectedPlayer protected_player = getPlayer(player_uuid);
|
||||
if (protected_player == null) { return; }
|
||||
protected_players.remove(protected_player);
|
||||
|
||||
ServerPlayerEntity player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(player_uuid);
|
||||
if (player == null) { return; }
|
||||
protected_players.remove(player);
|
||||
player.sendMessage(new StringTextComponent("Grace Period over!"), player_uuid);
|
||||
}
|
||||
|
||||
public void updateGracePeriods() {
|
||||
for (ProtectedPlayer protected_player : protected_players) {
|
||||
if (protected_player.isLoading() || protected_player.getGracePeriod() <= 0) { continue; }
|
||||
int grace_period = protected_player.getGracePeriod();
|
||||
protected_player.setGracePeriod(grace_period-1);
|
||||
if (protected_player.isLoading()) { continue; }
|
||||
|
||||
int grace_period = protected_player.getGracePeriod()-1;
|
||||
protected_player.setGracePeriod(grace_period);
|
||||
if (grace_period <= 0) {
|
||||
removePlayer(protected_player.getPlayerUUID());
|
||||
System.out.println(protected_player.getPlayerUUID() + " is no longer being protected!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user