From 80c46bb5a22754cbd5b000c44bd4dd22f6d1a567 Mon Sep 17 00:00:00 2001 From: blackassasin1234 <40329996+blackassasin1234@users.noreply.github.com> Date: Sat, 23 Nov 2019 08:56:00 +0700 Subject: [PATCH] Added some Events (#1096) * Added PlayerBanEvent, PlayerUnbanEvent, PlayerIpBanEvent, and PlayerIpUnbanEvent. * Removed Unecessary import (oops) * Formatted code * Fixed a little oopsie * Prevent NPE * add another line.. --- .../io/anuke/mindustry/game/EventType.java | 46 ++++++++++++++++--- .../anuke/mindustry/net/Administration.java | 15 ++++-- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/core/src/io/anuke/mindustry/game/EventType.java b/core/src/io/anuke/mindustry/game/EventType.java index ac56c86b6e..6be6f78b1b 100644 --- a/core/src/io/anuke/mindustry/game/EventType.java +++ b/core/src/io/anuke/mindustry/game/EventType.java @@ -138,7 +138,7 @@ public class EventType{ public final Player player; public final Item item; public final int amount; - + public DepositEvent(Tile tile, Player player, Item item, int amount){ this.tile = tile; this.player = player; @@ -146,7 +146,7 @@ public class EventType{ this.amount = amount; } } - + /** Called when the player taps a block. */ public static class TapEvent{ public final Tile tile; @@ -157,7 +157,7 @@ public class EventType{ this.player = player; } } - + /** Called when the player sets a specific block. */ public static class TapConfigEvent{ public final Tile tile; @@ -310,7 +310,7 @@ public class EventType{ /** Called after connecting; when a player recieves world data and is ready to play.*/ public static class PlayerJoin{ public final Player player; - + public PlayerJoin(Player player){ this.player = player; } @@ -327,11 +327,45 @@ public class EventType{ public static class PlayerLeave{ public final Player player; - + public PlayerLeave(Player player){ this.player = player; } } - + + public static class PlayerBanEvent{ + public final Player player; + + public PlayerBanEvent(Player player){ + this.player = player; + } + } + + public static class PlayerUnbanEvent{ + public final Player player; + + public PlayerUnbanEvent(Player player){ + this.player = player; + } + } + + public static class PlayerIpBanEvent{ + public final String ip; + + + public PlayerIpBanEvent(String ip){ + this.ip = ip; + } + } + + public static class PlayerIpUnbanEvent{ + public final String ip; + + + public PlayerIpUnbanEvent(String ip){ + this.ip = ip; + } + } + } diff --git a/core/src/io/anuke/mindustry/net/Administration.java b/core/src/io/anuke/mindustry/net/Administration.java index 0aaeb8542f..f7815e03d2 100644 --- a/core/src/io/anuke/mindustry/net/Administration.java +++ b/core/src/io/anuke/mindustry/net/Administration.java @@ -3,8 +3,11 @@ package io.anuke.mindustry.net; import io.anuke.annotations.Annotations.*; import io.anuke.arc.*; import io.anuke.arc.collection.*; +import io.anuke.mindustry.Vars; + import static io.anuke.mindustry.Vars.headless; +import static io.anuke.mindustry.game.EventType.*; public class Administration{ /** All player info. Maps UUIDs to info. This persists throughout restarts. */ @@ -76,7 +79,7 @@ public class Administration{ bannedIPs.add(ip); save(); - + Events.fire(new PlayerIpBanEvent(ip)); return true; } @@ -88,7 +91,7 @@ public class Administration{ getCreateInfo(id).banned = true; save(); - + Events.fire(new PlayerBanEvent(Vars.playerGroup.find(p -> id.equals(p.uuid)))); return true; } @@ -108,8 +111,10 @@ public class Administration{ bannedIPs.removeValue(ip, false); - if(found) save(); - + if(found){ + save(); + Events.fire(new PlayerIpUnbanEvent(ip)); + } return found; } @@ -126,7 +131,7 @@ public class Administration{ info.banned = false; bannedIPs.removeAll(info.ips, false); save(); - + Events.fire(new PlayerUnbanEvent(Vars.playerGroup.find(p -> id.equals(p.uuid)))); return true; }