refactor code

This commit is contained in:
Bixilon 2020-09-22 19:59:10 +02:00
parent 072be1549c
commit 6560a704c9
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
32 changed files with 13 additions and 52 deletions

View File

@ -34,7 +34,6 @@ import javafx.util.Callback;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
public class Launcher extends Application { public class Launcher extends Application {
public static void start() { public static void start() {

View File

@ -69,7 +69,6 @@ public class Minosoft {
accountList = config.getMojangAccounts(); accountList = config.getMojangAccounts();
selectAccount(accountList.get(config.getString(GameConfiguration.ACCOUNT_SELECTED))); selectAccount(accountList.get(config.getString(GameConfiguration.ACCOUNT_SELECTED)));
serverList = config.getServers(); serverList = config.getServers();
Launcher.start(); Launcher.start();
} }

View File

@ -233,4 +233,3 @@ public class Configuration {
} }
} }

View File

@ -18,7 +18,6 @@ public enum ChatTextPositions {
SYSTEM_MESSAGE, SYSTEM_MESSAGE,
ABOVE_HOTBAR; ABOVE_HOTBAR;
public static ChatTextPositions byId(int id) { public static ChatTextPositions byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -31,7 +31,6 @@ public enum Colors {
RED, RED,
BLACK; BLACK;
public static Colors byId(int id) { public static Colors byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -30,20 +30,20 @@ import java.util.UUID;
import static de.bixilon.minosoft.protocol.protocol.ProtocolDefinition.PLAYER_INVENTORY_ID; import static de.bixilon.minosoft.protocol.protocol.ProtocolDefinition.PLAYER_INVENTORY_ID;
public class Player { public class Player {
public final HashMap<UUID, PlayerListItem> playerList = new HashMap<>();
final MojangAccount account; final MojangAccount account;
final ScoreboardManager scoreboardManager = new ScoreboardManager(); final ScoreboardManager scoreboardManager = new ScoreboardManager();
public final HashMap<UUID, PlayerListItem> playerList = new HashMap<>(); final World world = new World("world");
final HashMap<Integer, Inventory> inventories = new HashMap<>();
float health; float health;
int food; int food;
float saturation; float saturation;
BlockPosition spawnLocation; BlockPosition spawnLocation;
GameModes gameMode; GameModes gameMode;
final World world = new World("world");
byte selectedSlot; byte selectedSlot;
int level; int level;
int totalExperience; int totalExperience;
OtherPlayer player; OtherPlayer player;
final HashMap<Integer, Inventory> inventories = new HashMap<>();
boolean spawnConfirmed = false; boolean spawnConfirmed = false;
TextComponent tabHeader; TextComponent tabHeader;

View File

@ -248,7 +248,6 @@ public class TextComponent {
final ChatColors color; final ChatColors color;
final String prefix; final String prefix;
ChatAttributes(String consolePrefix, ChatColors color) { ChatAttributes(String consolePrefix, ChatColors color) {
this.consolePrefix = consolePrefix; this.consolePrefix = consolePrefix;
this.color = color; this.color = color;

View File

@ -76,7 +76,6 @@ public class HorseMetaData extends AbstractHorseMetaData {
GOLD_ARMOR, GOLD_ARMOR,
DIAMOND_ARMOR; DIAMOND_ARMOR;
public static HorseArmors byId(int id) { public static HorseArmors byId(int id) {
return values()[id]; return values()[id];
} }
@ -95,7 +94,6 @@ public class HorseMetaData extends AbstractHorseMetaData {
GRAY, GRAY,
DARK_BROWN; DARK_BROWN;
public static HorseColors byId(int id) { public static HorseColors byId(int id) {
return values()[id]; return values()[id];
} }
@ -112,7 +110,6 @@ public class HorseMetaData extends AbstractHorseMetaData {
WHITE_DOTS, WHITE_DOTS,
BLACK_DOTS; BLACK_DOTS;
public static HorseDots byId(int id) { public static HorseDots byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -27,8 +27,8 @@ public class OtherPlayer extends Mob implements MobInterface {
final String name; final String name;
final PlayerPropertyData[] properties; final PlayerPropertyData[] properties;
final short currentItem; final short currentItem;
HumanMetaData metaData;
final Poses status = Poses.STANDING; final Poses status = Poses.STANDING;
HumanMetaData metaData;
public OtherPlayer(int entityId, String name, UUID uuid, PlayerPropertyData[] properties, Location location, int yaw, int pitch, int headYaw, short currentItem, HumanMetaData metaData) { public OtherPlayer(int entityId, String name, UUID uuid, PlayerPropertyData[] properties, Location location, int yaw, int pitch, int headYaw, short currentItem, HumanMetaData metaData) {
super(entityId, uuid, location, yaw, pitch, headYaw); super(entityId, uuid, location, yaw, pitch, headYaw);

View File

@ -68,7 +68,6 @@ public class InventorySlots {
HOTBAR_9, HOTBAR_9,
OFF_HAND; OFF_HAND;
public static PlayerInventorySlots byId(int id, int protocolId) { public static PlayerInventorySlots byId(int id, int protocolId) {
return values()[id]; return values()[id];
} }

View File

@ -77,7 +77,6 @@ public class Version {
this.mapping = mapping; this.mapping = mapping;
} }
public boolean isGettingLoaded() { public boolean isGettingLoaded() {
return isGettingLoaded; return isGettingLoaded;
} }

View File

@ -32,6 +32,7 @@ import java.util.HashSet;
public class VersionMapping { public class VersionMapping {
final Version version; final Version version;
final HashSet<Mappings> loaded = new HashSet<>();
HashBiMap<String, Motive> motiveIdentifierMap; HashBiMap<String, Motive> motiveIdentifierMap;
HashBiMap<String, Particle> particleIdentifierMap; HashBiMap<String, Particle> particleIdentifierMap;
HashBiMap<String, Statistic> statisticIdentifierMap; HashBiMap<String, Statistic> statisticIdentifierMap;
@ -45,7 +46,6 @@ public class VersionMapping {
HashBiMap<Integer, Enchantment> enchantmentMap; HashBiMap<Integer, Enchantment> enchantmentMap;
HashBiMap<Integer, Particle> particleIdMap; HashBiMap<Integer, Particle> particleIdMap;
HashBiMap<Integer, Statistic> statisticIdMap; HashBiMap<Integer, Statistic> statisticIdMap;
final HashSet<Mappings> loaded = new HashSet<>();
public VersionMapping(Version version) { public VersionMapping(Version version) {
this.version = version; this.version = version;

View File

@ -19,7 +19,6 @@ public class ScoreboardManager {
final HashMap<String, Team> teams = new HashMap<>(); final HashMap<String, Team> teams = new HashMap<>();
final HashMap<String, ScoreboardObjective> objectives = new HashMap<>(); final HashMap<String, ScoreboardObjective> objectives = new HashMap<>();
public void addTeam(Team team) { public void addTeam(Team team) {
teams.put(team.getName(), team); teams.put(team.getName(), team);
} }

View File

@ -19,10 +19,10 @@ import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer; import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
public class IndirectPalette implements Palette { public class IndirectPalette implements Palette {
int protocolId;
CustomMapping mapping;
final HashBiMap<Integer, Integer> map = HashBiMap.create(); final HashBiMap<Integer, Integer> map = HashBiMap.create();
final byte bitsPerBlock; final byte bitsPerBlock;
int protocolId;
CustomMapping mapping;
public IndirectPalette(byte bitsPerBlock) { public IndirectPalette(byte bitsPerBlock) {
this.bitsPerBlock = bitsPerBlock; this.bitsPerBlock = bitsPerBlock;

View File

@ -62,7 +62,6 @@ public class AccountListCell extends ListCell<MojangAccount> implements Initiali
return root; return root;
} }
@Override @Override
protected void updateItem(MojangAccount account, boolean empty) { protected void updateItem(MojangAccount account, boolean empty) {
super.updateItem(account, empty); super.updateItem(account, empty);

View File

@ -62,7 +62,6 @@ public class AccountWindow implements Initializable {
PasswordField password = new PasswordField(); PasswordField password = new PasswordField();
password.setPromptText("Password"); password.setPromptText("Password");
grid.add(new Label("Email:"), 0, 0); grid.add(new Label("Email:"), 0, 0);
grid.add(email, 1, 0); grid.add(email, 1, 0);
grid.add(new Label("Password:"), 0, 1); grid.add(new Label("Password:"), 0, 1);
@ -100,7 +99,6 @@ public class AccountWindow implements Initializable {
Window window = dialog.getDialogPane().getScene().getWindow(); Window window = dialog.getDialogPane().getScene().getWindow();
window.setOnCloseRequest(windowEvent -> window.hide()); window.setOnCloseRequest(windowEvent -> window.hide());
dialog.showAndWait(); dialog.showAndWait();
} }
} }

View File

@ -93,7 +93,6 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
return root; return root;
} }
@Override @Override
protected void updateItem(Server server, boolean empty) { protected void updateItem(Server server, boolean empty) {
super.updateItem(server, empty); super.updateItem(server, empty);
@ -215,7 +214,6 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
serverAddress.setPromptText("Server address"); serverAddress.setPromptText("Server address");
serverAddress.setText(server.getAddress()); serverAddress.setText(server.getAddress());
if (server.getDesiredVersion() == -1) { if (server.getDesiredVersion() == -1) {
GUITools.versionList.getSelectionModel().select(Versions.getLowestVersionSupported()); GUITools.versionList.getSelectionModel().select(Versions.getLowestVersionSupported());
} else { } else {
@ -281,7 +279,6 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
} }
private void resetCell() { private void resetCell() {
// clear all cells // clear all cells
setStyle(null); setStyle(null);
@ -336,7 +333,6 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
Label serverAddressLabel = new Label(server.getAddress()); Label serverAddressLabel = new Label(server.getAddress());
Label forcedVersionLabel = new Label(); Label forcedVersionLabel = new Label();
if (server.getDesiredVersion() == -1) { if (server.getDesiredVersion() == -1) {
forcedVersionLabel.setText(Versions.getLowestVersionSupported().getVersionName()); forcedVersionLabel.setText(Versions.getLowestVersionSupported().getVersionName());
} else { } else {
@ -375,7 +371,6 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
Label motdLabel = new Label(lastPing.getMotd().getRawMessage()); Label motdLabel = new Label(lastPing.getMotd().getRawMessage());
Label moddedBrandLabel = new Label(lastPing.getServerModInfo().getBrand()); Label moddedBrandLabel = new Label(lastPing.getServerModInfo().getBrand());
grid.add(new Label("Real server address:"), 0, ++column); grid.add(new Label("Real server address:"), 0, ++column);
grid.add(realServerAddressLabel, 1, column); grid.add(realServerAddressLabel, 1, column);
grid.add(new Label("Server version:"), 0, ++column); grid.add(new Label("Server version:"), 0, ++column);
@ -400,7 +395,6 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
} }
} }
dialog.getDialogPane().setContent(grid); dialog.getDialogPane().setContent(grid);
dialog.showAndWait(); dialog.showAndWait();

View File

@ -59,7 +59,6 @@ public class SessionListCell extends ListCell<Connection> implements Initializab
return root; return root;
} }
@Override @Override
protected void updateItem(Connection connection, boolean empty) { protected void updateItem(Connection connection, boolean empty) {
super.updateItem(connection, empty); super.updateItem(connection, empty);

View File

@ -44,7 +44,6 @@ public class ServerListPing {
} }
serverBrand = json.getAsJsonObject("version").get("name").getAsString(); serverBrand = json.getAsJsonObject("version").get("name").getAsString();
if (json.has("modinfo") && json.getAsJsonObject("modinfo").has("type") && json.getAsJsonObject("modinfo").get("type").getAsString().equals("FML")) { if (json.has("modinfo") && json.getAsJsonObject("modinfo").has("type") && json.getAsJsonObject("modinfo").get("type").getAsString().equals("FML")) {
serverModInfo = new ForgeModInfo(json.getAsJsonObject("modinfo")); serverModInfo = new ForgeModInfo(json.getAsJsonObject("modinfo"));
} else { } else {

View File

@ -146,8 +146,7 @@ public class Network {
break; break;
} }
// everything sent for now, waiting for data
// everything sent for now, waiting for data
int numRead = 0; int numRead = 0;
int length = 0; int length = 0;
int read; int read;
@ -269,7 +268,6 @@ public class Network {
Log.debug("Encryption enabled!"); Log.debug("Encryption enabled!");
} }
public void disconnect() { public void disconnect() {
connection.setConnectionState(ConnectionStates.DISCONNECTING); connection.setConnectionState(ConnectionStates.DISCONNECTING);
try { try {

View File

@ -29,11 +29,10 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class PacketAdvancements implements ClientboundPacket { public class PacketAdvancements implements ClientboundPacket {
boolean reset;
final HashMap<String, Advancement> advancements = new HashMap<>(); final HashMap<String, Advancement> advancements = new HashMap<>();
String[] toRemove;
final HashMap<String, AdvancementProgress> progresses = new HashMap<>(); final HashMap<String, AdvancementProgress> progresses = new HashMap<>();
boolean reset;
String[] toRemove;
@Override @Override
public boolean read(InByteBuffer buffer) { public boolean read(InByteBuffer buffer) {

View File

@ -129,7 +129,6 @@ public class PacketBossBar implements ClientboundPacket {
UPDATE_STYLE, UPDATE_STYLE,
UPDATE_FLAGS; UPDATE_FLAGS;
public static BossBarActions byId(int id) { public static BossBarActions byId(int id) {
return values()[id]; return values()[id];
} }
@ -164,7 +163,6 @@ public class PacketBossBar implements ClientboundPacket {
NOTCHES_12, NOTCHES_12,
NOTCHES_20; NOTCHES_20;
public static BossBarDivisions byId(int id) { public static BossBarDivisions byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -63,7 +63,6 @@ public class PacketCombatEvent implements ClientboundPacket {
END_COMBAT, END_COMBAT,
ENTITY_DEAD; ENTITY_DEAD;
public static CombatEvents byId(int id) { public static CombatEvents byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -24,8 +24,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class PacketEntityEquipment implements ClientboundPacket { public class PacketEntityEquipment implements ClientboundPacket {
int entityId;
final HashMap<InventorySlots.EntityInventorySlots, Slot> slots = new HashMap<>(); final HashMap<InventorySlots.EntityInventorySlots, Slot> slots = new HashMap<>();
int entityId;
@Override @Override
public boolean read(InByteBuffer buffer) { public boolean read(InByteBuffer buffer) {

View File

@ -82,7 +82,6 @@ public class PacketEntityStatus implements ClientboundPacket {
PORTAL_PARTICLE_CHORUS; PORTAL_PARTICLE_CHORUS;
// ToDo: 1.11+ (for each entity) // ToDo: 1.11+ (for each entity)
public static EntityStates byId(int id) { public static EntityStates byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -167,7 +167,6 @@ public class PacketMapData implements ClientboundPacket {
PLAYERS, PLAYERS,
SCALE; SCALE;
public static PacketMapDataDataActions byId(int id) { public static PacketMapDataDataActions byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -48,7 +48,6 @@ public class PacketClientStatus implements ServerboundPacket {
REQUEST_STATISTICS, REQUEST_STATISTICS,
OPEN_INVENTORY; OPEN_INVENTORY;
public static ClientStates byId(int id) { public static ClientStates byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -24,7 +24,6 @@ public enum ConnectionStates {
FAILED, FAILED,
FAILED_NO_RETRY; FAILED_NO_RETRY;
public static ConnectionStates byId(int id) { public static ConnectionStates byId(int id) {
return values()[id]; return values()[id];
} }

View File

@ -65,7 +65,7 @@ public class PacketHandler {
if (version == null) { if (version == null) {
Log.fatal(String.format("Server is running on unknown version or a invalid version was forced (version=%d, brand=\"%s\")", versionId, pkg.getResponse().getServerBrand())); Log.fatal(String.format("Server is running on unknown version or a invalid version was forced (version=%d, brand=\"%s\")", versionId, pkg.getResponse().getServerBrand()));
} else { } else {
connection.setVersion(version); connection.setVersion(version);
} }
Log.info(String.format("Status response received: %s/%s online. MotD: '%s'", pkg.getResponse().getPlayerOnline(), pkg.getResponse().getMaxPlayers(), pkg.getResponse().getMotd().getColoredMessage())); Log.info(String.format("Status response received: %s/%s online. MotD: '%s'", pkg.getResponse().getPlayerOnline(), pkg.getResponse().getMaxPlayers(), pkg.getResponse().getMotd().getColoredMessage()));
connection.handlePingCallbacks(pkg.getResponse()); connection.handlePingCallbacks(pkg.getResponse());

View File

@ -200,7 +200,6 @@ public class Packets {
PLAY_SET_COMPRESSION(PacketSetCompression.class), PLAY_SET_COMPRESSION(PacketSetCompression.class),
PLAY_ADVANCEMENT_PROGRESS(null); PLAY_ADVANCEMENT_PROGRESS(null);
final ConnectionStates state; final ConnectionStates state;
final Class<? extends ClientboundPacket> clazz; final Class<? extends ClientboundPacket> clazz;

View File

@ -21,7 +21,6 @@ public abstract class Protocol {
static final HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping = new HashMap<>(); static final HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping = new HashMap<>();
static final HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping = new HashMap<>(); static final HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping = new HashMap<>();
static { static {
serverboundPacketMapping.put(ConnectionStates.HANDSHAKING, HashBiMap.create()); serverboundPacketMapping.put(ConnectionStates.HANDSHAKING, HashBiMap.create());
serverboundPacketMapping.put(ConnectionStates.STATUS, HashBiMap.create()); serverboundPacketMapping.put(ConnectionStates.STATUS, HashBiMap.create());
@ -52,9 +51,8 @@ public abstract class Protocol {
clientboundPacketMapping.get(ConnectionStates.LOGIN).put(Packets.Clientbound.LOGIN_PLUGIN_REQUEST, 0x04); clientboundPacketMapping.get(ConnectionStates.LOGIN).put(Packets.Clientbound.LOGIN_PLUGIN_REQUEST, 0x04);
} }
public static int getPacketCommand(Packets.Serverbound packet) { public static int getPacketCommand(Packets.Serverbound packet) {
return serverboundPacketMapping.get(packet.getState()).get(packet); return serverboundPacketMapping.get(packet.getState()).get(packet);
} }
public static Packets.Clientbound getPacketByCommand(ConnectionStates state, int command) { public static Packets.Clientbound getPacketByCommand(ConnectionStates state, int command) {

View File

@ -19,7 +19,6 @@ import sys
javaPath = "/usr/lib/jvm/java-8-openjdk-amd64/bin/java" javaPath = "/usr/lib/jvm/java-8-openjdk-amd64/bin/java"
print("Minecraft server wrapper") print("Minecraft server wrapper")
def download(manifest, version): def download(manifest, version):
versionJson = "" versionJson = ""
for key in manifest["versions"]: for key in manifest["versions"]:
@ -31,7 +30,6 @@ def download(manifest, version):
return return
downloadVersion(requests.get(versionJson).json()) downloadVersion(requests.get(versionJson).json())
def downloadVersion(versionJson): def downloadVersion(versionJson):
server = versionJson["downloads"]["server"]["url"] server = versionJson["downloads"]["server"]["url"]
if server == "": if server == "":
@ -48,7 +46,6 @@ def downloadVersion(versionJson):
f.write(server.content) f.write(server.content)
print("done") print("done")
if len(sys.argv) > 1: if len(sys.argv) > 1:
# check args # check args
if sys.argv[1] == "download-all": if sys.argv[1] == "download-all":