3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-17 20:10:10 +01:00
Paper/Spigot-Server-Patches/0246-Call-PortalCreateEvent-for-exit-portals.patch

134 Zeilen
6.2 KiB
Diff

From 3d002d32e0ca98b0fe7dde739c78504adc12da55 Mon Sep 17 00:00:00 2001
From: MiniDigger <admin@minidigger.me>
Date: Sun, 18 Mar 2018 15:44:44 +0100
Subject: [PATCH] Call PortalCreateEvent for exit portals
diff --git a/src/main/java/net/minecraft/server/PortalTravelAgent.java b/src/main/java/net/minecraft/server/PortalTravelAgent.java
index 402d8d7d6..f36373450 100644
--- a/src/main/java/net/minecraft/server/PortalTravelAgent.java
+++ b/src/main/java/net/minecraft/server/PortalTravelAgent.java
@@ -3,16 +3,23 @@ package net.minecraft.server;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Random;
// CraftBukkit start
import org.bukkit.Location;
+import org.bukkit.block.Block;
import org.bukkit.event.entity.EntityPortalExitEvent;
+import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.util.Vector;
// CraftBukkit end
public class PortalTravelAgent {
- private static final BlockPortal a = (BlockPortal) Blocks.NETHER_PORTAL;
+ private static final BlockPortal a = (BlockPortal) Blocks.NETHER_PORTAL; private static final BlockPortal PORTAL_BLOCK = a; // Paper - OBFHELPER
public final WorldServer world; // Paper - private -> public
private final Random c;
private final Long2ObjectMap<PortalTravelAgent.ChunkCoordinatesPortal> d = new Long2ObjectOpenHashMap(4096);
@@ -48,6 +55,9 @@ public class PortalTravelAgent {
byte b0 = 1;
byte b1 = 0;
+ Collection<Block> bukkitBlocks = new HashSet<>(); // Paper
+ Map<BlockPosition, IBlockData> nmsBlocks = new HashMap<>(); // Paper
+
for (int l = -2; l <= 2; ++l) {
for (int i1 = -2; i1 <= 2; ++i1) {
for (int j1 = -1; j1 < 3; ++j1) {
@@ -56,11 +66,22 @@ public class PortalTravelAgent {
int i2 = k + i1 * 0 - l * 1;
boolean flag2 = j1 < 0;
- this.world.setTypeUpdate(new BlockPosition(k1, l1, i2), flag2 ? Blocks.OBSIDIAN.getBlockData() : Blocks.AIR.getBlockData());
+ // Paper start
+ BlockPosition pos = new BlockPosition(k1, l1, i2);
+ nmsBlocks.putIfAbsent(pos, flag2 ? Blocks.OBSIDIAN.getBlockData() : Blocks.AIR.getBlockData());
+ bukkitBlocks.add(this.world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+ // Paper end
}
}
}
+ // Paper start
+ PortalCreateEvent event = new PortalCreateEvent(bukkitBlocks, this.world.getWorld(), PortalCreateEvent.CreateReason.OBC_DESTINATION);
+ if(event.callEvent()){
+ nmsBlocks.forEach(this.world::setTypeUpdate);
+ }
+ // Paper end
+
// CraftBukkit start
return new BlockPosition(i, k, k);
}
@@ -404,6 +425,9 @@ public class PortalTravelAgent {
l5 = -l5;
}
+ Collection<Block> bukkitBlocks = new HashSet<>(); // Paper
+ Map<BlockPosition, IBlockData> nmsBlocks = new HashMap<>(); // Paper
+
if (d0 < 0.0D) {
i1 = MathHelper.clamp(i1, 70, this.world.aa() - 10);
j5 = i1;
@@ -416,8 +440,11 @@ public class PortalTravelAgent {
l3 = j2 + (l2 - 1) * l5 - k2 * k5;
boolean flag1 = i3 < 0;
- blockposition_mutableblockposition.c(j3, k3, l3);
- this.world.setTypeUpdate(blockposition_mutableblockposition, flag1 ? Blocks.OBSIDIAN.getBlockData() : Blocks.AIR.getBlockData());
+ // Paper start
+ BlockPosition pos = new BlockPosition(j3, k3, l3);
+ nmsBlocks.putIfAbsent(pos, flag1 ? Blocks.OBSIDIAN.getBlockData() : Blocks.AIR.getBlockData());
+ bukkitBlocks.add(this.world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+ // Paper end
}
}
}
@@ -427,7 +454,11 @@ public class PortalTravelAgent {
for (l2 = -1; l2 < 4; ++l2) {
if (k2 == -1 || k2 == 2 || l2 == -1 || l2 == 3) {
blockposition_mutableblockposition.c(i5 + k2 * k5, j5 + l2, j2 + k2 * l5);
- this.world.setTypeAndData(blockposition_mutableblockposition, Blocks.OBSIDIAN.getBlockData(), 3);
+ // Paper start
+ BlockPosition pos = new BlockPosition(blockposition_mutableblockposition.getX(), blockposition_mutableblockposition.getY(), blockposition_mutableblockposition.getZ());
+ nmsBlocks.putIfAbsent(pos, Blocks.OBSIDIAN.getBlockData());
+ bukkitBlocks.add(this.world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+ // Paper end
}
}
}
@@ -437,10 +468,22 @@ public class PortalTravelAgent {
for (l2 = 0; l2 < 2; ++l2) {
for (i3 = 0; i3 < 3; ++i3) {
blockposition_mutableblockposition.c(i5 + l2 * k5, j5 + i3, j2 + l2 * l5);
- this.world.setTypeAndData(blockposition_mutableblockposition, iblockdata, 18);
+
+ // Paper start
+ BlockPosition pos = new BlockPosition(blockposition_mutableblockposition.getX(), blockposition_mutableblockposition.getY(), blockposition_mutableblockposition.getZ());
+ nmsBlocks.putIfAbsent(pos, PORTAL_BLOCK.getBlockData());
+ bukkitBlocks.add(this.world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+ // paper end
}
}
+ // Paper start
+ PortalCreateEvent event = new PortalCreateEvent(bukkitBlocks, this.world.getWorld(), PortalCreateEvent.CreateReason.OBC_DESTINATION);
+ if(event.callEvent()){
+ nmsBlocks.forEach((pos, data) -> this.world.setTypeAndData(pos, data, 2));
+ }
+ // Paper end
+
return true;
}
--
2.18.0