BlockAction and BlockEntity, remove some more exceptions

This commit is contained in:
Bixilon 2020-06-24 23:44:13 +02:00
parent f0c2c4ff4c
commit 9b0e9b6bd6
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 60 additions and 17 deletions

View File

@ -210,7 +210,7 @@ public class Connection {
serverVersion = buffer.readString(); serverVersion = buffer.readString();
toSend.writeString(clientVersion); toSend.writeString(clientVersion);
} }
Log.info(String.format("Server is running %s, connected with %s", serverVersion, getVersion().getName())); Log.info(String.format("Server is running \"%s\", connected with %s", serverVersion, getVersion().getName()));
getPluginChannelHandler().sendRawData(DefaultPluginChannels.MC_BRAND.getName(), toSend); getPluginChannelHandler().sendRawData(DefaultPluginChannels.MC_BRAND.getName(), toSend);
}); });

View File

@ -35,7 +35,13 @@ public class PacketBlockAction implements ClientboundPacket {
public void read(InPacketBuffer buffer, ProtocolVersion v) { public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
case VERSION_1_8:
// that's the only difference here
if (v.getVersion() >= ProtocolVersion.VERSION_1_8.getVersion()) {
position = buffer.readPosition();
} else {
position = buffer.readBlockPositionShort(); position = buffer.readBlockPositionShort();
}
byte byte1 = buffer.readByte(); byte byte1 = buffer.readByte();
byte byte2 = buffer.readByte(); byte byte2 = buffer.readByte();
Class<? extends BlockAction> clazz; Class<? extends BlockAction> clazz;
@ -65,8 +71,6 @@ public class PacketBlockAction implements ClientboundPacket {
} }
break; break;
case VERSION_1_8:
//ToDO
} }
} }

View File

@ -23,7 +23,8 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketBlockEntityMetadata implements ClientboundPacket { public class PacketBlockEntityMetadata implements ClientboundPacket {
BlockPosition position; BlockPosition position;
Action action; Action_1_7_10 action_1_7_10;
Action_1_8 action_1_8;
CompoundTag nbt; CompoundTag nbt;
@ -32,12 +33,12 @@ public class PacketBlockEntityMetadata implements ClientboundPacket {
switch (v) { switch (v) {
case VERSION_1_7_10: case VERSION_1_7_10:
position = buffer.readBlockPositionShort(); position = buffer.readBlockPositionShort();
action = Action.byId(buffer.readByte()); action_1_7_10 = Action_1_7_10.byId(buffer.readByte());
nbt = buffer.readNBT(true); nbt = buffer.readNBT(true);
break; break;
case VERSION_1_8: case VERSION_1_8:
position = buffer.readPosition(); position = buffer.readPosition();
action = Action.byId(buffer.readByte()); action_1_8 = Action_1_8.byId(buffer.readByte());
nbt = buffer.readNBT(); nbt = buffer.readNBT();
break; break;
} }
@ -45,7 +46,7 @@ public class PacketBlockEntityMetadata implements ClientboundPacket {
@Override @Override
public void log() { public void log() {
Log.protocol(String.format("Receiving blockEntityMeta (position=%s, action=%s)", position.toString(), action.name())); Log.protocol(String.format("Receiving blockEntityMeta (position=%s, action=%s)", position.toString(), ((action_1_7_10 == null) ? action_1_8.name() : action_1_7_10.name())));
} }
@Override @Override
@ -57,15 +58,19 @@ public class PacketBlockEntityMetadata implements ClientboundPacket {
return position; return position;
} }
public Action getAction() { public Action_1_7_10 getAction1_7_10() {
return action; return action_1_7_10;
}
public Action_1_8 getAction1_8() {
return action_1_8;
} }
public CompoundTag getNbt() { public CompoundTag getNbt() {
return nbt; return nbt;
} }
public enum Action { public enum Action_1_7_10 {
SPAWNER(1), SPAWNER(1),
COMMAND_BLOCK(2), COMMAND_BLOCK(2),
SKULL(3), SKULL(3),
@ -73,14 +78,42 @@ public class PacketBlockEntityMetadata implements ClientboundPacket {
final int id; final int id;
Action(int id) { Action_1_7_10(int id) {
this.id = id; this.id = id;
} }
public static Action byId(int id) { public static Action_1_7_10 byId(int id) {
for (Action g : values()) { for (Action_1_7_10 a : values()) {
if (g.getId() == id) { if (a.getId() == id) {
return g; return a;
}
}
return null;
}
public int getId() {
return id;
}
}
public enum Action_1_8 {
SPAWNER(1),
COMMAND_BLOCK(2),
BEACON(3),
SKULL(4),
FLOWER_POT(5),
BANNER(6);
final int id;
Action_1_8(int id) {
this.id = id;
}
public static Action_1_8 byId(int id) {
for (Action_1_8 a : values()) {
if (a.getId() == id) {
return a;
} }
} }
return null; return null;

View File

@ -444,7 +444,13 @@ public class PacketHandler {
connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName()).addScore(new ScoreboardScore(pkg.getItemName(), pkg.getScoreName(), pkg.getScoreValue())); connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName()).addScore(new ScoreboardScore(pkg.getItemName(), pkg.getScoreName(), pkg.getScoreValue()));
break; break;
case REMOVE: case REMOVE:
connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName()).removeScore(pkg.getScoreName()); ScoreboardObjective objective = connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName());
//ToDo handle correctly
if (objective == null) {
Log.warn(String.format("Server tried to remove score with was not created before (itemName=\"%s\", scoreName=\"%s\")!", pkg.getItemName(), pkg.getScoreName()));
} else {
objective.removeScore(pkg.getItemName());
}
break; break;
} }