From 1bde25bb3328186c2d13b8e566b84ada543f1b1a Mon Sep 17 00:00:00 2001 From: T00thpick1 Date: Thu, 20 Dec 2012 16:51:27 -0500 Subject: [PATCH] Implement per-player Weather API. Adds BUKKIT-812 --- .../net/minecraft/server/EntityPlayer.java | 21 +++++++++++++++++++ .../java/net/minecraft/server/PlayerList.java | 3 ++- .../net/minecraft/server/WorldServer.java | 3 ++- .../craftbukkit/entity/CraftPlayer.java | 13 ++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 52fd5612c5..f3edc6a0ec 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -12,6 +12,7 @@ import java.util.List; // 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; @@ -829,6 +830,26 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } } + public WeatherType weather = null; + + public WeatherType getPlayerWeather() { + return this.weather; + } + + public void setPlayerWeather(WeatherType type, boolean plugin) { + if (!plugin && this.weather != null) { + return; + } + + this.weather = type; + this.playerConnection.sendPacket(new Packet70Bed(type == WeatherType.DOWNFALL ? 1 : 2, 0)); + } + + public void resetPlayerWeather() { + this.weather = null; + this.setPlayerWeather(this.o().getWorldData().hasStorm() ? WeatherType.DOWNFALL : WeatherType.CLEAR, false); + } + @Override public String toString() { return super.toString() + "(" + this.name + " at " + this.locX + "," + this.locY + "," + this.locZ + ")"; diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index 585595d245..d57ff15b22 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -15,6 +15,7 @@ import java.util.Map.Entry; // CraftBukkit start import org.bukkit.Location; import org.bukkit.TravelAgent; +import org.bukkit.WeatherType; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor; @@ -975,7 +976,7 @@ public abstract class PlayerList { public void b(EntityPlayer entityplayer, WorldServer worldserver) { entityplayer.playerConnection.sendPacket(new Packet4UpdateTime(worldserver.getTime(), worldserver.getDayTime())); if (worldserver.O()) { - entityplayer.playerConnection.sendPacket(new Packet70Bed(1, 0)); + entityplayer.setPlayerWeather(WeatherType.DOWNFALL, false); // CraftBukkit - handle player specific weather } } diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index ddcaaaa204..ce54462399 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -10,6 +10,7 @@ import java.util.Set; import java.util.TreeSet; // CraftBukkit start +import org.bukkit.WeatherType; import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.util.LongHash; @@ -896,7 +897,7 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate // CraftBukkit start - only sending weather packets to those affected for (int i = 0; i < this.players.size(); ++i) { if (((EntityPlayer) this.players.get(i)).world == this) { - ((EntityPlayer) this.players.get(i)).playerConnection.sendPacket(new Packet70Bed(flag ? 2 : 1, 0)); + ((EntityPlayer) this.players.get(i)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false); } } // CraftBukkit end diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index f8dbbee77c..70111e7a63 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -24,6 +24,7 @@ import org.bukkit.*; import org.bukkit.Achievement; import org.bukkit.Material; import org.bukkit.Statistic; +import org.bukkit.WeatherType; import org.bukkit.World; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.conversations.Conversation; @@ -497,6 +498,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player { setPlayerTime(0, true); } + public void setPlayerWeather(WeatherType type) { + getHandle().setPlayerWeather(type, true); + } + + public WeatherType getPlayerWeather() { + return getHandle().getPlayerWeather(); + } + + public void resetPlayerWeather() { + getHandle().resetPlayerWeather(); + } + public boolean isBanned() { return server.getHandle().getNameBans().isBanned(getName().toLowerCase()); }