Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Oct 20, 2023
1 parent 2cbb030 commit a4aa87f
Show file tree
Hide file tree
Showing 83 changed files with 277 additions and 454 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void register() {
wrapper.read(Type.VAR_INT); // protocolVersion
final String hostname = wrapper.read(Type.STRING); // hostName
final int port = wrapper.read(Type.UNSIGNED_SHORT); // port
wrapper.user().put(new HandshakeStorage(wrapper.user(), hostname, port));
wrapper.user().put(new HandshakeStorage(hostname, port));
});
}
});
Expand All @@ -60,7 +60,7 @@ public void register() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new ProtocolMetadataStorage(userConnection));
userConnection.put(new ProtocolMetadataStorage());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@
*/
package net.raphimc.vialegacy.api.splitter;

import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.protocol.Protocol;

import java.util.function.IntFunction;

public class PreNettySplitter extends StoredObject {
public class PreNettySplitter implements StorableObject {

private final IntFunction<PreNettyPacketType> packetTypeSupplier;
private final Class<? extends Protocol<?, ?, ?, ?>> protocolClass;

public PreNettySplitter(UserConnection user, Class<? extends Protocol<?, ?, ?, ?>> protocolClass, IntFunction<PreNettyPacketType> packetTypeSupplier) {
super(user);
public PreNettySplitter(Class<? extends Protocol<?, ?, ?, ?>> protocolClass, IntFunction<PreNettyPacketType> packetTypeSupplier) {
this.protocolClass = protocolClass;
this.packetTypeSupplier = packetTypeSupplier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void register() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_0_16_2toa1_0_15.class, ClientboundPacketsa1_0_15::getPacket));
userConnection.put(new PreNettySplitter(Protocola1_0_16_2toa1_0_15.class, ClientboundPacketsa1_0_15::getPacket));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public void register(ViaProviders providers) {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_0_17_1_0_17_4toa1_0_16_2.class, ClientboundPacketsa1_0_16::getPacket));
userConnection.put(new PreNettySplitter(Protocola1_0_17_1_0_17_4toa1_0_16_2.class, ClientboundPacketsa1_0_16::getPacket));

userConnection.put(new TimeLockStorage(userConnection, 0));
userConnection.put(new TimeLockStorage(0));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
*/
package net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.storage;

import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.connection.StorableObject;

public class TimeLockStorage extends StoredObject {
public class TimeLockStorage implements StorableObject {

private long time;

public TimeLockStorage(UserConnection user, final long time) {
super(user);
public TimeLockStorage(final long time) {
this.time = time;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void registerPackets() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.class, ClientboundPacketsa1_0_17::getPacket));
userConnection.put(new PreNettySplitter(Protocola1_1_0_1_1_2_1toa1_0_17_1_0_17_4.class, ClientboundPacketsa1_0_17::getPacket));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void register() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1.class, ClientboundPacketsa1_1_0::getPacket));
userConnection.put(new PreNettySplitter(Protocola1_2_0_1_2_1_1toa1_1_0_1_1_2_1.class, ClientboundPacketsa1_1_0::getPacket));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void register() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_2_2toa1_2_0_1_2_1_1.class, ClientboundPacketsa1_2_0::getPacket));
userConnection.put(new PreNettySplitter(Protocola1_2_2toa1_2_0_1_2_1_1.class, ClientboundPacketsa1_2_0::getPacket));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void register() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_2_3_1_2_3_4toa1_2_2.class, ClientboundPacketsa1_2_2::getPacket));
userConnection.put(new PreNettySplitter(Protocola1_2_3_1_2_3_4toa1_2_2.class, ClientboundPacketsa1_2_2::getPacket));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void register() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4.class, ClientboundPacketsa1_2_3::getPacket));
userConnection.put(new PreNettySplitter(Protocola1_2_3_5_1_2_6toa1_2_3_1_2_3_4.class, ClientboundPacketsa1_2_3::getPacket));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void register() {
wrapper.cancel();
final InventoryStorage tracker = wrapper.user().get(InventoryStorage.class);
final Position pos = wrapper.read(Types1_7_6.POSITION_SHORT); // position
final CompoundTag tag = wrapper.read(Types1_7_6.COMPRESSED_NBT); // data
final CompoundTag tag = wrapper.read(Types1_7_6.NBT); // data

if (tag.<IntTag>get("x").asInt() != pos.x() || tag.<IntTag>get("y").asInt() != pos.y() || tag.<IntTag>get("z").asInt() != pos.z()) {
return;
Expand Down Expand Up @@ -365,7 +365,7 @@ public void register() {
wrapper.write(Type.INT, tracker.openContainerPos.x());
wrapper.write(Type.SHORT, (short) tracker.openContainerPos.y());
wrapper.write(Type.INT, tracker.openContainerPos.z());
wrapper.write(Types1_7_6.COMPRESSED_NBT, tag);
wrapper.write(Types1_7_6.NBT, tag);
});
}
});
Expand All @@ -384,7 +384,7 @@ public void register() {
tag.put("Text2", new StringTag(wrapper.read(Typesb1_7_0_3.STRING))); // line 2
tag.put("Text3", new StringTag(wrapper.read(Typesb1_7_0_3.STRING))); // line 3
tag.put("Text4", new StringTag(wrapper.read(Typesb1_7_0_3.STRING))); // line 4
wrapper.write(Types1_7_6.COMPRESSED_NBT, tag); // data
wrapper.write(Types1_7_6.NBT, tag); // data
});
}
});
Expand Down Expand Up @@ -528,9 +528,9 @@ public void register(ViaProviders providers) {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class, ClientboundPacketsa1_2_6::getPacket));
userConnection.put(new PreNettySplitter(Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.class, ClientboundPacketsa1_2_6::getPacket));

userConnection.put(new InventoryStorage(userConnection));
userConnection.put(new InventoryStorage());
if (Via.getManager().getProviders().get(AlphaInventoryProvider.class).usesInventoryTracker()) {
userConnection.put(new AlphaInventoryTracker(userConnection));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
*/
package net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage;

import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.item.Item;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class InventoryStorage extends StoredObject {
public class InventoryStorage implements StorableObject {

public static final byte WORKBENCH_WID = 33;
public static final byte FURNACE_WID = 44;
Expand All @@ -42,8 +41,7 @@ public class InventoryStorage extends StoredObject {
public Position openContainerPos = null;
public short selectedHotbarSlot = 0;

public InventoryStorage(UserConnection user) {
super(user);
public InventoryStorage() {
this.resetPlayerInventory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void register() {
public void register() {
map(Type.BYTE); // window id
map(Type.SHORT); // slot
map(Types1_4_2.NBTLESS_ITEM, Types1_2_4.COMPRESSED_NBT_ITEM); // item
map(Types1_4_2.NBTLESS_ITEM, Types1_2_4.NBT_ITEM); // item
}
});
this.registerClientbound(ClientboundPacketsb1_8.WINDOW_ITEMS, new PacketHandlers() {
@Override
public void register() {
map(Type.BYTE); // window id
map(Types1_4_2.NBTLESS_ITEM_ARRAY, Types1_2_4.COMPRESSED_NBT_ITEM_ARRAY); // item
map(Types1_4_2.NBTLESS_ITEM_ARRAY, Types1_2_4.NBT_ITEM_ARRAY); // item
}
});

Expand All @@ -82,7 +82,7 @@ public void register() {
public void register() {
map(Types1_7_6.POSITION_UBYTE); // position
map(Type.UNSIGNED_BYTE); // direction
map(Types1_2_4.COMPRESSED_NBT_ITEM, Types1_4_2.NBTLESS_ITEM);
map(Types1_2_4.NBT_ITEM, Types1_4_2.NBTLESS_ITEM);
}
});
this.registerServerbound(ServerboundPackets1_0.CLICK_WINDOW, new PacketHandlers() {
Expand All @@ -93,14 +93,14 @@ public void register() {
map(Type.BYTE); // button
map(Type.SHORT); // action
map(Type.BYTE); // mode
map(Types1_2_4.COMPRESSED_NBT_ITEM, Types1_4_2.NBTLESS_ITEM); // item
map(Types1_2_4.NBT_ITEM, Types1_4_2.NBTLESS_ITEM); // item
}
});
this.registerServerbound(ServerboundPackets1_0.CREATIVE_INVENTORY_ACTION, new PacketHandlers() {
@Override
public void register() {
map(Type.SHORT); // slot
map(Types1_2_4.COMPRESSED_NBT_ITEM, Typesb1_8_0_1.CREATIVE_ITEM); // item
map(Types1_2_4.NBT_ITEM, Typesb1_8_0_1.CREATIVE_ITEM); // item
handler(wrapper -> itemRewriter.handleItemToServer(wrapper.get(Typesb1_8_0_1.CREATIVE_ITEM, 0)));
}
});
Expand All @@ -114,9 +114,9 @@ public void register(ViaProviders providers) {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocol1_0_0_1tob1_8_0_1.class, ClientboundPacketsb1_8::getPacket));
userConnection.put(new PreNettySplitter(Protocol1_0_0_1tob1_8_0_1.class, ClientboundPacketsb1_8::getPacket));

userConnection.put(new PlayerAirTimeStorage(userConnection));
userConnection.put(new PlayerAirTimeStorage());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@
*/
package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.storage;

import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.connection.StorableObject;

public class PlayerAirTimeStorage extends StoredObject {
public class PlayerAirTimeStorage implements StorableObject {

public final int MAX_AIR = 300;
public int air = MAX_AIR;
public boolean sentPacket = true;

public PlayerAirTimeStorage(UserConnection user) {
super(user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.google.common.collect.Lists;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
Expand Down Expand Up @@ -135,11 +134,7 @@ public void register() {
this.registerClientbound(ClientboundPacketsb1_1.CHUNK_DATA, new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> {
final ClientWorld clientWorld = new ClientWorld(wrapper.user());
clientWorld.setEnvironment(0);
BLOCK_DATA_REWRITER.remapChunk(wrapper.passthrough(Types1_1.CHUNK));
});
handler(wrapper -> BLOCK_DATA_REWRITER.remapChunk(wrapper.passthrough(Types1_1.CHUNK))); // chunk
}
});
this.registerClientbound(ClientboundPacketsb1_1.MULTI_BLOCK_CHANGE, new PacketHandlers() {
Expand Down Expand Up @@ -203,9 +198,9 @@ public void register() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_2_0_2tob1_1_2.class, ClientboundPacketsb1_1::getPacket));
userConnection.put(new PreNettySplitter(Protocolb1_2_0_2tob1_1_2.class, ClientboundPacketsb1_1::getPacket));

userConnection.put(new EntityFlagStorage(userConnection));
userConnection.put(new EntityFlagStorage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@
*/
package net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.storage;

import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;

public class EntityFlagStorage extends StoredObject {
public class EntityFlagStorage implements StorableObject {

private final Int2IntMap animationFlags = new Int2IntOpenHashMap();

public EntityFlagStorage(UserConnection user) {
super(user);
}

public boolean getFlag(final int entityId, final int index) {
return (this.getFlagMask(entityId) & 1 << index) != 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void register(ViaProviders providers) {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_3_0_1tob1_2_0_2.class, ClientboundPacketsb1_2::getPacket));
userConnection.put(new PreNettySplitter(Protocolb1_3_0_1tob1_2_0_2.class, ClientboundPacketsb1_2::getPacket));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Protocolb1_4_0_1tob1_3_0_1() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_4_0_1tob1_3_0_1.class, ClientboundPacketsb1_3::getPacket));
userConnection.put(new PreNettySplitter(Protocolb1_4_0_1tob1_3_0_1.class, ClientboundPacketsb1_3::getPacket));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private void rewriteMetadata(final List<Metadata> metadataList) {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_5_0_2tob1_4_0_1.class, ClientboundPacketsb1_4::getPacket));
userConnection.put(new PreNettySplitter(Protocolb1_5_0_2tob1_4_0_1.class, ClientboundPacketsb1_4::getPacket));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public void register(ViaProviders providers) {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_6_0_6tob1_5_0_2.class, ClientboundPacketsb1_5::getPacket));
userConnection.put(new PreNettySplitter(Protocolb1_6_0_6tob1_5_0_2.class, ClientboundPacketsb1_5::getPacket));

userConnection.put(new WorldTimeStorage(userConnection));
userConnection.put(new WorldTimeStorage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@
*/
package net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.storage;

import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.connection.StorableObject;

public class WorldTimeStorage extends StoredObject {
public class WorldTimeStorage implements StorableObject {

public long time;

public WorldTimeStorage(UserConnection user) {
super(user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ public void register() {

@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(userConnection, Protocolb1_8_0_1tob1_7_0_3.class, ClientboundPacketsb1_7::getPacket));
userConnection.put(new PreNettySplitter(Protocolb1_8_0_1tob1_7_0_3.class, ClientboundPacketsb1_7::getPacket));

userConnection.put(new PlayerNameTracker(userConnection));
userConnection.put(new PlayerHealthTracker(userConnection));
userConnection.put(new PlayerNameTracker());
userConnection.put(new PlayerHealthTracker());
}

private boolean isSword(final Item item) {
Expand Down
Loading

0 comments on commit a4aa87f

Please sign in to comment.