Skip to content

Commit

Permalink
Permission change. Also event changes. Removed unused mixin.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Apr 26, 2024
1 parent bf5d0cc commit fa2a705
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 69 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

name: Java Gradle

on: push
on: [pull_request,push]
permissions:
contents: write

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
import dev.heliosclient.event.Event;
import dev.heliosclient.event.LuaEvent;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;

@Cancelable
@LuaEvent("PlayerJoinEvent")
public class PlayerJoinEvent extends Event {
private final PlayerEntity player;
private final GameJoinS2CPacket packet;

public PlayerJoinEvent(PlayerEntity player) {

public PlayerJoinEvent(PlayerEntity player, GameJoinS2CPacket packet) {
this.player = player;
this.packet = packet;
}

public PlayerEntity getPlayer() {
return player;
}

public GameJoinS2CPacket getPacket() {
return packet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
import dev.heliosclient.event.Event;
import dev.heliosclient.event.LuaEvent;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;

@Cancelable
@LuaEvent("PlayerRespawnEvent")
public class PlayerRespawnEvent extends Event {
private final PlayerEntity player;
private final PlayerRespawnS2CPacket packet;

public PlayerRespawnEvent(PlayerEntity player) {
public PlayerRespawnEvent(PlayerEntity player, PlayerRespawnS2CPacket packet) {
this.player = player;
this.packet = packet;
}

public PlayerEntity getPlayer() {
return player;
}

public PlayerRespawnS2CPacket getPacket() {
return packet;
}
}
2 changes: 2 additions & 0 deletions src/main/java/dev/heliosclient/managers/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public void add(Command command) {
command.registerTo(DISPATCHER);
commands.add(command);
commandInstances.put(command.getClass(), command);

commands.sort(Comparator.comparing(Command::getName));
}

public Command getCommandByName(String commandName) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/dev/heliosclient/managers/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* Manager class for configs. Manages multiple config TOMLs and their maps for saving/loading.
*/
public class ConfigManager {
// Stores the configuration maps.
private final Map<String, Map<String, Object>> configMaps = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private static <T extends PacketListener> void onHandlePacket(Packet<T> packet,
@Inject(method = "send(Lnet/minecraft/network/packet/Packet;)V", at = @At("HEAD"), cancellable = true)
public void send(Packet<?> packet, CallbackInfo ci) {
if (EventManager.postEvent(new PacketEvent.SEND(packet)).isCanceled()) ci.cancel();

// Call commands if the prefix is sent
if (packet instanceof ChatMessageC2SPacket && ((ChatMessageC2SPacket) packet).chatMessage().startsWith(CommandManager.get().getPrefix())) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.heliosclient.event.Event;
import dev.heliosclient.event.events.player.PlayerDeathEvent;
import dev.heliosclient.event.events.player.PlayerJoinEvent;
import dev.heliosclient.event.events.player.PlayerRespawnEvent;
import dev.heliosclient.managers.EventManager;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -22,7 +23,7 @@ public abstract class MixinClientPlayNetworkHandler {
@Inject(method = "onGameJoin", at = @At("RETURN"), cancellable = true)
private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo info) {
PlayerEntity player = HeliosClient.MC.player;
Event event = new PlayerJoinEvent(player);
Event event = new PlayerJoinEvent(player,packet);
EventManager.postEvent(event);
if (event.isCanceled()) {
info.cancel();
Expand All @@ -33,9 +34,8 @@ private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo info) {
@Inject(method = "onPlayerRespawn", at = @At("RETURN"), cancellable = true)
private void onPlayerRespawn(PlayerRespawnS2CPacket packet, CallbackInfo info) {
PlayerEntity player = HeliosClient.MC.player;
Event event = new PlayerJoinEvent(player);
EventManager.postEvent(event);
if (event.isCanceled()) {
Event event = new PlayerRespawnEvent(player,packet);
if (EventManager.postEvent(event).isCanceled()) {
info.cancel();
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/dev/heliosclient/mixin/MixinPlayerEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,8 @@ private void onDeath(DamageSource damageSource, CallbackInfo ci) {
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
private void onPlayerDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
// This variable holds the event object
PlayerDamageEvent event = new PlayerDamageEvent((PlayerEntity) (Object) this, source);

// This line posts the event to the event manager
EventManager.postEvent(event);

// This line checks if the event is canceled and returns false if so
if (event.isCanceled()) {
cir.setReturnValue(event.isCanceled());
if(EventManager.postEvent(new PlayerDamageEvent((PlayerEntity) (Object) this, source)).isCanceled()){
cir.cancel();
}
}
}
1 change: 1 addition & 0 deletions src/main/java/dev/heliosclient/mixin/MouseMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public abstract class MouseMixin {

@Inject(method = "onMouseButton", at = @At(value = "TAIL"), cancellable = true)
private void onButton(long window, int button, int action, int mods, CallbackInfo ci) {
//Translate screen mouse positions to minecraft friendly positions
double mouseX = getX() * (double) this.client.getWindow().getScaledWidth() / (double) this.client.getWindow().getWidth();
double mouseY = getY() * (double) this.client.getWindow().getScaledHeight() / (double) this.client.getWindow().getHeight();

Expand Down
44 changes: 0 additions & 44 deletions src/main/java/dev/heliosclient/mixin/PlayerEntityModelMixin.java

This file was deleted.

12 changes: 5 additions & 7 deletions src/main/java/dev/heliosclient/module/Module_.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import dev.heliosclient.event.events.render.RenderEvent;
import dev.heliosclient.event.listener.Listener;
import dev.heliosclient.managers.EventManager;
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.managers.NotificationManager;
import dev.heliosclient.module.modules.misc.NotificationModule;
import dev.heliosclient.module.settings.BooleanSetting;
Expand All @@ -24,7 +23,6 @@
import net.minecraft.client.MinecraftClient;

import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;

/**
* Template for modules.
Expand All @@ -35,7 +33,7 @@ public abstract class Module_ implements Listener, ISettingChange, ISaveAndLoad
public String description;
public Category category;
public Set<SettingGroup> settingGroups;
public Set<Setting> quickSettings;
public Set<Setting<?>> quickSettings;
public boolean settingsOpen = false;
public SettingGroup sgbind = new SettingGroup("Bind");

Expand Down Expand Up @@ -116,7 +114,7 @@ public void addSettingGroup(SettingGroup settingGroup) {
* Adds a setting to the {@link #quickSettings} list
* @param setting setting to be added
*/
public void addQuickSetting(Setting setting) {
public void addQuickSetting(Setting<?> setting) {
this.quickSettings.add(setting);
}

Expand All @@ -128,7 +126,7 @@ public void addQuickSetting(Setting setting) {
*
* @param setting setting list to be added
*/
public void addQuickSettings(List<Setting> setting) {
public void addQuickSettings(List<Setting<?>> setting) {
this.quickSettings.addAll(setting);
}

Expand All @@ -152,7 +150,7 @@ public boolean isActive() {
}

/**
* Called on disable. Probably shouldn't disable original functionality since it will remove chat feedback.
* Called on disable. Probably shouldn't override without super call since it will remove chat feedback.
*/
public void onDisable() {
active.value = false;
Expand All @@ -164,7 +162,7 @@ public void onDisable() {
}

/**
* Called on motion.
* Called on player motion.
*/
@SubscribeEvent
public void onMotion(PlayerMotionEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class SettingGroup {
private final String name;
private final float groupNameHeight;
private List<Setting> settings = new ArrayList<>();
private List<Setting<?>> settings = new ArrayList<>();
private float height;
private boolean shouldRender = true;
private int x, y, windowWidth;
Expand Down Expand Up @@ -110,11 +110,11 @@ public int getWindowWidth() {
return windowWidth;
}

public List<Setting> getSettings() {
public List<Setting<?>> getSettings() {
return settings;
}

public void setSettings(List<Setting> settings) {
public void setSettings(List<Setting<?>> settings) {
this.settings = settings;
}

Expand Down

0 comments on commit fa2a705

Please sign in to comment.