NPE + Relever pseudo lors d'un onBlockActivated



  • Bonsoir j'ai un problème malgré le NPE je ne vois pas comment faire pour détecter le pseudo du joueur ou faire entity.getDisplayName() mais ça ne marche pas non plus 😕

    package fr.altiscraft.altiscraft.common;
    
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import net.minecraft.block.Block;
    import net.minecraft.block.material.Material;
    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.world.World;
    
    public class Garage2 extends Block {
    protected Garage2() {
    super(Material.ground);
    }
    public Minecraft mc;
    
    @SideOnly(Side.CLIENT)
        public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entity, int side, float hitX, float hitY, float hitZ)
        {
            if (this.mc.getSession().getUsername().equals("Alex_Gamer"))
        {
            world.setBlock(x, y, z, ModAltisCraft.Garage1, 0, 2);
            world.setBlock(x + 1, y, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 2, y, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 3, y, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 4, y, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 5, y, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 6, y, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 7, y, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 1, y - 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 2, y - 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 3, y - 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 4, y - 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 5, y - 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 6, y - 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 7, y - 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 1, y + 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 2, y + 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 3, y + 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 4, y + 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 5, y + 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 6, y + 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 7, y + 1, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 1, y + 2, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 2, y + 2, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 3, y + 2, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 4, y + 2, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 5, y + 2, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 6, y + 2, z, Blocks.quartz_block, 0, 2);
            world.setBlock(x + 7, y + 2, z, Blocks.quartz_block, 0, 2);
        }
            return true;
        }
    }
    

    Crash:

    –-- Minecraft Crash Report ----
    // Ooh. Shiny.

    Time: 06/11/15 18:19
    Description: Unexpected error

    java.lang.NullPointerException: Unexpected error
    at fr.altiscraft.altiscraft.common.Garage2.func_149727_a(Garage2.java:21)
    at net.minecraft.client.multiplayer.PlayerControllerMP.func_78760_a(PlayerControllerMP.java:326)
    at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1435)
    at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1941)
    at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:961)
    at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:887)
    at net.minecraft.client.main.Main.main(SourceFile:148)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at fr.minecraftforgefrance.updater.Updater.runMinecraft(Updater.java:133)
    at fr.minecraftforgefrance.updater.Updater.onFinish(Updater.java:145)
    at fr.minecraftforgefrance.common.ProcessInstall.finish(ProcessInstall.java:309)
    at fr.minecraftforgefrance.common.ProcessInstall$1.run(ProcessInstall.java:153)

    A detailed walkthrough of the error, its code path and all known details is as follows:

    -- Head --
    Stacktrace:
    at fr.altiscraft.altiscraft.common.Garage2.func_149727_a(Garage2.java:21)
    at net.minecraft.client.multiplayer.PlayerControllerMP.func_78760_a(PlayerControllerMP.java:326)
    at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1435)

    -- Affected level --
    Details:
    Level name: MpServer
    All players: 5 total; [EntityClientPlayerMP['Benjamin_Loison'/11967, l='MpServer', x=-8556,72, y=34,62, z=-3770,10], MCH_ViewEntityDummy['McHeliDummyEntity'/1, l='MpServer', x=0,50, y=101,62, z=0,50], MCH_ViewEntityDummy['McHeliDummyEntity'/1, l='MpServer', x=0,50, y=101,62, z=0,50], EntityOtherPlayerMP['Eclipse_Prod'/6896, l='MpServer', x=-8511,11, y=32,88, z=-3753,67], EntityOtherPlayerMP['MRCool_123'/10960, l='MpServer', x=-8558,91, y=33,00, z=-3753,72]]
    Chunk stats: MultiplayerChunkCache: 423, 423
    Level seed: 0
    Level generator: ID 02 - largeBiomes, ver 0. Features enabled: false
    Level generator options: 
    Level spawn location: World: (6,239,-14), Chunk: (at 6,14,2 in 0,-1; contains blocks 0,0,-16 to 15,255,-1), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
    Level time: 307224588 game time, 319017262 day time
    Level dimension: 0
    Level storage version: 0x00000 - Unknown?
    Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
    Forced entities: 48 total; [EntityClientPlayerMP['Benjamin_Loison'/11967, l='MpServer', x=-8556,72, y=34,62, z=-3770,10], MCH_ViewEntityDummy['McHeliDummyEntity'/1, l='MpServer', x=0,50, y=101,62, z=0,50], EntityVehicle['Quad'/258, l='MpServer', x=-8493,50, y=8,63, z=-3833,50], EntityWheel['entity.Wheel.name'/644, l='MpServer', x=-8344,53, y=36,00, z=-3661,53], EntityWheel['entity.Wheel.name'/646, l='MpServer', x=-8340,50, y=36,00, z=-3661,50], EntityOtherPlayerMP['twixethan'/9188, l='MpServer', x=-0,03, y=99,00, z=1,69], EntityMarketPNJ['PNJ personnalisable'/2195, l='MpServer', x=-2662,50, y=51,00, z=-3616,50], EntityOtherPlayerMP['minibuz77'/11441, l='MpServer', x=-8505,16, y=33,44, z=-3740,38], EntityOtherPlayerMP['AlphaTeech'/9677, l='MpServer', x=-8507,56, y=33,00, z=-3764,84], EntityVehicle['Pink Cadilac'/10918, l='MpServer', x=-8511,55, y=33,63, z=-3754,04], EntityOtherPlayerMP['Theo_Toilette'/10927, l='MpServer', x=-8482,69, y=33,00, z=-3752,69], EntitySeat['entity.Seat.name'/10919, l='MpServer', x=-8511,11, y=33,38, z=-3753,67], EntityOtherPlayerMP['DarkLouf'/911, l='MpServer', x=-8504,49, y=33,00, z=-3751,28], EntitySeat['entity.Seat.name'/10920, l='MpServer', x=-8511,98, y=33,38, z=-3753,67], EntitySeat['entity.Seat.name'/10921, l='MpServer', x=-8511,12, y=33,37, z=-3754,80], EntitySeat['entity.Seat.name'/10922, l='MpServer', x=-8511,99, y=33,37, z=-3754,79], EntityCamera['inconnu'/43, l='MpServer', x=-8523,50, y=7,63, z=-3741,50], EntityWheel['entity.Wheel.name'/10923, l='MpServer', x=-8510,56, y=33,07, z=-3755,37], EntityWheel['entity.Wheel.name'/10924, l='MpServer', x=-8512,56, y=33,07, z=-3755,36], EntityWheel['entity.Wheel.name'/10926, l='MpServer', x=-8510,54, y=33,07, z=-3752,60], EntityOtherPlayerMP['Rafalaofficiel'/10789, l='MpServer', x=-8495,69, y=33,97, z=-3775,81], EntityOtherPlayerMP['XxDarkEternalxX'/7846, l='MpServer', x=-8493,75, y=33,00, z=-3781,75], EntityOtherPlayerMP['baba38220'/10961, l='MpServer', x=-8479,75, y=33,00, z=-3734,00], EntityVehicle['Dogde Ram'/187, l='MpServer', x=-8523,50, y=7,63, z=-3741,50], EntityCamera['inconnu'/67, l='MpServer', x=-8511,39, y=33,65, z=-3757,52], EntityMarketPNJ['PNJ personnalisable'/198, l='MpServer', x=-8518,50, y=33,00, z=-3732,50], EntityOtherPlayerMP['Zzomblarz'/617, l='MpServer', x=-8466,50, y=33,00, z=-3800,00], EntityMarketPNJ['PNJ personnalisable'/203, l='MpServer', x=-8530,50, y=33,00, z=-3764,50], EntityOtherPlayerMP['MRCool_123'/10960, l='MpServer', x=-8558,91, y=33,00, z=-3753,72], EntityMarketPNJ['PNJ personnalisable'/214, l='MpServer', x=-8558,50, y=33,00, z=-3751,50], EntityMarketPNJ['PNJ personnalisable'/215, l='MpServer', x=-8547,50, y=34,00, z=-3763,50], EntityMarketPNJ['PNJ personnalisable'/216, l='MpServer', x=-8546,50, y=34,00, z=-3762,50], EntityMarketPNJ['PNJ personnalisable'/217, l='MpServer', x=-8547,50, y=34,00, z=-3762,50], EntityMarketPNJ['PNJ personnalisable'/218, l='MpServer', x=-8546,50, y=36,00, z=-3763,50], EntityWheel['entity.Wheel.name'/349, l='MpServer', x=-8420,09, y=36,00, z=-3757,59], EntitySeat['entity.Seat.name'/222, l='MpServer', x=-8523,60, y=7,81, z=-3742,11], EntitySeat['entity.Seat.name'/223, l='MpServer', x=-8522,98, y=7,81, z=-3741,17], EntityWheel['entity.Wheel.name'/224, l='MpServer', x=-8525,44, y=7,00, z=-3741,50], EntityWheel['entity.Wheel.name'/225, l='MpServer', x=-8524,27, y=7,00, z=-3739,72], EntityOtherPlayerMP['Isma22'/9676, l='MpServer', x=-8462,28, y=33,00, z=-3800,22], EntityWheel['entity.Wheel.name'/226, l='MpServer', x=-8521,61, y=7,00, z=-3741,50], EntitySeat['entity.Seat.name'/358, l='MpServer', x=-8493,56, y=8,63, z=-3834,12], EntityWheel['entity.Wheel.name'/616, l='MpServer', x=-8413,75, y=21,00, z=-3604,75], EntityWheel['entity.Wheel.name'/360, l='MpServer', x=-8494,50, y=8,00, z=-3831,75], EntityCamera['inconnu'/232, l='MpServer', x=-8493,50, y=8,65, z=-3833,50], EntityWheel['entity.Wheel.name'/362, l='MpServer', x=-8492,50, y=8,00, z=-3835,25], EntityOtherPlayerMP['Eclipse_Prod'/6896, l='MpServer', x=-8511,11, y=32,88, z=-3753,67], EntityOtherPlayerMP['Eclipse_Prod'/6896, l='MpServer', x=-8511,11, y=32,88, z=-3753,67]]
    Retry entities: 0 total; []
    Server brand: kcauldron,cauldron,craftbukkit,mcpc,fml,forge
    Server type: Non-integrated multiplayer server
    Stacktrace:
    at net.minecraft.client.multiplayer.WorldClient.func_72914_a(WorldClient.java:373)
    at net.minecraft.client.Minecraft.func_71396_d(Minecraft.java:2432)
    at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:916)
    at net.minecraft.client.main.Main.main(SourceFile:148)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at fr.minecraftforgefrance.updater.Updater.runMinecraft(Updater.java:133)
    at fr.minecraftforgefrance.updater.Updater.onFinish(Updater.java:145)
    at fr.minecraftforgefrance.common.ProcessInstall.finish(ProcessInstall.java:309)
    at fr.minecraftforgefrance.common.ProcessInstall$1.run(ProcessInstall.java:153)

    – System Details --
    Details:
    Minecraft Version: 1.7.10
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_25, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 509070656 bytes (485 MB) / 1009778688 bytes (963 MB) up to 1883242496 bytes (1796 MB)
    JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
    AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
    IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 103
    FML: MCP v9.05 FML v7.10.103.1355 Minecraft Forge 10.13.3.1355 Optifine OptiFine_1.7.10_HD_U_B6 11 mods loaded, 11 mods active
    mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    FML{7.10.103.1355} [Forge Mod Loader] (forge-1.7.10-10.13.3.1355-1.7.10.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    Forge{10.13.3.1355} [Minecraft Forge] (forge-1.7.10-10.13.3.1355-1.7.10.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    CarpentersBlocks{0.0.1 Beta} [AltisCraft.fr] (AltisCraft.fr.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    flansmod{@VERSION@} [Flan's Mod] (AltisCraft.fr.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    thirstmod{1.8.14} [Thirst Mod] (AltisCraft.fr.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    t4pro{1.0.1} [Project] (AltisCraft.fr.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    altiscraft.MODID{1.0.0} [AltisCraft.fr] (AltisCraft.fr.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    Backpack{2.0.1} [Backpack] (backpack-2.0.1-1.7.x.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    gvc{0.6.1} [§aGliby's§f Voice Chat Mod] (GlibysVC-1.7.10-0.6.1.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    mcheli{0.10.6} [MC Helicopter] (mcheli) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available
    Launched Version: AltisCraft
    LWJGL: 2.9.1
    OpenGL: GeForce GTX 850M/PCIe/SSE2 GL version 4.5.0 NVIDIA 355.60, NVIDIA Corporation
    GL Caps: Using GL 1.3 multitexturing.
    Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
    Anisotropic filtering is supported and maximum anisotropy is 16.
    Shaders are available because OpenGL 2.1 is supported.

    Is Modded: Definitely; Client brand changed to 'fml,forge'
    Type: Client (map_client.txt)
    Resource Packs: [AltisCraftChat-RP.zip]
    Current Language: Français (France)
    Profiler Position: N/A (disabled)
    Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
    Anisotropic Filtering: Off (1)



  • Le NPE : Tu utilises une instance de Minecraft sans l'avoir initialisée, de plus ton code ne marche que côté client or tu poses des blocks donc impossible.

    Tu devrais plutôt comparer les pseudos en vérifiant aussi que le joueur est connecté.


  • Administrateurs

    entity.getCommandSenderName() au lieu de this.mc.getSession().getUsername()



  • Merci des réponses ! 🙂