3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00
Paper/nms-patches/EntityPlayer.patch

1008 Zeilen
44 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityPlayer.java
+++ b/net/minecraft/server/EntityPlayer.java
2020-06-25 02:00:00 +02:00
@@ -14,6 +14,27 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import com.google.common.base.Preconditions;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
2018-07-15 02:00:00 +02:00
+import org.bukkit.Location;
+import org.bukkit.WeatherType;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.inventory.InventoryType;
2016-05-27 10:53:36 +02:00
+import org.bukkit.event.player.PlayerChangedMainHandEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerGameModeChangeEvent;
+import org.bukkit.event.player.PlayerLocaleChangeEvent;
2019-04-23 04:00:00 +02:00
+import org.bukkit.event.player.PlayerPortalEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
2016-05-27 10:53:36 +02:00
+import org.bukkit.inventory.MainHand;
+// CraftBukkit end
+
public class EntityPlayer extends EntityHuman implements ICrafting {
2019-04-23 04:00:00 +02:00
private static final Logger LOGGER = LogManager.getLogger();
2020-06-25 02:00:00 +02:00
@@ -56,6 +77,20 @@
public int ping;
public boolean viewingCredits;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ public String displayName;
+ public IChatBaseComponent listName;
+ public org.bukkit.Location compassTarget;
+ public int newExp = 0;
+ public int newLevel = 0;
+ public int newTotalExp = 0;
+ public boolean keepLevel = false;
+ public double maxHealthCache;
+ public boolean joining = true;
+ public boolean sentListPacket = false;
2018-11-02 11:24:14 +01:00
+ public Integer clientViewDistance;
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
2020-06-25 02:00:00 +02:00
super(worldserver, worldserver.getSpawn(), gameprofile);
this.spawnDimension = World.OVERWORLD;
@@ -66,7 +101,51 @@
2019-04-23 04:00:00 +02:00
this.advancementDataPlayer = minecraftserver.getPlayerList().f(this);
2020-06-25 02:00:00 +02:00
this.G = 1.0F;
this.b(worldserver);
+
+ // CraftBukkit start
+ this.displayName = this.getName();
+ this.canPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth();
+ }
+
2018-07-15 02:00:00 +02:00
+ // Yes, this doesn't match Vanilla, but it's the best we can do for now.
+ // If this is an issue, PRs are welcome
+ public final BlockPosition getSpawnPoint(WorldServer worldserver) {
+ BlockPosition blockposition = worldserver.getSpawn();
+
2020-06-25 02:00:00 +02:00
+ if (worldserver.getDimensionManager().hasSkyLight() && worldserver.worldDataServer.getGameType() != EnumGamemode.ADVENTURE) {
2018-07-15 02:00:00 +02:00
+ int i = Math.max(0, this.server.a(worldserver));
+ int j = MathHelper.floor(worldserver.getWorldBorder().b((double) blockposition.getX(), (double) blockposition.getZ()));
+
+ if (j < i) {
+ i = j;
+ }
+
+ if (j <= 1) {
+ i = 1;
+ }
+
2020-06-25 02:00:00 +02:00
+ long k = (long) (i * 2 + 1);
+ long l = k * k;
+ int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
+ int j1 = this.u(i1);
+ int k1 = (new Random()).nextInt(i1);
2018-07-15 02:00:00 +02:00
+
2020-06-25 02:00:00 +02:00
+ for (int l1 = 0; l1 < i1; ++l1) {
+ int i2 = (k1 + j1 * l1) % i1;
+ int j2 = i2 % (i * 2 + 1);
+ int k2 = i2 / (i * 2 + 1);
+ BlockPosition blockposition1 = WorldProviderNormal.a(worldserver, blockposition.getX() + j2 - i, blockposition.getZ() + k2 - i, false);
2018-07-15 02:00:00 +02:00
+
+ if (blockposition1 != null) {
+ return blockposition1;
2018-07-15 02:00:00 +02:00
+ }
+ }
+ }
+
+ return blockposition;
}
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
private void b(WorldServer worldserver) {
2018-07-15 02:00:00 +02:00
BlockPosition blockposition = worldserver.getSpawn();
@@ -137,11 +216,20 @@
2017-05-14 04:00:00 +02:00
if (nbttagcompound.hasKeyOfType("recipeBook", 10)) {
2020-06-25 02:00:00 +02:00
this.recipeBook.a(nbttagcompound.getCompound("recipeBook"), this.server.getCraftingManager());
}
+ this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit
2017-05-14 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
if (this.isSleeping()) {
2019-12-10 23:00:00 +01:00
this.entityWakeup();
2020-06-25 02:00:00 +02:00
}
+ // CraftBukkit start
+ String spawnWorld = nbttagcompound.getString("SpawnWorld");
+ CraftWorld oldWorld = (CraftWorld) Bukkit.getWorld(spawnWorld);
+ if (oldWorld != null) {
+ this.spawnDimension = oldWorld.getHandle().getDimensionKey();
+ }
+ // CraftBukkit end
+
if (nbttagcompound.hasKeyOfType("SpawnX", 99) && nbttagcompound.hasKeyOfType("SpawnY", 99) && nbttagcompound.hasKeyOfType("SpawnZ", 99)) {
this.spawn = new BlockPosition(nbttagcompound.getInt("SpawnX"), nbttagcompound.getInt("SpawnY"), nbttagcompound.getInt("SpawnZ"));
this.spawnForced = nbttagcompound.getBoolean("SpawnForced");
@@ -174,7 +262,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
2019-04-23 04:00:00 +02:00
- if (entity1 != null && entity != this && entity.hasSinglePlayerPassenger()) {
+ // CraftBukkit start - handle non-persistent vehicles
+ boolean persistVehicle = true;
+ if (entity1 != null) {
+ Entity vehicle;
+ for (vehicle = entity1; vehicle != null; vehicle = vehicle.getVehicle()) {
+ if (!vehicle.persist) {
+ persistVehicle = false;
+ break;
+ }
+ }
+ }
+
2019-04-23 04:00:00 +02:00
+ if (persistVehicle && entity1 != null && entity != this && entity.hasSinglePlayerPassenger()) {
+ // CraftBukkit end
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -191,7 +292,7 @@
2020-06-25 02:00:00 +02:00
nbttagcompound.setInt("SpawnY", this.spawn.getY());
nbttagcompound.setInt("SpawnZ", this.spawn.getZ());
nbttagcompound.setBoolean("SpawnForced", this.spawnForced);
- DataResult dataresult = MinecraftKey.a.encodeStart(DynamicOpsNBT.a, this.spawnDimension.a());
+ DataResult<NBTBase> dataresult = MinecraftKey.a.encodeStart(DynamicOpsNBT.a, this.spawnDimension.a()); // CraftBukkit - decompile error
Logger logger = EntityPlayer.LOGGER;
logger.getClass();
@@ -199,8 +300,32 @@
2020-06-25 02:00:00 +02:00
nbttagcompound.set("SpawnDimension", nbtbase);
});
2016-02-29 22:32:46 +01:00
}
2017-05-14 04:00:00 +02:00
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
+
+ }
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start - World fallback code, either respawn location or global spawn
+ public void spawnIn(World world) {
+ super.spawnIn(world);
+ if (world == null) {
+ this.dead = false;
2019-04-25 04:00:00 +02:00
+ Vec3D position = null;
2020-06-25 02:00:00 +02:00
+ if (this.spawnDimension != null) {
+ world = this.getWorldServer().getServer().getHandle().getServer().getWorldServer(this.spawnDimension);
+ if (world != null && this.getSpawn() != null) {
+ position = EntityHuman.getBed((WorldServer) world, this.getSpawn(), false, false).orElse(null);
+ }
+ }
+ if (world == null || position == null) {
+ world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle();
2020-06-25 02:00:00 +02:00
+ position = Vec3D.a(((WorldServer) world).getSpawn());
+ }
+ this.world = world;
2019-04-25 04:00:00 +02:00
+ this.setPosition(position.getX(), position.getY(), position.getZ());
+ }
+ this.playerInteractManager.a((WorldServer) world);
}
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
public void a(int i) {
float f = (float) this.getExpToLevel();
@@ -255,6 +380,11 @@
2019-04-23 04:00:00 +02:00
@Override
2018-07-15 02:00:00 +02:00
public void tick() {
+ // CraftBukkit start
+ if (this.joining) {
+ this.joining = false;
+ }
+ // CraftBukkit end
this.playerInteractManager.a();
--this.invulnerableTicks;
if (this.noDamageTicks > 0) {
@@ -322,7 +452,7 @@
}
2019-04-23 04:00:00 +02:00
if (this.getHealth() != this.lastHealthSent || this.lastFoodSent != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastSentSaturationZero) {
- this.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(this.getHealth(), this.foodData.getFoodLevel(), this.foodData.getSaturationLevel()));
+ this.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(this.getBukkitEntity().getScaledHealth(), this.foodData.getFoodLevel(), this.foodData.getSaturationLevel())); // CraftBukkit
this.lastHealthSent = this.getHealth();
2018-12-13 01:00:00 +01:00
this.lastFoodSent = this.foodData.getFoodLevel();
2019-04-23 04:00:00 +02:00
this.lastSentSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -353,6 +483,12 @@
2019-04-23 04:00:00 +02:00
this.a(IScoreboardCriteria.XP, MathHelper.f((float) this.lastExpTotalScored));
}
+ // CraftBukkit start - Force max health updates
+ if (this.maxHealthCache != this.getMaxHealth()) {
+ this.getBukkitEntity().updateScaledHealth();
2016-06-09 03:43:49 +02:00
+ }
+ // CraftBukkit end
2016-06-09 03:43:49 +02:00
+
2019-04-23 04:00:00 +02:00
if (this.expLevel != this.lastExpLevelScored) {
this.lastExpLevelScored = this.expLevel;
this.a(IScoreboardCriteria.LEVEL, MathHelper.f((float) this.lastExpLevelScored));
@@ -367,6 +503,16 @@
2018-07-15 02:00:00 +02:00
CriterionTriggers.p.a(this);
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - initialize oldLevel and fire PlayerLevelChangeEvent
+ if (this.oldLevel == -1) {
+ this.oldLevel = this.expLevel;
+ }
2015-02-26 23:41:06 +01:00
+
+ if (this.oldLevel != this.expLevel) {
+ CraftEventFactory.callPlayerLevelChangeEvent(this.world.getServer().getPlayer((EntityPlayer) this), this.oldLevel, this.expLevel);
+ this.oldLevel = this.expLevel;
+ }
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
@@ -377,7 +523,8 @@
}
private void a(IScoreboardCriteria iscoreboardcriteria, int i) {
2018-07-15 02:00:00 +02:00
- this.getScoreboard().getObjectivesForCriteria(iscoreboardcriteria, this.getName(), (scoreboardscore) -> {
+ // CraftBukkit - Use our scores instead
+ this.world.getServer().getScoreboardManager().getScoreboardScores(iscoreboardcriteria, this.getName(), (scoreboardscore) -> {
scoreboardscore.setScore(i);
2018-07-15 02:00:00 +02:00
});
}
@@ -385,9 +532,46 @@
2019-04-23 04:00:00 +02:00
@Override
2018-08-26 04:00:00 +02:00
public void die(DamageSource damagesource) {
2019-06-21 12:00:00 +02:00
boolean flag = this.world.getGameRules().getBoolean(GameRules.SHOW_DEATH_MESSAGES);
+ // CraftBukkit start - fire PlayerDeathEvent
+ if (this.dead) {
+ return;
+ }
2016-11-17 02:41:03 +01:00
+ java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>(this.inventory.getSize());
2019-06-21 12:00:00 +02:00
+ boolean keepInventory = this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || this.isSpectator();
+
+ if (!keepInventory) {
2016-11-17 02:41:03 +01:00
+ for (ItemStack item : this.inventory.getContents()) {
2017-05-14 04:00:00 +02:00
+ if (!item.isEmpty() && !EnchantmentManager.shouldNotDrop(item)) {
2016-11-17 02:41:03 +01:00
+ loot.add(CraftItemStack.asCraftMirror(item));
2016-02-29 22:32:46 +01:00
+ }
+ }
+ }
+ // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
+ this.a(damagesource, this.lastDamageByPlayerTime > 0);
+ for (org.bukkit.inventory.ItemStack item : this.drops) {
+ loot.add(item);
+ }
+ this.drops.clear(); // SPIGOT-5188: make sure to clear
2018-08-26 04:00:00 +02:00
- if (flag) {
- IChatBaseComponent ichatbasecomponent = this.getCombatTracker().getDeathMessage();
+ IChatBaseComponent defaultMessage = this.getCombatTracker().getDeathMessage();
+
2018-08-26 04:00:00 +02:00
+ String deathmessage = defaultMessage.getString();
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
2018-08-26 04:00:00 +02:00
+
+ // SPIGOT-943 - only call if they have an inventory open
+ if (this.activeContainer != this.defaultContainer) {
+ this.closeInventory();
+ }
+
+ String deathMessage = event.getDeathMessage();
+
2016-02-29 22:32:46 +01:00
+ if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
2018-08-26 04:00:00 +02:00
+ IChatBaseComponent ichatbasecomponent;
+ if (deathMessage.equals(deathmessage)) {
2018-08-26 04:00:00 +02:00
+ ichatbasecomponent = this.getCombatTracker().getDeathMessage();
+ } else {
+ ichatbasecomponent = org.bukkit.craftbukkit.util.CraftChatMessage.fromStringOrNull(deathMessage);
+ }
this.playerConnection.a((Packet) (new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, ichatbasecomponent)), (future) -> {
if (!future.isSuccess()) {
@@ -421,12 +605,18 @@
2020-06-25 02:00:00 +02:00
if (this.world.getGameRules().getBoolean(GameRules.FORGIVE_DEAD_PLAYERS)) {
this.eW();
}
2020-06-25 02:00:00 +02:00
-
2019-04-23 04:00:00 +02:00
- if (!this.isSpectator()) {
- this.d(damagesource);
+ // SPIGOT-5478 must be called manually now
+ this.dropExperience();
+ // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
+ if (!event.getKeepInventory()) {
2016-11-17 02:41:03 +01:00
+ this.inventory.clear();
}
- this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.DEATH_COUNT, this.getName(), ScoreboardScore::incrementScore);
+ this.setSpectatorTarget(this); // Remove spectated target
+ // CraftBukkit end
+
+ // CraftBukkit - Get our scores instead
2018-12-13 01:00:00 +01:00
+ this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.DEATH_COUNT, this.getName(), ScoreboardScore::incrementScore);
2019-04-23 04:00:00 +02:00
EntityLiving entityliving = this.getKillingEntity();
2018-07-15 02:00:00 +02:00
if (entityliving != null) {
@@ -462,10 +652,12 @@
2018-07-15 02:00:00 +02:00
String s = this.getName();
String s1 = entity.getName();
2018-12-13 01:00:00 +01:00
- this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.TOTAL_KILL_COUNT, s, ScoreboardScore::incrementScore);
2017-05-14 04:00:00 +02:00
+ // CraftBukkit - Get our scores instead
2018-12-13 01:00:00 +01:00
+ this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.TOTAL_KILL_COUNT, s, ScoreboardScore::incrementScore);
2017-05-14 04:00:00 +02:00
if (entity instanceof EntityHuman) {
2018-07-15 02:00:00 +02:00
this.a(StatisticList.PLAYER_KILLS);
2018-12-13 01:00:00 +01:00
- this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.PLAYER_KILL_COUNT, s, ScoreboardScore::incrementScore);
2017-05-14 04:00:00 +02:00
+ // CraftBukkit - Get our scores instead
2018-12-13 01:00:00 +01:00
+ this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.PLAYER_KILL_COUNT, s, ScoreboardScore::incrementScore);
2017-05-14 04:00:00 +02:00
} else {
2018-07-15 02:00:00 +02:00
this.a(StatisticList.MOB_KILLS);
2017-05-14 04:00:00 +02:00
}
@@ -483,7 +675,8 @@
2018-07-15 02:00:00 +02:00
int i = scoreboardteam.getColor().b();
2017-05-14 04:00:00 +02:00
2018-07-15 02:00:00 +02:00
if (i >= 0 && i < aiscoreboardcriteria.length) {
- this.getScoreboard().getObjectivesForCriteria(aiscoreboardcriteria[i], s, ScoreboardScore::incrementScore);
2017-05-14 04:00:00 +02:00
+ // CraftBukkit - Get our scores instead
2018-07-15 02:00:00 +02:00
+ this.world.getServer().getScoreboardManager().getScoreboardScores(aiscoreboardcriteria[i], s, ScoreboardScore::incrementScore);
2017-05-14 04:00:00 +02:00
}
}
@@ -527,17 +720,27 @@
}
2016-02-29 22:32:46 +01:00
private boolean canPvP() {
- return this.server.getPVP();
+ // CraftBukkit - this.server.getPvP() -> this.world.pvpMode
+ return this.world.pvpMode;
}
2016-05-10 13:47:39 +02:00
@Nullable
2019-04-23 04:00:00 +02:00
@Override
2020-06-25 02:00:00 +02:00
public Entity a(WorldServer worldserver) {
2016-06-09 03:43:49 +02:00
- this.worldChangeInvuln = true;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ return a(worldserver, TeleportCause.UNKNOWN);
2019-04-23 04:00:00 +02:00
+ }
+
+ @Nullable
2020-06-25 02:00:00 +02:00
+ public Entity a(WorldServer worldserver, PlayerTeleportEvent.TeleportCause cause) {
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
+ if (this.isSleeping()) return this; // CraftBukkit - SPIGOT-3154
2016-06-09 03:43:49 +02:00
+ // this.worldChangeInvuln = true; // CraftBukkit - Moved down and into PlayerList#changeDimension
2020-06-25 02:00:00 +02:00
WorldServer worldserver1 = this.getWorldServer();
- ResourceKey<World> resourcekey = worldserver1.getDimensionKey();
+ ResourceKey<DimensionManager> resourcekey = worldserver1.getTypeKey(); // CraftBukkit
2017-05-14 04:00:00 +02:00
- if (resourcekey == World.THE_END && worldserver.getDimensionKey() == World.OVERWORLD) {
+ if (resourcekey == DimensionManager.THE_END && worldserver.getTypeKey() == DimensionManager.OVERWORLD) { // CraftBukkit
2016-06-09 03:43:49 +02:00
+ this.worldChangeInvuln = true; // CraftBukkit - Moved down from above
2019-04-23 04:00:00 +02:00
this.decouple();
this.getWorldServer().removePlayer(this);
if (!this.viewingCredits) {
@@ -548,6 +751,8 @@
2019-04-23 04:00:00 +02:00
2020-06-25 02:00:00 +02:00
return this;
} else {
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ /*
2020-06-25 02:00:00 +02:00
WorldData worlddata = worldserver.getWorldData();
2019-12-11 02:36:03 +01:00
2020-06-25 02:00:00 +02:00
this.playerConnection.sendPacket(new PacketPlayOutRespawn(worldserver.getTypeKey(), worldserver.getDimensionKey(), BiomeManager.a(worldserver.getSeed()), this.playerInteractManager.getGameMode(), this.playerInteractManager.c(), worldserver.isDebugWorld(), worldserver.isFlatWorld(), true));
@@ -557,6 +762,8 @@
2019-04-23 04:00:00 +02:00
playerlist.d(this);
2020-06-25 02:00:00 +02:00
worldserver1.removePlayer(this);
2019-04-23 04:00:00 +02:00
this.dead = false;
+ */
+ // CraftBukkit end
2019-12-10 23:00:00 +01:00
double d0 = this.locX();
double d1 = this.locY();
double d2 = this.locZ();
@@ -567,7 +774,8 @@
worldserver1.getMethodProfiler().enter("moving");
double d3;
- if (worldserver.getDimensionKey() == World.THE_END) {
+ if (worldserver == null) { } else // CraftBukkit - empty to fall through to null to event
+ if (worldserver.getTypeKey() == DimensionManager.THE_END) { // CraftBukkit
BlockPosition blockposition = WorldServer.a;
d0 = (double) blockposition.getX();
@@ -576,7 +784,7 @@
f1 = 90.0F;
f = 0.0F;
} else {
- if (resourcekey == World.OVERWORLD && worldserver.getDimensionKey() == World.THE_NETHER) {
+ if (resourcekey == DimensionManager.OVERWORLD && worldserver.getTypeKey() == DimensionManager.THE_NETHER) { // CraftBukkit
this.cp = this.getPositionVector();
}
@@ -593,7 +801,26 @@
2020-06-25 02:00:00 +02:00
}
}
- this.setPositionRotation(d0, d1, d2, f1, f);
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ Location enter = this.getBukkitEntity().getLocation();
2020-06-25 02:00:00 +02:00
+ Location exit = (worldserver == null) ? null : new Location(worldserver.getWorld(), d0, d1, d2, f1, f);
+ PlayerPortalEvent event = new PlayerPortalEvent(this.getBukkitEntity(), enter, exit, cause, 128, true, resourcekey == DimensionManager.THE_END ? 0 : 16);
2019-04-23 04:00:00 +02:00
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled() || event.getTo() == null) {
+ return null;
+ }
+
+ exit = event.getTo();
+ if (exit == null) {
+ return null;
+ }
2020-06-25 02:00:00 +02:00
+ worldserver = ((CraftWorld) exit.getWorld()).getHandle();
2019-04-23 04:00:00 +02:00
+ d0 = exit.getX();
+ d1 = exit.getY();
+ d2 = exit.getZ();
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
+
+ // this.setPositionRotation(d0, d1, d2, f1, f); // CraftBukkit - PlayerTeleportEvent handles position changes
2020-06-25 02:00:00 +02:00
worldserver1.getMethodProfiler().exit();
worldserver1.getMethodProfiler().enter("placing");
double d4 = Math.min(-2.9999872E7D, worldserver.getWorldBorder().e() + 16.0D);
@@ -604,25 +831,74 @@
2020-06-25 02:00:00 +02:00
d0 = MathHelper.a(d0, d4, d5);
d2 = MathHelper.a(d2, d3, d6);
- this.setPositionRotation(d0, d1, d2, f1, f);
- if (worldserver.getDimensionKey() == World.THE_END) {
2020-06-25 02:00:00 +02:00
- int i = MathHelper.floor(this.locX());
- int j = MathHelper.floor(this.locY()) - 1;
- int k = MathHelper.floor(this.locZ());
-
- WorldServer.a(worldserver);
- this.setPositionRotation((double) i, (double) j, (double) k, f1, 0.0F);
- this.setMot(Vec3D.a);
- } else if (!worldserver.getTravelAgent().findAndTeleport(this, f2)) {
- worldserver.getTravelAgent().createPortal(this);
- worldserver.getTravelAgent().findAndTeleport(this, f2);
+ // this.setPositionRotation(d0, d1, d2, f1, f); // CraftBukkit - PlayerTeleportEvent handles position changes
+ // CraftBukkit start - PlayerPortalEvent implementation
+ Vec3D exitVelocity = Vec3D.a;
+ BlockPosition exitPosition = new BlockPosition(d0, d1, d2);
+ if (worldserver.getTypeKey() == DimensionManager.THE_END) { // CraftBukkit
+ int i = exitPosition.getX();
+ int j = exitPosition.getY() - 1;
+ int k = exitPosition.getZ();
+ if (event.getCanCreatePortal()) {
2020-06-25 02:00:00 +02:00
+ WorldServer.a(worldserver, this);
+ }
+ // handled below for PlayerTeleportEvent
+ // this.setPositionRotation((double) i, (double) j, (double) k, f1, 0.0F);
+ exit.setX(i);
+ exit.setY(j);
+ exit.setZ(k);
+ // this.setMot(Vec3D.a);
+ exitVelocity = Vec3D.a;
+ } else {
2020-06-25 02:00:00 +02:00
+ ShapeDetector.Shape portalShape = worldserver.getTravelAgent().findAndTeleport(this, exitPosition, f2, event.getSearchRadius(), true);
+ if (portalShape == null && event.getCanCreatePortal()) {
2020-06-25 02:00:00 +02:00
+ if (worldserver.getTravelAgent().createPortal(this, exitPosition, event.getCreationRadius())) { // Only check for new portal if creation succeeded
+ portalShape = worldserver.getTravelAgent().findAndTeleport(this, exitPosition, f2, event.getSearchRadius(), true);
+ }
+ }
+ // Check if portal was found
+ if (portalShape == null) {
+ return null;
+ }
+ // Teleport handling - logic from PortalTravelAgent#findAndTeleport
+ exitVelocity = portalShape.velocity;
+ exit.setX(portalShape.position.getX());
+ exit.setY(portalShape.position.getY());
+ exit.setZ(portalShape.position.getZ());
+ exit.setYaw(f2 + (float) portalShape.yaw);
+ // CraftBukkit end
}
2020-06-25 02:00:00 +02:00
worldserver1.getMethodProfiler().exit();
+ // CraftBukkit start - PlayerTeleportEvent
+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, cause);
+ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
+ if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
+ return null;
+ }
+
+ exit = tpEvent.getTo();
+ if (exit == null) {
+ return null;
+ }
2020-06-25 02:00:00 +02:00
+ worldserver = ((CraftWorld) exit.getWorld()).getHandle();
+ this.worldChangeInvuln = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
+
2020-06-25 02:00:00 +02:00
+ this.playerConnection.sendPacket(new PacketPlayOutRespawn(worldserver.getTypeKey(), worldserver.getDimensionKey(), BiomeManager.a(worldserver.getSeed()), this.playerInteractManager.getGameMode(), this.playerInteractManager.c(), worldserver.isDebugWorld(), worldserver.isFlatWorld(), true));
+ this.playerConnection.sendPacket(new PacketPlayOutServerDifficulty(this.world.getDifficulty(), this.world.getWorldData().isDifficultyLocked()));
+ PlayerList playerlist = this.server.getPlayerList();
+
+ playerlist.d(this);
2020-06-25 02:00:00 +02:00
+ worldserver1.removePlayer(this);
+ this.dead = false;
+
+ this.setMot(exitVelocity);
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
this.spawnIn(worldserver);
worldserver.addPlayerPortal(this);
this.triggerDimensionAdvancements(worldserver1);
- this.playerConnection.a(this.locX(), this.locY(), this.locZ(), f1, f);
+ this.playerConnection.teleport(exit); // CraftBukkit - use internal teleport without event
+ this.playerConnection.syncPosition(); // CraftBukkit - sync position after changing it (from PortalTravelAgent#findAndteleport)
2020-06-25 02:00:00 +02:00
this.playerInteractManager.a(worldserver);
this.playerConnection.sendPacket(new PacketPlayOutAbilities(this.abilities));
2020-06-25 02:00:00 +02:00
playerlist.a(this, worldserver);
@@ -639,6 +915,11 @@
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
this.lastFoodSent = -1;
+
+ // CraftBukkit start
+ PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.getBukkitEntity(), worldserver1.getWorld());
+ this.world.getServer().getPluginManager().callEvent(changeEvent);
+ // CraftBukkit end
return this;
2019-04-23 04:00:00 +02:00
}
}
@@ -680,10 +961,8 @@
2019-04-23 04:00:00 +02:00
this.activeContainer.c();
}
2019-04-23 04:00:00 +02:00
- @Override
2020-06-25 02:00:00 +02:00
- public Either<EntityHuman.EnumBedResult, Unit> sleep(BlockPosition blockposition) {
- EnumDirection enumdirection = (EnumDirection) this.world.getType(blockposition).get(BlockFacingHorizontal.FACING);
-
+ // CraftBukkit start - moved bed result checks from below into separate method
+ private Either<EntityHuman.EnumBedResult, Unit> getBedResult(BlockPosition blockposition, EnumDirection enumdirection) {
if (!this.isSleeping() && this.isAlive()) {
if (!this.world.getDimensionManager().isNatural()) {
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
@@ -709,7 +988,36 @@
2020-06-25 02:00:00 +02:00
}
}
- Either<EntityHuman.EnumBedResult, Unit> either = super.sleep(blockposition).ifRight((unit) -> {
+ return Either.right(Unit.INSTANCE);
+ }
+ }
+ } else {
+ return Either.left(EntityHuman.EnumBedResult.OTHER_PROBLEM);
+ }
+ }
+
2019-04-23 04:00:00 +02:00
+ @Override
+ public Either<EntityHuman.EnumBedResult, Unit> sleep(BlockPosition blockposition, boolean force) {
2020-06-25 02:00:00 +02:00
+ EnumDirection enumdirection = (EnumDirection) this.world.getType(blockposition).get(BlockFacingHorizontal.FACING);
+ Either<EntityHuman.EnumBedResult, Unit> bedResult = this.getBedResult(blockposition, enumdirection);
+
+ if (bedResult.left().orElse(null) == EntityHuman.EnumBedResult.OTHER_PROBLEM) {
+ return bedResult; // return immediately if the result is not bypassable by plugins
+ }
+
+ if (force) {
+ bedResult = Either.right(Unit.INSTANCE);
+ }
+
+ bedResult = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerBedEnterEvent(this, blockposition, bedResult);
+ if (bedResult.left().isPresent()) {
+ return bedResult;
+ }
+
+ {
+ {
+ {
+ Either<EntityHuman.EnumBedResult, Unit> either = super.sleep(blockposition, force).ifRight((unit) -> {
this.a(StatisticList.SLEEP_IN_BED);
CriterionTriggers.q.a(this);
});
@@ -718,9 +1026,8 @@
2020-06-25 02:00:00 +02:00
return either;
}
}
- } else {
- return Either.left(EntityHuman.EnumBedResult.OTHER_PROBLEM);
}
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
}
@Override
@@ -747,6 +1054,7 @@
2019-04-23 04:00:00 +02:00
@Override
2019-12-10 23:00:00 +01:00
public void wakeup(boolean flag, boolean flag1) {
2019-04-23 04:00:00 +02:00
+ if (!this.isSleeping()) return; // CraftBukkit - Can't leave bed if not in one!
if (this.isSleeping()) {
2019-04-23 04:00:00 +02:00
this.getWorldServer().getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutAnimation(this, 2));
}
@@ -818,8 +1126,9 @@
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
}
2016-02-29 22:32:46 +01:00
- public void nextContainerCounter() {
+ public int nextContainerCounter() { // CraftBukkit - void -> int
this.containerCounter = this.containerCounter % 100 + 1;
+ return containerCounter; // CraftBukkit
}
2019-04-23 04:00:00 +02:00
@Override
@@ -834,6 +1143,24 @@
2016-11-17 02:41:03 +01:00
this.nextContainerCounter();
2019-04-23 04:00:00 +02:00
Container container = itileinventory.createMenu(this.containerCounter, this.inventory, this);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start - Inventory open hook
+ if (container != null) {
+ container.setTitle(itileinventory.getScoreboardDisplayName());
+
2019-04-23 04:00:00 +02:00
+ boolean cancelled = false;
+ container = CraftEventFactory.callInventoryOpenEvent(this, container, cancelled);
+ if (container == null && !cancelled) { // Let pre-cancelled events fall through
+ // SPIGOT-5263 - close chest if cancelled
+ if (itileinventory instanceof IInventory) {
+ ((IInventory) itileinventory).closeContainer(this);
+ } else if (itileinventory instanceof BlockChest.DoubleInventory) {
+ // SPIGOT-5355 - double chests too :(
+ ((BlockChest.DoubleInventory) itileinventory).inventorylargechest.closeContainer(this);
+ }
2019-04-23 04:00:00 +02:00
+ return OptionalInt.empty();
+ }
+ }
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
if (container == null) {
if (this.isSpectator()) {
2020-06-25 02:00:00 +02:00
this.a((IChatBaseComponent) (new ChatMessage("container.spectatorCantOpen")).a(EnumChatFormat.RED), true);
@@ -841,9 +1168,11 @@
2019-04-23 04:00:00 +02:00
return OptionalInt.empty();
2016-02-29 22:32:46 +01:00
} else {
2019-04-23 04:00:00 +02:00
- this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, container.getType(), itileinventory.getScoreboardDisplayName()));
- container.addSlotListener(this);
+ // CraftBukkit start
this.activeContainer = container;
+ this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, container.getType(), container.getTitle()));
+ // CraftBukkit end
+ container.addSlotListener(this);
return OptionalInt.of(this.containerCounter);
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
}
@@ -856,13 +1185,24 @@
2019-04-23 04:00:00 +02:00
@Override
2016-11-17 02:41:03 +01:00
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
+ // CraftBukkit start - Inventory open hook
2019-04-23 04:00:00 +02:00
+ this.nextContainerCounter();
+ Container container = new ContainerHorse(this.containerCounter, this.inventory, iinventory, entityhorseabstract);
+ container.setTitle(entityhorseabstract.getScoreboardDisplayName());
+ container = CraftEventFactory.callInventoryOpenEvent(this, container);
+
+ if (container == null) {
+ iinventory.closeContainer(this);
+ return;
+ }
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
if (this.activeContainer != this.defaultContainer) {
this.closeInventory();
}
2019-04-23 04:00:00 +02:00
- this.nextContainerCounter();
+ // this.nextContainerCounter(); // CraftBukkit - moved up
this.playerConnection.sendPacket(new PacketPlayOutOpenWindowHorse(this.containerCounter, iinventory.getSize(), entityhorseabstract.getId()));
- this.activeContainer = new ContainerHorse(this.containerCounter, this.inventory, iinventory, entityhorseabstract);
2016-11-17 02:41:03 +01:00
+ this.activeContainer = container; // CraftBukkit
this.activeContainer.addSlotListener(this);
}
2019-04-23 04:00:00 +02:00
@@ -907,6 +1247,11 @@
2016-11-17 02:41:03 +01:00
public void a(Container container, NonNullList<ItemStack> nonnulllist) {
this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, nonnulllist));
this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried()));
+ // CraftBukkit start - Send a Set Slot to update the crafting result slot
+ if (java.util.EnumSet.of(InventoryType.CRAFTING,InventoryType.WORKBENCH).contains(container.getBukkitView().getType())) {
+ this.playerConnection.sendPacket(new PacketPlayOutSetSlot(container.windowId, 0, container.getSlot(0).getItem()));
+ }
+ // CraftBukkit end
}
2019-04-23 04:00:00 +02:00
@Override
@@ -916,6 +1261,7 @@
2019-04-23 04:00:00 +02:00
@Override
public void closeInventory() {
+ CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
2020-06-25 02:00:00 +02:00
this.o();
2018-07-15 02:00:00 +02:00
}
@@ -950,7 +1296,7 @@
2019-04-23 04:00:00 +02:00
@Override
2018-07-15 02:00:00 +02:00
public void a(Statistic<?> statistic, int i) {
2019-04-23 04:00:00 +02:00
this.serverStatisticManager.b(this, statistic, i);
2018-07-15 02:00:00 +02:00
- this.getScoreboard().getObjectivesForCriteria(statistic, this.getName(), (scoreboardscore) -> {
+ this.world.getServer().getScoreboardManager().getScoreboardScores(statistic, this.getName(), (scoreboardscore) -> { // CraftBukkit - Get our scores instead
scoreboardscore.addScore(i);
});
2017-05-14 04:00:00 +02:00
}
@@ -958,7 +1304,7 @@
2019-04-23 04:00:00 +02:00
@Override
2018-07-15 02:00:00 +02:00
public void a(Statistic<?> statistic) {
2019-04-23 04:00:00 +02:00
this.serverStatisticManager.setStatistic(this, statistic, 0);
2018-07-15 02:00:00 +02:00
- this.getScoreboard().getObjectivesForCriteria(statistic, this.getName(), ScoreboardScore::c);
+ this.world.getServer().getScoreboardManager().getScoreboardScores(statistic, this.getName(), ScoreboardScore::c); // CraftBukkit - Get our scores instead
}
2017-05-14 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
@Override
@@ -1007,7 +1353,16 @@
public void triggerHealthUpdate() {
2016-02-29 22:32:46 +01:00
this.lastHealthSent = -1.0E8F;
+ this.lastSentExp = -1; // CraftBukkit - Added to reset
2020-06-25 02:00:00 +02:00
+ }
+
+ // CraftBukkit start - Support multi-line messages
+ public void sendMessage(IChatBaseComponent[] ichatbasecomponent) {
+ for (IChatBaseComponent component : ichatbasecomponent) {
2020-06-25 02:00:00 +02:00
+ this.sendMessage(component, SystemUtils.b);
+ }
2020-06-25 02:00:00 +02:00
}
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
@Override
2016-11-17 02:41:03 +01:00
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
@@ -1062,12 +1417,14 @@
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
2018-12-13 01:00:00 +01:00
this.lastFoodSent = -1;
- this.recipeBook.a((RecipeBook) entityplayer.recipeBook);
+ // this.recipeBook.a((RecipeBook) entityplayer.recipeBook); // CraftBukkit
this.removeQueue.addAll(entityplayer.removeQueue);
2020-06-25 02:00:00 +02:00
this.ck = entityplayer.ck;
this.cp = entityplayer.cp;
this.setShoulderEntityLeft(entityplayer.getShoulderEntityLeft());
this.setShoulderEntityRight(entityplayer.getShoulderEntityRight());
+
2019-05-14 02:00:00 +02:00
+ this.inLava = false; // SPIGOT-4767
}
@Override
@@ -1135,6 +1492,18 @@
2019-04-23 04:00:00 +02:00
@Override
2016-06-09 03:43:49 +02:00
public void a(EnumGamemode enumgamemode) {
+ // CraftBukkit start
+ if (enumgamemode == this.playerInteractManager.getGameMode()) {
+ return;
+ }
+
+ PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(getBukkitEntity(), GameMode.getByValue(enumgamemode.getId()));
+ world.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
+
2016-06-09 03:43:49 +02:00
this.playerInteractManager.setGameMode(enumgamemode);
2020-06-25 02:00:00 +02:00
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.d, (float) enumgamemode.getId()));
2016-06-09 03:43:49 +02:00
if (enumgamemode == EnumGamemode.SPECTATOR) {
@@ -1184,7 +1553,20 @@
2020-06-25 02:00:00 +02:00
return s;
2016-05-27 10:53:36 +02:00
}
2020-06-25 02:00:00 +02:00
+ public String locale = "en_us"; // CraftBukkit - add, lowercase
2016-05-27 10:53:36 +02:00
public void a(PacketPlayInSettings packetplayinsettings) {
+ // CraftBukkit start
2016-06-09 03:43:49 +02:00
+ if (getMainHand() != packetplayinsettings.getMainHand()) {
2016-05-27 10:53:36 +02:00
+ PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(getBukkitEntity(), getMainHand() == EnumMainHand.LEFT ? MainHand.LEFT : MainHand.RIGHT);
+ this.server.server.getPluginManager().callEvent(event);
+ }
2020-06-25 02:00:00 +02:00
+ if (!this.locale.equals(packetplayinsettings.locale)) {
+ PlayerLocaleChangeEvent event = new PlayerLocaleChangeEvent(getBukkitEntity(), packetplayinsettings.locale);
+ this.server.server.getPluginManager().callEvent(event);
+ }
+ this.locale = packetplayinsettings.locale;
2018-12-06 00:00:00 +01:00
+ this.clientViewDistance = packetplayinsettings.viewDistance;
2016-05-27 10:53:36 +02:00
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
this.cf = packetplayinsettings.d();
this.cg = packetplayinsettings.e();
this.getDataWatcher().set(EntityPlayer.bp, (byte) packetplayinsettings.f());
@@ -1220,13 +1602,13 @@
2018-12-06 00:00:00 +01:00
if (entity instanceof EntityHuman) {
2019-05-27 22:30:00 +02:00
this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(new int[]{entity.getId()}));
2018-12-06 00:00:00 +01:00
} else {
- this.removeQueue.add(entity.getId());
+ this.removeQueue.add((Integer) entity.getId()); // CraftBukkit - decompile error
}
}
public void d(Entity entity) {
- this.removeQueue.remove(entity.getId());
+ this.removeQueue.remove((Integer) entity.getId()); // CraftBukkit - decompile error
}
2019-04-23 04:00:00 +02:00
@Override
@@ -1250,7 +1632,7 @@
2018-12-13 01:00:00 +01:00
this.spectatedEntity = (Entity) (entity == null ? this : entity);
if (entity1 != this.spectatedEntity) {
this.playerConnection.sendPacket(new PacketPlayOutCamera(this.spectatedEntity));
2019-12-10 23:00:00 +01:00
- this.enderTeleportTo(this.spectatedEntity.locX(), this.spectatedEntity.locY(), this.spectatedEntity.locZ());
+ this.playerConnection.a(this.spectatedEntity.locX(), this.spectatedEntity.locY(), this.spectatedEntity.locZ(), this.yaw, this.pitch, TeleportCause.SPECTATE); // CraftBukkit
}
}
@@ -1279,7 +1661,7 @@
2016-03-02 08:32:06 +01:00
2016-05-10 13:47:39 +02:00
@Nullable
2016-03-02 08:32:06 +01:00
public IChatBaseComponent getPlayerListName() {
- return null;
+ return listName; // CraftBukkit
}
2019-04-23 04:00:00 +02:00
@Override
@@ -1300,9 +1682,16 @@
2019-04-23 04:00:00 +02:00
return this.advancementDataPlayer;
2017-05-14 04:00:00 +02:00
}
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
public void a(WorldServer worldserver, double d0, double d1, double d2, float f, float f1) {
+ this.a(worldserver, d0, d1, d2, f, f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public void a(WorldServer worldserver, double d0, double d1, double d2, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
+ // CraftBukkit end
this.setSpectatorTarget(this);
this.stopRiding();
+ /* CraftBukkit start - replace with bukkit handling for multi-world
if (worldserver == this.world) {
this.playerConnection.a(d0, d1, d2, f, f1);
} else {
@@ -1323,6 +1712,9 @@
2019-04-23 04:00:00 +02:00
this.server.getPlayerList().a(this, worldserver);
2018-07-15 02:00:00 +02:00
this.server.getPlayerList().updateClient(this);
}
+ */
+ this.getBukkitEntity().teleport(new Location(worldserver.getWorld(), d0, d1, d2, f, f1), cause);
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
}
@@ -1409,4 +1801,144 @@
2019-04-23 04:00:00 +02:00
return entityitem;
}
}
+
+ // CraftBukkit start - Add per-player time and weather.
+ public long timeOffset = 0;
+ public boolean relativeTime = true;
+
+ public long getPlayerTime() {
+ if (this.relativeTime) {
+ // Adds timeOffset to the current server time.
+ return this.world.getDayTime() + this.timeOffset;
+ } else {
+ // Adds timeOffset to the beginning of this day.
+ return this.world.getDayTime() - (this.world.getDayTime() % 24000) + this.timeOffset;
+ }
+ }
+
+ public WeatherType weather = null;
+
+ public WeatherType getPlayerWeather() {
+ return this.weather;
+ }
+
+ public void setPlayerWeather(WeatherType type, boolean plugin) {
+ if (!plugin && this.weather != null) {
+ return;
+ }
+
+ if (plugin) {
+ this.weather = type;
+ }
+
+ if (type == WeatherType.DOWNFALL) {
2020-06-25 02:00:00 +02:00
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.c, 0));
+ } else {
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.b, 0));
+ }
+ }
2015-02-26 23:41:06 +01:00
+
+ private float pluginRainPosition;
+ private float pluginRainPositionPrevious;
2015-02-26 23:41:06 +01:00
+
+ public void updateWeather(float oldRain, float newRain, float oldThunder, float newThunder) {
+ if (this.weather == null) {
+ // Vanilla
+ if (oldRain != newRain) {
2020-06-25 02:00:00 +02:00
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, newRain));
2015-02-26 23:41:06 +01:00
+ }
+ } else {
+ // Plugin
+ if (pluginRainPositionPrevious != pluginRainPosition) {
2020-06-25 02:00:00 +02:00
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, pluginRainPosition));
2015-02-26 23:41:06 +01:00
+ }
+ }
+
+ if (oldThunder != newThunder) {
+ if (weather == WeatherType.DOWNFALL || weather == null) {
2020-06-25 02:00:00 +02:00
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.i, newThunder));
+ } else {
2020-06-25 02:00:00 +02:00
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.i, 0));
+ }
+ }
+ }
2015-02-26 23:41:06 +01:00
+
+ public void tickWeather() {
+ if (this.weather == null) return;
+
+ pluginRainPositionPrevious = pluginRainPosition;
+ if (weather == WeatherType.DOWNFALL) {
+ pluginRainPosition += 0.01;
+ } else {
+ pluginRainPosition -= 0.01;
+ }
+
+ pluginRainPosition = MathHelper.a(pluginRainPosition, 0.0F, 1.0F);
+ }
+
+ public void resetPlayerWeather() {
+ this.weather = null;
+ this.setPlayerWeather(this.world.getWorldData().hasStorm() ? WeatherType.DOWNFALL : WeatherType.CLEAR, false);
+ }
+
+ @Override
+ public String toString() {
2019-12-10 23:00:00 +01:00
+ return super.toString() + "(" + this.getName() + " at " + this.locX() + "," + this.locY() + "," + this.locZ() + ")";
+ }
+
+ // SPIGOT-1903, MC-98153
+ public void forceSetPositionRotation(double x, double y, double z, float yaw, float pitch) {
+ this.setPositionRotation(x, y, z, yaw, pitch);
2016-11-17 02:41:03 +01:00
+ this.playerConnection.syncPosition();
+ }
+
2016-11-29 23:16:01 +01:00
+ @Override
+ protected boolean isFrozen() {
+ return super.isFrozen() || !getBukkitEntity().isOnline();
+ }
+
+ @Override
+ public Scoreboard getScoreboard() {
+ return getBukkitEntity().getScoreboard().getHandle();
+ }
+
+ public void reset() {
+ float exp = 0;
2019-06-21 12:00:00 +02:00
+ boolean keepInventory = this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY);
+
+ if (this.keepLevel || keepInventory) {
+ exp = this.exp;
+ this.newTotalExp = this.expTotal;
+ this.newLevel = this.expLevel;
+ }
+
+ this.setHealth(this.getMaxHealth());
+ this.fireTicks = 0;
+ this.fallDistance = 0;
+ this.foodData = new FoodMetaData(this);
+ this.expLevel = this.newLevel;
+ this.expTotal = this.newTotalExp;
+ this.exp = 0;
+ this.deathTicks = 0;
2017-11-17 01:03:30 +01:00
+ this.setArrowCount(0);
+ this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.DEATH);
+ this.updateEffects = true;
+ this.activeContainer = this.defaultContainer;
+ this.killer = null;
+ this.lastDamager = null;
+ this.combatTracker = new CombatTracker(this);
+ this.lastSentExp = -1;
+ if (this.keepLevel || keepInventory) {
+ this.exp = exp;
+ } else {
+ this.giveExp(this.newExp);
+ }
+ this.keepLevel = false;
+ }
2019-04-23 04:00:00 +02:00
+
+ @Override
+ public CraftPlayer getBukkitEntity() {
+ return (CraftPlayer) super.getBukkitEntity();
2019-04-23 04:00:00 +02:00
+ }
+ // CraftBukkit end
}