more refactoring

This commit is contained in:
Bixilon 2020-10-15 00:00:23 +02:00
parent 2029deeca7
commit c54fac11d2
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
54 changed files with 169 additions and 253 deletions

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft;
import com.google.common.collect.HashBiMap;
import de.bixilon.minosoft.config.Configuration;
import de.bixilon.minosoft.config.GameConfiguration;
import de.bixilon.minosoft.config.ConfigurationPaths;
import de.bixilon.minosoft.data.mappings.versions.Versions;
import de.bixilon.minosoft.gui.main.AccountListCell;
import de.bixilon.minosoft.gui.main.MainWindow;
@ -34,7 +34,7 @@ import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
public class Minosoft {
public final class Minosoft {
public static final HashSet<EventManager> eventManagers = new HashSet<>();
private static final CountDownLatch startStatus = new CountDownLatch(2); // number of critical components (wait for them before other "big" actions)
public static HashBiMap<String, MojangAccount> accountList;
@ -55,9 +55,9 @@ public class Minosoft {
e.printStackTrace();
return;
}
Log.info(String.format("Loaded config file (version=%s)", config.getInt(GameConfiguration.CONFIG_VERSION)));
Log.info(String.format("Loaded config file (version=%s)", config.getInt(ConfigurationPaths.CONFIG_VERSION)));
// set log level from config
Log.setLevel(LogLevels.valueOf(config.getString(GameConfiguration.GENERAL_LOG_LEVEL)));
Log.setLevel(LogLevels.valueOf(config.getString(ConfigurationPaths.GENERAL_LOG_LEVEL)));
Log.info(String.format("Logging info with level: %s", Log.getLevel()));
serverList = config.getServers();
@ -79,7 +79,7 @@ public class Minosoft {
Log.debug("Refreshing client token...");
checkClientToken();
accountList = config.getMojangAccounts();
selectAccount(accountList.get(config.getString(GameConfiguration.ACCOUNT_SELECTED)));
selectAccount(accountList.get(config.getString(ConfigurationPaths.ACCOUNT_SELECTED)));
return true;
});
startCallables.add(() -> {
@ -92,6 +92,7 @@ public class Minosoft {
Launcher.start();
return true;
});
// If you add another "critical" component (wait for them at startup): You MUST adjust increment the number of the counter in `startStatus` (See in the first lines of this file)
try {
Util.executeInThreadPool("Start", startCallables);
} catch (Exception e) {
@ -105,8 +106,8 @@ public class Minosoft {
}
public static void checkClientToken() {
if (config.getString(GameConfiguration.CLIENT_TOKEN).isBlank()) {
config.putString(GameConfiguration.CLIENT_TOKEN, UUID.randomUUID().toString());
if (config.getString(ConfigurationPaths.CLIENT_TOKEN).isBlank()) {
config.putString(ConfigurationPaths.CLIENT_TOKEN, UUID.randomUUID().toString());
config.saveToFile();
}
}
@ -114,7 +115,7 @@ public class Minosoft {
public static void selectAccount(MojangAccount account) {
if (account == null) {
selectedAccount = null;
config.putString(GameConfiguration.ACCOUNT_SELECTED, "");
config.putString(ConfigurationPaths.ACCOUNT_SELECTED, "");
config.saveToFile();
return;
}
@ -126,7 +127,7 @@ public class Minosoft {
selectedAccount = null;
return;
}
config.putString(GameConfiguration.ACCOUNT_SELECTED, account.getUserId());
config.putString(ConfigurationPaths.ACCOUNT_SELECTED, account.getUserId());
selectedAccount = account;
if (MainWindow.accountMenu2 != null) {
MainWindow.accountMenu2.setText(String.format("Account (%s)", account.getPlayerName()));

View File

@ -88,21 +88,21 @@ public class Configuration {
thread.start();
}
public boolean getBoolean(GameConfiguration path) {
public boolean getBoolean(ConfigurationPaths path) {
return switch (path) {
case NETWORK_FAKE_CLIENT_BRAND -> config.getAsJsonObject("network").get("fake-network-brand").getAsBoolean();
default -> throw new RuntimeException(String.format("Illegal boolean value: %s", path));
};
}
public void putBoolean(GameConfiguration path, boolean value) {
public void putBoolean(ConfigurationPaths path, boolean value) {
switch (path) {
case NETWORK_FAKE_CLIENT_BRAND -> config.getAsJsonObject("network").addProperty("fake-network-brand", value);
default -> throw new RuntimeException(String.format("Illegal boolean value: %s", path));
}
}
public int getInt(GameConfiguration path) {
public int getInt(ConfigurationPaths path) {
return switch (path) {
case CONFIG_VERSION -> config.getAsJsonObject("general").get("version").getAsInt();
case GAME_RENDER_DISTANCE -> config.getAsJsonObject("game").get("render-distance").getAsInt();
@ -110,7 +110,7 @@ public class Configuration {
};
}
public void putInt(GameConfiguration path, int value) {
public void putInt(ConfigurationPaths path, int value) {
switch (path) {
case CONFIG_VERSION -> config.getAsJsonObject("general").addProperty("version", value);
case GAME_RENDER_DISTANCE -> config.getAsJsonObject("game").addProperty("render-distance", value);
@ -118,7 +118,7 @@ public class Configuration {
}
}
public String getString(GameConfiguration path) {
public String getString(ConfigurationPaths path) {
return switch (path) {
case ACCOUNT_SELECTED -> config.getAsJsonObject("accounts").get("selected").getAsString();
case GENERAL_LOG_LEVEL -> config.getAsJsonObject("general").get("log-level").getAsString();
@ -128,7 +128,7 @@ public class Configuration {
};
}
public void putString(GameConfiguration path, String value) {
public void putString(ConfigurationPaths path, String value) {
switch (path) {
case ACCOUNT_SELECTED -> config.getAsJsonObject("accounts").addProperty("selected", value);
case GENERAL_LOG_LEVEL -> config.getAsJsonObject("general").addProperty("log-level", value);

View File

@ -13,7 +13,7 @@
package de.bixilon.minosoft.config;
public enum GameConfiguration {
public enum ConfigurationPaths {
CONFIG_VERSION,
GAME_RENDER_DISTANCE,
NETWORK_FAKE_CLIENT_BRAND,
@ -21,4 +21,4 @@ public enum GameConfiguration {
CLIENT_TOKEN,
MAPPINGS_URL,
ACCOUNT_SELECTED
}
}

View File

@ -56,7 +56,7 @@ public abstract class AbstractHorseMetaData extends AnimalMetaData {
}
public HorseTypes getType() {
final int defaultValue = HorseTypes.HORSE.getId();
final int defaultValue = HorseTypes.HORSE.ordinal();
if (protocolId < 57) {
return HorseTypes.byId(sets.getInt(19, defaultValue));
}
@ -104,9 +104,5 @@ public abstract class AbstractHorseMetaData extends AnimalMetaData {
public static HorseTypes byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -19,7 +19,7 @@ public class HorseMetaData extends AbstractHorseMetaData {
}
public HorseColors getColor() {
final int defaultValue = HorseColors.WHITE.getId();
final int defaultValue = HorseColors.WHITE.ordinal();
if (protocolId < 57) {
return HorseColors.byId(sets.getInt(20, defaultValue) & 0xFF);
}
@ -33,7 +33,7 @@ public class HorseMetaData extends AbstractHorseMetaData {
}
public HorseDots getDots() {
final int defaultValue = HorseDots.NONE.getId() << 8;
final int defaultValue = HorseDots.NONE.ordinal() << 8;
if (protocolId < 57) {
return HorseDots.byId(sets.getInt(20, defaultValue) >> 8);
}
@ -47,7 +47,7 @@ public class HorseMetaData extends AbstractHorseMetaData {
}
public HorseArmors getArmor() {
final int defaultValue = HorseArmors.NO_ARMOR.getId();
final int defaultValue = HorseArmors.NO_ARMOR.ordinal();
if (protocolId < 57) {
return HorseArmors.byId(sets.getInt(21, defaultValue));
}
@ -79,10 +79,6 @@ public class HorseMetaData extends AbstractHorseMetaData {
public static HorseArmors byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
public enum HorseColors {
@ -97,10 +93,6 @@ public class HorseMetaData extends AbstractHorseMetaData {
public static HorseColors byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
public enum HorseDots {
@ -113,9 +105,5 @@ public class HorseMetaData extends AbstractHorseMetaData {
public static HorseDots byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -40,7 +40,7 @@ public class HumanMetaData extends LivingMetaData {
}
public Hands getMainHand() {
final int defaultValue = Hands.LEFT.getId();
final int defaultValue = Hands.LEFT.ordinal();
if (protocolId < 110) { //ToDo
return Hands.byId(defaultValue);
}

View File

@ -32,7 +32,7 @@ public abstract class LivingMetaData extends EntityMetaData {
}
public Hands getActiveHand() {
final int defaultValue = Hands.LEFT.getId();
final int defaultValue = Hands.LEFT.ordinal();
if (protocolId < 110) { //ToDo
return Hands.byId(defaultValue);
}

View File

@ -19,7 +19,7 @@ public class OcelotMetaData extends AnimalMetaData {
}
public OcelotTypes getType() {
final int defaultValue = OcelotTypes.UNTAMED.getId();
final int defaultValue = OcelotTypes.UNTAMED.ordinal();
if (protocolId < 57) {
return OcelotTypes.byId(sets.getInt(18, defaultValue));
}
@ -46,28 +46,13 @@ public class OcelotMetaData extends AnimalMetaData {
}
public enum OcelotTypes {
UNTAMED(0),
TUXEDO(1),
TABBY(2),
SIAMESE(3);
final int id;
OcelotTypes(int id) {
this.id = id;
}
UNTAMED,
TUXEDO,
TABBY,
SIAMESE;
public static OcelotTypes byId(int id) {
for (OcelotTypes type : values()) {
if (type.getId() == id) {
return type;
}
}
return null;
}
public int getId() {
return id;
return values()[id];
}
}
}

View File

@ -19,7 +19,7 @@ public class PufferfishMetaData extends AbstractFishMetaData {
}
public PufferStates getPufferState() {
final int defaultValue = PufferStates.UN_PUFFED.getId();
final int defaultValue = PufferStates.UN_PUFFED.ordinal();
if (protocolId < 401) { // ToDo
return PufferStates.byId(defaultValue);
}
@ -32,27 +32,12 @@ public class PufferfishMetaData extends AbstractFishMetaData {
}
public enum PufferStates {
UN_PUFFED(0),
SEMI_PUFFED(1),
FULLY_PUFFED(2);
final int id;
PufferStates(int id) {
this.id = id;
}
UN_PUFFED,
SEMI_PUFFED,
FULLY_PUFFED;
public static PufferStates byId(int id) {
for (PufferStates state : values()) {
if (state.getId() == id) {
return state;
}
}
return null;
}
public int getId() {
return id;
return values()[id];
}
}
}

View File

@ -74,9 +74,5 @@ public class ItemFrame extends EntityObject implements ObjectInterface {
public static FrameDirections byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -77,9 +77,5 @@ public class Minecart extends EntityObject implements ObjectInterface {
public static MinecartTypes byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -77,10 +77,6 @@ public class InventorySlots {
@Override
public int getId(int protocolId) {
return getId();
}
public int getId() {
return ordinal();
}
}

View File

@ -30,26 +30,11 @@ public class PistonAction implements BlockAction {
}
public enum PistonStates {
PUSH(0),
PULL(1);
final byte id;
PistonStates(int id) {
this.id = (byte) id;
}
PUSH,
PULL;
public static PistonStates byId(int id) {
for (PistonStates state : values()) {
if (state.getId() == id) {
return state;
}
}
return null;
}
public byte getId() {
return id;
return values()[id];
}
}
}

View File

@ -18,7 +18,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import de.bixilon.minosoft.Config;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.config.GameConfiguration;
import de.bixilon.minosoft.config.ConfigurationPaths;
import de.bixilon.minosoft.data.Mappings;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.protocol.ConnectionStates;
@ -135,7 +135,7 @@ public class Versions {
} catch (FileNotFoundException e) {
long downloadStartTime = System.currentTimeMillis();
Log.info(String.format("Mappings for %s are not available on disk. Downloading them...", version.getVersionName()));
Util.downloadFile(String.format(Minosoft.getConfig().getString(GameConfiguration.MAPPINGS_URL), version.getVersionName()), fileName);
Util.downloadFile(String.format(Minosoft.getConfig().getString(ConfigurationPaths.MAPPINGS_URL), version.getVersionName()), fileName);
try {
files = Util.readJsonTarGzFile(fileName);
} catch (ZipException e2) {

View File

@ -24,8 +24,4 @@ public enum Hands {
public static Hands byBoolean(boolean id) {
return id ? LEFT : RIGHT;
}
public int getId() {
return ordinal();
}
}

View File

@ -32,8 +32,7 @@ public enum PingBars {
return BARS_3;
} else if (ping < 1000) {
return BARS_2;
} else {
return BRAS_1;
}
return BRAS_1;
}
}

View File

@ -18,9 +18,9 @@ import de.bixilon.minosoft.data.Player;
import de.bixilon.minosoft.data.mappings.versions.Version;
import de.bixilon.minosoft.data.mappings.versions.Versions;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.ping.ForgeModInfo;
import de.bixilon.minosoft.ping.ServerListPing;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.ping.ForgeModInfo;
import de.bixilon.minosoft.protocol.ping.ServerListPing;
import de.bixilon.minosoft.util.DNSUtil;
import javafx.application.Platform;
import javafx.fxml.FXML;

View File

@ -14,7 +14,7 @@
package de.bixilon.minosoft.gui.main;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.config.GameConfiguration;
import de.bixilon.minosoft.config.ConfigurationPaths;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.logging.LogLevels;
import javafx.fxml.FXML;
@ -41,7 +41,7 @@ public class SettingsWindow implements Initializable {
return;
}
Log.setLevel(newLevel);
Minosoft.getConfig().putString(GameConfiguration.GENERAL_LOG_LEVEL, newLevel.name());
Minosoft.getConfig().putString(ConfigurationPaths.GENERAL_LOG_LEVEL, newLevel.name());
Minosoft.getConfig().saveToFile();
}));
}

View File

@ -0,0 +1,48 @@
/*
* Codename 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.modding.event.events;
import de.bixilon.minosoft.data.inventory.Slot;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketWindowItems;
public class MultiSlotChangeEvent extends Event {
private final byte windowId;
private final Slot[] data;
public MultiSlotChangeEvent(Connection connection, byte windowId, Slot[] data) {
super(connection);
this.windowId = windowId;
this.data = data;
}
public MultiSlotChangeEvent(Connection connection, PacketWindowItems pkg) {
super(connection);
this.windowId = pkg.getWindowId();
this.data = pkg.getData();
}
public byte getWindowId() {
return windowId;
}
/**
* @return Data array. Array position equals the slot id
*/
public Slot[] getData() {
return data;
}
}

View File

@ -17,20 +17,20 @@ import de.bixilon.minosoft.data.inventory.Slot;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketSetSlot;
public class SlotChangeEvent extends Event {
public class SingleSlotChangeEvent extends Event {
private final byte windowId;
private final short slotId;
private final Slot slot;
public SlotChangeEvent(Connection connection, byte windowId, short slotId, Slot slot) {
public SingleSlotChangeEvent(Connection connection, byte windowId, short slotId, Slot slot) {
super(connection);
this.windowId = windowId;
this.slotId = slotId;
this.slot = slot;
}
public SlotChangeEvent(Connection connection, PacketSetSlot pkg) {
public SingleSlotChangeEvent(Connection connection, PacketSetSlot pkg) {
super(connection);
this.windowId = pkg.getWindowId();
this.slotId = pkg.getSlotId();

View File

@ -13,9 +13,9 @@
package de.bixilon.minosoft.modding.event.events;
import de.bixilon.minosoft.ping.ServerListPing;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusResponse;
import de.bixilon.minosoft.protocol.ping.ServerListPing;
/**
* Fired when the connection status is "STATUS" and the server send general information such as players online, motd, etc

View File

@ -14,7 +14,6 @@
package de.bixilon.minosoft.protocol.network;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.PingCallback;
import de.bixilon.minosoft.data.Player;
import de.bixilon.minosoft.data.VelocityHandler;
import de.bixilon.minosoft.data.mappings.CustomMapping;
@ -30,13 +29,14 @@ import de.bixilon.minosoft.modding.event.events.CancelableEvent;
import de.bixilon.minosoft.modding.event.events.Event;
import de.bixilon.minosoft.modding.event.events.PacketReceiveEvent;
import de.bixilon.minosoft.modding.event.events.PacketSendEvent;
import de.bixilon.minosoft.ping.ServerListPing;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.packets.serverbound.handshaking.PacketHandshake;
import de.bixilon.minosoft.protocol.packets.serverbound.login.PacketLoginStart;
import de.bixilon.minosoft.protocol.packets.serverbound.status.PacketStatusPing;
import de.bixilon.minosoft.protocol.packets.serverbound.status.PacketStatusRequest;
import de.bixilon.minosoft.protocol.ping.PingCallback;
import de.bixilon.minosoft.protocol.ping.ServerListPing;
import de.bixilon.minosoft.protocol.protocol.*;
import de.bixilon.minosoft.util.DNSUtil;
import de.bixilon.minosoft.util.ServerAddress;

View File

@ -98,7 +98,7 @@ public class PacketDecoder extends ByteToMessageDecoder {
try {
packet = connection.getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand());
if (packet == null) {
Log.fatal(String.format("Version packet enum does not contain a packet with id 0x%x. Your version.json is broken!", inPacketBuffer.getCommand()));
Log.fatal(String.format("Packet mapping does not contain a packet with id 0x%x. The server sends bullshit or your versions.json broken!", inPacketBuffer.getCommand()));
nettyNetwork.disconnect();
throw new RuntimeException("Invalid packet 0x%x" + inPacketBuffer.getCommand());
}

View File

@ -45,12 +45,10 @@ public class PacketEncoder extends MessageToByteEncoder<ServerboundPacket> {
byte[] compressed = Util.compress(data);
compressedBuffer.writeVarInt(data.length);
compressedBuffer.writeBytes(compressed);
outRawBuffer.writeVarInt(compressedBuffer.getOutBytes().length);
outRawBuffer.writeBytes(compressedBuffer.getOutBytes());
outRawBuffer.prefixVarInt(compressedBuffer.getOutBytes().length);
} else {
outRawBuffer.prefixVarInt(0);
outRawBuffer.writeVarInt(data.length + 1); // 1 for the compressed length (0)
outRawBuffer.writeVarInt(0);
outRawBuffer.writeBytes(data);
}
data = outRawBuffer.getOutBytes();
} else {

View File

@ -108,12 +108,10 @@ public class SocketNetwork implements Network {
byte[] compressed = Util.compress(data);
compressedBuffer.writeVarInt(data.length);
compressedBuffer.writeBytes(compressed);
outRawBuffer.writeVarInt(compressedBuffer.getOutBytes().length);
outRawBuffer.writeBytes(compressedBuffer.getOutBytes());
outRawBuffer.prefixVarInt(compressedBuffer.getOutBytes().length);
} else {
outRawBuffer.prefixVarInt(0);
outRawBuffer.writeVarInt(data.length + 1); // 1 for the compressed length (0)
outRawBuffer.writeVarInt(0);
outRawBuffer.writeBytes(data);
}
data = outRawBuffer.getOutBytes();
} else {
@ -194,7 +192,7 @@ public class SocketNetwork implements Network {
try {
packet = connection.getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand());
if (packet == null) {
Log.fatal(String.format("Version packet enum does not contain a packet with id 0x%x. The server sent bullshit or your version.json is broken!", inPacketBuffer.getCommand()));
Log.fatal(String.format("Packet mapping does not contain a packet with id 0x%x. The server sends bullshit or your versions.json broken!", inPacketBuffer.getCommand()));
disconnect();
lastException = new RuntimeException("Invalid packet 0x" + inPacketBuffer.getCommand());
throw lastException;

View File

@ -124,10 +124,6 @@ public class PacketBossBar implements ClientboundPacket {
public static BossBarActions byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
public enum BossBarColors {
@ -142,10 +138,6 @@ public class PacketBossBar implements ClientboundPacket {
public static BossBarColors byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
public enum BossBarDivisions {
@ -158,9 +150,5 @@ public class PacketBossBar implements ClientboundPacket {
public static BossBarDivisions byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -66,9 +66,5 @@ public class PacketCombatEvent implements ClientboundPacket {
public static CombatEvents byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -84,9 +84,5 @@ public class PacketEntityProperties implements ClientboundPacket {
public static ModifierActions byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -85,9 +85,5 @@ public class PacketEntityStatus implements ClientboundPacket {
public static EntityStates byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -64,26 +64,11 @@ public class PacketFacePlayer implements ClientboundPacket {
}
public enum PlayerFaces {
FEET(0),
EYES(1);
final int id;
PlayerFaces(int id) {
this.id = id;
}
FEET,
EYES;
public static PlayerFaces byId(int id) {
for (PlayerFaces face : values()) {
if (face.getId() == id) {
return face;
}
}
return null;
}
public int getId() {
return id;
return values()[id];
}
}
}

View File

@ -170,10 +170,6 @@ public class PacketMapData implements ClientboundPacket {
public static PacketMapDataDataActions byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
public enum MapPinTypes {
@ -209,10 +205,6 @@ public class PacketMapData implements ClientboundPacket {
public static MapPinTypes byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
public static class MapPinSet {

View File

@ -105,9 +105,5 @@ public class PacketPlayerListItem implements ClientboundPacket {
public static PlayerListItemActions byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -85,10 +85,6 @@ public class PacketScoreboardObjective implements ClientboundPacket {
public static ScoreboardObjectiveActions byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
public enum ScoreboardObjectiveTypes {

View File

@ -80,9 +80,5 @@ public class PacketScoreboardUpdateScore implements ClientboundPacket {
public static ScoreboardUpdateScoreActions byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -125,9 +125,5 @@ public class PacketWorldBorder implements ClientboundPacket {
public static WorldBorderActions byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -14,8 +14,8 @@
package de.bixilon.minosoft.protocol.packets.clientbound.status;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.ping.ServerListPing;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.ping.ServerListPing;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;

View File

@ -31,7 +31,7 @@ public class PacketAnimation implements ServerboundPacket {
public OutPacketBuffer write(Connection connection) {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_ANIMATION);
if (buffer.getProtocolId() >= 49) {
buffer.writeVarInt(hand.getId());
buffer.writeVarInt(hand.ordinal());
}
return buffer;
}

View File

@ -53,7 +53,7 @@ public class PacketClientSettings implements ServerboundPacket {
buffer.writeByte((byte) 0b01111111); // ToDo: skin parts
}
if (buffer.getProtocolId() >= 49) {
buffer.writeVarInt(mainHand.getId());
buffer.writeVarInt(mainHand.ordinal());
}
return buffer;
}

View File

@ -31,9 +31,9 @@ public class PacketClientStatus implements ServerboundPacket {
public OutPacketBuffer write(Connection connection) {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CLIENT_STATUS);
if (buffer.getProtocolId() < 7) {
buffer.writeByte((byte) status.getId());
buffer.writeByte((byte) status.ordinal());
} else {
buffer.writeVarInt(status.getId());
buffer.writeVarInt(status.ordinal());
}
return buffer;
}
@ -51,9 +51,5 @@ public class PacketClientStatus implements ServerboundPacket {
public static ClientStates byId(int id) {
return values()[id];
}
public int getId() {
return ordinal();
}
}
}

View File

@ -80,7 +80,7 @@ public class PacketInteractEntity implements ServerboundPacket {
if (click == EntityInteractionClicks.INTERACT_AT || click == EntityInteractionClicks.INTERACT) {
if (buffer.getProtocolId() >= 49) {
buffer.writeVarInt(hand.getId());
buffer.writeVarInt(hand.ordinal());
}
if (buffer.getProtocolId() >= 725 && buffer.getProtocolId() < 729) {

View File

@ -65,7 +65,7 @@ public class PacketPlayerBlockPlacement implements ServerboundPacket {
public OutPacketBuffer write(Connection connection) {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_BLOCK_PLACEMENT);
if (buffer.getProtocolId() >= 453) {
buffer.writeVarInt(hand.getId());
buffer.writeVarInt(hand.ordinal());
}
if (buffer.getProtocolId() < 7) {
buffer.writeBlockPositionByte(position);
@ -78,7 +78,7 @@ public class PacketPlayerBlockPlacement implements ServerboundPacket {
} else {
buffer.writeVarInt(direction);
if (buffer.getProtocolId() < 453) {
buffer.writeVarInt(hand.getId());
buffer.writeVarInt(hand.ordinal());
}
}

View File

@ -30,7 +30,7 @@ public class PacketUseItem implements ServerboundPacket {
@Override
public OutPacketBuffer write(Connection connection) {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_USE_ITEM);
buffer.writeVarInt(hand.getId());
buffer.writeVarInt(hand.ordinal());
return buffer;
}

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.ping;
package de.bixilon.minosoft.protocol.ping;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;

View File

@ -11,9 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft;
import de.bixilon.minosoft.ping.ServerListPing;
package de.bixilon.minosoft.protocol.ping;
public interface PingCallback {
void handle(ServerListPing ping);

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.ping;
package de.bixilon.minosoft.protocol.ping;
import com.google.gson.JsonObject;
import de.bixilon.minosoft.data.text.BaseComponent;

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.ping;
package de.bixilon.minosoft.protocol.ping;
public interface ServerModInfo {
String getBrand();

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.ping;
package de.bixilon.minosoft.protocol.ping;
public class ServerModItem {
final String modId;

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.ping;
package de.bixilon.minosoft.protocol.ping;
public enum ServerModTypes {
VANILLA,

View File

@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.ping;
package de.bixilon.minosoft.protocol.ping;
public class VanillaModInfo implements ServerModInfo {
@Override

View File

@ -51,6 +51,13 @@ public class InByteBuffer {
this.protocolId = connection.getVersion().getProtocolVersion();
}
public InByteBuffer(InByteBuffer buffer) {
this.bytes = buffer.getBytes();
this.position = buffer.getPosition();
this.connection = buffer.getConnection();
this.protocolId = connection.getVersion().getProtocolVersion();
}
public byte[] readByteArray() {
int count;
if (protocolId < 19) {

View File

@ -26,15 +26,22 @@ import java.util.ArrayList;
import java.util.UUID;
public class OutByteBuffer {
final ArrayList<Byte> bytes = new ArrayList<>();
final ArrayList<Byte> bytes;
final Connection connection;
final int protocolId;
public OutByteBuffer(Connection connection) {
this.bytes = new ArrayList<>();
this.connection = connection;
this.protocolId = connection.getVersion().getProtocolVersion();
}
public OutByteBuffer(OutByteBuffer buffer) {
this.bytes = (ArrayList<Byte>) buffer.getBytes().clone();
this.connection = buffer.getConnection();
this.protocolId = buffer.getProtocolId();
}
public void writeByteArray(byte[] data) {
if (protocolId < 19) {
writeShort((short) data.length);
@ -135,10 +142,6 @@ public class OutByteBuffer {
writeInt((int) (d * 32.0D));
}
public void writeVarInt(int value) {
writeVarInt(value, bytes);
}
public ArrayList<Byte> getBytes() {
return bytes;
}
@ -155,7 +158,7 @@ public class OutByteBuffer {
writeLong((((long) (position.getX() & 0x3FFFFFF) << 38) | ((long) (position.getZ() & 0x3FFFFFF) << 12) | (long) (position.getY() & 0xFFF)));
}
public static void writeVarInt(int value, ArrayList<Byte> write) {
public void writeVarInt(int value) {
// thanks https://wiki.vg/Protocol#VarInt_and_VarLong
do
{
@ -165,12 +168,23 @@ public class OutByteBuffer {
if (value != 0) {
temp |= 0b10000000;
}
writeByte(temp, write);
writeByte(temp);
} while (value != 0);
}
public static void writeByte(byte b, ArrayList<Byte> write) {
write.add(b);
public void prefixVarInt(int value) {
int count = 0;
// thanks https://wiki.vg/Protocol#VarInt_and_VarLong
do
{
byte temp = (byte) (value & 0b01111111);
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
value >>>= 7;
if (value != 0) {
temp |= 0b10000000;
}
bytes.add(count++, temp);
} while (value != 0);
}
public void writeSlot(Slot slot) {
@ -245,4 +259,8 @@ public class OutByteBuffer {
writeVarInt(entityId);
}
}
public Connection getConnection() {
return connection;
}
}

View File

@ -15,8 +15,6 @@ package de.bixilon.minosoft.protocol.protocol;
import de.bixilon.minosoft.protocol.network.Connection;
import java.util.ArrayList;
public class OutPacketBuffer extends OutByteBuffer {
final int command;
@ -27,16 +25,9 @@ public class OutPacketBuffer extends OutByteBuffer {
@Override
public byte[] getOutBytes() {
ArrayList<Byte> before = getBytes();
ArrayList<Byte> after = new ArrayList<>();
writeVarInt(getCommand(), after); // second: command
after.addAll(before); // rest ist raw data
byte[] ret = new byte[after.size()];
for (int i = 0; i < after.size(); i++) {
ret[i] = after.get(i);
}
return ret;
OutByteBuffer ret = new OutByteBuffer(this);
ret.prefixVarInt(getCommand());
return ret.getOutBytes();
}
public int getCommand() {

View File

@ -14,7 +14,7 @@
package de.bixilon.minosoft.protocol.protocol;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.config.GameConfiguration;
import de.bixilon.minosoft.config.ConfigurationPaths;
import de.bixilon.minosoft.data.GameModes;
import de.bixilon.minosoft.data.entities.Entity;
import de.bixilon.minosoft.data.entities.meta.HumanMetaData;
@ -199,7 +199,7 @@ public class PacketHandler {
if (pkg.getChannel().equals(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(connection.getVersion().getProtocolVersion()))) {
InByteBuffer data = pkg.getDataAsBuffer();
String serverVersion;
String clientVersion = (Minosoft.getConfig().getBoolean(GameConfiguration.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft");
String clientVersion = (Minosoft.getConfig().getBoolean(ConfigurationPaths.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft");
OutByteBuffer toSend = new OutByteBuffer(connection);
if (connection.getVersion().getProtocolVersion() < 29) {
// no length prefix
@ -332,6 +332,8 @@ public class PacketHandler {
}
public void handle(PacketWindowItems pkg) {
connection.fireEvent(new MultiSlotChangeEvent(connection, pkg));
connection.getPlayer().setInventory(pkg.getWindowId(), pkg.getData());
}
@ -519,7 +521,7 @@ public class PacketHandler {
}
public void handle(PacketSetSlot pkg) {
connection.fireEvent(new SlotChangeEvent(connection, pkg));
connection.fireEvent(new SingleSlotChangeEvent(connection, pkg));
if (pkg.getWindowId() == -1) {
// invalid window Id

View File

@ -17,7 +17,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import de.bixilon.minosoft.Config;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.config.GameConfiguration;
import de.bixilon.minosoft.config.ConfigurationPaths;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.util.HTTP;
@ -26,7 +26,7 @@ import java.net.http.HttpResponse;
public final class MojangAuthentication {
public static MojangAccountAuthenticationAttempt login(String username, String password) {
return login(Minosoft.getConfig().getString(GameConfiguration.CLIENT_TOKEN), username, password);
return login(Minosoft.getConfig().getString(ConfigurationPaths.CLIENT_TOKEN), username, password);
}
public static MojangAccountAuthenticationAttempt login(String clientToken, String username, String password) {
@ -81,7 +81,7 @@ public final class MojangAuthentication {
}
public static String refresh(String accessToken) {
return refresh(Minosoft.getConfig().getString(GameConfiguration.CLIENT_TOKEN), accessToken);
return refresh(Minosoft.getConfig().getString(ConfigurationPaths.CLIENT_TOKEN), accessToken);
}
public static String refresh(String clientToken, String accessToken) {