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..
This commit is contained in:
blackassasin1234
2019-11-23 08:56:00 +07:00
committed by Anuken
parent cb29bee8f5
commit 80c46bb5a2
2 changed files with 50 additions and 11 deletions

View File

@@ -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;
}
}
}

View File

@@ -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;
}