Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoreboard Fix #4

Merged
merged 12 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public boolean handle(LoginPacket loginPacket) {
return true;
}

session.getUpstream().setPacketCodec(GeyserConnector.BEDROCK_PACKET_CODEC);

try {
JSONObject chainData = (JSONObject) JSONValue.parse(loginPacket.getChainData().array());
JSONArray chainArray = (JSONArray) chainData.get("chain");
Expand All @@ -82,6 +80,7 @@ public boolean handle(LoginPacket loginPacket) {

ResourcePacksInfoPacket resourcePacksInfo = new ResourcePacksInfoPacket();
session.getUpstream().sendPacketImmediately(resourcePacksInfo);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package org.geysermc.connector.network.session;

import com.github.steveice10.mc.auth.exception.request.RequestException;
import com.github.steveice10.mc.protocol.MinecraftProtocol;
import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector3i;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ObjectiveAction;
import com.github.steveice10.mc.protocol.data.message.ChatFormat;
import com.github.steveice10.mc.protocol.data.message.TranslationMessage;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
Expand Down Expand Up @@ -311,7 +312,7 @@ public static void addScoreboardPackets() {
objective.setDisplaySlot(ScoreboardObjective.DisplaySlot.SIDEBAR);
objective.setDisplayName(packet.getDisplayName().getFullText());
} else {
scoreboard.unregisterObjective(packet.getDisplayName().getFullText());
scoreboard.unregisterObjective(packet.getName());
}

scoreboard.onUpdate();
Expand All @@ -336,10 +337,10 @@ public static void addScoreboardPackets() {
System.out.println(packet.getEntry() + " <-> objective = " + packet.getObjective() + " val " + packet.getValue());
switch (packet.getAction()) {
case REMOVE:
objective.registerScore(packet.getObjective(), packet.getEntry(), packet.getValue(), SetScorePacket.Action.REMOVE);
objective.registerScore(packet.getEntry(), packet.getEntry(), packet.getValue(), SetScorePacket.Action.REMOVE);
break;
case ADD_OR_UPDATE:
objective.registerScore(packet.getObjective(), packet.getEntry(), packet.getValue(), SetScorePacket.Action.SET);
objective.registerScore(packet.getEntry(), packet.getEntry(), packet.getValue(), SetScorePacket.Action.SET);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.nukkitx.protocol.bedrock.packet.SetDisplayObjectivePacket;
import com.nukkitx.protocol.bedrock.packet.SetScorePacket;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.connector.network.session.GeyserSession;

import java.util.Arrays;
Expand All @@ -47,7 +48,10 @@ public class Scoreboard {

private GeyserSession session;

@Getter
@Setter
private long id;

private Map<String, ScoreboardObjective> objectiveMap = new HashMap<String, ScoreboardObjective>();

public Scoreboard(GeyserSession session) {
Expand Down Expand Up @@ -101,7 +105,7 @@ public void onUpdate() {
displayObjectivePacket.setObjectiveId(objective.getObjectiveName());
displayObjectivePacket.setDisplayName(objective.getDisplayName());
displayObjectivePacket.setCriteria("dummy");
displayObjectivePacket.setDisplaySlot(ScoreboardObjective.DisplaySlot.SIDEBAR.name());
displayObjectivePacket.setDisplaySlot("sidebar");
displayObjectivePacket.setSortOrder(1);
session.getUpstream().sendPacket(displayObjectivePacket);

Expand All @@ -110,7 +114,8 @@ public void onUpdate() {
fakeMap.put(entry.getKey(), entry.getValue());
}

for (Score score : fakeMap.values()) {
for (String string : fakeMap.keySet()) {
Score score = fakeMap.get(string);
ScoreInfo scoreInfo = new ScoreInfo(score.getScoreboardId(), objective.getObjectiveName(), score.getScore(), score.getFakeId());

SetScorePacket setScorePacket = new SetScorePacket();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,11 @@ public void setScore(String id, int value) {

public void setScoreText(String id, String text) {
if (scores.containsKey(id)) {
Score oldScore = scores.get(id);
oldScore.setAction(SetScorePacket.Action.REMOVE);
oldScore.setFakeId(id + "_old_changed");

Score newScore = new Score(this, text);
newScore.setScore(oldScore.getScore());
newScore.setScore(scores.get(id).getScore());
newScore.setFakeId(id);
scores.remove(id);
scores.put(id, newScore);
scores.put(id + "_old_changed", oldScore);
}
}

Expand Down
3 changes: 3 additions & 0 deletions connector/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ remote:
# The port of the remote (Java Edition) server
port: 25565
online-mode: false
#Online Mode Credentials -Logicism
email: [email protected]
password: password

# Relay the MOTD, player count and max players from the remote server
ping-passthrough: false
Expand Down