-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: ScoreboardListener to fix a bypass possible when to players wh…
…ere in the same minecraft team with a scoreboard enabled
- Loading branch information
Showing
5 changed files
with
61 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...java/com/deathmotion/antihealthindicator/packetlisteners/spoofers/ScoreboardListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.deathmotion.antihealthindicator.packetlisteners.spoofers; | ||
|
||
import com.deathmotion.antihealthindicator.AHIPlatform; | ||
import com.github.retrooper.packetevents.event.PacketListenerAbstract; | ||
import com.github.retrooper.packetevents.event.PacketSendEvent; | ||
import com.github.retrooper.packetevents.protocol.packettype.PacketType; | ||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerScoreboardObjective; | ||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateScore; | ||
|
||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class ScoreboardListener<P> extends PacketListenerAbstract { | ||
private final AHIPlatform<P> platform; | ||
|
||
// Use ConcurrentHashMap's KeySet for a thread-safe Set | ||
private final Set<String> healthObjectives = ConcurrentHashMap.newKeySet(); | ||
|
||
/** | ||
* Constructs a new EntityMetadataListener with the specified {@link AHIPlatform}. | ||
* | ||
* @param platform The platform to use. | ||
*/ | ||
public ScoreboardListener(AHIPlatform<P> platform) { | ||
this.platform = platform; | ||
|
||
platform.getLogManager().debug("Update Objective Listener initialized."); | ||
} | ||
|
||
@Override | ||
public void onPacketSend(PacketSendEvent event) { | ||
if (event.getPacketType().equals(PacketType.Play.Server.SCOREBOARD_OBJECTIVE)) { | ||
WrapperPlayServerScoreboardObjective packet = new WrapperPlayServerScoreboardObjective(event); | ||
WrapperPlayServerScoreboardObjective.RenderType renderType = packet.getRenderType(); | ||
|
||
if (renderType == WrapperPlayServerScoreboardObjective.RenderType.HEARTS) { | ||
healthObjectives.add(packet.getName()); | ||
} | ||
} | ||
|
||
if (event.getPacketType().equals(PacketType.Play.Server.UPDATE_SCORE)) { | ||
WrapperPlayServerUpdateScore packet = new WrapperPlayServerUpdateScore(event); | ||
|
||
// Check if the value is present and then compare | ||
if (healthObjectives.contains(packet.getObjectiveName()) && packet.getValue().isPresent()) { | ||
packet.setValue(Optional.of(-1)); | ||
event.markForReEncode(true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters