-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
522 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/cn/nukkit/network/protocol/RemoveObjectivePacket.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,27 @@ | ||
package cn.nukkit.network.protocol; | ||
|
||
import lombok.ToString; | ||
|
||
@ToString | ||
public class RemoveObjectivePacket extends DataPacket { | ||
|
||
public static final byte NETWORK_ID = ProtocolInfo.REMOVE_OBJECTIVE_PACKET; | ||
|
||
public String objectiveId; | ||
|
||
@Override | ||
public byte pid() { | ||
return NETWORK_ID; | ||
} | ||
|
||
@Override | ||
public void decode() { | ||
this.decodeUnsupported(); | ||
} | ||
|
||
@Override | ||
public void encode() { | ||
this.reset(); | ||
this.putString(this.objectiveId); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/cn/nukkit/network/protocol/SetDisplayObjectivePacket.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,36 @@ | ||
package cn.nukkit.network.protocol; | ||
|
||
import cn.nukkit.scoreboard.Scoreboard; | ||
import lombok.ToString; | ||
|
||
@ToString | ||
public class SetDisplayObjectivePacket extends DataPacket { | ||
|
||
public static final byte NETWORK_ID = ProtocolInfo.SET_DISPLAY_OBJECTIVE_PACKET; | ||
|
||
public Scoreboard.DisplaySlot displaySlot; | ||
public String objectiveId; | ||
public String displayName; | ||
public String criteria; | ||
public Scoreboard.SortOrder sortOrder; | ||
|
||
@Override | ||
public byte pid() { | ||
return NETWORK_ID; | ||
} | ||
|
||
@Override | ||
public void decode() { | ||
this.decodeUnsupported(); | ||
} | ||
|
||
@Override | ||
public void encode() { | ||
this.reset(); | ||
this.putString(this.displaySlot.getType()); | ||
this.putString(this.objectiveId); | ||
this.putString(this.displayName); | ||
this.putString(this.criteria); | ||
this.putVarInt(this.sortOrder.ordinal()); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/main/java/cn/nukkit/network/protocol/SetScorePacket.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,118 @@ | ||
package cn.nukkit.network.protocol; | ||
|
||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
@ToString | ||
public class SetScorePacket extends DataPacket { | ||
|
||
public static final byte NETWORK_ID = ProtocolInfo.SET_SCORE_PACKET; | ||
|
||
public Action action; | ||
public final List<ScoreInfo> infos = new ObjectArrayList<>(); | ||
|
||
@Override | ||
public byte pid() { | ||
return NETWORK_ID; | ||
} | ||
|
||
@Override | ||
public void decode() { | ||
this.decodeUnsupported(); | ||
} | ||
|
||
@Override | ||
public void encode() { | ||
this.reset(); | ||
this.putByte((byte) this.action.ordinal()); | ||
this.putUnsignedVarInt(this.infos.size()); | ||
|
||
for (ScoreInfo info : this.infos) { | ||
this.putVarLong(info.scoreboardId); | ||
this.putString(info.objectiveId); | ||
this.putLInt(info.score); | ||
|
||
if (this.action == Action.SET) { | ||
this.putByte((byte) info.type.ordinal()); | ||
|
||
switch (info.type) { | ||
case PLAYER: | ||
case ENTITY: | ||
this.putEntityUniqueId(info.entityId); | ||
break; | ||
case FAKE: | ||
this.putString(info.name); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Invalid score info type"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public enum Action { | ||
SET, | ||
REMOVE | ||
} | ||
|
||
@Getter | ||
@EqualsAndHashCode | ||
@ToString | ||
public static class ScoreInfo { | ||
|
||
private final long scoreboardId; | ||
private final String objectiveId; | ||
private final int score; | ||
private final ScorerType type; | ||
private final String name; | ||
private final long entityId; | ||
|
||
/** | ||
* Score info for fake player | ||
* @param scoreboardId | ||
* @param objectiveId | ||
* @param score score | ||
* @param name line text | ||
*/ | ||
public ScoreInfo(long scoreboardId, String objectiveId, int score, String name) { | ||
this.scoreboardId = scoreboardId; | ||
this.objectiveId = objectiveId; | ||
this.score = score; | ||
this.type = ScorerType.FAKE; | ||
this.name = name; | ||
this.entityId = -1; | ||
} | ||
|
||
/** | ||
* Score info for player/entity | ||
* @param scoreboardId | ||
* @param objectiveId | ||
* @param type entity type; PLAYER or ENTITY | ||
* @param score score | ||
* @param entityId entity id | ||
*/ | ||
public ScoreInfo(long scoreboardId, String objectiveId, int score, ScorerType type, long entityId) { | ||
if (type != ScorerType.PLAYER && type != ScorerType.ENTITY) { | ||
throw new IllegalArgumentException("Scorer type must be either PLAYER or ENTITY"); | ||
} | ||
|
||
this.scoreboardId = scoreboardId; | ||
this.objectiveId = objectiveId; | ||
this.score = score; | ||
this.type = type; | ||
this.name = null; | ||
this.entityId = entityId; | ||
} | ||
|
||
public enum ScorerType { | ||
INVALID, | ||
PLAYER, | ||
ENTITY, | ||
FAKE | ||
} | ||
} | ||
} |
Oops, something went wrong.