Skip to content

Commit

Permalink
Fixes for via hook
Browse files Browse the repository at this point in the history
  • Loading branch information
KaspianDev committed May 10, 2024
1 parent dc71bd1 commit b4b7e55
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 29 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ allprojects {
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringJoiner;

public class ViaVersionHook implements Hook {

Expand All @@ -32,19 +32,19 @@ public String getPluginName() {
@Override
public void register() {
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
for (Class<? extends ViaProtocolModifier<?>> modifier : modifiers) {
Iterator<Class<? extends ViaProtocolModifier<?>>> iterator = modifiers.iterator();
while (iterator.hasNext())
try {
Class<? extends ViaProtocolModifier<?>> modifier = iterator.next();
ViaProtocolModifier<?> modifierInstance = modifier.getDeclaredConstructor().newInstance();

if (serverVersion.is(modifierInstance.getComparison(), modifierInstance.getVersion())) {
modifierInstance.modify();
registeredModifiers.add(modifierInstance);
modifiers.remove(modifier);
AntiPopup.getInstance().getLogger().info(() -> getRegisteredMessage(modifierInstance));
}
} catch (IllegalAccessException | InvocationTargetException
| NoSuchMethodException | InstantiationException ignored) {}
}
}

private String getRegisteredMessage(ViaProtocolModifier<?> modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public Via_1_19_to_1_19_1() {
@Override
public void modify() {
protocol.appendClientbound(ClientboundPackets1_19.SERVER_DATA, (wrapper) -> {
wrapper.passthrough(Type.OPTIONAL_COMPONENT);
wrapper.passthrough(Type.OPTIONAL_STRING);
wrapper.passthrough(Type.BOOLEAN);
wrapper.write(Type.BOOLEAN, true);
wrapper.set(Type.BOOLEAN, 1, true);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,7 @@ public Via_1_20_4_to_1_20_5() {
@Override
public void modify() {
protocol.appendClientbound(ClientboundPackets1_20_3.JOIN_GAME, (wrapper) -> {
wrapper.passthrough(Type.INT); // Entity ID
wrapper.passthrough(Type.BOOLEAN); // Hardcore
wrapper.passthrough(Type.STRING_ARRAY); // World List
wrapper.passthrough(Type.VAR_INT); // Max players
wrapper.passthrough(Type.VAR_INT); // View distance
wrapper.passthrough(Type.VAR_INT); // Simulation distance
wrapper.passthrough(Type.BOOLEAN); // Reduced debug info
wrapper.passthrough(Type.BOOLEAN); // Show death screen
wrapper.passthrough(Type.BOOLEAN); // Limited crafting
wrapper.passthrough(Type.VAR_INT); // Dimension
wrapper.passthrough(Type.STRING); // World
wrapper.passthrough(Type.LONG); // Seed
wrapper.passthrough(Type.BYTE); // Gamemode
wrapper.passthrough(Type.BYTE); // Previous gamemode
wrapper.passthrough(Type.BOOLEAN); // Debug
wrapper.passthrough(Type.BOOLEAN); // Flat
wrapper.passthrough(Type.OPTIONAL_GLOBAL_POSITION); // Last death location
wrapper.passthrough(Type.VAR_INT); // Portal cooldown
wrapper.write(Type.BOOLEAN, true); // Enforces secure chat
wrapper.set(Type.BOOLEAN, 6, true); // Enforces secure chat
});
}

Expand Down

0 comments on commit b4b7e55

Please sign in to comment.