Scissors/patches/server/0049-Implement-command-block-events.patch

87 lines
4.1 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Fri, 2 Jun 2023 20:55:18 +0100
Subject: [PATCH] Implement command block events
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-06-09 00:58:46 +00:00
index a2b96f7b1e98586017dbbf28a73446196738ee99..0227e2c7197c3684677f76ff7f0fe0acc21b6c14 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1,6 +1,8 @@
package net.minecraft.server.network;
import me.totalfreedom.scissors.ScissorsConfig;
+import me.totalfreedom.scissors.event.block.CommandBlockPlayerEditEvent;
+import me.totalfreedom.scissors.event.block.CommandMinecartPlayerEditEvent;
import me.totalfreedom.scissors.event.player.SpectatorTeleportEvent;
import com.google.common.collect.Lists;
import com.google.common.primitives.Floats;
@@ -160,6 +162,7 @@ import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.ProfilePublicKey;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.vehicle.Boat;
+import net.minecraft.world.entity.vehicle.MinecartCommandBlock;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
@@ -188,6 +191,7 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
+import org.bukkit.entity.minecart.CommandMinecart;
import org.slf4j.Logger;
// CraftBukkit start
2023-06-09 00:58:46 +00:00
@@ -1001,6 +1005,21 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
this.player.level().getChunkAt(blockposition).setBlockEntity(tileentity);
}
+ // Scissors start - Implement command block events
+ if (commandblocklistenerabstract instanceof org.bukkit.block.CommandBlock commandBlock)
+ {
+ CommandBlockPlayerEditEvent event = new CommandBlockPlayerEditEvent(this.getCraftPlayer(), Objects.requireNonNullElse(commandblocklistenerabstract.getCommand(), ""), s, commandBlock);
+ event.callEvent();
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ s = event.getNewCommand();
+ }
+
+ // Scissors end
+
commandblocklistenerabstract.setCommand(s);
commandblocklistenerabstract.setTrackOutput(flag);
if (!flag) {
2023-06-09 00:58:46 +00:00
@@ -1032,7 +1051,27 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
BaseCommandBlock commandblocklistenerabstract = packet.getCommandBlock(this.player.level());
if (commandblocklistenerabstract != null) {
- commandblocklistenerabstract.setCommand(packet.getCommand());
+ // Scissors start - Implement command block events
+ String command = packet.getCommand();
+
+ if (commandblocklistenerabstract instanceof CommandMinecart commandMinecart)
+ {
+ CommandMinecartPlayerEditEvent event = new CommandMinecartPlayerEditEvent(this.getCraftPlayer(), Objects.requireNonNullElse(commandblocklistenerabstract.getCommand(), ""), command, commandMinecart);
+ event.callEvent();
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ command = event.getNewCommand();
+ }
+
+ commandblocklistenerabstract.setCommand(command);
+
+ // commandblocklistenerabstract.setCommand(packet.getCommand());
+
+ // Scissors end
+
commandblocklistenerabstract.setTrackOutput(packet.isTrackOutput());
if (!packet.isTrackOutput()) {
commandblocklistenerabstract.setLastOutput((Component) null);