Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
ping server event cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 29, 2017
1 parent bdee8a9 commit 9cf6938
Showing 1 changed file with 7 additions and 5 deletions.
Expand Up @@ -6,6 +6,7 @@
import com.denizenscript.denizen2core.tags.objects.IntegerTag;
import com.denizenscript.denizen2core.tags.objects.TextTag;
import com.denizenscript.denizen2core.utilities.debugging.Debug;
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.server.ClientPingServerEvent;
Expand Down Expand Up @@ -61,15 +62,16 @@ public boolean matches(ScriptEventData data) {

public TextTag version;

// TODO: FormattedTextTag!
public TextTag motd;
public FormattedTextTag motd;

public IntegerTag num_players;

public IntegerTag max_players;

public ClientPingServerEvent internal;

// TODO: Thread safety!

@Override
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEventData data) {
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data);
Expand Down Expand Up @@ -99,7 +101,7 @@ public void onClientPingServer(ClientPingServerEvent evt) {
ClientPingServerEvent.Response response = evt.getResponse();
event.address = new TextTag(client.getAddress().toString());
event.version = new TextTag(client.getVersion().getName());
event.motd = new TextTag(response.getDescription().toPlain());
event.motd = new FormattedTextTag(response.getDescription());
Optional<ClientPingServerEvent.Response.Players> optPlayers = response.getPlayers();
int numPlayers = 0;
int maxPlayers = 0;
Expand All @@ -117,8 +119,8 @@ public void onClientPingServer(ClientPingServerEvent evt) {
@Override
public void applyDetermination(boolean errors, String determination, AbstractTagObject value) {
if (determination.equals("motd")) {
motd = new TextTag(value.toString());
internal.getResponse().setDescription(Text.of(motd.toString()));
motd = FormattedTextTag.getFor(this::error, value);
internal.getResponse().setDescription(motd.getInternal());
}
else if (determination.equals("max_players")) {
max_players = IntegerTag.getFor(this::error, value);
Expand Down

0 comments on commit 9cf6938

Please sign in to comment.