1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-21 13:28:12 +03:00

Extra events (#630)

* eventype player join

* playerjoin event

* player leave

* player leave event

* typo

* remove

* leave fix
This commit is contained in:
J-VdS 2019-09-03 01:37:38 +02:00 committed by Anuken
parent e640042e5d
commit ef0b56eb22
2 changed files with 24 additions and 3 deletions

View File

@ -20,7 +20,7 @@ import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
import io.anuke.mindustry.entities.traits.Entity;
import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.gen.Call;
@ -74,7 +74,7 @@ public class NetServer implements ApplicationListener{
});
Net.handleServer(Disconnect.class, (id, packet) -> {
Player player = connections.get(id);
Player player = connections.get(id);
if(player != null){
onDisconnect(player, packet.reason);
}
@ -185,6 +185,8 @@ public class NetServer implements ApplicationListener{
sendWorldData(player, id);
platform.updateRPC();
Events.fire(new PlayerJoin(player));
});
Net.handleServer(InvokePacket.class, (id, packet) -> {
@ -402,8 +404,9 @@ public class NetServer implements ApplicationListener{
}
if(player.con.hasConnected){
Events.fire(new PlayerLeave(player));
Call.sendMessage("[accent]" + player.name + "[accent] has disconnected.");
Call.onPlayerDisconnect(player.id);
Call.onPlayerDisconnect(player.id);
}
player.remove();
netServer.connections.remove(player.con.id);

View File

@ -5,6 +5,7 @@ import io.anuke.mindustry.entities.traits.BuilderTrait;
import io.anuke.mindustry.entities.type.Unit;
import io.anuke.mindustry.type.Zone;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.entities.type.Player;
public class EventType{
@ -184,5 +185,22 @@ public class EventType{
public static class ResizeEvent{
}
public static class PlayerJoin{
public final Player player;
public PlayerJoin(Player player){
this.player = player;
}
}
public static class PlayerLeave{
public final Player player;
public PlayerLeave(Player player){
this.player = player;
}
}
}