mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
more events, fix some errors in Modding.md
This commit is contained in:
parent
07c1c75e40
commit
767462170e
@ -130,21 +130,28 @@ Your XYListener class needs to implement `de.bixilon.minosoft.modding.event.Even
|
||||
```java
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.modding.event.events.ChatMessageReceivingEvent;
|
||||
import de.bixilon.minosoft.modding.event.events.ChatMessageSendingEvent;
|
||||
|
||||
public class ChatEvent extends EventListener {
|
||||
@Override
|
||||
public void onChatMessageReceiving(ChatMessageReceivingEvent event) {
|
||||
if(event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (event.getMessage().getRawMessage().contains("Bixilon")) {
|
||||
MinosoftExampleMod.getInstance().getLogger().game("Bixilon is awful, suppressing this bad chat message!");
|
||||
MinosoftExampleMod.getInstance().getLogger().game("Bixilon is awful, suppressing this potential bad chat message!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChatMessageSending(ChatMessageSendingEvent event) {
|
||||
if(event.getMessage().contains("jeb_")){
|
||||
if(event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if(event.getMessage().contains("jeb_ is stupid")){
|
||||
event.setCancelled(true);
|
||||
event.getConnection().getSender().sendChatMessage("_jeb is awesome!");
|
||||
event.getConnection().getSender().sendChatMessage("jeb_ is awesome!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,4 +47,37 @@ public class EventListener {
|
||||
@Unsafe
|
||||
public void onPacketReceive(PacketReceiveEvent event) {
|
||||
}
|
||||
|
||||
public void onPongEvent(StatusPongEvent event) {
|
||||
}
|
||||
|
||||
public void onStatusResponse(StatusResponseEvent event) {
|
||||
}
|
||||
|
||||
public void onBlockAction(BlockActionEvent event) {
|
||||
}
|
||||
|
||||
public void onBlockChange(BlockChangeEvent event) {
|
||||
}
|
||||
|
||||
public void onBossBarChange(BossBarChangeEvent event) {
|
||||
}
|
||||
|
||||
public void onEntitySpectate(EntitySpectateEvent event) {
|
||||
}
|
||||
|
||||
public void onChangeGameState(ChangeGameStateEvent event) {
|
||||
}
|
||||
|
||||
public void onWindowClose(CloseWindowEvent event) {
|
||||
}
|
||||
|
||||
public void onItemCollectAnimation(CollectItemAnimationEvent event) {
|
||||
}
|
||||
|
||||
public void onEntityDespawn(EntityDespawnEvent event) {
|
||||
}
|
||||
|
||||
public void onEntityEquipmentChange(EntityEquipmentChangeEvent event) {
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.actions.BlockAction;
|
||||
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketBlockAction;
|
||||
|
||||
/**
|
||||
* Fired when a block actions happens (like opening a chest, changing instrument/note/etc on a note block, etc)
|
||||
*/
|
||||
public class BlockActionEvent extends CancelableEvent {
|
||||
private final BlockPosition position;
|
||||
private final BlockAction data;
|
||||
|
||||
public BlockActionEvent(Connection connection, BlockPosition position, BlockAction data) {
|
||||
super(connection);
|
||||
this.position = position;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public BlockActionEvent(Connection connection, PacketBlockAction pkg) {
|
||||
super(connection);
|
||||
this.position = pkg.getPosition();
|
||||
this.data = pkg.getData();
|
||||
}
|
||||
|
||||
public BlockPosition getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public BlockAction getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onBlockAction(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketBlockChange;
|
||||
|
||||
/**
|
||||
* Fired when one block is changed
|
||||
*/
|
||||
public class BlockChangeEvent extends Event {
|
||||
private final BlockPosition position;
|
||||
private final Block block;
|
||||
|
||||
public BlockChangeEvent(Connection connection, BlockPosition position, Block block) {
|
||||
super(connection);
|
||||
this.position = position;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public BlockChangeEvent(Connection connection, PacketBlockChange pkg) {
|
||||
super(connection);
|
||||
this.position = pkg.getPosition();
|
||||
this.block = pkg.getBlock();
|
||||
}
|
||||
|
||||
public BlockPosition getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onBlockChange(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.TextComponent;
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketBossBar;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Fired when the/one boss bar changes
|
||||
*/
|
||||
public class BossBarChangeEvent extends CancelableEvent {
|
||||
private UUID uuid;
|
||||
private PacketBossBar.BossBarActions action;
|
||||
private TextComponent title;
|
||||
private float health;
|
||||
private PacketBossBar.BossBarColors color;
|
||||
private PacketBossBar.BossBarDivisions divisions;
|
||||
private boolean isDragonBar;
|
||||
private boolean shouldDarkenSky;
|
||||
private boolean createFog;
|
||||
|
||||
|
||||
public BossBarChangeEvent(Connection connection, UUID uuid, PacketBossBar.BossBarActions action, TextComponent title, float health, PacketBossBar.BossBarColors color, PacketBossBar.BossBarDivisions divisions, boolean isDragonBar, boolean shouldDarkenSky, boolean createFog) {
|
||||
super(connection);
|
||||
this.uuid = uuid;
|
||||
this.action = action;
|
||||
this.title = title;
|
||||
this.health = health;
|
||||
this.color = color;
|
||||
this.divisions = divisions;
|
||||
this.isDragonBar = isDragonBar;
|
||||
this.shouldDarkenSky = shouldDarkenSky;
|
||||
this.createFog = createFog;
|
||||
}
|
||||
|
||||
public BossBarChangeEvent(Connection connection, PacketBossBar pkg) {
|
||||
super(connection);
|
||||
this.uuid = pkg.getUUID();
|
||||
this.action = pkg.getAction();
|
||||
this.title = pkg.getTitle();
|
||||
this.health = pkg.getHealth();
|
||||
this.color = pkg.getColor();
|
||||
this.divisions = pkg.getDivisions();
|
||||
this.isDragonBar = pkg.isDragonBar();
|
||||
this.shouldDarkenSky = pkg.shouldDarkenSky();
|
||||
this.createFog = pkg.createFog();
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUUID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public PacketBossBar.BossBarActions getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(PacketBossBar.BossBarActions action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public TextComponent getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(TextComponent title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public void setHealth(float health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public PacketBossBar.BossBarColors getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(PacketBossBar.BossBarColors color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public PacketBossBar.BossBarDivisions getDivisions() {
|
||||
return divisions;
|
||||
}
|
||||
|
||||
public void setDivisions(PacketBossBar.BossBarDivisions divisions) {
|
||||
this.divisions = divisions;
|
||||
}
|
||||
|
||||
public boolean isDragonBar() {
|
||||
return isDragonBar;
|
||||
}
|
||||
|
||||
public void setDragonBar(boolean dragonBar) {
|
||||
isDragonBar = dragonBar;
|
||||
}
|
||||
|
||||
public boolean isShouldDarkenSky() {
|
||||
return shouldDarkenSky;
|
||||
}
|
||||
|
||||
public void setShouldDarkenSky(boolean shouldDarkenSky) {
|
||||
this.shouldDarkenSky = shouldDarkenSky;
|
||||
}
|
||||
|
||||
public boolean isCreateFog() {
|
||||
return createFog;
|
||||
}
|
||||
|
||||
public void setCreateFog(boolean createFog) {
|
||||
this.createFog = createFog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onBossBarChange(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketChangeGameState;
|
||||
|
||||
/**
|
||||
* Fired when the player should spectate an entity
|
||||
*/
|
||||
public class ChangeGameStateEvent extends CancelableEvent {
|
||||
private final PacketChangeGameState.Reason reason;
|
||||
private final float value;
|
||||
|
||||
public ChangeGameStateEvent(Connection connection, PacketChangeGameState.Reason reason, float value) {
|
||||
super(connection);
|
||||
this.reason = reason;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public ChangeGameStateEvent(Connection connection, PacketChangeGameState pkg) {
|
||||
super(connection);
|
||||
this.reason = pkg.getReason();
|
||||
this.value = pkg.getValue();
|
||||
}
|
||||
|
||||
public PacketChangeGameState.Reason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public float getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onChangeGameState(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketCloseWindowReceiving;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketCloseWindowSending;
|
||||
|
||||
/**
|
||||
* Fired when a inventory (window) closes
|
||||
*/
|
||||
public class CloseWindowEvent extends CancelableEvent {
|
||||
private final byte windowId;
|
||||
private final Initiators initiator;
|
||||
|
||||
public CloseWindowEvent(Connection connection, byte windowId, Initiators initiator) {
|
||||
super(connection);
|
||||
this.windowId = windowId;
|
||||
this.initiator = initiator;
|
||||
}
|
||||
|
||||
public CloseWindowEvent(Connection connection, PacketCloseWindowReceiving pkg) {
|
||||
super(connection);
|
||||
this.windowId = pkg.getWindowId();
|
||||
this.initiator = Initiators.SERVER;
|
||||
}
|
||||
|
||||
public CloseWindowEvent(Connection connection, PacketCloseWindowSending pkg) {
|
||||
super(connection);
|
||||
this.windowId = pkg.getWindowId();
|
||||
this.initiator = Initiators.CLIENT;
|
||||
}
|
||||
|
||||
public byte getWindowId() {
|
||||
return windowId;
|
||||
}
|
||||
|
||||
public Initiators getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onWindowClose(this);
|
||||
}
|
||||
|
||||
public enum Initiators {
|
||||
CLIENT,
|
||||
SERVER
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.items.Item;
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketCollectItem;
|
||||
|
||||
public class CollectItemAnimationEvent extends CancelableEvent {
|
||||
private final Item item;
|
||||
private final int collectorEntityId;
|
||||
private final int count;
|
||||
|
||||
public CollectItemAnimationEvent(Connection connection, Item item, int collectorEntityId, int count) {
|
||||
super(connection);
|
||||
this.item = item;
|
||||
this.collectorEntityId = collectorEntityId;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public CollectItemAnimationEvent(Connection connection, PacketCollectItem pkg) {
|
||||
super(connection);
|
||||
this.item = pkg.getItem();
|
||||
this.collectorEntityId = pkg.getCollectorId();
|
||||
this.count = pkg.getCount();
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getCollectorEntityId() {
|
||||
return collectorEntityId;
|
||||
}
|
||||
|
||||
@MinimumProtocolVersion(protocolId = 301)
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onItemCollectAnimation(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Entity;
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketDestroyEntity;
|
||||
|
||||
public class EntityDespawnEvent extends Event {
|
||||
private final int[] entityIds;
|
||||
|
||||
public EntityDespawnEvent(Connection connection, int[] entityIds) {
|
||||
super(connection);
|
||||
this.entityIds = entityIds;
|
||||
}
|
||||
|
||||
public EntityDespawnEvent(Connection connection, PacketDestroyEntity pkg) {
|
||||
super(connection);
|
||||
this.entityIds = pkg.getEntityIds();
|
||||
}
|
||||
|
||||
public Entity[] getEntities() {
|
||||
Entity[] ret = new Entity[entityIds.length];
|
||||
for (int i = 0; i < entityIds.length; i++) {
|
||||
ret[i] = getConnection().getPlayer().getWorld().getEntity(entityIds[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int[] getEntityIds() {
|
||||
return entityIds;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onEntityDespawn(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Entity;
|
||||
import de.bixilon.minosoft.game.datatypes.inventory.InventorySlots;
|
||||
import de.bixilon.minosoft.game.datatypes.inventory.Slot;
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketEntityEquipment;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class EntityEquipmentChangeEvent extends Event {
|
||||
private final int entityId;
|
||||
private final HashMap<InventorySlots.EntityInventorySlots, Slot> slots;
|
||||
|
||||
public EntityEquipmentChangeEvent(Connection connection, int entityId, HashMap<InventorySlots.EntityInventorySlots, Slot> slots) {
|
||||
super(connection);
|
||||
this.entityId = entityId;
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
public EntityEquipmentChangeEvent(Connection connection, PacketEntityEquipment pkg) {
|
||||
super(connection);
|
||||
this.entityId = pkg.getEntityId();
|
||||
this.slots = pkg.getSlots();
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return getConnection().getPlayer().getWorld().getEntity(entityId);
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public HashMap<InventorySlots.EntityInventorySlots, Slot> getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onEntityEquipmentChange(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketCamera;
|
||||
|
||||
/**
|
||||
* Fired when the player should spectate an entity
|
||||
*/
|
||||
public class EntitySpectateEvent extends Event {
|
||||
private final int entityId;
|
||||
|
||||
public EntitySpectateEvent(Connection connection, int entityId) {
|
||||
super(connection);
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public EntitySpectateEvent(Connection connection, PacketCamera pkg) {
|
||||
super(connection);
|
||||
this.entityId = pkg.getEntityId();
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onEntitySpectate(this);
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
|
||||
@Unsafe
|
||||
public class PacketReceiveEvent extends Event {
|
||||
private final ClientboundPacket packet;
|
||||
|
||||
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
|
||||
|
||||
@Unsafe
|
||||
public class PacketSendEvent extends Event {
|
||||
private final ServerboundPacket packet;
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusPong;
|
||||
|
||||
/**
|
||||
* Fired when the connection status is "STATUS" and the ping gets pack (pong)
|
||||
*/
|
||||
public class StatusPongEvent extends Event {
|
||||
private final long pongId;
|
||||
|
||||
public StatusPongEvent(Connection connection, long pongId) {
|
||||
super(connection);
|
||||
this.pongId = pongId;
|
||||
}
|
||||
|
||||
public StatusPongEvent(Connection connection, PacketStatusPong pkg) {
|
||||
super(connection);
|
||||
this.pongId = pkg.getID();
|
||||
}
|
||||
|
||||
public long getPongId() {
|
||||
return pongId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onPongEvent(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events;
|
||||
|
||||
import de.bixilon.minosoft.modding.event.EventListener;
|
||||
import de.bixilon.minosoft.ping.ServerListPing;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusResponse;
|
||||
|
||||
/**
|
||||
* Fired when the connection status is "STATUS" and the server send general information such as players online, motd, etc
|
||||
*/
|
||||
public class StatusResponseEvent extends Event {
|
||||
private final ServerListPing response;
|
||||
|
||||
public StatusResponseEvent(Connection connection, ServerListPing response) {
|
||||
super(connection);
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public StatusResponseEvent(Connection connection, PacketStatusResponse pkg) {
|
||||
super(connection);
|
||||
this.response = pkg.getResponse();
|
||||
}
|
||||
|
||||
public ServerListPing getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventListener listener) {
|
||||
listener.onStatusResponse(this);
|
||||
}
|
||||
}
|
@ -58,6 +58,14 @@ public class PacketBlockAction implements ClientboundPacket {
|
||||
return true;
|
||||
}
|
||||
|
||||
public BlockPosition getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public BlockAction getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketHandler h) {
|
||||
h.handle(this);
|
||||
|
@ -13,31 +13,29 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.items.Item;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
|
||||
public class PacketCollectItem implements ClientboundPacket {
|
||||
int itemId;
|
||||
Item item;
|
||||
int collectorId;
|
||||
int count;
|
||||
|
||||
@Override
|
||||
public boolean read(InByteBuffer buffer) {
|
||||
if (buffer.getProtocolId() < 7) {
|
||||
itemId = buffer.readInt();
|
||||
item = buffer.getConnection().getMapping().getItemById(buffer.readInt());
|
||||
collectorId = buffer.readInt();
|
||||
return true;
|
||||
}
|
||||
if (buffer.getProtocolId() < 301) {
|
||||
itemId = buffer.readVarInt();
|
||||
collectorId = buffer.readVarInt();
|
||||
return true;
|
||||
}
|
||||
itemId = buffer.readVarInt();
|
||||
item = buffer.getConnection().getMapping().getItemById(buffer.readVarInt());
|
||||
collectorId = buffer.readVarInt();
|
||||
if (buffer.getProtocolId() >= 301) {
|
||||
count = buffer.readVarInt();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -48,17 +46,17 @@ public class PacketCollectItem implements ClientboundPacket {
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("Item %d was collected by %d (count=%s)", itemId, collectorId, ((count == 0) ? "?" : count)));
|
||||
Log.protocol(String.format("Item %s was collected by %d (count=%s)", item, collectorId, ((count == 0) ? "?" : count)));
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getCollectorId() {
|
||||
return collectorId;
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
@ -34,6 +34,10 @@ public class PacketCloseWindowSending implements ServerboundPacket {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public byte getWindowId() {
|
||||
return windowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("Sending Close window packet (windowId=%d)", windowId));
|
||||
|
@ -54,6 +54,8 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketStatusResponse pkg) {
|
||||
connection.fireEvent(new StatusResponseEvent(connection, pkg));
|
||||
|
||||
// now we know the version, set it, if the config allows it
|
||||
Version version;
|
||||
int versionId = connection.getDesiredVersionNumber();
|
||||
@ -71,6 +73,8 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketStatusPong pkg) {
|
||||
connection.fireEvent(new StatusPongEvent(connection, pkg));
|
||||
|
||||
ConnectionPing ping = connection.getConnectionStatusPing();
|
||||
if (ping.getPingId() != pkg.getID()) {
|
||||
Log.warn(String.format("Server sent unknown ping answer (pingId=%d, expected=%d)", pkg.getID(), ping.getPingId()));
|
||||
@ -210,7 +214,11 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketChangeGameState pkg) {
|
||||
// ToDo: handle all updates
|
||||
ChangeGameStateEvent event = new ChangeGameStateEvent(connection, pkg);
|
||||
if (connection.fireEvent(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pkg.getReason()) {
|
||||
case START_RAIN -> connection.getPlayer().getWorld().setRaining(true);
|
||||
case END_RAIN -> connection.getPlayer().getWorld().setRaining(false);
|
||||
@ -239,6 +247,8 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketDestroyEntity pkg) {
|
||||
connection.fireEvent(new EntityDespawnEvent(connection, pkg));
|
||||
|
||||
for (int entityId : pkg.getEntityIds()) {
|
||||
connection.getPlayer().getWorld().removeEntity(entityId);
|
||||
}
|
||||
@ -284,10 +294,14 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketEntityEquipment pkg) {
|
||||
connection.fireEvent(new EntityEquipmentChangeEvent(connection, pkg));
|
||||
|
||||
connection.getPlayer().getWorld().getEntity(pkg.getEntityId()).setEquipment(pkg.getSlots());
|
||||
}
|
||||
|
||||
public void handle(PacketBlockChange pkg) {
|
||||
connection.fireEvent(new BlockChangeEvent(connection, pkg));
|
||||
|
||||
connection.getPlayer().getWorld().setBlock(pkg.getPosition(), pkg.getBlock());
|
||||
}
|
||||
|
||||
@ -401,6 +415,10 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketBlockAction pkg) {
|
||||
BlockActionEvent event = new BlockActionEvent(connection, pkg);
|
||||
if (connection.fireEvent(event)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(PacketExplosion pkg) {
|
||||
@ -416,6 +434,9 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketCollectItem pkg) {
|
||||
if (connection.fireEvent(new CollectItemAnimationEvent(connection, pkg))) {
|
||||
return;
|
||||
}
|
||||
// ToDo
|
||||
}
|
||||
|
||||
@ -424,6 +445,11 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketCloseWindowReceiving pkg) {
|
||||
CloseWindowEvent event = new CloseWindowEvent(connection, pkg);
|
||||
if (connection.fireEvent(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
connection.getPlayer().deleteInventory(pkg.getWindowId());
|
||||
}
|
||||
|
||||
@ -553,7 +579,10 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketBossBar pkg) {
|
||||
// ToDo
|
||||
BossBarChangeEvent event = new BossBarChangeEvent(connection, pkg);
|
||||
if (connection.fireEvent(event)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(PacketSetPassenger pkg) {
|
||||
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.protocol.protocol;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.player.Hands;
|
||||
import de.bixilon.minosoft.modding.event.events.ChatMessageSendingEvent;
|
||||
import de.bixilon.minosoft.modding.event.events.CloseWindowEvent;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.*;
|
||||
|
||||
@ -76,6 +77,10 @@ public class PacketSender {
|
||||
}
|
||||
|
||||
public void closeWindow(byte windowId) {
|
||||
CloseWindowEvent event = new CloseWindowEvent(connection, windowId, CloseWindowEvent.Initiators.CLIENT);
|
||||
if (connection.fireEvent(event)) {
|
||||
return;
|
||||
}
|
||||
connection.sendPacket(new PacketCloseWindowSending(windowId));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user