Skip to content

Commit

Permalink
Fix score reset not being sent when objective is null
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Jun 26, 2024
1 parent 3c97303 commit 4562bab
Showing 1 changed file with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
package com.velocitypowered.proxy.data;

import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.scoreboard.ProxyObjective;
import com.velocitypowered.api.scoreboard.ProxyTeam;
import com.velocitypowered.api.scoreboard.ScoreboardManager;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.backend.BackendPlaySessionHandler;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.protocol.packet.scoreboard.*;
import com.velocitypowered.proxy.scoreboard.VelocityObjective;
import com.velocitypowered.proxy.scoreboard.VelocityScoreboard;
import com.velocitypowered.proxy.scoreboard.VelocityScoreboardManager;
import com.velocitypowered.proxy.scoreboard.VelocityTeam;
import com.velocitypowered.proxy.scoreboard.*;
import com.velocitypowered.proxy.scoreboard.downstream.DownstreamScoreboard;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -139,14 +137,18 @@ public static boolean handle(@NotNull MinecraftSessionHandler handler, @NotNull
if (getDownstream(handler).handle(packet)) return true;

if (packet.getObjectiveName() == null) {
// Remove from all objectives, cancel for now //TODO
return true;
}

VelocityObjective objective = getProxy(handler).getObjective(packet.getObjectiveName()); // TODO Nullable on remove on 1.7.x, fix
if (objective != null) {
// Proxy is occupying this objective, cancel packet
return true;
// Null objective removes from all objectives, add back what was set by proxy
for (ProxyObjective objective : getProxy(handler).getObjectives()) {
VelocityScore score = (VelocityScore) objective.getScore(packet.getScoreHolder());
if (score != null) score.sendUpdate();
}
return false;
} else {
VelocityObjective objective = getProxy(handler).getObjective(packet.getObjectiveName());
if (objective != null) {
// Proxy is occupying this objective, cancel packet
return true;
}
}

return false;
Expand All @@ -166,13 +168,18 @@ public static boolean handle(@NotNull MinecraftSessionHandler handler, @NotNull
if (getDownstream(handler).handle(packet)) return true;

if (packet.getObjectiveName() == null) {
// Remove from all objectives, cancel for now //TODO
return true;
}
VelocityObjective objective = getProxy(handler).getObjective(packet.getObjectiveName());
if (objective != null) {
// Proxy is occupying this objective, cancel packet
return true;
// Null objective removes from all objectives, add back what was set by proxy
for (ProxyObjective objective : getProxy(handler).getObjectives()) {
VelocityScore score = (VelocityScore) objective.getScore(packet.getScoreHolder());
if (score != null) score.sendUpdate();
}
return false;
} else {
VelocityObjective objective = getProxy(handler).getObjective(packet.getObjectiveName());
if (objective != null) {
// Proxy is occupying this objective, cancel packet
return true;
}
}

return false;
Expand Down

0 comments on commit 4562bab

Please sign in to comment.