2023-06-16 23:54:59 -04:00
|
|
|
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/network/protocol/game/ServerboundSetCommandMinecartPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundSetCommandMinecartPacket.java
|
|
|
|
index c99fc118013cb3d4043638e2001a8297e79ddf9c..cdaa81e1f2167b29ec01cc25e51a8400deb533d2 100644
|
|
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundSetCommandMinecartPacket.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundSetCommandMinecartPacket.java
|
|
|
|
@@ -9,7 +9,7 @@ import net.minecraft.world.level.BaseCommandBlock;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
|
|
|
|
public class ServerboundSetCommandMinecartPacket implements Packet<ServerGamePacketListener> {
|
|
|
|
- private final int entity;
|
|
|
|
+ public final int entity; // Scissors - private -> public
|
|
|
|
private final String command;
|
|
|
|
private final boolean trackOutput;
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2023-10-15 18:45:13 -04:00
|
|
|
index 19f573a1f62280bd9b67a4027962fcb7de6d2514..f5cdac55c8cbe334b96c5a0b2c34f216109120d3 100644
|
2023-06-16 23:54:59 -04:00
|
|
|
--- 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;
|
|
|
|
|
2023-07-01 16:21:13 -04:00
|
|
|
import me.totalfreedom.scissors.ScissorsConfig; // Scissors
|
|
|
|
+import me.totalfreedom.scissors.event.block.CommandBlockPlayerEditEvent; // Scissors
|
|
|
|
+import me.totalfreedom.scissors.event.block.CommandMinecartPlayerEditEvent; // Scissors
|
|
|
|
import me.totalfreedom.scissors.event.player.SpectatorTeleportEvent; // Scissors
|
2023-06-16 23:54:59 -04:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import com.google.common.primitives.Floats;
|
2023-10-15 18:45:13 -04:00
|
|
|
@@ -154,6 +156,7 @@ import net.minecraft.world.entity.player.Inventory;
|
2023-06-16 23:54:59 -04:00
|
|
|
import net.minecraft.world.entity.player.ProfilePublicKey;
|
|
|
|
import net.minecraft.world.entity.projectile.AbstractArrow;
|
|
|
|
import net.minecraft.world.entity.vehicle.Boat;
|
2023-07-01 16:21:13 -04:00
|
|
|
+import net.minecraft.world.entity.vehicle.MinecartCommandBlock; // Scissors
|
2023-06-16 23:54:59 -04:00
|
|
|
import net.minecraft.world.item.BlockItem;
|
|
|
|
import net.minecraft.world.item.BucketItem;
|
|
|
|
import net.minecraft.world.item.Item;
|
2023-10-15 18:45:13 -04:00
|
|
|
@@ -181,6 +184,8 @@ import net.minecraft.world.phys.Vec3;
|
2023-06-16 23:54:59 -04:00
|
|
|
import net.minecraft.world.phys.shapes.BooleanOp;
|
|
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
2023-07-01 16:21:13 -04:00
|
|
|
+import org.bukkit.craftbukkit.block.CraftCommandBlock; // Scissors
|
|
|
|
+import org.bukkit.craftbukkit.entity.CraftMinecartCommand; // Scissors
|
2023-06-16 23:54:59 -04:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
2023-10-15 18:45:13 -04:00
|
|
|
@@ -892,6 +897,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
2023-06-16 23:54:59 -04:00
|
|
|
this.player.level().getChunkAt(blockposition).setBlockEntity(tileentity);
|
|
|
|
}
|
|
|
|
|
2023-07-01 16:21:13 -04:00
|
|
|
+ // Scissors start
|
2023-06-16 23:54:59 -04:00
|
|
|
+ CommandBlockPlayerEditEvent event = new CommandBlockPlayerEditEvent(this.getCraftPlayer(), commandblocklistenerabstract.getCommand(), s, new CraftCommandBlock(this.player.level().getWorld(), tileentitycommand));
|
|
|
|
+
|
|
|
|
+ if (!event.callEvent()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ s = event.getNewCommand();
|
|
|
|
+ // Scissors end
|
|
|
|
+
|
|
|
|
commandblocklistenerabstract.setCommand(s);
|
|
|
|
commandblocklistenerabstract.setTrackOutput(flag);
|
|
|
|
if (!flag) {
|
2023-10-15 18:45:13 -04:00
|
|
|
@@ -923,7 +938,18 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
2023-06-16 23:54:59 -04:00
|
|
|
BaseCommandBlock commandblocklistenerabstract = packet.getCommandBlock(this.player.level());
|
|
|
|
|
|
|
|
if (commandblocklistenerabstract != null) {
|
|
|
|
- commandblocklistenerabstract.setCommand(packet.getCommand());
|
|
|
|
+ // Scissors start - Implement command block events
|
|
|
|
+ String command = packet.getCommand();
|
|
|
|
+ CommandMinecartPlayerEditEvent event = new CommandMinecartPlayerEditEvent(this.getCraftPlayer(), commandblocklistenerabstract.getCommand(), command, new CraftMinecartCommand(this.cserver, (MinecartCommandBlock) this.player.level().getEntity(packet.entity)));
|
|
|
|
+
|
|
|
|
+ if (!event.callEvent()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ command = event.getNewCommand();
|
|
|
|
+ commandblocklistenerabstract.setCommand(command);
|
|
|
|
+
|
|
|
|
+ // Scissors end
|
|
|
|
commandblocklistenerabstract.setTrackOutput(packet.isTrackOutput());
|
|
|
|
if (!packet.isTrackOutput()) {
|
|
|
|
commandblocklistenerabstract.setLastOutput((Component) null);
|