13
0
geforkt von Mirrors/Paper

SPIGOT-2222, SPIGOT-6687: Pre-set keepLevel and only use it

By: DerFrZocker <derrieple@gmail.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2021-08-11 18:49:49 +10:00
Ursprung 4a49f6bf8b
Commit 72591f6038
2 geänderte Dateien mit 35 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -263,7 +263,7 @@
scoreboardscore.setScore(i);
});
}
@@ -552,9 +708,46 @@
@@ -552,9 +708,47 @@
@Override
public void die(DamageSource damagesource) {
boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
@ -293,6 +293,7 @@
+ IChatBaseComponent defaultMessage = this.getCombatTracker().getDeathMessage();
+
+ String deathmessage = defaultMessage.getString();
+ keepLevel = keepInventory; // SPIGOT-2222: pre-set keepLevel
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
+
+ // SPIGOT-943 - only call if they have an inventory open
@ -312,7 +313,7 @@
this.connection.a((Packet) (new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), ichatbasecomponent)), (future) -> {
if (!future.isSuccess()) {
@@ -588,12 +781,18 @@
@@ -588,12 +782,18 @@
if (this.level.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.fI();
}
@ -335,7 +336,7 @@
EntityLiving entityliving = this.getKillingEntity();
if (entityliving != null) {
@@ -630,10 +829,12 @@
@@ -630,10 +830,12 @@
String s = this.getName();
String s1 = entity.getName();
@ -350,7 +351,7 @@
} else {
this.a(StatisticList.MOB_KILLS);
}
@@ -651,7 +852,8 @@
@@ -651,7 +853,8 @@
int i = scoreboardteam.getColor().b();
if (i >= 0 && i < aiscoreboardcriteria.length) {
@ -360,7 +361,7 @@
}
}
@@ -695,18 +897,20 @@
@@ -695,18 +898,20 @@
}
private boolean canPvP() {
@ -384,7 +385,7 @@
} else {
return shapedetectorshape;
}
@@ -715,11 +919,20 @@
@@ -715,11 +920,20 @@
@Nullable
@Override
public Entity b(WorldServer worldserver) {
@ -408,7 +409,7 @@
this.decouple();
this.getWorldServer().a(this, Entity.RemovalReason.CHANGED_DIMENSION);
if (!this.wonGame) {
@@ -730,6 +943,8 @@
@@ -730,6 +944,8 @@
return this;
} else {
@ -417,7 +418,7 @@
WorldData worlddata = worldserver.getWorldData();
this.connection.sendPacket(new PacketPlayOutRespawn(worldserver.getDimensionManager(), worldserver.getDimensionKey(), BiomeManager.a(worldserver.getSeed()), this.gameMode.getGameMode(), this.gameMode.c(), worldserver.isDebugWorld(), worldserver.isFlatWorld(), true));
@@ -739,22 +954,52 @@
@@ -739,22 +955,52 @@
playerlist.d(this);
worldserver1.a(this, Entity.RemovalReason.CHANGED_DIMENSION);
this.unsetRemoved();
@ -476,7 +477,7 @@
worldserver1.getMethodProfiler().exit();
this.triggerDimensionAdvancements(worldserver1);
this.connection.sendPacket(new PacketPlayOutAbilities(this.getAbilities()));
@@ -772,12 +1017,31 @@
@@ -772,12 +1018,31 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@ -508,7 +509,7 @@
private void a(WorldServer worldserver, BlockPosition blockposition) {
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.i();
@@ -794,17 +1058,17 @@
@@ -794,17 +1059,17 @@
}
@Override
@ -531,7 +532,7 @@
}
return optional1;
@@ -814,13 +1078,21 @@
@@ -814,13 +1079,21 @@
public void triggerDimensionAdvancements(WorldServer worldserver) {
ResourceKey<World> resourcekey = worldserver.getDimensionKey();
ResourceKey<World> resourcekey1 = this.level.getDimensionKey();
@ -556,7 +557,7 @@
this.enteredNetherPosition = null;
}
@@ -848,10 +1120,8 @@
@@ -848,10 +1121,8 @@
this.containerMenu.d();
}
@ -569,7 +570,7 @@
if (!this.isSleeping() && this.isAlive()) {
if (!this.level.getDimensionManager().isNatural()) {
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
@@ -877,7 +1147,36 @@
@@ -877,7 +1148,36 @@
}
}
@ -607,7 +608,7 @@
this.a(StatisticList.SLEEP_IN_BED);
CriterionTriggers.SLEPT_IN_BED.a(this);
});
@@ -890,9 +1189,8 @@
@@ -890,9 +1190,8 @@
return either;
}
}
@ -618,7 +619,7 @@
}
@Override
@@ -919,6 +1217,24 @@
@@ -919,6 +1218,24 @@
@Override
public void wakeup(boolean flag, boolean flag1) {
@ -643,7 +644,7 @@
if (this.isSleeping()) {
this.getWorldServer().getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutAnimation(this, 2));
}
@@ -1000,8 +1316,9 @@
@@ -1000,8 +1317,9 @@
this.connection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
}
@ -654,7 +655,7 @@
}
@Override
@@ -1009,13 +1326,35 @@
@@ -1009,13 +1327,35 @@
if (itileinventory == null) {
return OptionalInt.empty();
} else {
@ -690,7 +691,7 @@
if (container == null) {
if (this.isSpectator()) {
this.a((IChatBaseComponent) (new ChatMessage("container.spectatorCantOpen")).a(EnumChatFormat.RED), true);
@@ -1023,9 +1362,11 @@
@@ -1023,9 +1363,11 @@
return OptionalInt.empty();
} else {
@ -704,7 +705,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1038,13 +1379,24 @@
@@ -1038,13 +1380,24 @@
@Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@ -731,7 +732,7 @@
this.initMenu(this.containerMenu);
}
@@ -1068,6 +1420,7 @@
@@ -1068,6 +1421,7 @@
@Override
public void closeInventory() {
@ -739,7 +740,7 @@
this.connection.sendPacket(new PacketPlayOutCloseWindow(this.containerMenu.containerId));
this.o();
}
@@ -1097,7 +1450,7 @@
@@ -1097,7 +1451,7 @@
@Override
public void a(Statistic<?> statistic, int i) {
this.stats.b(this, statistic, i);
@ -748,7 +749,7 @@
scoreboardscore.addScore(i);
});
}
@@ -1105,7 +1458,7 @@
@@ -1105,7 +1459,7 @@
@Override
public void a(Statistic<?> statistic) {
this.stats.setStatistic(this, statistic, 0);
@ -757,7 +758,7 @@
}
@Override
@@ -1121,7 +1474,7 @@
@@ -1121,7 +1475,7 @@
for (int j = 0; j < i; ++j) {
MinecraftKey minecraftkey = aminecraftkey1[j];
@ -766,7 +767,7 @@
Objects.requireNonNull(list);
optional.ifPresent(list::add);
@@ -1156,7 +1509,16 @@
@@ -1156,7 +1510,16 @@
public void triggerHealthUpdate() {
this.lastSentHealth = -1.0E8F;
@ -783,7 +784,7 @@
@Override
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
@@ -1211,11 +1573,12 @@
@@ -1211,11 +1574,12 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@ -797,7 +798,7 @@
}
@Override
@@ -1337,7 +1700,20 @@
@@ -1337,7 +1701,20 @@
return s;
}
@ -818,7 +819,7 @@
this.chatVisibility = packetplayinsettings.d();
this.canChatColor = packetplayinsettings.e();
this.textFilteringEnabled = packetplayinsettings.h();
@@ -1407,7 +1783,7 @@
@@ -1407,7 +1784,7 @@
this.camera = (Entity) (entity == null ? this : entity);
if (entity1 != this.camera) {
this.connection.sendPacket(new PacketPlayOutCamera(this.camera));
@ -827,7 +828,7 @@
}
}
@@ -1436,7 +1812,7 @@
@@ -1436,7 +1813,7 @@
@Nullable
public IChatBaseComponent getPlayerListName() {
@ -836,7 +837,7 @@
}
@Override
@@ -1457,9 +1833,16 @@
@@ -1457,9 +1834,16 @@
return this.advancements;
}
@ -853,7 +854,7 @@
if (worldserver == this.level) {
this.connection.b(d0, d1, d2, f, f1);
} else {
@@ -1479,6 +1862,9 @@
@@ -1479,6 +1863,9 @@
this.server.getPlayerList().a(this, worldserver);
this.server.getPlayerList().updateClient(this);
}
@ -863,7 +864,7 @@
}
@@ -1634,4 +2020,145 @@
@@ -1634,4 +2021,145 @@
});
return this.a(itemstack, false, true) != null;
}
@ -972,7 +973,7 @@
+ float exp = 0;
+ boolean keepInventory = this.level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY);
+
+ if (this.keepLevel || keepInventory) {
+ if (this.keepLevel) { // CraftBukkit - SPIGOT-6687: Only use keepLevel (was pre-set with RULE_KEEPINVENTORY value in PlayerDeathEvent)
+ exp = this.experienceProgress;
+ this.newTotalExp = this.totalExperience;
+ this.newLevel = this.experienceLevel;
@ -995,7 +996,7 @@
+ this.lastHurtByMob = null;
+ this.combatTracker = new CombatTracker(this);
+ this.lastSentExp = -1;
+ if (this.keepLevel || keepInventory) {
+ if (this.keepLevel) { // CraftBukkit - SPIGOT-6687: Only use keepLevel (was pre-set with RULE_KEEPINVENTORY value in PlayerDeathEvent)
+ this.experienceProgress = exp;
+ } else {
+ this.giveExp(this.newExp);

Datei anzeigen

@ -799,6 +799,7 @@ public class CraftEventFactory {
CraftPlayer entity = victim.getBukkitEntity();
PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
event.setKeepInventory(keepInventory);
event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel
org.bukkit.World world = entity.getWorld();
Bukkit.getServer().getPluginManager().callEvent(event);