1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-02-17 18:47:40 +01:00

PlayerTeleportEndGatewayEvent

Allows you to access the Gateway being used in a teleport event
Fix the offset used for player teleportation
This commit is contained in:
Aikar 2016-12-31 21:44:50 -05:00
parent 746f540e81
commit 2aa9d5bf18

View file

@ -114,12 +114,12 @@
@Nullable
private Vec3 startingToFallPosition;
@Nullable
@@ -258,6 +293,25 @@
@@ -258,7 +293,26 @@
private final CommandSource commandSource;
private int containerCounter;
public boolean wonGame;
+ private int containerUpdateDelay; // Paper - Configurable container update tick rate
+
+ // CraftBukkit start
+ public CraftPlayer.TransferCookieConnection transferCookieConnection;
+ public String displayName;
@ -137,9 +137,10 @@
+ public String kickLeaveMessage = null; // SPIGOT-3034: Forward leave message to PlayerQuitEvent
+ // CraftBukkit end
+ public boolean isRealPlayer; // Paper
+
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
this.chatVisibility = ChatVisiblity.FULL;
@@ -266,7 +320,7 @@
this.canChatColor = true;
this.lastActionTime = Util.getMillis();
@ -514,7 +515,7 @@
+ // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
+ this.dropFromLootTable(this.serverLevel(), damageSource, this.lastHurtByPlayerTime > 0);
+ this.dropCustomDeathLoot(this.serverLevel(), damageSource, flag);
+
+ loot.addAll(this.drops);
+ this.drops.clear(); // SPIGOT-5188: make sure to clear
+
@ -528,7 +529,7 @@
+ if (this.containerMenu != this.inventoryMenu) {
+ this.closeContainer();
+ }
+
+ net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure
+
+ if (deathMessage != null && deathMessage != net.kyori.adventure.text.Component.empty() && flag) { // Paper - Adventure // TODO: allow plugins to override?
@ -710,7 +711,7 @@
if (this.isRemoved()) {
return null;
} else {
@@ -1169,39 +1439,73 @@
@@ -1169,39 +1439,78 @@
ServerLevel worldserver = teleportTarget.newLevel();
ServerLevel worldserver1 = this.serverLevel();
@ -722,6 +723,11 @@
+ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this), PositionMoveRotation.of(teleportTarget), teleportTarget.relatives());
+ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(absolutePosition.position(), worldserver.getWorld(), absolutePosition.yRot(), absolutePosition.xRot());
+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, teleportTarget.cause());
+ // Paper start - gateway-specific teleport event
+ if (this.portalProcess != null && this.portalProcess.isSamePortal(((net.minecraft.world.level.block.EndGatewayBlock) net.minecraft.world.level.block.Blocks.END_GATEWAY)) && this.serverLevel().getBlockEntity(this.portalProcess.getEntryPosition()) instanceof net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity theEndGatewayBlockEntity) {
+ tpEvent = new com.destroystokyo.paper.event.player.PlayerTeleportEndGatewayEvent(this.getBukkitEntity(), enter, exit, new org.bukkit.craftbukkit.block.CraftEndGateway(this.serverLevel().getWorld(), theEndGatewayBlockEntity));
+ }
+ // Paper end - gateway-specific teleport event
+ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
+ Location newExit = tpEvent.getTo();
+ if (tpEvent.isCancelled() || newExit == null) {
@ -792,7 +798,7 @@
this.connection.resetPosition();
worldserver.addDuringTeleport(this);
gameprofilerfiller.pop();
@@ -1215,12 +1519,30 @@
@@ -1215,12 +1524,30 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@ -823,7 +829,7 @@
public void forceSetRotation(float yaw, float pitch) {
this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch));
}
@@ -1228,13 +1550,21 @@
@@ -1228,13 +1555,21 @@
public void triggerDimensionChangeTriggers(ServerLevel origin) {
ResourceKey<Level> resourcekey = origin.dimension();
ResourceKey<Level> resourcekey1 = this.level().dimension();
@ -848,7 +854,7 @@
this.enteredNetherPosition = null;
}
@@ -1251,36 +1581,63 @@
@@ -1251,36 +1586,63 @@
this.containerMenu.broadcastChanges();
}
@ -927,7 +933,7 @@
this.awardStat(Stats.SLEEP_IN_BED);
CriteriaTriggers.SLEPT_IN_BED.trigger(this);
});
@@ -1293,9 +1650,8 @@
@@ -1293,9 +1655,8 @@
return either;
}
}
@ -938,7 +944,7 @@
}
@Override
@@ -1322,13 +1678,31 @@
@@ -1322,13 +1683,31 @@
@Override
public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) {
@ -971,7 +977,7 @@
}
}
@@ -1387,8 +1761,9 @@
@@ -1387,8 +1766,9 @@
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front));
}
@ -982,7 +988,7 @@
}
@Override
@@ -1396,13 +1771,35 @@
@@ -1396,13 +1776,35 @@
if (factory == null) {
return OptionalInt.empty();
} else {
@ -1018,7 +1024,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true);
@@ -1410,9 +1807,11 @@
@@ -1410,9 +1812,11 @@
return OptionalInt.empty();
} else {
@ -1032,7 +1038,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1425,15 +1824,26 @@
@@ -1425,15 +1829,26 @@
@Override
public void openHorseInventory(AbstractHorse horse, Container inventory) {
@ -1061,7 +1067,7 @@
this.initMenu(this.containerMenu);
}
@@ -1456,6 +1866,7 @@
@@ -1456,6 +1871,7 @@
@Override
public void closeContainer() {
@ -1069,7 +1075,7 @@
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
this.doCloseContainer();
}
@@ -1485,19 +1896,19 @@
@@ -1485,19 +1901,19 @@
i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F);
if (i > 0) {
this.awardStat(Stats.SWIM_ONE_CM, i);
@ -1092,7 +1098,7 @@
}
} else if (this.onClimbable()) {
if (deltaY > 0.0D) {
@@ -1508,13 +1919,13 @@
@@ -1508,13 +1924,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(Stats.SPRINT_ONE_CM, i);
@ -1109,7 +1115,7 @@
}
}
} else if (this.isFallFlying()) {
@@ -1557,7 +1968,7 @@
@@ -1557,7 +1973,7 @@
@Override
public void awardStat(Stat<?> stat, int amount) {
this.stats.increment(this, stat, amount);
@ -1118,7 +1124,7 @@
scoreaccess.add(amount);
});
}
@@ -1565,7 +1976,7 @@
@@ -1565,7 +1981,7 @@
@Override
public void resetStat(Stat<?> stat) {
this.stats.setValue(this, stat, 0);
@ -1127,7 +1133,7 @@
}
@Override
@@ -1597,9 +2008,9 @@
@@ -1597,9 +2013,9 @@
super.jumpFromGround();
this.awardStat(Stats.JUMP);
if (this.isSprinting()) {
@ -1139,7 +1145,7 @@
}
}
@@ -1625,6 +2036,7 @@
@@ -1625,6 +2041,7 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@ -1147,7 +1153,7 @@
}
@Override
@@ -1661,7 +2073,7 @@
@@ -1661,7 +2078,7 @@
this.onUpdateAbilities();
if (alive) {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1156,7 +1162,7 @@
this.setHealth(oldPlayer.getHealth());
this.foodData = oldPlayer.foodData;
Iterator iterator = oldPlayer.getActiveEffects().iterator();
@@ -1669,7 +2081,7 @@
@@ -1669,7 +2086,7 @@
while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
@ -1165,7 +1171,7 @@
}
this.getInventory().replaceWith(oldPlayer.getInventory());
@@ -1680,7 +2092,7 @@
@@ -1680,7 +2097,7 @@
this.portalProcess = oldPlayer.portalProcess;
} else {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1174,7 +1180,7 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) {
this.getInventory().replaceWith(oldPlayer.getInventory());
this.experienceLevel = oldPlayer.experienceLevel;
@@ -1696,7 +2108,7 @@
@@ -1696,7 +2113,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@ -1183,7 +1189,7 @@
this.seenCredits = oldPlayer.seenCredits;
this.enteredNetherPosition = oldPlayer.enteredNetherPosition;
this.chunkTrackingView = oldPlayer.chunkTrackingView;
@@ -1752,19 +2164,19 @@
@@ -1752,19 +2169,19 @@
}
@Override
@ -1207,7 +1213,7 @@
}
return flag1;
@@ -1861,8 +2273,13 @@
@@ -1861,8 +2278,13 @@
}
public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
@ -1222,7 +1228,7 @@
}
}
@@ -1878,7 +2295,18 @@
@@ -1878,7 +2300,18 @@
}
public void updateOptions(ClientInformation clientOptions) {
@ -1241,7 +1247,7 @@
this.requestedViewDistance = clientOptions.viewDistance();
this.chatVisibility = clientOptions.chatVisibility();
this.canChatColor = clientOptions.chatColors();
@@ -1962,7 +2390,7 @@
@@ -1962,7 +2395,7 @@
if (world instanceof ServerLevel) {
ServerLevel worldserver = (ServerLevel) world;
@ -1250,7 +1256,7 @@
}
if (entity != null) {
@@ -1999,11 +2427,11 @@
@@ -1999,11 +2432,11 @@
@Nullable
public Component getTabListDisplayName() {
@ -1264,7 +1270,7 @@
}
@Override
@@ -2046,17 +2474,43 @@
@@ -2046,17 +2479,43 @@
}
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
@ -1315,7 +1321,7 @@
} else {
this.respawnPosition = null;
this.respawnDimension = Level.OVERWORLD;
@@ -2088,18 +2542,44 @@
@@ -2088,18 +2547,44 @@
}
@Override
@ -1364,7 +1370,7 @@
}
this.awardStat(Stats.DROP);
@@ -2375,10 +2855,12 @@
@@ -2375,16 +2860,160 @@
return TicketType.ENDER_PEARL.timeout();
}
@ -1380,10 +1386,11 @@
}
private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) {
@@ -2387,4 +2869,146 @@
Vec3 vec3d1 = Vec3.atBottomCenterOf(currentPos).subtract(respawnPos).normalize();
return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
}
}
+ }
+ }
+
+ // CraftBukkit start - Add per-player time and weather.
+ public long timeOffset = 0;
@ -1396,8 +1403,8 @@
+ } else {
+ // Adds timeOffset to the beginning of this day.
+ return this.level().getDayTime() - (this.level().getDayTime() % 24000) + this.timeOffset;
+ }
+ }
}
}
+
+ public WeatherType weather = null;
+