2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/server/level/EntityPlayer.java
|
|
|
|
+++ b/net/minecraft/server/level/EntityPlayer.java
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -140,6 +140,34 @@
|
2022-02-28 16:00:00 +01:00
|
|
|
import net.minecraft.world.scores.criteria.IScoreboardCriteria;
|
|
|
|
import org.slf4j.Logger;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
2021-03-15 23:00:00 +01:00
|
|
|
+import net.minecraft.nbt.NBTBase;
|
|
|
|
+import net.minecraft.world.damagesource.CombatTracker;
|
|
|
|
+import net.minecraft.world.food.FoodMetaData;
|
|
|
|
+import net.minecraft.world.item.enchantment.EnchantmentManager;
|
|
|
|
+import net.minecraft.world.level.block.BlockChest;
|
2021-11-23 08:39:43 +01:00
|
|
|
+import net.minecraft.world.level.dimension.WorldDimension;
|
2021-03-15 23:00:00 +01:00
|
|
|
+import net.minecraft.world.scores.Scoreboard;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.Bukkit;
|
2018-07-15 02:00:00 +02:00
|
|
|
+import org.bukkit.Location;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.WeatherType;
|
|
|
|
+import org.bukkit.craftbukkit.CraftWorld;
|
2022-04-09 01:39:33 +02:00
|
|
|
+import org.bukkit.craftbukkit.CraftWorldBorder;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
2020-08-14 00:26:40 +02:00
|
|
|
+import org.bukkit.craftbukkit.event.CraftPortalEvent;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
2021-05-15 02:06:25 +02:00
|
|
|
+import org.bukkit.craftbukkit.util.CraftDimensionUtil;
|
2021-01-29 01:22:42 +01:00
|
|
|
+import org.bukkit.event.player.PlayerBedLeaveEvent;
|
2016-05-27 10:53:36 +02:00
|
|
|
+import org.bukkit.event.player.PlayerChangedMainHandEvent;
|
2019-05-06 00:38:29 +02:00
|
|
|
+import org.bukkit.event.player.PlayerChangedWorldEvent;
|
2017-05-26 23:37:06 +02:00
|
|
|
+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;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2016-05-27 10:53:36 +02:00
|
|
|
+import org.bukkit.inventory.MainHand;
|
2014-11-25 22:32:16 +01:00
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
public class EntityPlayer extends EntityHuman {
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2022-02-28 16:00:00 +01:00
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -194,6 +222,21 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
public int latency;
|
|
|
|
public boolean wonGame;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +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;
|
2017-04-28 06:53:31 +02:00
|
|
|
+ public boolean sentListPacket = false;
|
2018-11-02 11:24:14 +01:00
|
|
|
+ public Integer clientViewDistance;
|
2022-03-16 09:49:07 +01:00
|
|
|
+ public String kickLeaveMessage = null; // SPIGOT-3034: Forward leave message to PlayerQuitEvent
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile) {
|
2021-11-21 23:00:00 +01:00
|
|
|
super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile);
|
2021-06-11 07:00:00 +02:00
|
|
|
this.chatVisibility = EnumChatVisibility.FULL;
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -256,12 +299,56 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
this.advancements = minecraftserver.getPlayerList().getPlayerAdvancements(this);
|
2021-06-11 07:00:00 +02:00
|
|
|
this.maxUpStep = 1.0F;
|
2021-11-21 23:00:00 +01:00
|
|
|
this.fudgeSpawnLocation(worldserver);
|
2018-03-07 11:43:33 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.displayName = this.getScoreboardName();
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.bukkitPickUpLoot = true;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ this.maxHealthCache = this.getMaxHealth();
|
2021-06-11 07:00:00 +02:00
|
|
|
+ }
|
|
|
|
+
|
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) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ BlockPosition blockposition = worldserver.getSharedSpawnPos();
|
2018-07-15 02:00:00 +02:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ if (worldserver.dimensionType().hasSkyLight() && worldserver.serverLevelData.getGameType() != EnumGamemode.ADVENTURE) {
|
|
|
|
+ int i = Math.max(0, this.server.getSpawnRadius(worldserver));
|
|
|
|
+ int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ()));
|
2018-07-15 02:00:00 +02:00
|
|
|
+
|
|
|
|
+ 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;
|
2021-11-21 23:00:00 +01:00
|
|
|
+ int j1 = this.getCoprime(i1);
|
2020-06-25 02:00:00 +02:00
|
|
|
+ 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);
|
2021-11-21 23:00:00 +01:00
|
|
|
+ BlockPosition blockposition1 = WorldProviderNormal.getOverworldRespawnPos(worldserver, blockposition.getX() + j2 - i, blockposition.getZ() + k2 - i);
|
2018-07-15 02:00:00 +02:00
|
|
|
+
|
|
|
|
+ if (blockposition1 != null) {
|
2020-06-30 02:35:28 +02:00
|
|
|
+ return blockposition1;
|
2018-07-15 02:00:00 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2018-03-07 11:43:33 +01:00
|
|
|
+ return blockposition;
|
2021-06-11 07:00:00 +02:00
|
|
|
}
|
2018-03-07 11:43:33 +01:00
|
|
|
+ // CraftBukkit end
|
2021-06-11 07:00:00 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
private void fudgeSpawnLocation(WorldServer worldserver) {
|
|
|
|
BlockPosition blockposition = worldserver.getSharedSpawnPos();
|
2020-07-17 00:56:56 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- if (worldserver.dimensionType().hasSkyLight() && worldserver.getServer().getWorldData().getGameType() != EnumGamemode.ADVENTURE) {
|
|
|
|
+ if (worldserver.dimensionType().hasSkyLight() && worldserver.serverLevelData.getGameType() != EnumGamemode.ADVENTURE) { // CraftBukkit
|
|
|
|
int i = Math.max(0, this.server.getSpawnRadius(worldserver));
|
|
|
|
int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ()));
|
2020-07-17 00:56:56 +02:00
|
|
|
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -319,17 +406,26 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
if (nbttagcompound.contains("recipeBook", 10)) {
|
|
|
|
this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager());
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
+ this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit
|
2017-05-14 04:00:00 +02:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
if (this.isSleeping()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.stopSleeping();
|
2020-06-25 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ String spawnWorld = nbttagcompound.getString("SpawnWorld");
|
|
|
|
+ CraftWorld oldWorld = (CraftWorld) Bukkit.getWorld(spawnWorld);
|
|
|
|
+ if (oldWorld != null) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.respawnDimension = oldWorld.getHandle().dimension();
|
2020-06-25 02:00:00 +02:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
if (nbttagcompound.contains("SpawnX", 99) && nbttagcompound.contains("SpawnY", 99) && nbttagcompound.contains("SpawnZ", 99)) {
|
2021-06-11 07:00:00 +02:00
|
|
|
this.respawnPosition = new BlockPosition(nbttagcompound.getInt("SpawnX"), nbttagcompound.getInt("SpawnY"), nbttagcompound.getInt("SpawnZ"));
|
|
|
|
this.respawnForced = nbttagcompound.getBoolean("SpawnForced");
|
2022-02-28 16:00:00 +01:00
|
|
|
this.respawnAngle = nbttagcompound.getFloat("SpawnAngle");
|
|
|
|
if (nbttagcompound.contains("SpawnDimension")) {
|
|
|
|
- DataResult dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("SpawnDimension"));
|
|
|
|
+ DataResult<ResourceKey<World>> dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("SpawnDimension")); // CraftBukkit - decompile error
|
|
|
|
Logger logger = EntityPlayer.LOGGER;
|
|
|
|
|
|
|
|
Objects.requireNonNull(logger);
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -356,7 +452,20 @@
|
2018-06-14 19:59:21 +02:00
|
|
|
Entity entity = this.getRootVehicle();
|
|
|
|
Entity entity1 = this.getVehicle();
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- if (entity1 != null && entity != this && entity.hasExactlyOnePlayerPassenger()) {
|
2018-06-14 19:59:21 +02:00
|
|
|
+ // 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ if (persistVehicle && entity1 != null && entity != this && entity.hasExactlyOnePlayerPassenger()) {
|
2018-06-14 19:59:21 +02:00
|
|
|
+ // CraftBukkit end
|
|
|
|
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
|
|
|
|
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
|
|
|
|
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -374,7 +483,7 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
nbttagcompound.putInt("SpawnZ", this.respawnPosition.getZ());
|
|
|
|
nbttagcompound.putBoolean("SpawnForced", this.respawnForced);
|
|
|
|
nbttagcompound.putFloat("SpawnAngle", this.respawnAngle);
|
|
|
|
- DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.respawnDimension.location());
|
|
|
|
+ DataResult<NBTBase> dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.respawnDimension.location()); // CraftBukkit - decompile error
|
2020-06-25 02:00:00 +02:00
|
|
|
Logger logger = EntityPlayer.LOGGER;
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
Objects.requireNonNull(logger);
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -382,9 +491,33 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
nbttagcompound.put("SpawnDimension", nbtbase);
|
2020-06-25 02:00:00 +02:00
|
|
|
});
|
2016-02-29 22:32:46 +01:00
|
|
|
}
|
2017-05-14 04:00:00 +02:00
|
|
|
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
|
2020-08-11 23:00:00 +02:00
|
|
|
|
|
|
|
}
|
2020-06-25 02:00:00 +02:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - World fallback code, either respawn location or global spawn
|
|
|
|
+ public void spawnIn(World world) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.level = world;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ if (world == null) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.unsetRemoved();
|
2019-04-25 04:00:00 +02:00
|
|
|
+ Vec3D position = null;
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (this.respawnDimension != null) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ world = this.getLevel().getCraftServer().getHandle().getServer().getLevel(this.respawnDimension);
|
|
|
|
+ if (world != null && this.getRespawnPosition() != null) {
|
|
|
|
+ position = EntityHuman.findRespawnPositionAndUseSpawnBlock((WorldServer) world, this.getRespawnPosition(), this.getRespawnAngle(), false, false).orElse(null);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (world == null || position == null) {
|
|
|
|
+ world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle();
|
2021-11-21 23:00:00 +01:00
|
|
|
+ position = Vec3D.atCenterOf(((WorldServer) world).getSharedSpawnPos());
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.level = world;
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.setPos(position.x(), position.y(), position.z());
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.gameMode.setLevel((WorldServer) world);
|
2020-08-11 23:00:00 +02:00
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
2020-08-11 23:00:00 +02:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
public void setExperiencePoints(int i) {
|
|
|
|
float f = (float) this.getXpNeededForNextLevel();
|
2020-08-11 23:00:00 +02:00
|
|
|
float f1 = (f - 1.0F) / f;
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -443,6 +576,11 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2018-07-15 02:00:00 +02:00
|
|
|
public void tick() {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ if (this.joining) {
|
|
|
|
+ this.joining = false;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
this.gameMode.tick();
|
2021-06-11 07:00:00 +02:00
|
|
|
--this.spawnInvulnerableTime;
|
|
|
|
if (this.invulnerableTime > 0) {
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -498,7 +636,7 @@
|
2016-03-05 22:38:01 +01:00
|
|
|
}
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.connection.send(new PacketPlayOutUpdateHealth(this.getHealth(), this.foodData.getFoodLevel(), this.foodData.getSaturationLevel()));
|
|
|
|
+ this.connection.send(new PacketPlayOutUpdateHealth(this.getBukkitEntity().getScaledHealth(), this.foodData.getFoodLevel(), this.foodData.getSaturationLevel())); // CraftBukkit
|
2021-06-11 07:00:00 +02:00
|
|
|
this.lastSentHealth = this.getHealth();
|
|
|
|
this.lastSentFood = this.foodData.getFoodLevel();
|
|
|
|
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -529,6 +667,12 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience));
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // CraftBukkit start - Force max health updates
|
|
|
|
+ if (this.maxHealthCache != this.getMaxHealth()) {
|
|
|
|
+ this.getBukkitEntity().updateScaledHealth();
|
2016-06-09 03:43:49 +02:00
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
2016-06-09 03:43:49 +02:00
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
if (this.experienceLevel != this.lastRecordedLevel) {
|
|
|
|
this.lastRecordedLevel = this.experienceLevel;
|
2021-11-21 23:00:00 +01:00
|
|
|
this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel));
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -543,6 +687,20 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
CriterionTriggers.LOCATION.trigger(this);
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2022-04-09 01:39:33 +02:00
|
|
|
+ // CraftBukkit start - initialize oldLevel, fire PlayerLevelChangeEvent, and tick client-sided world border
|
2014-11-25 22:32:16 +01:00
|
|
|
+ if (this.oldLevel == -1) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.oldLevel = this.experienceLevel;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (this.oldLevel != this.experienceLevel) {
|
2021-06-20 01:27:32 +02:00
|
|
|
+ CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.oldLevel = this.experienceLevel;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2022-04-09 01:39:33 +02:00
|
|
|
+
|
|
|
|
+ if (this.getBukkitEntity().hasClientWorldBorder()) {
|
|
|
|
+ ((CraftWorldBorder) this.getBukkitEntity().getWorldBorder()).getHandle().tick();
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+ // CraftBukkit end
|
2014-11-25 22:32:16 +01:00
|
|
|
} catch (Throwable throwable) {
|
2021-11-21 23:00:00 +01:00
|
|
|
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
|
|
|
|
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked");
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -585,7 +743,8 @@
|
2016-03-12 07:57:40 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) {
|
|
|
|
- this.getScoreboard().forAllObjectives(iscoreboardcriteria, this.getScoreboardName(), (scoreboardscore) -> {
|
2018-07-15 02:00:00 +02:00
|
|
|
+ // CraftBukkit - Use our scores instead
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.level.getCraftServer().getScoreboardManager().getScoreboardScores(iscoreboardcriteria, this.getScoreboardName(), (scoreboardscore) -> {
|
2016-03-12 07:57:40 +01:00
|
|
|
scoreboardscore.setScore(i);
|
2018-07-15 02:00:00 +02:00
|
|
|
});
|
|
|
|
}
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -593,9 +752,47 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2018-08-26 04:00:00 +02:00
|
|
|
public void die(DamageSource damagesource) {
|
2021-06-11 07:00:00 +02:00
|
|
|
boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - fire PlayerDeathEvent
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (this.isRemoved()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return;
|
|
|
|
+ }
|
2021-11-21 23:00:00 +01:00
|
|
|
+ java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>(this.getInventory().getContainerSize());
|
2021-06-11 07:00:00 +02:00
|
|
|
+ boolean keepInventory = this.level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ if (!keepInventory) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ for (ItemStack item : this.getInventory().getContents()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ if (!item.isEmpty() && !EnchantmentManager.hasVanishingCurse(item)) {
|
2016-11-17 02:41:03 +01:00
|
|
|
+ loot.add(CraftItemStack.asCraftMirror(item));
|
2016-02-29 22:32:46 +01:00
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2019-07-22 04:12:48 +02:00
|
|
|
+ }
|
|
|
|
+ // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.dropFromLootTable(damagesource, this.lastHurtByPlayerTime > 0);
|
2019-07-22 04:12:48 +02:00
|
|
|
+ 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-06-14 19:59:21 +02:00
|
|
|
+
|
2018-08-26 04:00:00 +02:00
|
|
|
+ String deathmessage = defaultMessage.getString();
|
2021-08-11 10:49:49 +02:00
|
|
|
+ keepLevel = keepInventory; // SPIGOT-2222: pre-set keepLevel
|
2018-06-14 19:59:21 +02:00
|
|
|
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
|
2018-08-26 04:00:00 +02:00
|
|
|
+
|
2018-12-27 01:36:53 +01:00
|
|
|
+ // SPIGOT-943 - only call if they have an inventory open
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (this.containerMenu != this.inventoryMenu) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.closeContainer();
|
2018-12-27 01:36:53 +01:00
|
|
|
+ }
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ 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;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), ichatbasecomponent), (future) -> {
|
2018-08-26 04:00:00 +02:00
|
|
|
if (!future.isSuccess()) {
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -629,12 +826,18 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
if (this.level.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.tellNeutralMobsThatIDied();
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2020-06-25 02:00:00 +02:00
|
|
|
-
|
2019-04-23 04:00:00 +02:00
|
|
|
- if (!this.isSpectator()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.dropAllDeathLoot(damagesource);
|
2019-12-24 04:07:25 +01:00
|
|
|
+ // SPIGOT-5478 must be called manually now
|
|
|
|
+ this.dropExperience();
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
|
|
|
|
+ if (!event.getKeepInventory()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.getInventory().clearContent();
|
2019-04-23 06:00:30 +02:00
|
|
|
}
|
2018-12-27 01:36:53 +01:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.getScoreboard().forAllObjectives(IScoreboardCriteria.DEATH_COUNT, this.getScoreboardName(), ScoreboardScore::increment);
|
|
|
|
+ this.setCamera(this); // Remove spectated target
|
2019-04-23 06:00:30 +02:00
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit - Get our scores instead
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.level.getCraftServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.DEATH_COUNT, this.getScoreboardName(), ScoreboardScore::increment);
|
|
|
|
EntityLiving entityliving = this.getKillCredit();
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
if (entityliving != null) {
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -671,10 +874,12 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
String s = this.getScoreboardName();
|
|
|
|
String s1 = entity.getScoreboardName();
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.getScoreboard().forAllObjectives(IScoreboardCriteria.KILL_COUNT_ALL, s, ScoreboardScore::increment);
|
2017-05-14 04:00:00 +02:00
|
|
|
+ // CraftBukkit - Get our scores instead
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.level.getCraftServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.KILL_COUNT_ALL, s, ScoreboardScore::increment);
|
2017-05-14 04:00:00 +02:00
|
|
|
if (entity instanceof EntityHuman) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.awardStat(StatisticList.PLAYER_KILLS);
|
|
|
|
- this.getScoreboard().forAllObjectives(IScoreboardCriteria.KILL_COUNT_PLAYERS, s, ScoreboardScore::increment);
|
2017-05-14 04:00:00 +02:00
|
|
|
+ // CraftBukkit - Get our scores instead
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.level.getCraftServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.KILL_COUNT_PLAYERS, s, ScoreboardScore::increment);
|
2017-05-14 04:00:00 +02:00
|
|
|
} else {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.awardStat(StatisticList.MOB_KILLS);
|
2017-05-14 04:00:00 +02:00
|
|
|
}
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -692,7 +897,8 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
int i = scoreboardteam.getColor().getId();
|
2017-05-14 04:00:00 +02:00
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
if (i >= 0 && i < aiscoreboardcriteria.length) {
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.getScoreboard().forAllObjectives(aiscoreboardcriteria[i], s, ScoreboardScore::increment);
|
2017-05-14 04:00:00 +02:00
|
|
|
+ // CraftBukkit - Get our scores instead
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.level.getCraftServer().getScoreboardManager().getScoreboardScores(aiscoreboardcriteria[i], s, ScoreboardScore::increment);
|
2017-05-14 04:00:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -736,18 +942,20 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
private boolean isPvpAllowed() {
|
|
|
|
- return this.server.isPvpAllowed();
|
|
|
|
+ // CraftBukkit - this.server.isPvpAllowed() -> this.world.pvpMode
|
2021-06-11 07:00:00 +02:00
|
|
|
+ return this.level.pvpMode;
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-05-10 13:47:39 +02:00
|
|
|
@Nullable
|
2020-08-26 10:14:49 +02:00
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
protected ShapeDetectorShape findDimensionEntryPoint(WorldServer worldserver) {
|
|
|
|
ShapeDetectorShape shapedetectorshape = super.findDimensionEntryPoint(worldserver);
|
2020-08-26 10:14:49 +02:00
|
|
|
+ worldserver = (shapedetectorshape == null) ? worldserver : shapedetectorshape.world; // CraftBukkit
|
2020-08-11 23:00:00 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- if (shapedetectorshape != null && this.level.dimension() == World.OVERWORLD && worldserver.dimension() == World.END) {
|
2021-11-23 08:39:43 +01:00
|
|
|
+ if (shapedetectorshape != null && this.level.getTypeKey() == WorldDimension.OVERWORLD && worldserver != null && worldserver.getTypeKey() == WorldDimension.END) { // CraftBukkit
|
2021-06-11 07:00:00 +02:00
|
|
|
Vec3D vec3d = shapedetectorshape.pos.add(0.0D, -1.0D, 0.0D);
|
2020-08-11 23:00:00 +02:00
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
- return new ShapeDetectorShape(vec3d, Vec3D.ZERO, 90.0F, 0.0F);
|
|
|
|
+ return new ShapeDetectorShape(vec3d, Vec3D.ZERO, 90.0F, 0.0F, worldserver, shapedetectorshape.portalEventInfo); // CraftBukkit
|
2020-08-11 23:00:00 +02:00
|
|
|
} else {
|
|
|
|
return shapedetectorshape;
|
|
|
|
}
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -756,11 +964,20 @@
|
2020-08-11 23:00:00 +02:00
|
|
|
@Nullable
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
public Entity changeDimension(WorldServer worldserver) {
|
2021-06-11 07:00:00 +02:00
|
|
|
- this.isChangingDimension = true;
|
2019-04-23 04:00:00 +02:00
|
|
|
+ // CraftBukkit start
|
2021-11-21 23:00:00 +01:00
|
|
|
+ return changeDimension(worldserver, TeleportCause.UNKNOWN);
|
2019-04-23 04:00:00 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
2021-11-21 23:00:00 +01:00
|
|
|
+ public Entity changeDimension(WorldServer worldserver, PlayerTeleportEvent.TeleportCause cause) {
|
2019-04-23 04:00:00 +02:00
|
|
|
+ // CraftBukkit end
|
2017-03-30 12:53:23 +02:00
|
|
|
+ if (this.isSleeping()) return this; // CraftBukkit - SPIGOT-3154
|
2021-11-21 23:00:00 +01:00
|
|
|
+ // this.isChangingDimension = true; // CraftBukkit - Moved down and into PlayerList#changeDimension
|
|
|
|
WorldServer worldserver1 = this.getLevel();
|
|
|
|
- ResourceKey<World> resourcekey = worldserver1.dimension();
|
2021-11-23 08:39:43 +01:00
|
|
|
+ ResourceKey<WorldDimension> resourcekey = worldserver1.getTypeKey(); // CraftBukkit
|
2017-05-14 04:00:00 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- if (resourcekey == World.END && worldserver.dimension() == World.OVERWORLD) {
|
2021-11-23 08:39:43 +01:00
|
|
|
+ if (resourcekey == WorldDimension.END && worldserver != null && worldserver.getTypeKey() == WorldDimension.OVERWORLD) { // CraftBukkit
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.isChangingDimension = true; // CraftBukkit - Moved down from above
|
2021-11-21 23:00:00 +01:00
|
|
|
this.unRide();
|
|
|
|
this.getLevel().removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
|
2021-06-11 07:00:00 +02:00
|
|
|
if (!this.wonGame) {
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -771,6 +988,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
|
|
|
|
+ /*
|
2021-11-21 23:00:00 +01:00
|
|
|
WorldData worlddata = worldserver.getLevelData();
|
2019-12-11 02:36:03 +01:00
|
|
|
|
2022-02-28 16:00:00 +01:00
|
|
|
this.connection.send(new PacketPlayOutRespawn(worldserver.dimensionTypeRegistration(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), true));
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -780,22 +999,52 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
playerlist.sendPlayerPermissionLevel(this);
|
|
|
|
worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
|
2021-06-11 07:00:00 +02:00
|
|
|
this.unsetRemoved();
|
2019-04-23 04:00:00 +02:00
|
|
|
+ */
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
ShapeDetectorShape shapedetectorshape = this.findDimensionEntryPoint(worldserver);
|
2020-08-11 23:00:00 +02:00
|
|
|
|
|
|
|
if (shapedetectorshape != null) {
|
2021-11-21 23:00:00 +01:00
|
|
|
worldserver1.getProfiler().push("moving");
|
|
|
|
- if (resourcekey == World.OVERWORLD && worldserver.dimension() == World.NETHER) {
|
2020-08-11 23:00:00 +02:00
|
|
|
+ worldserver = shapedetectorshape.world; // CraftBukkit
|
|
|
|
+ if (worldserver == null) { } else // CraftBukkit - empty to fall through to null to event
|
2021-11-23 08:39:43 +01:00
|
|
|
+ if (resourcekey == WorldDimension.OVERWORLD && worldserver.getTypeKey() == WorldDimension.NETHER) { // CraftBukkit
|
2021-11-21 23:00:00 +01:00
|
|
|
this.enteredNetherPosition = this.position();
|
|
|
|
- } else if (worldserver.dimension() == World.END) {
|
2021-11-23 08:39:43 +01:00
|
|
|
+ } else if (worldserver.getTypeKey() == WorldDimension.END && shapedetectorshape.portalEventInfo != null && shapedetectorshape.portalEventInfo.getCanCreatePortal()) { // CraftBukkit
|
2021-11-21 23:00:00 +01:00
|
|
|
this.createEndPlatform(worldserver, new BlockPosition(shapedetectorshape.pos));
|
2020-06-25 02:00:00 +02:00
|
|
|
}
|
2020-08-11 23:00:00 +02:00
|
|
|
+ // CraftBukkit start
|
2020-08-14 00:26:40 +02:00
|
|
|
+ } else {
|
|
|
|
+ return null;
|
2020-08-11 23:00:00 +02:00
|
|
|
+ }
|
2019-04-23 04:00:00 +02:00
|
|
|
+ Location enter = this.getBukkitEntity().getLocation();
|
2021-06-11 07:00:00 +02:00
|
|
|
+ Location exit = (worldserver == null) ? null : new Location(worldserver.getWorld(), shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, shapedetectorshape.xRot);
|
2020-01-12 01:02:13 +01:00
|
|
|
+ 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();
|
2020-06-25 02:00:00 +02:00
|
|
|
+ worldserver = ((CraftWorld) exit.getWorld()).getHandle();
|
2020-08-11 23:00:00 +02:00
|
|
|
+ // CraftBukkit end
|
2020-01-12 01:02:13 +01:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ worldserver1.getProfiler().pop();
|
|
|
|
+ worldserver1.getProfiler().push("placing");
|
2020-08-11 23:00:00 +02:00
|
|
|
+ if (true) { // CraftBukkit
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.isChangingDimension = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
|
2020-01-12 01:02:13 +01:00
|
|
|
+
|
2022-02-28 16:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutRespawn(worldserver.dimensionTypeRegistration(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), true));
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutServerDifficulty(this.level.getDifficulty(), this.level.getLevelData().isDifficultyLocked()));
|
2020-08-11 23:00:00 +02:00
|
|
|
+ PlayerList playerlist = this.server.getPlayerList();
|
2020-01-12 01:02:13 +01:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ playerlist.sendPlayerPermissionLevel(this);
|
|
|
|
+ worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.unsetRemoved();
|
2020-08-14 00:26:40 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- worldserver1.getProfiler().pop();
|
|
|
|
- worldserver1.getProfiler().push("placing");
|
2020-08-11 23:00:00 +02:00
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
this.setLevel(worldserver);
|
|
|
|
worldserver.addDuringPortalTeleport(this);
|
|
|
|
- this.setRot(shapedetectorshape.yRot, shapedetectorshape.xRot);
|
|
|
|
- this.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.connection.teleport(exit); // CraftBukkit - use internal teleport without event
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.resetPosition(); // CraftBukkit - sync position after changing it (from PortalTravelAgent#findAndteleport)
|
|
|
|
worldserver1.getProfiler().pop();
|
|
|
|
this.triggerDimensionChangeTriggers(worldserver1);
|
|
|
|
this.connection.send(new PacketPlayOutAbilities(this.getAbilities()));
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -813,12 +1062,31 @@
|
2020-08-11 23:00:00 +02:00
|
|
|
this.lastSentExp = -1;
|
2021-06-11 07:00:00 +02:00
|
|
|
this.lastSentHealth = -1.0F;
|
|
|
|
this.lastSentFood = -1;
|
2020-08-11 23:00:00 +02:00
|
|
|
+
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.getBukkitEntity(), worldserver1.getWorld());
|
2021-06-11 13:33:49 +02:00
|
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(changeEvent);
|
2020-08-11 23:00:00 +02:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2019-05-06 00:38:29 +02:00
|
|
|
return this;
|
2020-08-14 00:26:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ @Override
|
|
|
|
+ protected CraftPortalEvent callPortalEvent(Entity entity, WorldServer exitWorldServer, BlockPosition exitPosition, TeleportCause cause, int searchRadius, int creationRadius) {
|
|
|
|
+ Location enter = this.getBukkitEntity().getLocation();
|
2021-06-11 07:00:00 +02:00
|
|
|
+ Location exit = new Location(exitWorldServer.getWorld(), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ(), getYRot(), getXRot());
|
2020-11-13 08:06:34 +01:00
|
|
|
+ PlayerPortalEvent event = new PlayerPortalEvent(this.getBukkitEntity(), enter, exit, cause, searchRadius, true, creationRadius);
|
2020-08-14 00:26:40 +02:00
|
|
|
+ Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
+ if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return new CraftPortalEvent(event);
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
private void createEndPlatform(WorldServer worldserver, BlockPosition blockposition) {
|
|
|
|
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable();
|
2020-08-14 00:26:40 +02:00
|
|
|
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -835,17 +1103,17 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
}
|
2020-08-11 23:00:00 +02:00
|
|
|
|
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
- protected Optional<BlockUtil.Rectangle> getExitPortal(WorldServer worldserver, BlockPosition blockposition, boolean flag, WorldBorder worldborder) {
|
|
|
|
- Optional<BlockUtil.Rectangle> optional = super.getExitPortal(worldserver, blockposition, flag, worldborder);
|
|
|
|
+ protected Optional<BlockUtil.Rectangle> getExitPortal(WorldServer worldserver, BlockPosition blockposition, boolean flag, WorldBorder worldborder, int searchRadius, boolean canCreatePortal, int createRadius) { // CraftBukkit
|
|
|
|
+ Optional<BlockUtil.Rectangle> optional = super.getExitPortal(worldserver, blockposition, flag, worldborder, searchRadius, canCreatePortal, createRadius); // CraftBukkit
|
2020-08-11 23:00:00 +02:00
|
|
|
|
2020-08-14 00:26:40 +02:00
|
|
|
- if (optional.isPresent()) {
|
|
|
|
+ if (optional.isPresent() || !canCreatePortal) { // CraftBukkit
|
2020-08-11 23:00:00 +02:00
|
|
|
return optional;
|
2020-08-14 00:26:40 +02:00
|
|
|
} else {
|
2021-11-21 23:00:00 +01:00
|
|
|
EnumDirection.EnumAxis enumdirection_enumaxis = (EnumDirection.EnumAxis) this.level.getBlockState(this.portalEntrancePos).getOptionalValue(BlockPortal.AXIS).orElse(EnumDirection.EnumAxis.X);
|
|
|
|
- Optional<BlockUtil.Rectangle> optional1 = worldserver.getPortalForcer().createPortal(blockposition, enumdirection_enumaxis);
|
|
|
|
+ Optional<BlockUtil.Rectangle> optional1 = worldserver.getPortalForcer().createPortal(blockposition, enumdirection_enumaxis, this, createRadius); // CraftBukkit
|
2020-08-14 00:26:40 +02:00
|
|
|
|
|
|
|
if (!optional1.isPresent()) {
|
2020-09-29 10:10:57 +02:00
|
|
|
- EntityPlayer.LOGGER.error("Unable to create a portal, likely target out of worldborder");
|
|
|
|
+ // EntityPlayer.LOGGER.error("Unable to create a portal, likely target out of worldborder"); // CraftBukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
return optional1;
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -855,13 +1123,21 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
public void triggerDimensionChangeTriggers(WorldServer worldserver) {
|
|
|
|
ResourceKey<World> resourcekey = worldserver.dimension();
|
|
|
|
ResourceKey<World> resourcekey1 = this.level.dimension();
|
2021-05-15 02:06:25 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ ResourceKey<World> maindimensionkey = CraftDimensionUtil.getMainDimensionKey(worldserver);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ ResourceKey<World> maindimensionkey1 = CraftDimensionUtil.getMainDimensionKey(this.level);
|
2022-04-09 01:39:33 +02:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ CriterionTriggers.CHANGED_DIMENSION.trigger(this, maindimensionkey, maindimensionkey1);
|
2021-05-15 02:06:25 +02:00
|
|
|
+ if (maindimensionkey != resourcekey || maindimensionkey1 != resourcekey1) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1);
|
2021-05-15 02:06:25 +02:00
|
|
|
+ }
|
2022-04-09 01:39:33 +02:00
|
|
|
|
|
|
|
- CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1);
|
|
|
|
- if (resourcekey == World.NETHER && resourcekey1 == World.OVERWORLD && this.enteredNetherPosition != null) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (maindimensionkey == World.NETHER && maindimensionkey1 == World.OVERWORLD && this.enteredNetherPosition != null) {
|
2021-05-15 02:06:25 +02:00
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
CriterionTriggers.NETHER_TRAVEL.trigger(this, this.enteredNetherPosition);
|
2021-05-15 02:06:25 +02:00
|
|
|
}
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
- if (resourcekey1 != World.NETHER) {
|
|
|
|
+ if (maindimensionkey1 != World.NETHER) { // CraftBukkit
|
|
|
|
this.enteredNetherPosition = null;
|
2021-05-15 02:06:25 +02:00
|
|
|
}
|
|
|
|
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -878,12 +1154,10 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
this.containerMenu.broadcastChanges();
|
2019-03-13 04:48:19 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
- @Override
|
2021-11-21 23:00:00 +01:00
|
|
|
- public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition) {
|
|
|
|
- EnumDirection enumdirection = (EnumDirection) this.level.getBlockState(blockposition).getValue(BlockFacingHorizontal.FACING);
|
2020-06-25 02:00:00 +02:00
|
|
|
-
|
|
|
|
+ // 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()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
- if (!this.level.dimensionType().natural()) {
|
|
|
|
+ if (!this.level.dimensionType().natural() || !this.level.dimensionType().bedWorks()) {
|
2020-06-25 02:00:00 +02:00
|
|
|
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
|
2021-11-21 23:00:00 +01:00
|
|
|
} else if (!this.bedInRange(blockposition, enumdirection)) {
|
2021-09-01 11:02:09 +02:00
|
|
|
return Either.left(EntityHuman.EnumBedResult.TOO_FAR_AWAY);
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -907,7 +1181,36 @@
|
2020-06-25 02:00:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- Either<EntityHuman.EnumBedResult, Unit> either = super.startSleepInBed(blockposition).ifRight((unit) -> {
|
2020-06-25 02:00:00 +02:00
|
|
|
+ return Either.right(Unit.INSTANCE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return Either.left(EntityHuman.EnumBedResult.OTHER_PROBLEM);
|
|
|
|
+ }
|
2019-03-13 04:48:19 +01:00
|
|
|
+ }
|
|
|
|
+
|
2019-04-23 04:00:00 +02:00
|
|
|
+ @Override
|
2021-11-21 23:00:00 +01:00
|
|
|
+ public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition, boolean force) {
|
|
|
|
+ EnumDirection enumdirection = (EnumDirection) this.level.getBlockState(blockposition).getValue(BlockFacingHorizontal.FACING);
|
2020-06-25 02:00:00 +02:00
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ {
|
|
|
|
+ {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ Either<EntityHuman.EnumBedResult, Unit> either = super.startSleepInBed(blockposition, force).ifRight((unit) -> {
|
|
|
|
this.awardStat(StatisticList.SLEEP_IN_BED);
|
|
|
|
CriterionTriggers.SLEPT_IN_BED.trigger(this);
|
2020-06-25 02:00:00 +02:00
|
|
|
});
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -920,9 +1223,8 @@
|
2020-06-25 02:00:00 +02:00
|
|
|
return either;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- } else {
|
|
|
|
- return Either.left(EntityHuman.EnumBedResult.OTHER_PROBLEM);
|
|
|
|
}
|
2019-03-13 04:48:19 +01:00
|
|
|
+ // CraftBukkit end
|
2020-06-25 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -949,6 +1251,24 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
public void stopSleepInBed(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!
|
2021-01-29 01:22:42 +01:00
|
|
|
+ // CraftBukkit start - fire PlayerBedLeaveEvent
|
|
|
|
+ CraftPlayer player = this.getBukkitEntity();
|
2021-11-21 23:00:00 +01:00
|
|
|
+ BlockPosition bedPosition = this.getSleepingPos().orElse(null);
|
2021-01-29 01:22:42 +01:00
|
|
|
+
|
|
|
|
+ org.bukkit.block.Block bed;
|
|
|
|
+ if (bedPosition != null) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ bed = this.level.getWorld().getBlockAt(bedPosition.getX(), bedPosition.getY(), bedPosition.getZ());
|
2021-01-29 01:22:42 +01:00
|
|
|
+ } else {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ bed = this.level.getWorld().getBlockAt(player.getLocation());
|
2021-01-29 01:22:42 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed, true);
|
2021-06-11 13:33:49 +02:00
|
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(event);
|
2021-01-29 01:22:42 +01:00
|
|
|
+ if (event.isCancelled()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2014-11-25 22:32:16 +01:00
|
|
|
if (this.isSleeping()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.getLevel().getChunkSource().broadcastAndSend(this, new PacketPlayOutAnimation(this, 2));
|
2015-02-20 05:37:17 +01:00
|
|
|
}
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1030,8 +1350,9 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos()));
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-29 22:32:46 +01:00
|
|
|
- public void nextContainerCounter() {
|
|
|
|
+ public int nextContainerCounter() { // CraftBukkit - void -> int
|
2014-11-25 22:32:16 +01:00
|
|
|
this.containerCounter = this.containerCounter % 100 + 1;
|
|
|
|
+ return containerCounter; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1039,13 +1360,35 @@
|
2021-07-30 11:08:43 +02:00
|
|
|
if (itileinventory == null) {
|
|
|
|
return OptionalInt.empty();
|
|
|
|
} else {
|
|
|
|
+ // CraftBukkit start - SPIGOT-6552: Handle inventory closing in CraftEventFactory#callInventoryOpenEvent(...)
|
|
|
|
+ /*
|
|
|
|
if (this.containerMenu != this.inventoryMenu) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.closeContainer();
|
2021-07-30 11:08:43 +02:00
|
|
|
}
|
|
|
|
+ */
|
|
|
|
+ // CraftBukkit end
|
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
this.nextContainerCounter();
|
2021-06-11 07:00:00 +02:00
|
|
|
Container container = itileinventory.createMenu(this.containerCounter, this.getInventory(), this);
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
+ // CraftBukkit start - Inventory open hook
|
|
|
|
+ if (container != null) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ container.setTitle(itileinventory.getDisplayName());
|
2014-12-28 16:14:53 +01:00
|
|
|
+
|
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
|
2019-08-24 12:02:14 +02:00
|
|
|
+ // SPIGOT-5263 - close chest if cancelled
|
|
|
|
+ if (itileinventory instanceof IInventory) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ ((IInventory) itileinventory).stopOpen(this);
|
2019-10-09 10:51:18 +02:00
|
|
|
+ } else if (itileinventory instanceof BlockChest.DoubleInventory) {
|
|
|
|
+ // SPIGOT-5355 - double chests too :(
|
2021-11-21 23:00:00 +01:00
|
|
|
+ ((BlockChest.DoubleInventory) itileinventory).inventorylargechest.stopOpen(this);
|
2019-08-24 12:02:14 +02:00
|
|
|
+ }
|
2019-04-23 04:00:00 +02:00
|
|
|
+ return OptionalInt.empty();
|
|
|
|
+ }
|
2017-01-09 23:56:20 +01:00
|
|
|
+ }
|
2019-04-23 04:00:00 +02:00
|
|
|
+ // CraftBukkit end
|
|
|
|
if (container == null) {
|
|
|
|
if (this.isSpectator()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.displayClientMessage((new ChatMessage("container.spectatorCantOpen")).withStyle(EnumChatFormat.RED), true);
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1053,9 +1396,11 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
return OptionalInt.empty();
|
2016-02-29 22:32:46 +01:00
|
|
|
} else {
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.connection.send(new PacketPlayOutOpenWindow(container.containerId, container.getType(), itileinventory.getDisplayName()));
|
2021-06-11 07:00:00 +02:00
|
|
|
- this.initMenu(container);
|
2019-04-23 04:00:00 +02:00
|
|
|
+ // CraftBukkit start
|
2021-06-11 07:00:00 +02:00
|
|
|
this.containerMenu = container;
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutOpenWindow(container.containerId, container.getType(), container.getTitle()));
|
2019-04-23 04:00:00 +02:00
|
|
|
+ // CraftBukkit end
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.initMenu(container);
|
2019-04-23 04:00:00 +02:00
|
|
|
return OptionalInt.of(this.containerCounter);
|
2016-02-29 22:32:46 +01:00
|
|
|
}
|
2019-04-23 04:00:00 +02:00
|
|
|
}
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1068,13 +1413,24 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2016-11-17 02:41:03 +01:00
|
|
|
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - Inventory open hook
|
2019-04-23 04:00:00 +02:00
|
|
|
+ this.nextContainerCounter();
|
2021-06-11 07:00:00 +02:00
|
|
|
+ Container container = new ContainerHorse(this.containerCounter, this.getInventory(), iinventory, entityhorseabstract);
|
2021-11-21 23:00:00 +01:00
|
|
|
+ container.setTitle(entityhorseabstract.getDisplayName());
|
2019-05-10 09:41:05 +02:00
|
|
|
+ container = CraftEventFactory.callInventoryOpenEvent(this, container);
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ if (container == null) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ iinventory.stopOpen(this);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return;
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+ // CraftBukkit end
|
2021-06-11 07:00:00 +02:00
|
|
|
if (this.containerMenu != this.inventoryMenu) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.closeContainer();
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
- this.nextContainerCounter();
|
|
|
|
+ // this.nextContainerCounter(); // CraftBukkit - moved up
|
2021-11-21 23:00:00 +01:00
|
|
|
this.connection.send(new PacketPlayOutOpenWindowHorse(this.containerCounter, iinventory.getContainerSize(), entityhorseabstract.getId()));
|
2021-06-11 07:00:00 +02:00
|
|
|
- this.containerMenu = new ContainerHorse(this.containerCounter, this.getInventory(), iinventory, entityhorseabstract);
|
|
|
|
+ this.containerMenu = container; // CraftBukkit
|
|
|
|
this.initMenu(this.containerMenu);
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1097,6 +1453,7 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
public void closeContainer() {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
|
2021-11-21 23:00:00 +01:00
|
|
|
this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId));
|
|
|
|
this.doCloseContainer();
|
2018-07-15 02:00:00 +02:00
|
|
|
}
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1126,7 +1483,7 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
public void awardStat(Statistic<?> statistic, int i) {
|
|
|
|
this.stats.increment(this, statistic, i);
|
|
|
|
- this.getScoreboard().forAllObjectives(statistic, this.getScoreboardName(), (scoreboardscore) -> {
|
|
|
|
+ this.level.getCraftServer().getScoreboardManager().getScoreboardScores(statistic, this.getScoreboardName(), (scoreboardscore) -> { // CraftBukkit - Get our scores instead
|
|
|
|
scoreboardscore.add(i);
|
2018-07-15 02:00:00 +02:00
|
|
|
});
|
2017-05-14 04:00:00 +02:00
|
|
|
}
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1134,7 +1491,7 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
public void resetStat(Statistic<?> statistic) {
|
|
|
|
this.stats.setValue(this, statistic, 0);
|
|
|
|
- this.getScoreboard().forAllObjectives(statistic, this.getScoreboardName(), ScoreboardScore::reset);
|
|
|
|
+ this.level.getCraftServer().getScoreboardManager().getScoreboardScores(statistic, this.getScoreboardName(), ScoreboardScore::reset); // CraftBukkit - Get our scores instead
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
2017-05-14 04:00:00 +02:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1150,7 +1507,7 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
MinecraftKey minecraftkey = aminecraftkey1[j];
|
2021-11-21 23:00:00 +01:00
|
|
|
- Optional optional = this.server.getRecipeManager().byKey(minecraftkey);
|
|
|
|
+ Optional<? extends IRecipe<?>> optional = this.server.getRecipeManager().byKey(minecraftkey); // CraftBukkit - decompile error
|
2021-06-11 07:00:00 +02:00
|
|
|
|
|
|
|
Objects.requireNonNull(list);
|
|
|
|
optional.ifPresent(list::add);
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1185,7 +1542,16 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
public void resetSentInfo() {
|
2021-06-11 07:00:00 +02:00
|
|
|
this.lastSentHealth = -1.0E8F;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ this.lastSentExp = -1; // CraftBukkit - Added to reset
|
2022-04-09 01:39:33 +02:00
|
|
|
+ }
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - Support multi-line messages
|
2020-11-03 09:02:28 +01:00
|
|
|
+ public void sendMessage(UUID uuid, IChatBaseComponent[] ichatbasecomponent) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ for (IChatBaseComponent component : ichatbasecomponent) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.sendMessage(component, (uuid == null) ? SystemUtils.NIL_UUID : uuid);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2022-04-09 01:39:33 +02:00
|
|
|
}
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
2022-04-09 01:39:33 +02:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
public void displayClientMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1240,7 +1606,7 @@
|
2017-05-15 10:11:48 +02:00
|
|
|
this.lastSentExp = -1;
|
2021-06-11 07:00:00 +02:00
|
|
|
this.lastSentHealth = -1.0F;
|
|
|
|
this.lastSentFood = -1;
|
2021-11-21 23:00:00 +01:00
|
|
|
- this.recipeBook.copyOverData(entityplayer.recipeBook);
|
|
|
|
+ // this.recipeBook.copyOverData(entityplayer.recipeBook); // CraftBukkit
|
2021-06-11 07:00:00 +02:00
|
|
|
this.seenCredits = entityplayer.seenCredits;
|
|
|
|
this.enteredNetherPosition = entityplayer.enteredNetherPosition;
|
2019-04-26 09:12:45 +02:00
|
|
|
this.setShoulderEntityLeft(entityplayer.getShoulderEntityLeft());
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1367,7 +1733,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
|
2021-11-21 23:00:00 +01:00
|
|
|
public void updateOptions(PacketPlayInSettings packetplayinsettings) {
|
2016-05-27 10:53:36 +02:00
|
|
|
+ // CraftBukkit start
|
2021-11-21 23:00:00 +01:00
|
|
|
+ if (getMainArm() != packetplayinsettings.mainHand()) {
|
|
|
|
+ PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(getBukkitEntity(), getMainArm() == EnumMainHand.LEFT ? MainHand.LEFT : MainHand.RIGHT);
|
2016-05-27 10:53:36 +02:00
|
|
|
+ this.server.server.getPluginManager().callEvent(event);
|
|
|
|
+ }
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (!this.locale.equals(packetplayinsettings.language)) {
|
|
|
|
+ PlayerLocaleChangeEvent event = new PlayerLocaleChangeEvent(getBukkitEntity(), packetplayinsettings.language);
|
2017-05-26 23:37:06 +02:00
|
|
|
+ this.server.server.getPluginManager().callEvent(event);
|
|
|
|
+ }
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.locale = packetplayinsettings.language;
|
2018-12-06 00:00:00 +01:00
|
|
|
+ this.clientViewDistance = packetplayinsettings.viewDistance;
|
2016-05-27 10:53:36 +02:00
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
this.chatVisibility = packetplayinsettings.chatVisibility();
|
|
|
|
this.canChatColor = packetplayinsettings.chatColors();
|
|
|
|
this.textFilteringEnabled = packetplayinsettings.textFilteringEnabled();
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1438,7 +1817,7 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
this.camera = (Entity) (entity == null ? this : entity);
|
|
|
|
if (entity1 != this.camera) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.connection.send(new PacketPlayOutCamera(this.camera));
|
|
|
|
- this.teleportTo(this.camera.getX(), this.camera.getY(), this.camera.getZ());
|
|
|
|
+ this.connection.teleport(this.camera.getX(), this.camera.getY(), this.camera.getZ(), this.getYRot(), this.getXRot(), TeleportCause.SPECTATE); // CraftBukkit
|
2017-03-24 05:08:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1467,7 +1846,7 @@
|
2016-03-02 08:32:06 +01:00
|
|
|
|
2016-05-10 13:47:39 +02:00
|
|
|
@Nullable
|
2021-11-21 23:00:00 +01:00
|
|
|
public IChatBaseComponent getTabListDisplayName() {
|
2016-03-02 08:32:06 +01:00
|
|
|
- return null;
|
|
|
|
+ return listName; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1488,9 +1867,16 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
return this.advancements;
|
2017-05-14 04:00:00 +02:00
|
|
|
}
|
2018-07-15 02:00:00 +02:00
|
|
|
|
|
|
|
+ // CraftBukkit start
|
2021-11-21 23:00:00 +01:00
|
|
|
public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1) {
|
|
|
|
+ this.teleportTo(worldserver, d0, d1, d2, f, f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
2018-07-15 02:00:00 +02:00
|
|
|
+ }
|
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
|
2018-07-15 02:00:00 +02:00
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
this.setCamera(this);
|
2018-07-15 02:00:00 +02:00
|
|
|
this.stopRiding();
|
|
|
|
+ /* CraftBukkit start - replace with bukkit handling for multi-world
|
2021-06-11 07:00:00 +02:00
|
|
|
if (worldserver == this.level) {
|
2021-11-21 23:00:00 +01:00
|
|
|
this.connection.teleport(d0, d1, d2, f, f1);
|
2018-07-15 02:00:00 +02:00
|
|
|
} else {
|
2022-04-09 01:39:33 +02:00
|
|
|
@@ -1510,6 +1896,9 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
this.server.getPlayerList().sendLevelInfo(this, worldserver);
|
|
|
|
this.server.getPlayerList().sendAllPlayerInfo(this);
|
2018-07-15 02:00:00 +02:00
|
|
|
}
|
|
|
|
+ */
|
|
|
|
+ this.getBukkitEntity().teleport(new Location(worldserver.getWorld(), d0, d1, d2, f, f1), cause);
|
|
|
|
+ // CraftBukkit end
|
2019-04-23 04:00:00 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-17 11:22:58 +02:00
|
|
|
@@ -1668,4 +2057,146 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
public boolean allowsListing() {
|
|
|
|
return this.allowsListing;
|
2019-04-23 04:00:00 +02:00
|
|
|
}
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ // 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.
|
2021-06-11 07:00:00 +02:00
|
|
|
+ return this.level.getDayTime() + this.timeOffset;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ } else {
|
|
|
|
+ // Adds timeOffset to the beginning of this day.
|
2021-06-11 07:00:00 +02:00
|
|
|
+ return this.level.getDayTime() - (this.level.getDayTime() % 24000) + this.timeOffset;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.STOP_RAINING, 0));
|
2020-06-29 00:25:59 +02:00
|
|
|
+ } else {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.START_RAINING, 0));
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-12-02 16:13:07 +01:00
|
|
|
+ private float pluginRainPosition;
|
|
|
|
+ private float pluginRainPositionPrevious;
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-12-02 16:13:07 +01:00
|
|
|
+ public void updateWeather(float oldRain, float newRain, float oldThunder, float newThunder) {
|
|
|
|
+ if (this.weather == null) {
|
|
|
|
+ // Vanilla
|
|
|
|
+ if (oldRain != newRain) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, newRain));
|
2015-02-26 23:41:06 +01:00
|
|
|
+ }
|
2014-12-02 16:13:07 +01:00
|
|
|
+ } else {
|
|
|
|
+ // Plugin
|
|
|
|
+ if (pluginRainPositionPrevious != pluginRainPosition) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, pluginRainPosition));
|
2015-02-26 23:41:06 +01:00
|
|
|
+ }
|
2014-12-02 16:13:07 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (oldThunder != newThunder) {
|
|
|
|
+ if (weather == WeatherType.DOWNFALL || weather == null) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, newThunder));
|
2014-12-02 16:13:07 +01:00
|
|
|
+ } else {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, 0));
|
2014-12-02 16:13:07 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-12-02 16:13:07 +01:00
|
|
|
+ public void tickWeather() {
|
|
|
|
+ if (this.weather == null) return;
|
|
|
|
+
|
|
|
|
+ pluginRainPositionPrevious = pluginRainPosition;
|
|
|
|
+ if (weather == WeatherType.DOWNFALL) {
|
|
|
|
+ pluginRainPosition += 0.01;
|
|
|
|
+ } else {
|
|
|
|
+ pluginRainPosition -= 0.01;
|
|
|
|
+ }
|
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ pluginRainPosition = MathHelper.clamp(pluginRainPosition, 0.0F, 1.0F);
|
2014-12-02 16:13:07 +01:00
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ public void resetPlayerWeather() {
|
|
|
|
+ this.weather = null;
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.setPlayerWeather(this.level.getLevelData().isRaining() ? WeatherType.DOWNFALL : WeatherType.CLEAR, false);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String toString() {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ return super.toString() + "(" + this.getScoreboardName() + " at " + this.getX() + "," + this.getY() + "," + this.getZ() + ")";
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
2016-10-23 05:00:35 +02:00
|
|
|
+ // SPIGOT-1903, MC-98153
|
|
|
|
+ public void forceSetPositionRotation(double x, double y, double z, float yaw, float pitch) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.moveTo(x, y, z, yaw, pitch);
|
|
|
|
+ this.connection.resetPosition();
|
2016-10-23 05:00:35 +02:00
|
|
|
+ }
|
|
|
|
+
|
2016-11-29 23:16:01 +01:00
|
|
|
+ @Override
|
2021-11-21 23:00:00 +01:00
|
|
|
+ public boolean isImmobile() {
|
|
|
|
+ return super.isImmobile() || !getBukkitEntity().isOnline();
|
2016-11-29 23:16:01 +01:00
|
|
|
+ }
|
|
|
|
+
|
2017-08-05 01:15:52 +02:00
|
|
|
+ @Override
|
|
|
|
+ public Scoreboard getScoreboard() {
|
|
|
|
+ return getBukkitEntity().getScoreboard().getHandle();
|
|
|
|
+ }
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public void reset() {
|
|
|
|
+ float exp = 0;
|
2021-06-11 07:00:00 +02:00
|
|
|
+ boolean keepInventory = this.level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2021-08-11 10:49:49 +02:00
|
|
|
+ if (this.keepLevel) { // CraftBukkit - SPIGOT-6687: Only use keepLevel (was pre-set with RULE_KEEPINVENTORY value in PlayerDeathEvent)
|
2021-06-11 07:00:00 +02:00
|
|
|
+ exp = this.experienceProgress;
|
|
|
|
+ this.newTotalExp = this.totalExperience;
|
|
|
|
+ this.newLevel = this.experienceLevel;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.setHealth(this.getMaxHealth());
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.stopUsingItem(); // CraftBukkit - SPIGOT-6682: Clear active item on reset
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.remainingFireTicks = 0;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ this.fallDistance = 0;
|
|
|
|
+ this.foodData = new FoodMetaData(this);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.experienceLevel = this.newLevel;
|
|
|
|
+ this.totalExperience = this.newTotalExp;
|
|
|
|
+ this.experienceProgress = 0;
|
|
|
|
+ this.deathTime = 0;
|
2020-09-02 10:52:40 +02:00
|
|
|
+ this.setArrowCount(0, true); // CraftBukkit - ArrowBodyCountChangeEvent
|
2018-07-20 08:04:37 +02:00
|
|
|
+ this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.DEATH);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.effectsDirty = true;
|
|
|
|
+ this.containerMenu = this.inventoryMenu;
|
|
|
|
+ this.lastHurtByPlayer = null;
|
|
|
|
+ this.lastHurtByMob = null;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ this.combatTracker = new CombatTracker(this);
|
|
|
|
+ this.lastSentExp = -1;
|
2021-08-11 10:49:49 +02:00
|
|
|
+ if (this.keepLevel) { // CraftBukkit - SPIGOT-6687: Only use keepLevel (was pre-set with RULE_KEEPINVENTORY value in PlayerDeathEvent)
|
2021-06-11 07:00:00 +02:00
|
|
|
+ this.experienceProgress = exp;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ } else {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ this.giveExperiencePoints(this.newExp);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ this.keepLevel = false;
|
2022-05-17 11:22:58 +02:00
|
|
|
+ this.setDeltaMovement(0, 0, 0); // CraftBukkit - SPIGOT-6948: Reset velocity on death
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2019-04-23 04:00:00 +02:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ @Override
|
|
|
|
+ public CraftPlayer getBukkitEntity() {
|
|
|
|
+ return (CraftPlayer) super.getBukkitEntity();
|
2019-04-23 04:00:00 +02:00
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|