Skip to content

Commit

Permalink
Add player and network handler null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
darraghd493 committed Sep 13, 2023
1 parent 53ef4eb commit dbb41fc
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/main/java/widecat/meteorcrashaddon/modules/AACCrash.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public AACCrash() {

@Override
public void onActivate() {
if (mc.getNetworkHandler() == null || mc.player == null) return;

if (Utils.canUpdate() && !onTick.get()) {
switch (crashMode.get()) {
case NEW -> {
Expand All @@ -63,6 +65,8 @@ public void onActivate() {

@EventHandler
public void onTick(TickEvent.Pre tickEvent) {
if (mc.getNetworkHandler() == null || mc.player == null) return;

if (onTick.get()) {
switch (crashMode.get()) {
case NEW -> {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/widecat/meteorcrashaddon/modules/BookCrash.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private void onTick(TickEvent.Pre event) {
}

private void sendBadBook() {
if (mc.getNetworkHandler() == null || mc.player == null) return;

String title = "/stop" + Math.random() * 400;
String mm255 = RandomStringUtils.randomAlphanumeric(255);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public ContainerCrash() {

@EventHandler
private void onTick(TickEvent.Pre event) {
if (mc.getNetworkHandler() == null || mc.player == null) return;

if (GLFW.glfwGetKey(mc.getWindow().getHandle(), GLFW.GLFW_KEY_ESCAPE) == GLFW.GLFW_PRESS) {
toggle();
mc.player.closeHandledScreen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public CraftingCrash() {

@EventHandler
private void onTick(TickEvent.Post event) {
if (!(mc.player.currentScreenHandler instanceof CraftingScreenHandler) || mc.getNetworkHandler() == null) return;
if (mc.getNetworkHandler() == null || mc.player == null || !(mc.player.currentScreenHandler instanceof CraftingScreenHandler)) return;

try {
List<RecipeResultCollection> recipeResultCollectionList = mc.player.getRecipeBook().getOrderedResults();
for (RecipeResultCollection recipeResultCollection : recipeResultCollectionList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public CreativeCrash() {

@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.getNetworkHandler() == null || mc.player == null) return;

if (!mc.player.getAbilities().creativeMode) {
error("its literally called creative crash why are you trying this in survival");
toggle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public EntityCrash() {

@EventHandler
public void onTick(TickEvent.Post event) {
if (mc.getNetworkHandler() == null || mc.player == null) return;

Entity vehicle = mc.player.getVehicle();
if (vehicle == null) {
error("You must be riding an entity, toggling");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public ErrorCrash() {

@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.getNetworkHandler() == null || mc.player == null) return;

Int2ObjectMap<ItemStack> REAL = new Int2ObjectArrayMap<>();
REAL.put(0, new ItemStack(Items.RED_DYE, 1));
for (int i = 0; i < amount.get(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ private Vec3d pickRandomPos() {

@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.getNetworkHandler() == null) return;

switch (mode.get()) {
case NoCom -> {
for (int i = 0; i < amount.get(); i++) {
Vec3d cpos = pickRandomPos();
mc.getNetworkHandler().sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, new BlockHitResult(cpos, Direction.DOWN, BlockPos.ofFloored(cpos), false), 0));
Vec3d cpos = pickRandomPos();
mc.getNetworkHandler().sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, new BlockHitResult(cpos, Direction.DOWN, BlockPos.ofFloored(cpos), false), 0));
}
}
case OOB -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public LecternCrash() {

@EventHandler
private void onOpenScreenEvent(OpenScreenEvent event) {
if (!(event.screen instanceof LecternScreen)) return;
if (!(event.screen instanceof LecternScreen) || mc.getNetworkHandler() == null || mc.player == null) return;
mc.getNetworkHandler().sendPacket(new ClickSlotC2SPacket(mc.player.currentScreenHandler.syncId, mc.player.currentScreenHandler.getRevision(), 0, 0, SlotActionType.QUICK_MOVE, mc.player.currentScreenHandler.getCursorStack().copy(), Int2ObjectMaps.emptyMap()));
toggle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,22 @@ private void onGameLeft(GameLeftEvent event) {

private void sendLagMessage() {
String message = generateLagMessage();
ChatUtils.sendPlayerMsg(message);
ChatUtils.sendPlayerMsg(message);
}

private void sendLagWhisper() {
List<AbstractClientPlayerEntity> players = mc.world.getPlayers();
PlayerEntity player = players.get(new Random().nextInt(players.size()));
String message = generateLagMessage();

ChatUtils.sendPlayerMsg("/msg " + player.getGameProfile().getName() + " " + message);
ChatUtils.sendPlayerMsg("/msg " + player.getGameProfile().getName() + " " + message);
}

private String generateLagMessage() {
String message = null;
StringBuilder message = new StringBuilder();
for (int i = 0; i < messageLength.get(); i++) {
message += (char) (Math.floor(Math.random() * 0x1D300) + 0x800);
message.append((char) (Math.floor(Math.random() * 0x1D300) + 0x800));
}
return message;
return message.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public static double rndD(double rad) {

@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.getNetworkHandler() == null) return;
if (mc.getNetworkHandler() == null || mc.player == null) return;

try {
Vec3d current_pos = mc.player.getPos();
for (int i = 0; i < packets.get(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public PacketSpammer() {

@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.getNetworkHandler() == null) return;

for (int i = 0; i < amount.get(); i++) {
mc.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(Math.random() >= 0.5));
mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public SequenceCrash() {

@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.getNetworkHandler() == null || mc.player == null) return;

switch (mode.get()) {
case Item -> {
for (int i = 0; i < amount.get(); i++) {
Expand Down

0 comments on commit dbb41fc

Please sign in to comment.