SPIGOT-6829: Add per-player world border API

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
CraftBukkit/Spigot 2022-04-09 09:39:33 +10:00
parent 6cd6b91c36
commit b0e366dc99
5 changed files with 170 additions and 56 deletions

View File

@ -7,8 +7,8 @@
- this.newCenterX = worldborder.getCenterX(); - this.newCenterX = worldborder.getCenterX();
- this.newCenterZ = worldborder.getCenterZ(); - this.newCenterZ = worldborder.getCenterZ();
+ // CraftBukkit start - multiply out nether border + // CraftBukkit start - multiply out nether border
+ this.newCenterX = worldborder.getCenterX() * worldborder.world.dimensionType().coordinateScale(); + this.newCenterX = worldborder.getCenterX() * (worldborder.world != null ? worldborder.world.dimensionType().coordinateScale() : 1.0);
+ this.newCenterZ = worldborder.getCenterZ() * worldborder.world.dimensionType().coordinateScale(); + this.newCenterZ = worldborder.getCenterZ() * (worldborder.world != null ? worldborder.world.dimensionType().coordinateScale() : 1.0);
+ // CraftBukkit end + // CraftBukkit end
} }

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/EntityPlayer.java --- a/net/minecraft/server/level/EntityPlayer.java
+++ b/net/minecraft/server/level/EntityPlayer.java +++ b/net/minecraft/server/level/EntityPlayer.java
@@ -140,6 +140,33 @@ @@ -140,6 +140,34 @@
import net.minecraft.world.scores.criteria.IScoreboardCriteria; import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -16,6 +16,7 @@
+import org.bukkit.Location; +import org.bukkit.Location;
+import org.bukkit.WeatherType; +import org.bukkit.WeatherType;
+import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.CraftWorldBorder;
+import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.event.CraftPortalEvent; +import org.bukkit.craftbukkit.event.CraftPortalEvent;
@ -34,7 +35,7 @@
public class EntityPlayer extends EntityHuman { public class EntityPlayer extends EntityHuman {
private static final Logger LOGGER = LogUtils.getLogger(); private static final Logger LOGGER = LogUtils.getLogger();
@@ -194,6 +221,21 @@ @@ -194,6 +222,21 @@
public int latency; public int latency;
public boolean wonGame; public boolean wonGame;
@ -56,7 +57,7 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile) { public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile) {
super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile); super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile);
this.chatVisibility = EnumChatVisibility.FULL; this.chatVisibility = EnumChatVisibility.FULL;
@@ -256,12 +298,56 @@ @@ -256,12 +299,56 @@
this.advancements = minecraftserver.getPlayerList().getPlayerAdvancements(this); this.advancements = minecraftserver.getPlayerList().getPlayerAdvancements(this);
this.maxUpStep = 1.0F; this.maxUpStep = 1.0F;
this.fudgeSpawnLocation(worldserver); this.fudgeSpawnLocation(worldserver);
@ -114,7 +115,7 @@
int i = Math.max(0, this.server.getSpawnRadius(worldserver)); int i = Math.max(0, this.server.getSpawnRadius(worldserver));
int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ())); int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ()));
@@ -319,17 +405,26 @@ @@ -319,17 +406,26 @@
if (nbttagcompound.contains("recipeBook", 10)) { if (nbttagcompound.contains("recipeBook", 10)) {
this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager()); this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager());
} }
@ -142,7 +143,7 @@
Logger logger = EntityPlayer.LOGGER; Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -356,7 +451,20 @@ @@ -356,7 +452,20 @@
Entity entity = this.getRootVehicle(); Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle(); Entity entity1 = this.getVehicle();
@ -164,7 +165,7 @@
NBTTagCompound nbttagcompound2 = new NBTTagCompound(); NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound(); NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -374,7 +482,7 @@ @@ -374,7 +483,7 @@
nbttagcompound.putInt("SpawnZ", this.respawnPosition.getZ()); nbttagcompound.putInt("SpawnZ", this.respawnPosition.getZ());
nbttagcompound.putBoolean("SpawnForced", this.respawnForced); nbttagcompound.putBoolean("SpawnForced", this.respawnForced);
nbttagcompound.putFloat("SpawnAngle", this.respawnAngle); nbttagcompound.putFloat("SpawnAngle", this.respawnAngle);
@ -173,7 +174,7 @@
Logger logger = EntityPlayer.LOGGER; Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -382,9 +490,33 @@ @@ -382,9 +491,33 @@
nbttagcompound.put("SpawnDimension", nbtbase); nbttagcompound.put("SpawnDimension", nbtbase);
}); });
} }
@ -207,7 +208,7 @@
public void setExperiencePoints(int i) { public void setExperiencePoints(int i) {
float f = (float) this.getXpNeededForNextLevel(); float f = (float) this.getXpNeededForNextLevel();
float f1 = (f - 1.0F) / f; float f1 = (f - 1.0F) / f;
@@ -443,6 +575,11 @@ @@ -443,6 +576,11 @@
@Override @Override
public void tick() { public void tick() {
@ -219,7 +220,7 @@
this.gameMode.tick(); this.gameMode.tick();
--this.spawnInvulnerableTime; --this.spawnInvulnerableTime;
if (this.invulnerableTime > 0) { if (this.invulnerableTime > 0) {
@@ -498,7 +635,7 @@ @@ -498,7 +636,7 @@
} }
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) { if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@ -228,7 +229,7 @@
this.lastSentHealth = this.getHealth(); this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel(); this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F; this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -529,6 +666,12 @@ @@ -529,6 +667,12 @@
this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience)); this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience));
} }
@ -241,11 +242,11 @@
if (this.experienceLevel != this.lastRecordedLevel) { if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel; this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel)); this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel));
@@ -543,6 +686,16 @@ @@ -543,6 +687,20 @@
CriterionTriggers.LOCATION.trigger(this); CriterionTriggers.LOCATION.trigger(this);
} }
+ // CraftBukkit start - initialize oldLevel and fire PlayerLevelChangeEvent + // CraftBukkit start - initialize oldLevel, fire PlayerLevelChangeEvent, and tick client-sided world border
+ if (this.oldLevel == -1) { + if (this.oldLevel == -1) {
+ this.oldLevel = this.experienceLevel; + this.oldLevel = this.experienceLevel;
+ } + }
@ -254,11 +255,15 @@
+ CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel); + CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel);
+ this.oldLevel = this.experienceLevel; + this.oldLevel = this.experienceLevel;
+ } + }
+
+ if (this.getBukkitEntity().hasClientWorldBorder()) {
+ ((CraftWorldBorder) this.getBukkitEntity().getWorldBorder()).getHandle().tick();
+ }
+ // CraftBukkit end + // CraftBukkit end
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player"); CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked"); CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked");
@@ -585,7 +738,8 @@ @@ -585,7 +743,8 @@
} }
private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) { private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) {
@ -268,7 +273,7 @@
scoreboardscore.setScore(i); scoreboardscore.setScore(i);
}); });
} }
@@ -593,9 +747,47 @@ @@ -593,9 +752,47 @@
@Override @Override
public void die(DamageSource damagesource) { public void die(DamageSource damagesource) {
boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
@ -318,7 +323,7 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), ichatbasecomponent), (future) -> { this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), ichatbasecomponent), (future) -> {
if (!future.isSuccess()) { if (!future.isSuccess()) {
@@ -629,12 +821,18 @@ @@ -629,12 +826,18 @@
if (this.level.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { if (this.level.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied(); this.tellNeutralMobsThatIDied();
} }
@ -341,7 +346,7 @@
EntityLiving entityliving = this.getKillCredit(); EntityLiving entityliving = this.getKillCredit();
if (entityliving != null) { if (entityliving != null) {
@@ -671,10 +869,12 @@ @@ -671,10 +874,12 @@
String s = this.getScoreboardName(); String s = this.getScoreboardName();
String s1 = entity.getScoreboardName(); String s1 = entity.getScoreboardName();
@ -356,7 +361,7 @@
} else { } else {
this.awardStat(StatisticList.MOB_KILLS); this.awardStat(StatisticList.MOB_KILLS);
} }
@@ -692,7 +892,8 @@ @@ -692,7 +897,8 @@
int i = scoreboardteam.getColor().getId(); int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < aiscoreboardcriteria.length) { if (i >= 0 && i < aiscoreboardcriteria.length) {
@ -366,7 +371,7 @@
} }
} }
@@ -736,18 +937,20 @@ @@ -736,18 +942,20 @@
} }
private boolean isPvpAllowed() { private boolean isPvpAllowed() {
@ -390,7 +395,7 @@
} else { } else {
return shapedetectorshape; return shapedetectorshape;
} }
@@ -756,11 +959,20 @@ @@ -756,11 +964,20 @@
@Nullable @Nullable
@Override @Override
public Entity changeDimension(WorldServer worldserver) { public Entity changeDimension(WorldServer worldserver) {
@ -414,7 +419,7 @@
this.unRide(); this.unRide();
this.getLevel().removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); this.getLevel().removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
if (!this.wonGame) { if (!this.wonGame) {
@@ -771,6 +983,8 @@ @@ -771,6 +988,8 @@
return this; return this;
} else { } else {
@ -423,7 +428,7 @@
WorldData worlddata = worldserver.getLevelData(); WorldData worlddata = worldserver.getLevelData();
this.connection.send(new PacketPlayOutRespawn(worldserver.dimensionTypeRegistration(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), true)); this.connection.send(new PacketPlayOutRespawn(worldserver.dimensionTypeRegistration(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), true));
@@ -780,22 +994,52 @@ @@ -780,22 +999,52 @@
playerlist.sendPlayerPermissionLevel(this); playerlist.sendPlayerPermissionLevel(this);
worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
this.unsetRemoved(); this.unsetRemoved();
@ -482,7 +487,7 @@
worldserver1.getProfiler().pop(); worldserver1.getProfiler().pop();
this.triggerDimensionChangeTriggers(worldserver1); this.triggerDimensionChangeTriggers(worldserver1);
this.connection.send(new PacketPlayOutAbilities(this.getAbilities())); this.connection.send(new PacketPlayOutAbilities(this.getAbilities()));
@@ -813,12 +1057,31 @@ @@ -813,12 +1062,31 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastSentHealth = -1.0F; this.lastSentHealth = -1.0F;
this.lastSentFood = -1; this.lastSentFood = -1;
@ -514,7 +519,7 @@
private void createEndPlatform(WorldServer worldserver, BlockPosition blockposition) { private void createEndPlatform(WorldServer worldserver, BlockPosition blockposition) {
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable(); BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable();
@@ -835,17 +1098,17 @@ @@ -835,17 +1103,17 @@
} }
@Override @Override
@ -537,21 +542,21 @@
} }
return optional1; return optional1;
@@ -855,13 +1118,21 @@ @@ -855,13 +1123,21 @@
public void triggerDimensionChangeTriggers(WorldServer worldserver) { public void triggerDimensionChangeTriggers(WorldServer worldserver) {
ResourceKey<World> resourcekey = worldserver.dimension(); ResourceKey<World> resourcekey = worldserver.dimension();
ResourceKey<World> resourcekey1 = this.level.dimension(); ResourceKey<World> resourcekey1 = this.level.dimension();
+ // CraftBukkit start + // CraftBukkit start
+ ResourceKey<World> maindimensionkey = CraftDimensionUtil.getMainDimensionKey(worldserver); + ResourceKey<World> maindimensionkey = CraftDimensionUtil.getMainDimensionKey(worldserver);
+ ResourceKey<World> maindimensionkey1 = CraftDimensionUtil.getMainDimensionKey(this.level); + ResourceKey<World> maindimensionkey1 = CraftDimensionUtil.getMainDimensionKey(this.level);
+
- CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1);
- if (resourcekey == World.NETHER && resourcekey1 == World.OVERWORLD && this.enteredNetherPosition != null) {
+ CriterionTriggers.CHANGED_DIMENSION.trigger(this, maindimensionkey, maindimensionkey1); + CriterionTriggers.CHANGED_DIMENSION.trigger(this, maindimensionkey, maindimensionkey1);
+ if (maindimensionkey != resourcekey || maindimensionkey1 != resourcekey1) { + if (maindimensionkey != resourcekey || maindimensionkey1 != resourcekey1) {
+ CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1); + CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1);
+ } + }
+
- CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1);
- if (resourcekey == World.NETHER && resourcekey1 == World.OVERWORLD && this.enteredNetherPosition != null) {
+ if (maindimensionkey == World.NETHER && maindimensionkey1 == World.OVERWORLD && this.enteredNetherPosition != null) { + if (maindimensionkey == World.NETHER && maindimensionkey1 == World.OVERWORLD && this.enteredNetherPosition != null) {
+ // CraftBukkit end + // CraftBukkit end
CriterionTriggers.NETHER_TRAVEL.trigger(this, this.enteredNetherPosition); CriterionTriggers.NETHER_TRAVEL.trigger(this, this.enteredNetherPosition);
@ -562,7 +567,7 @@
this.enteredNetherPosition = null; this.enteredNetherPosition = null;
} }
@@ -878,12 +1149,10 @@ @@ -878,12 +1154,10 @@
this.containerMenu.broadcastChanges(); this.containerMenu.broadcastChanges();
} }
@ -578,7 +583,7 @@
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE); return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
} else if (!this.bedInRange(blockposition, enumdirection)) { } else if (!this.bedInRange(blockposition, enumdirection)) {
return Either.left(EntityHuman.EnumBedResult.TOO_FAR_AWAY); return Either.left(EntityHuman.EnumBedResult.TOO_FAR_AWAY);
@@ -907,7 +1176,36 @@ @@ -907,7 +1181,36 @@
} }
} }
@ -616,7 +621,7 @@
this.awardStat(StatisticList.SLEEP_IN_BED); this.awardStat(StatisticList.SLEEP_IN_BED);
CriterionTriggers.SLEPT_IN_BED.trigger(this); CriterionTriggers.SLEPT_IN_BED.trigger(this);
}); });
@@ -920,9 +1218,8 @@ @@ -920,9 +1223,8 @@
return either; return either;
} }
} }
@ -627,7 +632,7 @@
} }
@Override @Override
@@ -949,6 +1246,24 @@ @@ -949,6 +1251,24 @@
@Override @Override
public void stopSleepInBed(boolean flag, boolean flag1) { public void stopSleepInBed(boolean flag, boolean flag1) {
@ -652,7 +657,7 @@
if (this.isSleeping()) { if (this.isSleeping()) {
this.getLevel().getChunkSource().broadcastAndSend(this, new PacketPlayOutAnimation(this, 2)); this.getLevel().getChunkSource().broadcastAndSend(this, new PacketPlayOutAnimation(this, 2));
} }
@@ -1030,8 +1345,9 @@ @@ -1030,8 +1350,9 @@
this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos())); this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos()));
} }
@ -663,7 +668,7 @@
} }
@Override @Override
@@ -1039,13 +1355,35 @@ @@ -1039,13 +1360,35 @@
if (itileinventory == null) { if (itileinventory == null) {
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -699,7 +704,7 @@
if (container == null) { if (container == null) {
if (this.isSpectator()) { if (this.isSpectator()) {
this.displayClientMessage((new ChatMessage("container.spectatorCantOpen")).withStyle(EnumChatFormat.RED), true); this.displayClientMessage((new ChatMessage("container.spectatorCantOpen")).withStyle(EnumChatFormat.RED), true);
@@ -1053,9 +1391,11 @@ @@ -1053,9 +1396,11 @@
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -713,7 +718,7 @@
return OptionalInt.of(this.containerCounter); return OptionalInt.of(this.containerCounter);
} }
} }
@@ -1068,13 +1408,24 @@ @@ -1068,13 +1413,24 @@
@Override @Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) { public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@ -740,7 +745,7 @@
this.initMenu(this.containerMenu); this.initMenu(this.containerMenu);
} }
@@ -1097,6 +1448,7 @@ @@ -1097,6 +1453,7 @@
@Override @Override
public void closeContainer() { public void closeContainer() {
@ -748,7 +753,7 @@
this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId)); this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId));
this.doCloseContainer(); this.doCloseContainer();
} }
@@ -1126,7 +1478,7 @@ @@ -1126,7 +1483,7 @@
@Override @Override
public void awardStat(Statistic<?> statistic, int i) { public void awardStat(Statistic<?> statistic, int i) {
this.stats.increment(this, statistic, i); this.stats.increment(this, statistic, i);
@ -757,7 +762,7 @@
scoreboardscore.add(i); scoreboardscore.add(i);
}); });
} }
@@ -1134,7 +1486,7 @@ @@ -1134,7 +1491,7 @@
@Override @Override
public void resetStat(Statistic<?> statistic) { public void resetStat(Statistic<?> statistic) {
this.stats.setValue(this, statistic, 0); this.stats.setValue(this, statistic, 0);
@ -766,7 +771,7 @@
} }
@Override @Override
@@ -1150,7 +1502,7 @@ @@ -1150,7 +1507,7 @@
for (int j = 0; j < i; ++j) { for (int j = 0; j < i; ++j) {
MinecraftKey minecraftkey = aminecraftkey1[j]; MinecraftKey minecraftkey = aminecraftkey1[j];
@ -775,25 +780,24 @@
Objects.requireNonNull(list); Objects.requireNonNull(list);
optional.ifPresent(list::add); optional.ifPresent(list::add);
@@ -1185,8 +1537,17 @@ @@ -1185,7 +1542,16 @@
public void resetSentInfo() { public void resetSentInfo() {
this.lastSentHealth = -1.0E8F; this.lastSentHealth = -1.0E8F;
+ this.lastSentExp = -1; // CraftBukkit - Added to reset + this.lastSentExp = -1; // CraftBukkit - Added to reset
} + }
+
+ // CraftBukkit start - Support multi-line messages + // CraftBukkit start - Support multi-line messages
+ public void sendMessage(UUID uuid, IChatBaseComponent[] ichatbasecomponent) { + public void sendMessage(UUID uuid, IChatBaseComponent[] ichatbasecomponent) {
+ for (IChatBaseComponent component : ichatbasecomponent) { + for (IChatBaseComponent component : ichatbasecomponent) {
+ this.sendMessage(component, (uuid == null) ? SystemUtils.NIL_UUID : uuid); + this.sendMessage(component, (uuid == null) ? SystemUtils.NIL_UUID : uuid);
+ } + }
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
@Override @Override
public void displayClientMessage(IChatBaseComponent ichatbasecomponent, boolean flag) { public void displayClientMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.sendMessage(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT, SystemUtils.NIL_UUID); @@ -1240,7 +1606,7 @@
@@ -1240,7 +1601,7 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastSentHealth = -1.0F; this.lastSentHealth = -1.0F;
this.lastSentFood = -1; this.lastSentFood = -1;
@ -802,7 +806,7 @@
this.seenCredits = entityplayer.seenCredits; this.seenCredits = entityplayer.seenCredits;
this.enteredNetherPosition = entityplayer.enteredNetherPosition; this.enteredNetherPosition = entityplayer.enteredNetherPosition;
this.setShoulderEntityLeft(entityplayer.getShoulderEntityLeft()); this.setShoulderEntityLeft(entityplayer.getShoulderEntityLeft());
@@ -1367,7 +1728,20 @@ @@ -1367,7 +1733,20 @@
return s; return s;
} }
@ -823,7 +827,7 @@
this.chatVisibility = packetplayinsettings.chatVisibility(); this.chatVisibility = packetplayinsettings.chatVisibility();
this.canChatColor = packetplayinsettings.chatColors(); this.canChatColor = packetplayinsettings.chatColors();
this.textFilteringEnabled = packetplayinsettings.textFilteringEnabled(); this.textFilteringEnabled = packetplayinsettings.textFilteringEnabled();
@@ -1438,7 +1812,7 @@ @@ -1438,7 +1817,7 @@
this.camera = (Entity) (entity == null ? this : entity); this.camera = (Entity) (entity == null ? this : entity);
if (entity1 != this.camera) { if (entity1 != this.camera) {
this.connection.send(new PacketPlayOutCamera(this.camera)); this.connection.send(new PacketPlayOutCamera(this.camera));
@ -832,7 +836,7 @@
} }
} }
@@ -1467,7 +1841,7 @@ @@ -1467,7 +1846,7 @@
@Nullable @Nullable
public IChatBaseComponent getTabListDisplayName() { public IChatBaseComponent getTabListDisplayName() {
@ -841,7 +845,7 @@
} }
@Override @Override
@@ -1488,9 +1862,16 @@ @@ -1488,9 +1867,16 @@
return this.advancements; return this.advancements;
} }
@ -858,7 +862,7 @@
if (worldserver == this.level) { if (worldserver == this.level) {
this.connection.teleport(d0, d1, d2, f, f1); this.connection.teleport(d0, d1, d2, f, f1);
} else { } else {
@@ -1510,6 +1891,9 @@ @@ -1510,6 +1896,9 @@
this.server.getPlayerList().sendLevelInfo(this, worldserver); this.server.getPlayerList().sendLevelInfo(this, worldserver);
this.server.getPlayerList().sendAllPlayerInfo(this); this.server.getPlayerList().sendAllPlayerInfo(this);
} }
@ -868,7 +872,7 @@
} }
@@ -1668,4 +2052,145 @@ @@ -1668,4 +2057,145 @@
public boolean allowsListing() { public boolean allowsListing() {
return this.allowsListing; return this.allowsListing;
} }

View File

@ -127,6 +127,7 @@ import org.bukkit.UnsafeValues;
import org.bukkit.Warning.WarningState; import org.bukkit.Warning.WarningState;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldBorder;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.boss.BarColor; import org.bukkit.boss.BarColor;
@ -1184,6 +1185,11 @@ public final class CraftServer implements Server {
worlds.put(world.getName().toLowerCase(java.util.Locale.ENGLISH), world); worlds.put(world.getName().toLowerCase(java.util.Locale.ENGLISH), world);
} }
@Override
public WorldBorder createWorldBorder() {
return new CraftWorldBorder(new net.minecraft.world.level.border.WorldBorder());
}
@Override @Override
public Logger getLogger() { public Logger getLogger() {
return logger; return logger;

View File

@ -16,6 +16,16 @@ public class CraftWorldBorder implements WorldBorder {
this.handle = world.getHandle().getWorldBorder(); this.handle = world.getHandle().getWorldBorder();
} }
public CraftWorldBorder(net.minecraft.world.level.border.WorldBorder handle) {
this.world = null;
this.handle = handle;
}
@Override
public World getWorld() {
return world;
}
@Override @Override
public void reset() { public void reset() {
this.setSize(6.0E7D); this.setSize(6.0E7D);
@ -115,6 +125,14 @@ public class CraftWorldBorder implements WorldBorder {
public boolean isInside(Location location) { public boolean isInside(Location location) {
Preconditions.checkArgument(location != null, "location"); Preconditions.checkArgument(location != null, "location");
return location.getWorld().equals(this.world) && this.handle.isWithinBounds(new BlockPosition(location.getX(), location.getY(), location.getZ())); return (world == null || location.getWorld().equals(this.world)) && this.handle.isWithinBounds(new BlockPosition(location.getX(), location.getY(), location.getZ()));
}
public net.minecraft.world.level.border.WorldBorder getHandle() {
return handle;
}
public boolean isVirtual() {
return world == null;
} }
} }

View File

@ -35,6 +35,11 @@ import net.minecraft.network.chat.ChatComponentText;
import net.minecraft.network.chat.ChatMessageType; import net.minecraft.network.chat.ChatMessageType;
import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket; import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
import net.minecraft.network.protocol.game.ClientboundSetBorderCenterPacket;
import net.minecraft.network.protocol.game.ClientboundSetBorderLerpSizePacket;
import net.minecraft.network.protocol.game.ClientboundSetBorderSizePacket;
import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDelayPacket;
import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDistancePacket;
import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket;
import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket; import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket;
@ -76,6 +81,7 @@ import net.minecraft.world.item.EnumColor;
import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.level.EnumGamemode;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.TileEntitySign; import net.minecraft.world.level.block.entity.TileEntitySign;
import net.minecraft.world.level.border.IWorldBorderListener;
import net.minecraft.world.level.saveddata.maps.MapIcon; import net.minecraft.world.level.saveddata.maps.MapIcon;
import net.minecraft.world.level.saveddata.maps.WorldMap; import net.minecraft.world.level.saveddata.maps.WorldMap;
import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.Vec3D;
@ -96,6 +102,7 @@ import org.bukkit.Particle;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.Statistic; import org.bukkit.Statistic;
import org.bukkit.WeatherType; import org.bukkit.WeatherType;
import org.bukkit.WorldBorder;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
@ -111,6 +118,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftSound; import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.CraftStatistic; import org.bukkit.craftbukkit.CraftStatistic;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.CraftWorldBorder;
import org.bukkit.craftbukkit.advancement.CraftAdvancement; import org.bukkit.craftbukkit.advancement.CraftAdvancement;
import org.bukkit.craftbukkit.advancement.CraftAdvancementProgress; import org.bukkit.craftbukkit.advancement.CraftAdvancementProgress;
import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.craftbukkit.block.CraftSign;
@ -156,6 +164,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
private double health = 20; private double health = 20;
private boolean scaledHealth = false; private boolean scaledHealth = false;
private double healthScale = 20; private double healthScale = 20;
private CraftWorldBorder clientWorldBorder = null;
private IWorldBorderListener clientWorldBorderListener = createWorldBorderListener();
public CraftPlayer(CraftServer server, EntityPlayer entity) { public CraftPlayer(CraftServer server, EntityPlayer entity) {
super(server, entity); super(server, entity);
@ -663,6 +673,82 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
getHandle().connection.send(new PacketPlayOutEntityEquipment(entity.getEntityId(), equipment)); getHandle().connection.send(new PacketPlayOutEntityEquipment(entity.getEntityId(), equipment));
} }
@Override
public WorldBorder getWorldBorder() {
return clientWorldBorder;
}
@Override
public void setWorldBorder(WorldBorder border) {
CraftWorldBorder craftBorder = (CraftWorldBorder) border;
if (border != null && !craftBorder.isVirtual() && !craftBorder.getWorld().equals(getWorld())) {
throw new UnsupportedOperationException("Cannot set player world border to that of another world");
}
// Nullify the old client-sided world border listeners so that calls to it will not affect this player
if (clientWorldBorder != null) {
this.clientWorldBorder.getHandle().removeListener(clientWorldBorderListener);
}
net.minecraft.world.level.border.WorldBorder newWorldBorder;
if (craftBorder == null || !craftBorder.isVirtual()) {
this.clientWorldBorder = null;
newWorldBorder = ((CraftWorldBorder) getWorld().getWorldBorder()).getHandle();
} else {
this.clientWorldBorder = craftBorder;
this.clientWorldBorder.getHandle().addListener(clientWorldBorderListener);
newWorldBorder = clientWorldBorder.getHandle();
}
// Send all world border update packets to the player
PlayerConnection connection = getHandle().connection;
connection.send(new ClientboundSetBorderSizePacket(newWorldBorder));
connection.send(new ClientboundSetBorderLerpSizePacket(newWorldBorder));
connection.send(new ClientboundSetBorderCenterPacket(newWorldBorder));
connection.send(new ClientboundSetBorderWarningDelayPacket(newWorldBorder));
connection.send(new ClientboundSetBorderWarningDistancePacket(newWorldBorder));
}
private IWorldBorderListener createWorldBorderListener() {
return new IWorldBorderListener() {
@Override
public void onBorderSizeSet(net.minecraft.world.level.border.WorldBorder border, double size) {
getHandle().connection.send(new ClientboundSetBorderSizePacket(border));
}
@Override
public void onBorderSizeLerping(net.minecraft.world.level.border.WorldBorder border, double size, double newSize, long time) {
getHandle().connection.send(new ClientboundSetBorderLerpSizePacket(border));
}
@Override
public void onBorderCenterSet(net.minecraft.world.level.border.WorldBorder border, double x, double z) {
getHandle().connection.send(new ClientboundSetBorderCenterPacket(border));
}
@Override
public void onBorderSetWarningTime(net.minecraft.world.level.border.WorldBorder border, int warningTime) {
getHandle().connection.send(new ClientboundSetBorderWarningDelayPacket(border));
}
@Override
public void onBorderSetWarningBlocks(net.minecraft.world.level.border.WorldBorder border, int warningBlocks) {
getHandle().connection.send(new ClientboundSetBorderWarningDistancePacket(border));
}
@Override
public void onBorderSetDamagePerBlock(net.minecraft.world.level.border.WorldBorder border, double damage) {} // NO OP
@Override
public void onBorderSetDamageSafeZOne(net.minecraft.world.level.border.WorldBorder border, double blocks) {} // NO OP
};
}
public boolean hasClientWorldBorder() {
return clientWorldBorder != null;
}
@Override @Override
public void sendMap(MapView map) { public void sendMap(MapView map) {
if (getHandle().connection == null) return; if (getHandle().connection == null) return;