-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a6628a
commit 1fd14a6
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(() => { | ||
PluginAPI.dedicatedServer.appendCode(function () { | ||
PluginAPI.addEventListener("processcommand", (event) => { | ||
if (!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(event.sender.getRef())) { return } | ||
|
||
if (event.command.toLowerCase().startsWith("/spawnnpc")) { | ||
const world = event.sender.getServerForPlayer(); | ||
const playerPos = event.sender.getPosition(); | ||
|
||
// Create a fake player entity | ||
const FakePlayerClass = ModAPI.reflect.getClassById("com.mojang.authlib.GameProfile"); | ||
const fakeProfile = FakePlayerClass.constructors[2]( | ||
java.util.UUID.randomUUID(), ModAPI.util.str("Steve") | ||
); | ||
|
||
const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP"); | ||
const fakePlayer = EntityPlayerMPClass.constructors[1]( | ||
world.getMinecraftServer(), world.getRef(), fakeProfile, world.getPlayerInteractionManager() | ||
); | ||
|
||
// Set the player position | ||
fakePlayer.setPosition(playerPos.$getX(), playerPos.$getY(), playerPos.$getZ()); | ||
|
||
// Add the fake player to the world | ||
world.addEntityToWorld(fakePlayer.getEntityId(), fakePlayer); | ||
|
||
// Send a confirmation message to the player | ||
event.sender.addChatMessage(ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0](ModAPI.util.str("Fake Steve has been spawned!"))); | ||
|
||
event.preventDefault = true; | ||
} | ||
}); | ||
}); | ||
})(); |