refactor some scoreboard packets

This commit is contained in:
Bixilon 2021-05-14 16:31:22 +02:00
parent 9055dba6cd
commit df9cdfa548
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
18 changed files with 395 additions and 375 deletions

View File

@ -1,45 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.scoreboard;
import java.util.HashMap;
public class ScoreboardManager {
private final HashMap<String, Team> teams = new HashMap<>();
private final HashMap<String, ScoreboardObjective> objectives = new HashMap<>();
public void addTeam(Team team) {
this.teams.put(team.getName(), team);
}
public Team getTeam(String name) {
return this.teams.get(name);
}
public void removeTeam(String name) {
this.teams.remove(name);
}
public void addObjective(ScoreboardObjective objective) {
this.objectives.put(objective.getObjectiveName(), objective);
}
public void removeObjective(String name) {
this.objectives.remove(name);
}
public ScoreboardObjective getObjective(String objective) {
return this.objectives.get(objective);
}
}

View File

@ -0,0 +1,18 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.scoreboard
class ScoreboardManager {
val teams: MutableMap<String, Team> = mutableMapOf()
val objectives: MutableMap<String, ScoreboardObjective> = mutableMapOf()
}

View File

@ -1,63 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.scoreboard;
import de.bixilon.minosoft.data.text.ChatComponent;
import java.util.HashMap;
public class ScoreboardObjective {
private final String objectiveName;
private final HashMap<String, ScoreboardScore> scores = new HashMap<>();
ChatComponent objectiveValue;
public ScoreboardObjective(String objectiveName, ChatComponent objectiveValue) {
this.objectiveName = objectiveName;
this.objectiveValue = objectiveValue;
}
public String getObjectiveName() {
return this.objectiveName;
}
public ChatComponent getObjectiveValue() {
return this.objectiveValue;
}
public HashMap<String, ScoreboardScore> getScores() {
return this.scores;
}
public void addScore(ScoreboardScore score) {
if (this.scores.containsKey(score.getItemName())) {
// update
this.scores.get(score.getItemName()).setScoreName(score.getScoreName());
this.scores.get(score.getItemName()).setScore(score.getScore());
return;
}
this.scores.put(score.getItemName(), score);
}
public void removeScore(String itemName) {
this.scores.remove(itemName);
}
public ScoreboardScore getScore(String itemName) {
return this.scores.get(itemName);
}
public void setValue(ChatComponent value) {
this.objectiveValue = value;
}
}

View File

@ -10,37 +10,15 @@
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.scoreboard
package de.bixilon.minosoft.data.scoreboard;
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.objective.CreateScoreboardObjectiveS2CP
public class ScoreboardScore {
private final String itemName;
String scoreName;
int score;
public ScoreboardScore(String itemName, String scoreName, int score) {
this.itemName = itemName;
this.scoreName = scoreName;
this.score = score;
}
public String getItemName() {
return this.itemName;
}
public String getScoreName() {
return this.scoreName;
}
public void setScoreName(String scoreName) {
this.scoreName = scoreName;
}
public int getScore() {
return this.score;
}
public void setScore(int score) {
this.score = score;
}
class ScoreboardObjective(
val name: String,
var displayName: ChatComponent,
var unit: CreateScoreboardObjectiveS2CP.ObjectiveUnits,
) {
val scores: MutableMap<String, ScoreboardScore> = mutableMapOf()
}

View File

@ -0,0 +1,15 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.scoreboard
class ScoreboardScore(val entity: String, var objective: String, var score: Int)

View File

@ -1,126 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play;
import de.bixilon.minosoft.data.scoreboard.ScoreboardObjective;
import de.bixilon.minosoft.data.text.ChatComponent;
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
import de.bixilon.minosoft.util.logging.Log;
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.*;
public class PacketScoreboardObjective extends PlayS2CPacket {
private final String name;
private final ScoreboardObjectiveActions action;
private ChatComponent value;
private ScoreboardObjectiveTypes type;
public PacketScoreboardObjective(PlayInByteBuffer buffer) {
this.name = buffer.readString();
if (buffer.getVersionId() < V_14W04A) { // ToDo
this.value = buffer.readChatComponent();
}
this.action = ScoreboardObjectiveActions.byId(buffer.readUnsignedByte());
if (this.action == ScoreboardObjectiveActions.CREATE || this.action == ScoreboardObjectiveActions.UPDATE) {
if (buffer.getVersionId() >= V_14W04A) { // ToDo
this.value = buffer.readChatComponent();
}
if (buffer.getVersionId() >= V_14W08A) {
if (buffer.getVersionId() >= V_17W47A && buffer.getVersionId() < V_17W49A) {
// got removed in these 3 versions
return;
}
if (buffer.getVersionId() < V_17W49A) {
this.type = ScoreboardObjectiveTypes.byName(buffer.readString());
} else {
this.type = ScoreboardObjectiveTypes.byId(buffer.readVarInt());
}
}
}
return;
}
@Override
public void handle(PlayConnection connection) {
switch (getAction()) {
case CREATE -> connection.getScoreboardManager().addObjective(new ScoreboardObjective(getName(), getValue()));
case UPDATE -> connection.getScoreboardManager().getObjective(getName()).setValue(getValue());
case REMOVE -> connection.getScoreboardManager().removeObjective(getName());
}
}
@Override
public void log() {
if (this.action == ScoreboardObjectiveActions.CREATE || this.action == ScoreboardObjectiveActions.UPDATE) {
Log.protocol(String.format("[IN] Received scoreboard objective action (action=%s, name=\"%s\", value=\"%s\", type=%s)", this.action, this.name, this.value.getAnsiColoredMessage(), this.type));
} else {
Log.protocol(String.format("[IN] Received scoreboard objective action (action=%s, name=\"%s\")", this.action, this.name));
}
}
public String getName() {
return this.name;
}
public ChatComponent getValue() {
return this.value;
}
public ScoreboardObjectiveActions getAction() {
return this.action;
}
public enum ScoreboardObjectiveActions {
CREATE,
REMOVE,
UPDATE;
private static final ScoreboardObjectiveActions[] SCOREBOARD_OBJECTIVE_ACTIONS = values();
public static ScoreboardObjectiveActions byId(int id) {
return SCOREBOARD_OBJECTIVE_ACTIONS[id];
}
}
public enum ScoreboardObjectiveTypes {
INTEGER("integer"),
HEARTS("hearts");
private static final ScoreboardObjectiveTypes[] SCOREBOARD_OBJECTIVE_TYPES = values();
private final String name;
ScoreboardObjectiveTypes(String name) {
this.name = name;
}
public static ScoreboardObjectiveTypes byName(String name) {
for (ScoreboardObjectiveTypes type : values()) {
if (type.getName().equals(name)) {
return type;
}
}
return null;
}
public static ScoreboardObjectiveTypes byId(int id) {
return SCOREBOARD_OBJECTIVE_TYPES[id];
}
public String getName() {
return this.name;
}
}
}

View File

@ -1,97 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play;
import de.bixilon.minosoft.data.scoreboard.ScoreboardObjective;
import de.bixilon.minosoft.data.scoreboard.ScoreboardScore;
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
import de.bixilon.minosoft.util.logging.Log;
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W04A;
public class PacketScoreboardUpdateScore extends PlayS2CPacket {
private final String itemName;
private final ScoreboardUpdateScoreActions action;
private String scoreName;
private int scoreValue;
public PacketScoreboardUpdateScore(PlayInByteBuffer buffer) {
this.itemName = buffer.readString();
this.action = ScoreboardUpdateScoreActions.byId(buffer.readUnsignedByte());
if (buffer.getVersionId() < V_14W04A) { // ToDo
if (this.action == ScoreboardUpdateScoreActions.REMOVE) {
return;
}
// not present id action == REMOVE
this.scoreName = buffer.readString();
this.scoreValue = buffer.readInt();
return;
}
this.scoreName = buffer.readString();
if (this.action == ScoreboardUpdateScoreActions.REMOVE) {
return;
}
// not present id action == REMOVE
this.scoreValue = buffer.readVarInt();
}
@Override
public void handle(PlayConnection connection) {
switch (getAction()) {
case CREATE_UPDATE -> connection.getScoreboardManager().getObjective(getScoreName()).addScore(new ScoreboardScore(getItemName(), getScoreName(), getScoreValue()));
case REMOVE -> {
ScoreboardObjective objective = connection.getScoreboardManager().getObjective(getScoreName());
if (objective != null) {
// thanks mojang
objective.removeScore(getItemName());
}
}
}
}
@Override
public void log() {
Log.protocol(String.format("[IN] Received scoreboard score update (itemName=\"%s\", action=%s, scoreName=\"%s\", scoreValue=%d", this.itemName, this.action, this.scoreName, this.scoreValue));
}
public String getItemName() {
return this.itemName;
}
public ScoreboardUpdateScoreActions getAction() {
return this.action;
}
public String getScoreName() {
return this.scoreName;
}
public int getScoreValue() {
return this.scoreValue;
}
public enum ScoreboardUpdateScoreActions {
CREATE_UPDATE,
REMOVE;
private static final ScoreboardUpdateScoreActions[] SCOREBOARD_UPDATE_SCORE_ACTIONS = values();
public static ScoreboardUpdateScoreActions byId(int id) {
return SCOREBOARD_UPDATE_SCORE_ACTIONS[id];
}
}
}

View File

@ -18,7 +18,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum
object WorldBorderS2CFactory {
object WorldBorderS2CF {
// this function was signed by Maximilian Rosenmüller
// and that means A LOT!

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play;
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard;
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play;
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard;
import de.bixilon.minosoft.data.scoreboard.Team;
import de.bixilon.minosoft.data.text.ChatCode;
@ -89,11 +89,11 @@ public class PacketTeams extends PlayS2CPacket {
@Override
public void handle(PlayConnection connection) {
switch (getAction()) {
case CREATE -> connection.getScoreboardManager().addTeam(new Team(getName(), getDisplayName(), getPrefix(), getSuffix(), isFriendlyFireEnabled(), isSeeingFriendlyInvisibles(), getPlayerNames()));
case INFORMATION_UPDATE -> connection.getScoreboardManager().getTeam(getName()).updateInformation(getDisplayName(), getPrefix(), getSuffix(), isFriendlyFireEnabled(), isSeeingFriendlyInvisibles());
case REMOVE -> connection.getScoreboardManager().removeTeam(getName());
case PLAYER_ADD -> connection.getScoreboardManager().getTeam(getName()).addPlayers(Arrays.asList(getPlayerNames()));
case PLAYER_REMOVE -> connection.getScoreboardManager().getTeam(getName()).removePlayers(Arrays.asList(getPlayerNames()));
case CREATE -> connection.getScoreboardManager().getTeams().put(getName(), new Team(getName(), getDisplayName(), getPrefix(), getSuffix(), isFriendlyFireEnabled(), isSeeingFriendlyInvisibles(), getPlayerNames()));
case INFORMATION_UPDATE -> connection.getScoreboardManager().getTeams().get(getName()).updateInformation(getDisplayName(), getPrefix(), getSuffix(), isFriendlyFireEnabled(), isSeeingFriendlyInvisibles());
case REMOVE -> connection.getScoreboardManager().getTeams().remove(getName());
case PLAYER_ADD -> connection.getScoreboardManager().getTeams().get(getName()).addPlayers(Arrays.asList(getPlayerNames()));
case PLAYER_REMOVE -> connection.getScoreboardManager().getTeams().get(getName()).removePlayers(Arrays.asList(getPlayerNames()));
}
}

View File

@ -0,0 +1,71 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.objective
import de.bixilon.minosoft.data.scoreboard.ScoreboardObjective
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class CreateScoreboardObjectiveS2CP(val objective: String, private var _displayName: ChatComponent?, buffer: PlayInByteBuffer) : PlayS2CPacket() {
val displayName: ChatComponent
get() = _displayName!!
var unit: ObjectiveUnits = ObjectiveUnits.INTEGER
private set
init {
if (buffer.versionId >= ProtocolVersions.V_14W04A) { // ToDo
this._displayName = buffer.readChatComponent()
}
if (buffer.versionId >= ProtocolVersions.V_14W08A) {
when {
buffer.versionId >= ProtocolVersions.V_17W47A && buffer.versionId < ProtocolVersions.V_17W49A -> {
}
buffer.versionId < ProtocolVersions.V_17W49A -> {
unit = ObjectiveUnits[buffer.readString()]
}
else -> {
unit = ObjectiveUnits[buffer.readVarInt()]
}
}
}
}
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Create scoreboard objective (objective=$objective, displayName=$displayName, unit=$unit)" }
}
override fun handle(connection: PlayConnection) {
connection.scoreboardManager.objectives[objective] = ScoreboardObjective(objective, displayName, unit)
}
enum class ObjectiveUnits {
INTEGER,
HEARTS,
;
companion object : ValuesEnum<ObjectiveUnits> {
override val VALUES: Array<ObjectiveUnits> = values()
override val NAME_MAP: Map<String, ObjectiveUnits> = KUtil.getEnumValues(VALUES)
}
}
}

View File

@ -0,0 +1,33 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.objective
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class RemoveScoreboardObjectiveS2CP(val objective: String, buffer: PlayInByteBuffer) : PlayS2CPacket() {
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Remove scoreboard objective (objective=$objective)" }
}
override fun handle(connection: PlayConnection) {
connection.scoreboardManager.objectives.remove(objective)
}
}

View File

@ -0,0 +1,50 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.objective
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.score.RemoveScoreboardScoreS2CP
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum
object ScoreboardObjectiveS2CF {
fun createPacket(buffer: PlayInByteBuffer): PlayS2CPacket {
val objective = buffer.readString()
val displayName = if (buffer.versionId < ProtocolVersions.V_14W04A) { // ToDo
buffer.readChatComponent()
} else {
null
}
return when (ScoreboardScoreActions[buffer.readUnsignedByte()]) {
ScoreboardScoreActions.CREATE -> CreateScoreboardObjectiveS2CP(objective, displayName, buffer)
ScoreboardScoreActions.REMOVE -> RemoveScoreboardScoreS2CP(objective, buffer)
ScoreboardScoreActions.UPDATE -> UpdateScoreboardObjectiveS2CP(objective, displayName, buffer)
}
}
enum class ScoreboardScoreActions {
CREATE,
REMOVE,
UPDATE,
;
companion object : ValuesEnum<ScoreboardScoreActions> {
override val VALUES: Array<ScoreboardScoreActions> = values()
override val NAME_MAP: Map<String, ScoreboardScoreActions> = KUtil.getEnumValues(VALUES)
}
}
}

View File

@ -0,0 +1,59 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.objective
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class UpdateScoreboardObjectiveS2CP(val objective: String, private var _displayName: ChatComponent?, buffer: PlayInByteBuffer) : PlayS2CPacket() {
val displayName: ChatComponent
get() = _displayName!!
var unit: CreateScoreboardObjectiveS2CP.ObjectiveUnits = CreateScoreboardObjectiveS2CP.ObjectiveUnits.INTEGER
private set
init {
if (buffer.versionId >= ProtocolVersions.V_14W04A) { // ToDo
this._displayName = buffer.readChatComponent()
}
if (buffer.versionId >= ProtocolVersions.V_14W08A) {
when {
buffer.versionId >= ProtocolVersions.V_17W47A && buffer.versionId < ProtocolVersions.V_17W49A -> {
}
buffer.versionId < ProtocolVersions.V_17W49A -> {
unit = CreateScoreboardObjectiveS2CP.ObjectiveUnits[buffer.readString()]
}
else -> {
unit = CreateScoreboardObjectiveS2CP.ObjectiveUnits[buffer.readVarInt()]
}
}
}
}
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Update scoreboard objective (objective=$objective, displayName=$displayName, unit=$unit)" }
}
override fun handle(connection: PlayConnection) {
connection.scoreboardManager.objectives[objective]?.let {
it.displayName = displayName
it.unit = unit
}
}
}

View File

@ -0,0 +1,41 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.score
import de.bixilon.minosoft.data.scoreboard.ScoreboardScore
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class PutScoreboardScoreS2CP(val entity: String, buffer: PlayInByteBuffer) : PlayS2CPacket() {
val objective = buffer.readString()
val score: Int = if (buffer.versionId < ProtocolVersions.V_14W04A) { // ToDo
buffer.readInt()
} else {
buffer.readVarInt()
}
override fun handle(connection: PlayConnection) {
connection.scoreboardManager.objectives[objective]?.scores?.put(entity, ScoreboardScore(entity, objective, score))
}
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Put scoreboard score (entity=$entity, objective=$objective, score=$score)" }
}
}

View File

@ -0,0 +1,41 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.score
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
class RemoveScoreboardScoreS2CP(val entity: String, buffer: PlayInByteBuffer) : PlayS2CPacket() {
val objective = if (buffer.versionId >= ProtocolVersions.V_14W04A) { // ToDo
buffer.readString()
} else {
null
}
override fun handle(connection: PlayConnection) {
objective?.let {
connection.scoreboardManager.objectives[objective]?.scores?.remove(entity)
} ?: TODO()
}
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Remove scoreboard score (entity=$entity, objective=$objective)" }
}
}

View File

@ -0,0 +1,41 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.score
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum
object ScoreboardScoreS2CF {
fun createPacket(buffer: PlayInByteBuffer): PlayS2CPacket {
val entity = buffer.readString()
return when (ScoreboardScoreActions[buffer.readUnsignedByte()]) {
ScoreboardScoreActions.PUT -> PutScoreboardScoreS2CP(entity, buffer)
ScoreboardScoreActions.REMOVE -> RemoveScoreboardScoreS2CP(entity, buffer)
}
}
enum class ScoreboardScoreActions {
PUT,
REMOVE,
;
companion object : ValuesEnum<ScoreboardScoreActions> {
override val VALUES: Array<ScoreboardScoreActions> = values()
override val NAME_MAP: Map<String, ScoreboardScoreActions> = KUtil.getEnumValues(VALUES)
}
}
}

View File

@ -42,6 +42,10 @@ import de.bixilon.minosoft.protocol.packets.s2c.play.combat.CombatEventEndS2CP
import de.bixilon.minosoft.protocol.packets.s2c.play.combat.CombatEventEnterS2CP
import de.bixilon.minosoft.protocol.packets.s2c.play.combat.CombatEventKillS2CP
import de.bixilon.minosoft.protocol.packets.s2c.play.combat.CombatEventS2CF
import de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.PacketScoreboardDisplayScoreboard
import de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.PacketTeams
import de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.objective.ScoreboardObjectiveS2CF
import de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.score.ScoreboardScoreS2CF
import de.bixilon.minosoft.protocol.packets.s2c.play.title.*
import de.bixilon.minosoft.protocol.packets.s2c.status.PacketStatusResponse
import de.bixilon.minosoft.protocol.packets.s2c.status.StatusPongS2CP
@ -216,7 +220,7 @@ class PacketTypes {
PLAY_RESPAWN({ RespawnS2CP(it) }, isThreadSafe = false),
PLAY_ENTITY_HEAD_ROTATION({ EntityHeadRotationS2CP(it) }),
PLAY_SELECT_ADVANCEMENT_TAB({ PacketSelectAdvancementTab(it) }),
PLAY_WORLD_BORDER({ WorldBorderS2CFactory.createPacket(it) }),
PLAY_WORLD_BORDER({ WorldBorderS2CF.createPacket(it) }),
PLAY_WORLD_BORDER_INITIALIZE({ InitializeWorldBorderS2CPacket(it) }),
PLAY_WORLD_BORDER_SET_CENTER({ SetCenterWorldBorderS2CPacket(it) }),
PLAY_WORLD_BORDER_LERP_SIZE({ LerpSizeWorldBorderS2CPacket(it) }),
@ -233,10 +237,10 @@ class PacketTypes {
PLAY_ENTITY_EQUIPMENT({ EntityEquipmentS2CP(it) }),
PLAY_EXPERIENCE_SET({ ExperienceSetS2CP(it) }),
PLAY_HEALTH_SET({ HealthSetS2CP(it) }),
PLAY_SCOREBOARD_OBJECTIVE({ PacketScoreboardObjective(it) }),
PLAY_SCOREBOARD_OBJECTIVE({ ScoreboardObjectiveS2CF.createPacket(it) }),
PLAY_ENTITY_PASSENGER_SET({ EntityPassengerSetS2CP(it) }),
PLAY_TEAMS({ PacketTeams(it) }),
PLAY_UPDATE_SCORE({ PacketScoreboardUpdateScore(it) }),
PLAY_UPDATE_SCORE({ ScoreboardScoreS2CF.createPacket(it) }),
PLAY_SPAWN_POSITION_SET({ SpawnPositionSetS2CP(it) }),
PLAY_WORLD_TIME_SET({ WorldTimeSetS2CP(it) }),
PLAY_ENTITY_SOUND_EVENT({ EntitySoundEventS2CP(it) }),