Jump to content

[1.16.4] HandleCommand on PlayerWakeUpEvent crashing with java.lang.StackOverflowError


cheesecake441

Recommended Posts

Hi folks, 

Very new to game-dev work so my apologies if I'm just a n00b but I've been combing the forums for hours and my head is sore from banging it against the wall:

 

I'm trying to add an event listener on the "PlayerWakeUpEvent" that will send a message in chat and throw the player across the world using the "/teleport" command.

It worked absolutely perfectly when I used the "PlayerSleepInBedEvent" but for the wake-up event I seem to get stuck in a loop whereby my chat message and the error stack is verbose'd indefinitely until the game crashes (I was going to post the full error logs but there are 569773 lines so I just took what looked important)

 

Logs:

https://pastebin.com/5gFYL6Y4

 

package com.cheesecake.helloworld.events;

import com.cheesecake.helloworld.HelloWorld;
import com.cheesecake.helloworld.util.RegistryHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = HelloWorld.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ModClientEvents {

    @SubscribeEvent
    public static void onPlayerWakeUp(PlayerWakeUpEvent event){
        PlayerEntity player = event.getPlayer();
        World world = player.getEntityWorld();
        MinecraftServer server = world.getServer();
        CommandSource source = player.getCommandSource();

        //Static X Y Z Values until we can find biomes
        int px = 4226;
        int py = 67; // Above sea level but below clouds
        int pz = -79;

        if(!event.getPlayer().getEntityWorld().isRemote()) {
            player.sendMessage(new StringTextComponent("Have a nice trip"), player.getUniqueID());
            try {
                server.getCommandManager().handleCommand(source, "/teleport " + player.getUniqueID() + " " + px + " " + py + " " + pz);
            } catch (Exception e) {
                HelloWorld.LOGGER.info("Could not teleport the player");
            }
        }
    }
}

 

For reference here is the PlayerSleepInBedEvent I was using earlier (I disabled it when running the above in case of conflicts)
 

@SubscribeEvent
public static void MagicalDreamBed(PlayerSleepInBedEvent event){
   LivingEntity player = event.getPlayer();
   World world = player.getEntityWorld();
   MinecraftServer server = world.getServer();
   CommandSource commandsource = server.getCommandSource();

   // Static X Y Z Values until we can find biomes
   int px = 4226;
   int py = 67; // Above sea level but below clouds
   int pz = -79;

   if(!event.getPlayer().getEntityWorld().isRemote()){
       server.getCommandManager().handleCommand(commandsource, "/tp " + player.getUniqueID() + " " + px + " " + py + " " + pz);
       player.sendMessage(new StringTextComponent("Have a nice trip"), player.getUniqueID());
   }
}

 

I'm pretty sure its the server.getCommandManager().handleCommand part thats the problem but I have no idea as to why

Thanks in advance folks

"It's not broken, it just doesn't work" - Will Jones 2019

Link to comment
Share on other sites

Rather than trying to fake executing a command, just do the things that the command does.

i.e. instead of telling the server "the player typed /teleport, run the teleport command" just...teleport the player by changing their position.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

19 minutes ago, Draco18s said:

Rather than trying to fake executing a command, just do the things that the command does.

i.e. instead of telling the server "the player typed /teleport, run the teleport command" just...teleport the player by changing their position.

Thanks for the response - I've tried implementing player.setPositionAndUpdate (having changed my coord variables to doubles) as per the below but its not actually doing anything o.O

        if(!event.getPlayer().getEntityWorld().isRemote()) {
            player.sendMessage(new StringTextComponent("Have a nice trip"), player.getUniqueID());
            try {
                player.setPositionAndUpdate(px, py, pz);
                HelloWorld.LOGGER.info("The player has been teleported");
            } catch (Exception e) {
                HelloWorld.LOGGER.info("Could not teleport the player");
            }
        }

 

I've tried it with player as a LivingEntity and a PlayerEntity but neither works

"It's not broken, it just doesn't work" - Will Jones 2019

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Make a test without practical_plushies_mobs, practical_plushies_animals and dark-waters - looks like it is not working with sinytra connector
    • VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi   VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi   VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi
    • Maybe your file codes are missing. Therefore it is crashing.
    • I've been trying to make a mod pack for the last day or so now and I haven't been able to launch it once even with all mods disabled. It keeps showing up with Exit Code 1. I gave the modpack to a friend to try and it didn't launch on their pc either due to the same exit code, so I'm not entirely certain what the problem is or how to check it in the logs. So far I've attempted: - Changing from forge version 43.3.0 to 43.3.5 - Downloading Java - Disabling mods (both entirely and individually) I have an NVIDIA GeForce GTX 1070 driver, and I haven't tried to uninstall or reinstall it yet because I'm not certain how to and would have to mess anything up further. I have the latest .txt file of the crash report here: [16:24:34] [main/WARN]: Failed to add PDH Counter: \Paging File(_Total)\% Usage, Error code: 0xC0000BB8 [16:24:34] [main/WARN]: Failed to add counter for PDH counter: \Paging File(_Total)\% Usage [16:24:34] [main/WARN]: Disabling further attempts to query Paging File. [16:24:36] [main/WARN]: COM exception: Invalid Query: SELECT PERCENTUSAGE FROM Win32_PerfRawData_PerfOS_PagingFile [16:24:39] [Datafixer Bootstrap/INFO]: 198 Datafixer optimizations took 149 milliseconds [16:24:40] [Render thread/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD] [16:24:40] [Render thread/INFO]: Setting user: CatDoodlee [16:24:41] [Render thread/INFO]: Backend library: LWJGL version 3.3.2+13 [16:24:42] [Render thread/INFO]: Reloading ResourceManager: vanilla [16:24:42] [Worker-Main-11/INFO]: Found unifont_all_no_pua-15.1.04.hex, loading [16:24:44] [Render thread/WARN]: Missing sound for event: minecraft:item.goat_horn.play [16:24:44] [Render thread/WARN]: Missing sound for event: minecraft:entity.goat.screaming.horn_break [16:24:44] [Render thread/INFO]: OpenAL initialized on device OpenAL Soft on Speakers (Atrix Wired Elite Headset) [16:24:44] [Render thread/INFO]: Sound engine started [16:24:44] [Render thread/INFO]: Created: 1024x512x4 minecraft:textures/atlas/blocks.png-atlas [16:24:44] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/signs.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/shield_patterns.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/banner_patterns.png-atlas [16:24:44] [Render thread/INFO]: Created: 1024x1024x4 minecraft:textures/atlas/armor_trims.png-atlas [16:24:44] [Render thread/INFO]: Created: 128x64x4 minecraft:textures/atlas/decorated_pot.png-atlas [16:24:44] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/chest.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/shulker_boxes.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/beds.png-atlas [16:24:45] [Render thread/WARN]: Shader rendertype_entity_translucent_emissive could not find sampler named Sampler2 in the specified shader program. [16:24:45] [Render thread/INFO]: Created: 512x256x0 minecraft:textures/atlas/particles.png-atlas [16:24:45] [Render thread/INFO]: Created: 256x256x0 minecraft:textures/atlas/paintings.png-atlas [16:24:45] [Render thread/INFO]: Created: 128x128x0 minecraft:textures/atlas/mob_effects.png-atlas [16:24:45] [Render thread/INFO]: Created: 1024x512x0 minecraft:textures/atlas/gui.png-atlas [16:25:41] [Render thread/INFO]: Stopping! any form of help is greatly appreciated ❤️
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.