Skip to content

Commit

Permalink
Fixed gamemode event firing when changing gamemodes for fake players …
Browse files Browse the repository at this point in the history
…causing errors from other plugins
  • Loading branch information
OmerBenGera committed Jan 4, 2022
1 parent 15b1318 commit 927a017
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bgsoftware.wildloaders.nms;

import com.bgsoftware.common.reflection.ReflectMethod;
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
import com.bgsoftware.wildloaders.handlers.NPCHandler;
import com.bgsoftware.wildloaders.npc.DummyChannel;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.network.protocol.game.PacketPlayInWindowClick;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.PlayerInteractManager;
import net.minecraft.server.level.WorldServer;
import net.minecraft.server.network.PlayerConnection;
import net.minecraft.world.entity.Entity;
Expand All @@ -27,6 +29,9 @@

public final class ChunkLoaderNPC_v1_17_R1 extends EntityPlayer implements ChunkLoaderNPC {

private static final ReflectMethod<Void> SET_GAMEMODE = new ReflectMethod<>(PlayerInteractManager.class,
1, EnumGamemode.class, EnumGamemode.class);

private boolean dieCall = false;

public ChunkLoaderNPC_v1_17_R1(MinecraftServer minecraftServer, Location location, UUID uuid){
Expand All @@ -35,7 +40,7 @@ public ChunkLoaderNPC_v1_17_R1(MinecraftServer minecraftServer, Location locatio

this.b = new DummyPlayerConnection(minecraftServer, this);

this.d.setGameMode(EnumGamemode.b);
SET_GAMEMODE.invoke(this.d, EnumGamemode.b);
clientViewDistance = 1;

fauxSleeping = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bgsoftware.wildloaders.nms;

import com.bgsoftware.common.reflection.ReflectMethod;
import net.minecraft.core.BaseBlockPosition;
import net.minecraft.core.BlockPosition;
import net.minecraft.nbt.NBTBase;
Expand All @@ -19,12 +20,14 @@
import net.minecraft.world.level.block.entity.TileEntityTypes;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.chunk.IChunkAccess;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.Map;

public final class NMSMappings_v1_18_R1 {

private static final ReflectMethod<Void> SET_GAMEMODE = new ReflectMethod<>(PlayerInteractManager.class,
1, EnumGamemode.class, EnumGamemode.class);

private NMSMappings_v1_18_R1() {

}
Expand Down Expand Up @@ -118,7 +121,7 @@ public static TileEntityTypes<?> getTileType(TileEntity tileEntity) {
}

public static void setGameMode(PlayerInteractManager playerInteractManager, EnumGamemode gamemode) {
playerInteractManager.a(gamemode);
SET_GAMEMODE.invoke(playerInteractManager, gamemode, null);
}

public static World getWorld(Entity entity) {
Expand Down

0 comments on commit 927a017

Please sign in to comment.