mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 21:10:54 +00:00
Begin on plugin API
This commit is contained in:
parent
f176408d41
commit
9ee8974fea
5
src/main/java/emu/grasscutter/plugin/api/Item.java
Normal file
5
src/main/java/emu/grasscutter/plugin/api/Item.java
Normal file
@ -0,0 +1,5 @@
|
||||
package emu.grasscutter.plugin.api;
|
||||
|
||||
public enum Item {
|
||||
/* TODO: Use handbook to generate an Item enum. */
|
||||
}
|
113
src/main/java/emu/grasscutter/plugin/api/PlayerHook.java
Normal file
113
src/main/java/emu/grasscutter/plugin/api/PlayerHook.java
Normal file
@ -0,0 +1,113 @@
|
||||
package emu.grasscutter.plugin.api;
|
||||
|
||||
import emu.grasscutter.game.GenshinPlayer;
|
||||
import emu.grasscutter.game.avatar.GenshinAvatar;
|
||||
import emu.grasscutter.game.entity.EntityAvatar;
|
||||
import emu.grasscutter.game.props.EnterReason;
|
||||
import emu.grasscutter.game.props.FightProperty;
|
||||
import emu.grasscutter.net.packet.GenshinPacket;
|
||||
import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify;
|
||||
import emu.grasscutter.utils.Position;
|
||||
|
||||
/**
|
||||
* Hooks into the {@link GenshinPlayer} class, adding convenient ways to do certain things.
|
||||
*/
|
||||
public final class PlayerHook {
|
||||
private final GenshinPlayer player;
|
||||
|
||||
/**
|
||||
* Hooks into the player.
|
||||
* @param player The player to hook into.
|
||||
*/
|
||||
public PlayerHook(GenshinPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks a player from the server.
|
||||
*/
|
||||
public void kick() {
|
||||
this.player.getSession().close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a player to another scene.
|
||||
* @param sceneId The scene to send the player to.
|
||||
*/
|
||||
public void changeScenes(int sceneId) {
|
||||
this.player.getWorld().transferPlayerToScene(this.player, sceneId, this.player.getPos());
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts an avatar property notify to all world players.
|
||||
* @param property The property that was updated.
|
||||
*/
|
||||
public void updateFightProperty(FightProperty property) {
|
||||
this.broadcastPacketToWorld(new PacketAvatarFightPropUpdateNotify(this.getCurrentAvatar(), property));
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts the packet sent to all world players.
|
||||
* @param packet The packet to send.
|
||||
*/
|
||||
public void broadcastPacketToWorld(GenshinPacket packet) {
|
||||
this.player.getWorld().broadcastPacket(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the currently equipped avatar's health.
|
||||
* @param health The health to set the avatar to.
|
||||
*/
|
||||
public void setHealth(float health) {
|
||||
this.getCurrentAvatarEntity().setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
|
||||
this.updateFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revives the specified avatar.
|
||||
* @param avatar The avatar to revive.
|
||||
*/
|
||||
public void reviveAvatar(GenshinAvatar avatar) {
|
||||
this.broadcastPacketToWorld(new PacketAvatarLifeStateChangeNotify(avatar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a player to a position.
|
||||
* This will **not** transfer the player to another scene.
|
||||
* @param position The position to teleport the player to.
|
||||
*/
|
||||
public void teleport(Position position) {
|
||||
this.player.getPos().set(position);
|
||||
this.player.sendPacket(new PacketPlayerEnterSceneNotify(this.player,
|
||||
EnterType.EnterJump, EnterReason.TransPoint,
|
||||
this.player.getSceneId(), position
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently selected avatar's max health.
|
||||
* @return The max health as a float.
|
||||
*/
|
||||
public float getMaxHealth() {
|
||||
return this.getCurrentAvatarEntity().getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently selected avatar in entity form.
|
||||
* @return The avatar as an {@link EntityAvatar}.
|
||||
*/
|
||||
public EntityAvatar getCurrentAvatarEntity() {
|
||||
return this.player.getTeamManager().getCurrentAvatarEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently selected avatar.
|
||||
* @return The avatar as an {@link GenshinAvatar}.
|
||||
*/
|
||||
public GenshinAvatar getCurrentAvatar() {
|
||||
return this.getCurrentAvatarEntity().getAvatar();
|
||||
}
|
||||
}
|
2
src/main/java/emu/grasscutter/plugin/api/README.md
Normal file
2
src/main/java/emu/grasscutter/plugin/api/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Grasscutter Plugin API
|
||||
**Warning!** As of now, this is a work in progress and isn't completely documented.
|
Loading…
Reference in New Issue
Block a user