SPIGOT-248: PortalCreateEvent not fired when exit portal is created automatically.

This commit is contained in:
Aquazus 2019-05-04 14:51:54 +02:00 committed by md_5
parent 3be0bc1c51
commit e8c929356e
2 changed files with 117 additions and 32 deletions

View file

@ -53,7 +53,7 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) { public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super((World) worldserver, gameprofile); super((World) worldserver, gameprofile);
playerinteractmanager.player = this; playerinteractmanager.player = this;
@@ -62,8 +96,50 @@ @@ -62,7 +96,49 @@
this.advancementDataPlayer = minecraftserver.getPlayerList().f(this); this.advancementDataPlayer = minecraftserver.getPlayerList().f(this);
this.K = 1.0F; this.K = 1.0F;
this.a(worldserver); this.a(worldserver);
@ -62,8 +62,8 @@
+ this.displayName = this.getName(); + this.displayName = this.getName();
+ this.canPickUpLoot = true; + this.canPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth(); + this.maxHealthCache = this.getMaxHealth();
} + }
+
+ // Yes, this doesn't match Vanilla, but it's the best we can do for now. + // Yes, this doesn't match Vanilla, but it's the best we can do for now.
+ // If this is an issue, PRs are welcome + // If this is an issue, PRs are welcome
+ public final BlockPosition getSpawnPoint(WorldServer worldserver) { + public final BlockPosition getSpawnPoint(WorldServer worldserver) {
@ -98,12 +98,11 @@
+ } + }
+ +
+ return blockposition; + return blockposition;
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
private void a(WorldServer worldserver) { private void a(WorldServer worldserver) {
BlockPosition blockposition = worldserver.getSpawn(); BlockPosition blockposition = worldserver.getSpawn();
@@ -131,6 +207,7 @@ @@ -131,6 +207,7 @@
if (nbttagcompound.hasKeyOfType("recipeBook", 10)) { if (nbttagcompound.hasKeyOfType("recipeBook", 10)) {
this.recipeBook.a(nbttagcompound.getCompound("recipeBook")); this.recipeBook.a(nbttagcompound.getCompound("recipeBook"));
@ -427,7 +426,41 @@
this.setPositionRotation(d0, d1, d2, f1, f); this.setPositionRotation(d0, d1, d2, f1, f);
worldserver.getMethodProfiler().exit(); worldserver.getMethodProfiler().exit();
worldserver.getMethodProfiler().enter("placing"); worldserver.getMethodProfiler().enter("placing");
@@ -618,7 +859,7 @@ @@ -572,6 +813,7 @@
int k = MathHelper.floor(this.locZ);
boolean flag = true;
boolean flag1 = false;
+ org.bukkit.craftbukkit.util.BlockStateListPopulator blockList = new org.bukkit.craftbukkit.util.BlockStateListPopulator(this.world); // CraftBukkit - Use BlockStateListPopulator
for (int l = -2; l <= 2; ++l) {
for (int i1 = -2; i1 <= 2; ++i1) {
@@ -581,11 +823,24 @@
int i2 = k + i1 * 0 - l * 1;
boolean flag2 = j1 < 0;
- worldserver1.setTypeUpdate(new BlockPosition(k1, l1, i2), flag2 ? Blocks.OBSIDIAN.getBlockData() : Blocks.AIR.getBlockData());
+ blockList.setTypeAndData(new BlockPosition(k1, l1, i2), flag2 ? Blocks.OBSIDIAN.getBlockData() : Blocks.AIR.getBlockData(), 3); // CraftBukkit
}
}
}
+ // CraftBukkit start
+ org.bukkit.World bworld = worldserver1.getWorld();
+ List<org.bukkit.block.Block> bukkitBlocks = Lists.newArrayList();
+ for (BlockPosition cpos : blockList.getBlocks()) {
+ bukkitBlocks.add(bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ()));
+ }
+
+ org.bukkit.event.world.PortalCreateEvent portalEvent = new org.bukkit.event.world.PortalCreateEvent(bukkitBlocks, bworld, org.bukkit.event.world.PortalCreateEvent.CreateReason.OBC_DESTINATION);
+ this.world.getServer().getPluginManager().callEvent(portalEvent);
+ if (!portalEvent.isCancelled()) {
+ blockList.updateList();
+ }
+ // CraftBukkit end
this.setPositionRotation((double) i, (double) j, (double) k, f1, 0.0F);
this.setMot(Vec3D.a);
} else if (!worldserver1.getTravelAgent().a(this, f2)) {
@@ -618,7 +873,7 @@
} }
} }
@ -436,7 +469,7 @@
DimensionManager dimensionmanager = worldserver.worldProvider.getDimensionManager(); DimensionManager dimensionmanager = worldserver.worldProvider.getDimensionManager();
DimensionManager dimensionmanager1 = this.world.worldProvider.getDimensionManager(); DimensionManager dimensionmanager1 = this.world.worldProvider.getDimensionManager();
@@ -655,9 +896,16 @@ @@ -655,9 +910,16 @@
this.activeContainer.c(); this.activeContainer.c();
} }
@ -455,7 +488,7 @@
this.a(StatisticList.SLEEP_IN_BED); this.a(StatisticList.SLEEP_IN_BED);
CriterionTriggers.q.a(this); CriterionTriggers.q.a(this);
}); });
@@ -665,6 +913,7 @@ @@ -665,6 +927,7 @@
@Override @Override
public void wakeup(boolean flag, boolean flag1, boolean flag2) { public void wakeup(boolean flag, boolean flag1, boolean flag2) {
@ -463,7 +496,7 @@
if (this.isSleeping()) { if (this.isSleeping()) {
this.getWorldServer().getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutAnimation(this, 2)); this.getWorldServer().getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutAnimation(this, 2));
} }
@@ -752,8 +1001,9 @@ @@ -752,8 +1015,9 @@
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition())); this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
} }
@ -474,7 +507,7 @@
} }
@Override @Override
@@ -768,6 +1018,17 @@ @@ -768,6 +1032,17 @@
this.nextContainerCounter(); this.nextContainerCounter();
Container container = itileinventory.createMenu(this.containerCounter, this.inventory, this); Container container = itileinventory.createMenu(this.containerCounter, this.inventory, this);
@ -492,7 +525,7 @@
if (container == null) { if (container == null) {
if (this.isSpectator()) { if (this.isSpectator()) {
this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).a(EnumChatFormat.RED), true); this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).a(EnumChatFormat.RED), true);
@@ -775,9 +1036,11 @@ @@ -775,9 +1050,11 @@
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -506,7 +539,7 @@
return OptionalInt.of(this.containerCounter); return OptionalInt.of(this.containerCounter);
} }
} }
@@ -790,13 +1053,21 @@ @@ -790,13 +1067,21 @@
@Override @Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) { public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@ -530,7 +563,7 @@
this.activeContainer.addSlotListener(this); this.activeContainer.addSlotListener(this);
} }
@@ -841,6 +1112,11 @@ @@ -841,6 +1126,11 @@
public void a(Container container, NonNullList<ItemStack> nonnulllist) { public void a(Container container, NonNullList<ItemStack> nonnulllist) {
this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, nonnulllist)); this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, nonnulllist));
this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried())); this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried()));
@ -542,7 +575,7 @@
} }
@Override @Override
@@ -850,6 +1126,7 @@ @@ -850,6 +1140,7 @@
@Override @Override
public void closeInventory() { public void closeInventory() {
@ -550,7 +583,7 @@
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId)); this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
this.m(); this.m();
} }
@@ -884,7 +1161,7 @@ @@ -884,7 +1175,7 @@
@Override @Override
public void a(Statistic<?> statistic, int i) { public void a(Statistic<?> statistic, int i) {
this.serverStatisticManager.b(this, statistic, i); this.serverStatisticManager.b(this, statistic, i);
@ -559,7 +592,7 @@
scoreboardscore.addScore(i); scoreboardscore.addScore(i);
}); });
} }
@@ -892,7 +1169,7 @@ @@ -892,7 +1183,7 @@
@Override @Override
public void a(Statistic<?> statistic) { public void a(Statistic<?> statistic) {
this.serverStatisticManager.setStatistic(this, statistic, 0); this.serverStatisticManager.setStatistic(this, statistic, 0);
@ -568,25 +601,24 @@
} }
@Override @Override
@@ -941,8 +1218,17 @@ @@ -941,7 +1232,16 @@
public void triggerHealthUpdate() { public void triggerHealthUpdate() {
this.lastHealthSent = -1.0E8F; this.lastHealthSent = -1.0E8F;
+ this.lastSentExp = -1; // CraftBukkit - Added to reset + this.lastSentExp = -1; // CraftBukkit - Added to reset
} + }
+
+ // CraftBukkit start - Support multi-line messages + // CraftBukkit start - Support multi-line messages
+ public void sendMessage(IChatBaseComponent[] ichatbasecomponent) { + public void sendMessage(IChatBaseComponent[] ichatbasecomponent) {
+ for (IChatBaseComponent component : ichatbasecomponent) { + for (IChatBaseComponent component : ichatbasecomponent) {
+ this.sendMessage(component); + this.sendMessage(component);
+ } + }
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
@Override @Override
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) { public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT)); @@ -996,12 +1296,14 @@
@@ -996,12 +1282,14 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastHealthSent = -1.0F; this.lastHealthSent = -1.0F;
this.lastFoodSent = -1; this.lastFoodSent = -1;
@ -602,7 +634,7 @@
} }
@Override @Override
@@ -1063,6 +1351,18 @@ @@ -1063,6 +1365,18 @@
@Override @Override
public void a(EnumGamemode enumgamemode) { public void a(EnumGamemode enumgamemode) {
@ -621,7 +653,7 @@
this.playerInteractManager.setGameMode(enumgamemode); this.playerInteractManager.setGameMode(enumgamemode);
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId())); this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId()));
if (enumgamemode == EnumGamemode.SPECTATOR) { if (enumgamemode == EnumGamemode.SPECTATOR) {
@@ -1113,6 +1413,17 @@ @@ -1113,6 +1427,17 @@
} }
public void a(PacketPlayInSettings packetplayinsettings) { public void a(PacketPlayInSettings packetplayinsettings) {
@ -639,7 +671,7 @@
this.locale = packetplayinsettings.b(); this.locale = packetplayinsettings.b();
this.ck = packetplayinsettings.d(); this.ck = packetplayinsettings.d();
this.cl = packetplayinsettings.e(); this.cl = packetplayinsettings.e();
@@ -1149,13 +1460,13 @@ @@ -1149,13 +1474,13 @@
if (entity instanceof EntityHuman) { if (entity instanceof EntityHuman) {
this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(new int[] { entity.getId()})); this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(new int[] { entity.getId()}));
} else { } else {
@ -655,7 +687,7 @@
} }
@Override @Override
@@ -1179,7 +1490,7 @@ @@ -1179,7 +1504,7 @@
this.spectatedEntity = (Entity) (entity == null ? this : entity); this.spectatedEntity = (Entity) (entity == null ? this : entity);
if (entity1 != this.spectatedEntity) { if (entity1 != this.spectatedEntity) {
this.playerConnection.sendPacket(new PacketPlayOutCamera(this.spectatedEntity)); this.playerConnection.sendPacket(new PacketPlayOutCamera(this.spectatedEntity));
@ -664,7 +696,7 @@
} }
} }
@@ -1208,7 +1519,7 @@ @@ -1208,7 +1533,7 @@
@Nullable @Nullable
public IChatBaseComponent getPlayerListName() { public IChatBaseComponent getPlayerListName() {
@ -673,7 +705,7 @@
} }
@Override @Override
@@ -1226,21 +1537,33 @@ @@ -1226,21 +1551,33 @@
} }
public void J() { public void J() {
@ -707,7 +739,7 @@
if (worldserver == this.world) { if (worldserver == this.world) {
this.playerConnection.a(d0, d1, d2, f, f1); this.playerConnection.a(d0, d1, d2, f, f1);
} else { } else {
@@ -1263,6 +1586,9 @@ @@ -1263,6 +1600,9 @@
this.server.getPlayerList().a(this, worldserver); this.server.getPlayerList().a(this, worldserver);
this.server.getPlayerList().updateClient(this); this.server.getPlayerList().updateClient(this);
} }
@ -717,7 +749,7 @@
} }
@@ -1314,4 +1640,144 @@ @@ -1314,4 +1654,144 @@
return entityitem; return entityitem;
} }
} }

View file

@ -0,0 +1,53 @@
--- a/net/minecraft/server/PortalTravelAgent.java
+++ b/net/minecraft/server/PortalTravelAgent.java
@@ -258,6 +258,7 @@
l5 = -l5;
}
+ org.bukkit.craftbukkit.util.BlockStateListPopulator blockList = new org.bukkit.craftbukkit.util.BlockStateListPopulator(this.world); // CraftBukkit - Use BlockStateListPopulator
if (d0 < 0.0D) {
i1 = MathHelper.clamp(i1, 70, this.world.getHeight() - 10);
j5 = i1;
@@ -271,7 +272,7 @@
boolean flag1 = l2 < 0;
blockposition_mutableblockposition.d(j3, l3, i4);
- this.world.setTypeUpdate(blockposition_mutableblockposition, flag1 ? Blocks.OBSIDIAN.getBlockData() : Blocks.AIR.getBlockData());
+ blockList.setTypeAndData(blockposition_mutableblockposition, flag1 ? Blocks.OBSIDIAN.getBlockData() : Blocks.AIR.getBlockData(), 3); // CraftBukkit
}
}
}
@@ -281,7 +282,7 @@
for (i3 = -1; i3 < 4; ++i3) {
if (k2 == -1 || k2 == 2 || i3 == -1 || i3 == 3) {
blockposition_mutableblockposition.d(i5 + k2 * k5, j5 + i3, j2 + k2 * l5);
- this.world.setTypeAndData(blockposition_mutableblockposition, Blocks.OBSIDIAN.getBlockData(), 3);
+ blockList.setTypeAndData(blockposition_mutableblockposition, Blocks.OBSIDIAN.getBlockData(), 3); // CraftBukkit
}
}
}
@@ -291,10 +292,23 @@
for (i3 = 0; i3 < 2; ++i3) {
for (l2 = 0; l2 < 3; ++l2) {
blockposition_mutableblockposition.d(i5 + i3 * k5, j5 + l2, j2 + i3 * l5);
- this.world.setTypeAndData(blockposition_mutableblockposition, iblockdata, 18);
+ blockList.setTypeAndData(blockposition_mutableblockposition, iblockdata, 18); // CraftBukkit
}
}
+ // CraftBukkit start
+ org.bukkit.World bworld = this.world.getWorld();
+ java.util.List<org.bukkit.block.Block> bukkitBlocks = com.google.common.collect.Lists.newArrayList();
+ for (BlockPosition cpos : blockList.getBlocks()) {
+ bukkitBlocks.add(bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ()));
+ }
+
+ org.bukkit.event.world.PortalCreateEvent event = new org.bukkit.event.world.PortalCreateEvent(bukkitBlocks, bworld, org.bukkit.event.world.PortalCreateEvent.CreateReason.OBC_DESTINATION);
+ this.world.getServer().getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ blockList.updateList();
+ }
+ // CraftBukkit end
return true;
}