Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import java.util.ArrayList;
4import java.util.List;
5
6class PlayerInstance {
7
8 private List b;
9 private int chunkX;
10 private int chunkZ;
11 private ChunkCoordIntPair location;
12 private short[] dirtyBlocks;
13 private int dirtyCount;
14 private int h;
15 private int i;
16 private int j;
17 private int k;
18 private int l;
19 private int m;
20
21 final PlayerManager playerManager;
22
23 public PlayerInstance(PlayerManager playermanager, int i, int j) {
24 this.playerManager = playermanager;
25 this.b = new ArrayList();
26 this.dirtyBlocks = new short[10];
27 this.dirtyCount = 0;
28 this.chunkX = i;
29 this.chunkZ = j;
30 this.location = new ChunkCoordIntPair(i, j);
31 playermanager.a().chunkProviderServer.getChunkAt(i, j);
32 }
33
34 public void a(EntityPlayer entityplayer) {
35 if (this.b.contains(entityplayer)) {
36 throw new IllegalStateException("Failed to add player. " + entityplayer + " already is in chunk " + this.chunkX + ", " + this.chunkZ);
37 } else {
38 // CraftBukkit start
39 if (entityplayer.playerChunkCoordIntPairs.add(this.location)) {
40 entityplayer.netServerHandler.sendPacket(new Packet50PreChunk(this.location.x, this.location.z, true));
41 }
42 // CraftBukkit end
43
44 this.b.add(entityplayer);
45 entityplayer.chunkCoordIntPairQueue.add(this.location);
46 }
47 }
48
49 public void b(EntityPlayer entityplayer) {
50 if (this.b.contains(entityplayer)) {
51 this.b.remove(entityplayer);
52 if (this.b.size() == 0) {
53 long i = (long) this.chunkX + 2147483647L | (long) this.chunkZ + 2147483647L << 32;
54
55 PlayerManager.a(this.playerManager).b(i);
56 if (this.dirtyCount > 0) {
57 PlayerManager.b(this.playerManager).remove(this);
58 }
59
60 this.playerManager.a().chunkProviderServer.queueUnload(this.chunkX, this.chunkZ);
61 }
62
63 entityplayer.chunkCoordIntPairQueue.remove(this.location);
64 // CraftBukkit - contains -> remove -- TODO VERIFY!!!!
65 if (entityplayer.playerChunkCoordIntPairs.remove(this.location)) {
66 entityplayer.netServerHandler.sendPacket(new Packet50PreChunk(this.chunkX, this.chunkZ, false));
67 }
68 }
69 }
70
71 public void a(int i, int j, int k) {
72 if (this.dirtyCount == 0) {
73 PlayerManager.b(this.playerManager).add(this);
74 this.h = this.i = i;
75 this.j = this.k = j;
76 this.l = this.m = k;
77 }
78
79 if (this.h > i) {
80 this.h = i;
81 }
82
83 if (this.i < i) {
84 this.i = i;
85 }
86
87 if (this.j > j) {
88 this.j = j;
89 }
90
91 if (this.k < j) {
92 this.k = j;
93 }
94
95 if (this.l > k) {
96 this.l = k;
97 }
98
99 if (this.m < k) {
100 this.m = k;
101 }
102
103 if (this.dirtyCount < 10) {
104 short short1 = (short) (i << 12 | k << 8 | j);
105
106 for (int l = 0; l < this.dirtyCount; ++l) {
107 if (this.dirtyBlocks[l] == short1) {
108 return;
109 }
110 }
111
112 this.dirtyBlocks[this.dirtyCount++] = short1;
113 }
114 }
115
116 public void sendAll(Packet packet) {
117 for (int i = 0; i < this.b.size(); ++i) {
118 EntityPlayer entityplayer = (EntityPlayer) this.b.get(i);
119
120 if (entityplayer.playerChunkCoordIntPairs.contains(this.location)) {
121 entityplayer.netServerHandler.sendPacket(packet.clone());
122 }
123 }
124 }
125
126 public void a() {
127 WorldServer worldserver = this.playerManager.a();
128
129 if (this.dirtyCount != 0) {
130 int i;
131 int j;
132 int k;
133
134 if (this.dirtyCount == 1) {
135 i = this.chunkX * 16 + this.h;
136 j = this.j;
137 k = this.chunkZ * 16 + this.l;
138 this.sendAll(new Packet53BlockChange(i, j, k, worldserver));
139 if (Block.isTileEntity[worldserver.getTypeId(i, j, k)]) {
140 this.sendTileEntity(worldserver.getTileEntity(i, j, k));
141 }
142 } else {
143 int l;
144
145 if (this.dirtyCount == 10) {
146 this.j = this.j / 2 * 2;
147 this.k = (this.k / 2 + 1) * 2;
148 i = this.h + this.chunkX * 16;
149 j = this.j;
150 k = this.l + this.chunkZ * 16;
151 l = this.i - this.h + 1;
152 int i1 = this.k - this.j + 2;
153 int j1 = this.m - this.l + 1;
154
155 this.sendAll(new Packet51MapChunk(i, j, k, l, i1, j1, worldserver));
156 List list = worldserver.getTileEntities(i, j, k, i + l, j + i1, k + j1);
157
158 for (int k1 = 0; k1 < list.size(); ++k1) {
159 this.sendTileEntity((TileEntity) list.get(k1));
160 }
161 } else {
162 this.sendAll(new Packet52MultiBlockChange(this.chunkX, this.chunkZ, this.dirtyBlocks, this.dirtyCount, worldserver));
163
164 for (i = 0; i < this.dirtyCount; ++i) {
165 // CraftBukkit start - Fixes TileEntity updates occurring upon a multi-block change; dirtyCount -> dirtyBlocks[i]
166 j = this.chunkX * 16 + (this.dirtyBlocks[i] >> 12 & 15);
167 k = this.dirtyBlocks[i] & 255;
168 l = this.chunkZ * 16 + (this.dirtyBlocks[i] >> 8 & 15);
169 // CraftBukkit end
170
171 if (Block.isTileEntity[worldserver.getTypeId(j, k, l)]) {
172 // System.out.println("Sending!"); // CraftBukkit
173 this.sendTileEntity(worldserver.getTileEntity(j, k, l));
174 }
175 }
176 }
177 }
178
179 this.dirtyCount = 0;
180 }
181 }
182
183 private void sendTileEntity(TileEntity tileentity) {
184 if (tileentity != null) {
185 Packet packet = tileentity.f();
186
187 if (packet != null) {
188 this.sendAll(packet);
189 }
190 }
191 }
192
193 // Poseidon
194 static ChunkCoordIntPair a(PlayerInstance playerchunk) {
195 return playerchunk.location;
196 }
197
198 static List b(PlayerInstance playerchunk) {
199 return playerchunk.b;
200 }
201}