Paper/nms-patches/EntityPlayer.patch

651 lines
28 KiB
Diff

--- a/net/minecraft/server/EntityPlayer.java
+++ b/net/minecraft/server/EntityPlayer.java
@@ -12,6 +12,17 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.WeatherType;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+// CraftBukkit end
+
public class EntityPlayer extends EntityHuman implements ICrafting {
private static final Logger bR = LogManager.getLogger();
@@ -38,12 +49,24 @@
private boolean ch = true;
private long ci = System.currentTimeMillis();
private Entity cj = null;
- private boolean ck;
+ protected boolean ck; // PAIL: private -> protected, rename worldChangeInvuln
private int containerCounter;
public boolean f;
public int ping;
public boolean viewingCredits;
+ // 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;
+ // CraftBukkit end
+
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super(worldserver, gameprofile);
playerinteractmanager.player = this;
@@ -74,6 +97,11 @@
this.setPosition(this.locX, this.locY + 1.0D, this.locZ);
}
+ // CraftBukkit start
+ this.displayName = this.getName();
+ // this.canPickUpLoot = true; TODO
+ this.maxHealthCache = this.getMaxHealth();
+ // CraftBukkit end
}
public void a(NBTTagCompound nbttagcompound) {
@@ -86,6 +114,7 @@
}
}
+ this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit
}
public void b(NBTTagCompound nbttagcompound) {
@@ -102,8 +131,33 @@
nbttagcompound1.set("Entity", nbttagcompound2);
nbttagcompound.set("RootVehicle", nbttagcompound1);
}
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
+ }
+ // CraftBukkit start - World fallback code, either respawn location or global spawn
+ public void spawnIn(World world) {
+ super.spawnIn(world);
+ if (world == null) {
+ this.dead = false;
+ BlockPosition position = null;
+ if (this.spawnWorld != null && !this.spawnWorld.equals("")) {
+ CraftWorld cworld = (CraftWorld) Bukkit.getServer().getWorld(this.spawnWorld);
+ if (cworld != null && this.getBed() != null) {
+ world = cworld.getHandle();
+ position = EntityHuman.getBed(cworld.getHandle(), this.getBed(), false);
+ }
+ }
+ if (world == null || position == null) {
+ world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle();
+ position = world.getSpawn();
+ }
+ this.world = world;
+ this.setPosition(position.getX() + 0.5, position.getY(), position.getZ() + 0.5);
+ }
+ this.dimension = ((WorldServer) this.world).dimension;
+ this.playerInteractManager.a((WorldServer) world);
}
+ // CraftBukkit end
public void levelDown(int i) {
super.levelDown(i);
@@ -134,6 +188,11 @@
}
public void m() {
+ // CraftBukkit start
+ if (this.joining) {
+ this.joining = false;
+ }
+ // CraftBukkit end
this.playerInteractManager.a();
--this.invulnerableTicks;
if (this.noDamageTicks > 0) {
@@ -193,7 +252,7 @@
}
if (this.getHealth() != this.lastHealthSent || this.cc != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.cd) {
- this.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(this.getHealth(), this.foodData.getFoodLevel(), this.foodData.getSaturationLevel()));
+ this.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(this.getBukkitEntity().getScaledHealth(), this.foodData.getFoodLevel(), this.foodData.getSaturationLevel())); // CraftBukkit
this.lastHealthSent = this.getHealth();
this.cc = this.foodData.getFoodLevel();
this.cd = this.foodData.getSaturationLevel() == 0.0F;
@@ -214,10 +273,11 @@
this.a(IScoreboardCriteria.i, MathHelper.f((float) this.bX));
}
- if (this.getArmorStrength() != this.bY) {
- this.bY = this.getArmorStrength();
- this.a(IScoreboardCriteria.j, MathHelper.f((float) this.bY));
+ // CraftBukkit start - Force max health updates
+ if (this.maxHealthCache != this.getMaxHealth()) {
+ this.getBukkitEntity().updateScaledHealth();
}
+ // CraftBukkit end
if (this.expTotal != this.ca) {
this.ca = this.expTotal;
@@ -238,6 +298,16 @@
this.o();
}
+ // CraftBukkit start - initialize oldLevel and fire PlayerLevelChangeEvent
+ if (this.oldLevel == -1) {
+ this.oldLevel = this.expLevel;
+ }
+
+ if (this.oldLevel != this.expLevel) {
+ CraftEventFactory.callPlayerLevelChangeEvent(this.world.getServer().getPlayer((EntityPlayer) this), this.oldLevel, this.expLevel);
+ this.oldLevel = this.expLevel;
+ }
+ // CraftBukkit end
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
@@ -248,12 +318,11 @@
}
private void a(IScoreboardCriteria iscoreboardcriteria, int i) {
- Collection collection = this.getScoreboard().getObjectivesForCriteria(iscoreboardcriteria);
+ Collection collection = this.world.getServer().getScoreboardManager().getScoreboardScores(iscoreboardcriteria, this.getName(), new java.util.ArrayList<ScoreboardScore>()); // CraftBukkit - Use our scores instead
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
- ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next();
- ScoreboardScore scoreboardscore = this.getScoreboard().getPlayerScoreForObjective(this.getName(), scoreboardobjective);
+ ScoreboardScore scoreboardscore = (ScoreboardScore) iterator.next(); // CraftBukkit - Use our scores instead
scoreboardscore.setScore(i);
}
@@ -302,30 +371,79 @@
boolean flag = this.world.getGameRules().getBoolean("showDeathMessages");
this.playerConnection.sendPacket(new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, flag));
- if (flag) {
- ScoreboardTeamBase scoreboardteambase = this.aO();
+ // CraftBukkit start - fire PlayerDeathEvent
+ if (this.dead) {
+ return;
+ }
+ java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
+ boolean keepInventory = this.world.getGameRules().getBoolean("keepInventory");
+
+ if (!keepInventory) {
+ for (int i = 0; i < this.inventory.items.length; ++i) {
+ if (this.inventory.items[i] != null) {
+ loot.add(CraftItemStack.asCraftMirror(this.inventory.items[i]));
+ }
+ }
+ for (int i = 0; i < this.inventory.armor.length; ++i) {
+ if (this.inventory.armor[i] != null) {
+ loot.add(CraftItemStack.asCraftMirror(this.inventory.armor[i]));
+ }
+ }
+ for (int i = 0; i < this.inventory.extraSlots.length; ++i) {
+ if (this.inventory.extraSlots[i] != null) {
+ loot.add(CraftItemStack.asCraftMirror(this.inventory.extraSlots[i]));
+ }
+ }
+ }
- if (scoreboardteambase != null && scoreboardteambase.getDeathMessageVisibility() != ScoreboardTeamBase.EnumNameTagVisibility.ALWAYS) {
- if (scoreboardteambase.getDeathMessageVisibility() == ScoreboardTeamBase.EnumNameTagVisibility.HIDE_FOR_OTHER_TEAMS) {
- this.server.getPlayerList().a((EntityHuman) this, this.getCombatTracker().getDeathMessage());
- } else if (scoreboardteambase.getDeathMessageVisibility() == ScoreboardTeamBase.EnumNameTagVisibility.HIDE_FOR_OWN_TEAM) {
- this.server.getPlayerList().b((EntityHuman) this, this.getCombatTracker().getDeathMessage());
+ IChatBaseComponent chatmessage = this.getCombatTracker().getDeathMessage();
+
+ String deathmessage = chatmessage.toPlainText();
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
+
+ String deathMessage = event.getDeathMessage();
+
+ if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
+ if (deathMessage.equals(deathmessage)) {
+ ScoreboardTeamBase scoreboardteambase = this.aO();
+
+ if (scoreboardteambase != null && scoreboardteambase.getDeathMessageVisibility() != ScoreboardTeamBase.EnumNameTagVisibility.ALWAYS) {
+ if (scoreboardteambase.getDeathMessageVisibility() == ScoreboardTeamBase.EnumNameTagVisibility.HIDE_FOR_OTHER_TEAMS) {
+ this.server.getPlayerList().a((EntityHuman) this, chatmessage);
+ } else if (scoreboardteambase.getDeathMessageVisibility() == ScoreboardTeamBase.EnumNameTagVisibility.HIDE_FOR_OWN_TEAM) {
+ this.server.getPlayerList().b((EntityHuman) this, chatmessage);
+ }
+ } else {
+ this.server.getPlayerList().sendMessage(chatmessage);
}
} else {
- this.server.getPlayerList().sendMessage(this.getCombatTracker().getDeathMessage());
+ this.server.getPlayerList().sendMessage(org.bukkit.craftbukkit.util.CraftChatMessage.fromString(deathMessage));
}
}
- if (!this.world.getGameRules().getBoolean("keepInventory") && !this.isSpectator()) {
- this.inventory.n();
+ // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
+ if (!event.getKeepInventory()) {
+ for (int i = 0; i < this.inventory.items.length; ++i) {
+ this.inventory.items[i] = null;
+ }
+ for (int i = 0; i < this.inventory.armor.length; ++i) {
+ this.inventory.armor[i] = null;
+ }
+ for (int i = 0; i < this.inventory.extraSlots.length; ++i) {
+ this.inventory.extraSlots[i] = null;
+ }
}
- Collection collection = this.world.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.d);
+ this.closeInventory();
+ this.setSpectatorTarget(this); // Remove spectated target
+ // CraftBukkit end
+
+ // CraftBukkit - Get our scores instead
+ Collection collection = this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.d, this.getName(), new java.util.ArrayList<ScoreboardScore>());
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
- ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next();
- ScoreboardScore scoreboardscore = this.getScoreboard().getPlayerScoreForObjective(this.getName(), scoreboardobjective);
+ ScoreboardScore scoreboardscore = (ScoreboardScore) iterator.next(); // CraftBukkit - Use our scores instead
scoreboardscore.incrementScore();
}
@@ -382,13 +500,15 @@
}
private boolean canPvP() {
- return this.server.getPVP();
+ // CraftBukkit - this.server.getPvP() -> this.world.pvpMode
+ return this.world.pvpMode;
}
@Nullable
public Entity c(int i) {
- this.ck = true;
+ //this.ck = true; // CraftBukkit - Moved down and into PlayerList#changeDimension
if (this.dimension == 1 && i == 1) {
+ this.ck = true; // CraftBukkit - Moved down from above
this.world.kill(this);
if (!this.viewingCredits) {
this.viewingCredits = true;
@@ -409,7 +529,10 @@
this.b((Statistic) AchievementList.y);
}
- this.server.getPlayerList().a(this, i);
+ // CraftBukkit start
+ TeleportCause cause = (this.dimension == 1 || i == 1) ? TeleportCause.END_PORTAL : TeleportCause.NETHER_PORTAL;
+ this.server.getPlayerList().changeDimension(this, i, cause); // PAIL: check all this
+ // CraftBukkit end
this.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1032, BlockPosition.ZERO, 0, false));
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
@@ -454,6 +577,7 @@
}
public void a(boolean flag, boolean flag1, boolean flag2) {
+ if (!this.sleeping) return; // CraftBukkit - Can't leave bed if not in one!
if (this.isSleeping()) {
this.x().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(this, 2));
}
@@ -532,23 +656,48 @@
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
}
- public void nextContainerCounter() {
+ public int nextContainerCounter() { // CraftBukkit - void -> int
this.containerCounter = this.containerCounter % 100 + 1;
+ return containerCounter; // CraftBukkit
}
public void openTileEntity(ITileEntityContainer itileentitycontainer) {
- if (itileentitycontainer instanceof ILootable && ((ILootable) itileentitycontainer).b() != null && this.isSpectator()) {
- this.sendMessage((new ChatMessage("container.spectatorCantOpen", new Object[0])).setChatModifier((new ChatModifier()).setColor(EnumChatFormat.RED)));
- } else {
- this.nextContainerCounter();
- this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, itileentitycontainer.getContainerName(), itileentitycontainer.getScoreboardDisplayName()));
- this.activeContainer = itileentitycontainer.createContainer(this.inventory, this);
- this.activeContainer.windowId = this.containerCounter;
- this.activeContainer.addSlotListener(this);
+ // CraftBukkit start - Inventory open hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, itileentitycontainer.createContainer(this.inventory, this));
+ if (container == null) {
+ return;
}
+
+ this.nextContainerCounter();
+ this.activeContainer = container;
+ this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, itileentitycontainer.getContainerName(), itileentitycontainer.getScoreboardDisplayName()));
+ // CraftBukkit end
+ this.activeContainer.windowId = this.containerCounter;
+ this.activeContainer.addSlotListener(this);
}
public void openContainer(IInventory iinventory) {
+ // CraftBukkit start - Inventory open hook
+ // Copied from below
+ boolean cancelled = false;
+ if (iinventory instanceof ITileInventory) {
+ ITileInventory itileinventory = (ITileInventory) iinventory;
+ cancelled = itileinventory.x_() && !this.a(itileinventory.y_()) && !this.isSpectator(); // PAIL: rename
+ }
+
+ Container container;
+ if (iinventory instanceof ITileEntityContainer) {
+ container = ((ITileEntityContainer) iinventory).createContainer(this.inventory, this);
+ } else {
+ container = new ContainerChest(this.inventory, iinventory, this);
+ }
+ container = CraftEventFactory.callInventoryOpenEvent(this, container, cancelled);
+ if (container == null && !cancelled) { // Let pre-cancelled events fall through
+ iinventory.closeContainer(this);
+ return;
+ }
+ // CraftBukkit end
+
if (iinventory instanceof ILootable && ((ILootable) iinventory).b() != null && this.isSpectator()) {
this.sendMessage((new ChatMessage("container.spectatorCantOpen", new Object[0])).setChatModifier((new ChatModifier()).setColor(EnumChatFormat.RED)));
} else {
@@ -562,18 +711,21 @@
if (itileinventory.x_() && !this.a(itileinventory.y_()) && !this.isSpectator()) {
this.playerConnection.sendPacket(new PacketPlayOutChat(new ChatMessage("container.isLocked", new Object[] { iinventory.getScoreboardDisplayName()}), (byte) 2));
this.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.W, SoundCategory.BLOCKS, this.locX, this.locY, this.locZ, 1.0F, 1.0F));
+ iinventory.closeContainer(this); // CraftBukkit
return;
}
}
this.nextContainerCounter();
+ // CraftBukkit start
if (iinventory instanceof ITileEntityContainer) {
+ this.activeContainer = container;
this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, ((ITileEntityContainer) iinventory).getContainerName(), iinventory.getScoreboardDisplayName(), iinventory.getSize()));
- this.activeContainer = ((ITileEntityContainer) iinventory).createContainer(this.inventory, this);
} else {
+ this.activeContainer = container;
this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, "minecraft:container", iinventory.getScoreboardDisplayName(), iinventory.getSize()));
- this.activeContainer = new ContainerChest(this.inventory, iinventory, this);
}
+ // CraftBukkit end
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
@@ -581,8 +733,14 @@
}
public void openTrade(IMerchant imerchant) {
+ // CraftBukkit start - Inventory open hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerMerchant(this.inventory, imerchant, this.world));
+ if (container == null) {
+ return;
+ }
+ // CraftBukkit end
this.nextContainerCounter();
- this.activeContainer = new ContainerMerchant(this.inventory, imerchant, this.world);
+ this.activeContainer = container; // CraftBukkit
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).e();
@@ -601,14 +759,21 @@
}
- public void openHorseInventory(EntityHorse entityhorse, IInventory iinventory) {
+ public void a(EntityHorse entityhorse, IInventory iinventory) {
+ // CraftBukkit start - Inventory open hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerHorse(this.inventory, iinventory, entityhorse, this));
+ if (container == null) {
+ iinventory.closeContainer(this);
+ return;
+ }
+ // CraftBukkit end
if (this.activeContainer != this.defaultContainer) {
this.closeInventory();
}
this.nextContainerCounter();
this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, "EntityHorse", iinventory.getScoreboardDisplayName(), iinventory.getSize(), entityhorse.getId()));
- this.activeContainer = new ContainerHorse(this.inventory, iinventory, entityhorse, this);
+ this.activeContainer = container;
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
}
@@ -648,6 +813,11 @@
public void a(Container container, List<ItemStack> list) {
this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, list));
this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried()));
+ // CraftBukkit start - Send a Set Slot to update the crafting result slot
+ if (java.util.EnumSet.of(InventoryType.CRAFTING,InventoryType.WORKBENCH).contains(container.getBukkitView().getType())) {
+ this.playerConnection.sendPacket(new PacketPlayOutSetSlot(container.windowId, 0, container.getSlot(0).getItem()));
+ }
+ // CraftBukkit end
}
public void setContainerData(Container container, int i, int j) {
@@ -662,6 +832,7 @@
}
public void closeInventory() {
+ CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
this.s();
}
@@ -743,7 +914,16 @@
public void triggerHealthUpdate() {
this.lastHealthSent = -1.0E8F;
+ this.lastSentExp = -1; // CraftBukkit - Added to reset
+ }
+
+ // CraftBukkit start - Support multi-line messages
+ public void sendMessage(IChatBaseComponent[] ichatbasecomponent) {
+ for (IChatBaseComponent component : ichatbasecomponent) {
+ this.sendMessage(component);
+ }
}
+ // CraftBukkit end
public void b(IChatBaseComponent ichatbasecomponent) {
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent));
@@ -804,6 +984,8 @@
}
public void a(WorldSettings.EnumGamemode worldsettings_enumgamemode) {
+ getBukkitEntity().setGameMode(org.bukkit.GameMode.getByValue(worldsettings_enumgamemode.getId()));
+ /* CraftBukkit start - defer to our setGameMode
this.playerInteractManager.setGameMode(worldsettings_enumgamemode);
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) worldsettings_enumgamemode.getId()));
if (worldsettings_enumgamemode == WorldSettings.EnumGamemode.SPECTATOR) {
@@ -814,6 +996,7 @@
this.updateAbilities();
this.cr();
+ // CraftBukkit end */
}
public boolean isSpectator() {
@@ -829,6 +1012,7 @@
}
public boolean a(int i, String s) {
+ /* CraftBukkit start
if ("seed".equals(s) && !this.server.aa()) {
return true;
} else if (!"tell".equals(s) && !"help".equals(s) && !"me".equals(s) && !"trigger".equals(s)) {
@@ -842,6 +1026,15 @@
} else {
return true;
}
+ */
+ if ("@".equals(s)) {
+ return getBukkitEntity().hasPermission("minecraft.command.selector");
+ }
+ if ("".equals(s)) {
+ return getBukkitEntity().isOp();
+ }
+ return getBukkitEntity().hasPermission("minecraft.command." + s);
+ // CraftBukkit end
}
public String A() {
@@ -941,7 +1134,7 @@
@Nullable
public IChatBaseComponent getPlayerListName() {
- return null;
+ return listName; // CraftBukkit
}
public void a(EnumHand enumhand) {
@@ -958,11 +1151,139 @@
}
public void M() {
+ if (!CraftEventFactory.callToggleGlideEvent(this, true).isCancelled()) // CraftBukkit
this.setFlag(7, true);
}
public void N() {
- this.setFlag(7, true);
- this.setFlag(7, false);
+ // CraftBukkit start
+ if (!CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) {
+ this.setFlag(7, true);
+ this.setFlag(7, false);
+ }
+ // CraftBukkit end
+ }
+
+ // CraftBukkit start - Add per-player time and weather.
+ public long timeOffset = 0;
+ public boolean relativeTime = true;
+
+ public long getPlayerTime() {
+ if (this.relativeTime) {
+ // Adds timeOffset to the current server time.
+ return this.world.getDayTime() + this.timeOffset;
+ } else {
+ // Adds timeOffset to the beginning of this day.
+ return this.world.getDayTime() - (this.world.getDayTime() % 24000) + this.timeOffset;
+ }
+ }
+
+ public WeatherType weather = null;
+
+ public WeatherType getPlayerWeather() {
+ return this.weather;
+ }
+
+ public void setPlayerWeather(WeatherType type, boolean plugin) {
+ if (!plugin && this.weather != null) {
+ return;
+ }
+
+ if (plugin) {
+ this.weather = type;
+ }
+
+ if (type == WeatherType.DOWNFALL) {
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(2, 0));
+ } else {
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(1, 0));
+ }
+ }
+
+ private float pluginRainPosition;
+ private float pluginRainPositionPrevious;
+
+ public void updateWeather(float oldRain, float newRain, float oldThunder, float newThunder) {
+ if (this.weather == null) {
+ // Vanilla
+ if (oldRain != newRain) {
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(7, newRain));
+ }
+ } else {
+ // Plugin
+ if (pluginRainPositionPrevious != pluginRainPosition) {
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(7, pluginRainPosition));
+ }
+ }
+
+ if (oldThunder != newThunder) {
+ if (weather == WeatherType.DOWNFALL || weather == null) {
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(8, newThunder));
+ } else {
+ this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(8, 0));
+ }
+ }
+ }
+
+ public void tickWeather() {
+ if (this.weather == null) return;
+
+ pluginRainPositionPrevious = pluginRainPosition;
+ if (weather == WeatherType.DOWNFALL) {
+ pluginRainPosition += 0.01;
+ } else {
+ pluginRainPosition -= 0.01;
+ }
+
+ pluginRainPosition = MathHelper.a(pluginRainPosition, 0.0F, 1.0F);
+ }
+
+ public void resetPlayerWeather() {
+ this.weather = null;
+ this.setPlayerWeather(this.world.getWorldData().hasStorm() ? WeatherType.DOWNFALL : WeatherType.CLEAR, false);
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "(" + this.getName() + " at " + this.locX + "," + this.locY + "," + this.locZ + ")";
+ }
+
+ public void reset() {
+ float exp = 0;
+ boolean keepInventory = this.world.getGameRules().getBoolean("keepInventory");
+
+ if (this.keepLevel || keepInventory) {
+ exp = this.exp;
+ this.newTotalExp = this.expTotal;
+ this.newLevel = this.expLevel;
+ }
+
+ this.setHealth(this.getMaxHealth());
+ this.fireTicks = 0;
+ this.fallDistance = 0;
+ this.foodData = new FoodMetaData(this);
+ this.expLevel = this.newLevel;
+ this.expTotal = this.newTotalExp;
+ this.exp = 0;
+ this.deathTicks = 0;
+ this.removeAllEffects();
+ this.updateEffects = true;
+ this.activeContainer = this.defaultContainer;
+ this.killer = null;
+ this.lastDamager = null;
+ this.combatTracker = new CombatTracker(this);
+ this.lastSentExp = -1;
+ if (this.keepLevel || keepInventory) {
+ this.exp = exp;
+ } else {
+ this.giveExp(this.newExp);
+ }
+ this.keepLevel = false;
+ }
+
+ @Override
+ public CraftPlayer getBukkitEntity() {
+ return (CraftPlayer) super.getBukkitEntity();
}
+ // CraftBukkit end
}