Added new data class for list of protected players. Created new event for entities getting damaged and made it so that protected players don't take damage.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.micle.loginprotection;
|
||||
|
||||
import com.micle.loginprotection.data.ProtectedPlayer;
|
||||
import com.micle.loginprotection.data.ProtectedPlayers;
|
||||
import com.micle.loginprotection.setup.Registration;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@ -11,7 +12,7 @@ import java.util.List;
|
||||
@Mod(LoginProtection.MOD_ID)
|
||||
public class LoginProtection {
|
||||
public static final String MOD_ID = "loginprotection";
|
||||
public static List<ProtectedPlayer> protected_players = new ArrayList<>();
|
||||
public static ProtectedPlayers protected_players = new ProtectedPlayers();
|
||||
|
||||
public LoginProtection() {
|
||||
Registration.register();
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.micle.loginprotection.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ProtectedPlayers {
|
||||
private final List<ProtectedPlayer> protected_players = new ArrayList<>();
|
||||
|
||||
public ProtectedPlayers() { }
|
||||
|
||||
public void addPlayer(UUID player_uuid) {
|
||||
protected_players.add(new ProtectedPlayer(player_uuid));
|
||||
}
|
||||
|
||||
public ProtectedPlayer getPlayer(UUID player_uuid) {
|
||||
ProtectedPlayer player = null;
|
||||
for (ProtectedPlayer protected_player : protected_players) {
|
||||
player = protected_player;
|
||||
if (player.getPlayerUUID() == player_uuid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.micle.loginprotection.events;
|
||||
|
||||
import com.micle.loginprotection.LoginProtection;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDamageEvent;
|
||||
|
||||
public class OnEntityDamageEventHandler {
|
||||
@SubscribeEvent
|
||||
public void LivingDamageEvent(LivingDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof PlayerEntity)) { return; }
|
||||
PlayerEntity player = (PlayerEntity) event.getEntity();
|
||||
|
||||
if (LoginProtection.protected_players.getPlayer(player.getUUID()) != null) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,6 @@ public class OnEntityJoinEventHandler {
|
||||
if (!(event.getEntity() instanceof PlayerEntity)) { return; }
|
||||
PlayerEntity player = (PlayerEntity) event.getEntity();
|
||||
|
||||
LoginProtection.protected_players.add(new ProtectedPlayer(player.getUUID()));
|
||||
LoginProtection.protected_players.addPlayer(player.getUUID());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.micle.loginprotection.setup;
|
||||
|
||||
import com.micle.loginprotection.events.OnEntityDamageEventHandler;
|
||||
import com.micle.loginprotection.events.OnEntityJoinEventHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
@ -10,5 +11,6 @@ public class Registration {
|
||||
IEventBus mod_event_bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new OnEntityJoinEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new OnEntityDamageEventHandler());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user