Commits
md_5 authored ecf4b4238a3
41 41 | private int u; |
42 42 | |
43 43 | + // CraftBukkit start |
44 44 | + private CraftServer cserver; |
45 45 | + |
46 46 | public PlayerList(MinecraftServer minecraftserver) { |
47 47 | + this.cserver = minecraftserver.server = new CraftServer(minecraftserver, this); |
48 48 | + minecraftserver.console = org.bukkit.craftbukkit.command.ColouredConsoleSender.getInstance(); |
49 49 | + minecraftserver.reader.addCompleter(new org.bukkit.craftbukkit.command.ConsoleCommandCompleter(minecraftserver.server)); |
50 50 | + // CraftBukkit end |
51 - | + |
51 + | + |
52 52 | this.k = new GameProfileBanList(PlayerList.a); |
53 53 | this.l = new IpBanList(PlayerList.b); |
54 54 | this.operators = new OpList(PlayerList.c); |
55 55 | |
56 56 | |
57 57 | usercache.a(gameprofile); |
58 58 | NBTTagCompound nbttagcompound = this.a(entityplayer); |
59 59 | + // CraftBukkit start - Better rename detection |
60 60 | + if (nbttagcompound != null && nbttagcompound.hasKey("bukkit")) { |
61 61 | + NBTTagCompound bukkit = nbttagcompound.getCompound("bukkit"); |
157 157 | public void b(WorldBorder worldborder, double d0) {} |
158 158 | |
159 159 | } |
160 160 | |
161 161 | public NBTTagCompound a(EntityPlayer entityplayer) { |
162 162 | - NBTTagCompound nbttagcompound = this.server.worldServer[0].getWorldData().h(); |
163 163 | + NBTTagCompound nbttagcompound = this.server.worlds.get(0).getWorldData().h(); // CraftBukkit |
164 164 | NBTTagCompound nbttagcompound1; |
165 165 | |
166 166 | if (entityplayer.getName().equals(this.server.Q()) && nbttagcompound != null) { |
167 - | |
167 + | |
168 168 | |
169 169 | } |
170 170 | |
171 171 | - public void onPlayerJoin(EntityPlayer entityplayer) { |
172 172 | + public void onPlayerJoin(EntityPlayer entityplayer, String joinMessage) { // CraftBukkit added param |
173 173 | this.players.add(entityplayer); |
174 174 | this.j.put(entityplayer.getUniqueID(), entityplayer); |
175 175 | - this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { entityplayer})); |
176 176 | + // this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { entityplayer})); // CraftBukkit - replaced with loop below |
177 177 | WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); |
229 229 | WorldServer worldserver = entityplayer.x(); |
230 230 | |
231 231 | entityplayer.b(StatisticList.f); |
232 232 | + |
233 233 | + // CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it |
234 234 | + org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(entityplayer); |
235 235 | + |
236 236 | + PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.getName() + " left the game."); |
237 237 | + cserver.getPluginManager().callEvent(playerQuitEvent); |
238 238 | + entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage()); |
239 + | + |
240 + | + entityplayer.world.entityJoinedWorld(entityplayer, false); // SPIGOT-924 |
239 241 | + // CraftBukkit end |
240 - | + |
242 + | + |
241 243 | this.savePlayerFile(entityplayer); |
242 244 | if (entityplayer.isPassenger()) { |
243 245 | Entity entity = entityplayer.getVehicle(); |
244 - | |
246 + | |
245 247 | this.o.remove(uuid); |
246 248 | } |
247 249 | |
248 250 | - this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[] { entityplayer})); |
249 251 | + // CraftBukkit start |
250 252 | + // this.sendAll(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[] { entityplayer})); |
251 253 | + PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entityplayer); |
252 254 | + for (int i = 0; i < players.size(); i++) { |
253 255 | + EntityPlayer entityplayer2 = (EntityPlayer) this.players.get(i); |
254 256 | + |
299 301 | + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), gameprofile, new PlayerInteractManager(server.getWorldServer(0))); |
300 302 | + Player player = entity.getBukkitEntity(); |
301 303 | + PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((java.net.InetSocketAddress) socketaddress).getAddress()); |
302 304 | String s; |
303 305 | |
304 306 | - if (this.k.isBanned(gameprofile)) { |
305 307 | + if (getProfileBans().isBanned(gameprofile) && !getProfileBans().get(gameprofile).hasExpired()) { |
306 308 | GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.k.get(gameprofile); |
307 309 | |
308 310 | s = "You are banned from this server!\nReason: " + gameprofilebanentry.getReason(); |
309 - | |
311 + | |
310 312 | s = s + "\nYour ban will be removed on " + PlayerList.g.format(gameprofilebanentry.getExpires()); |
311 313 | } |
312 314 | |
313 315 | - return s; |
314 316 | + // return s; |
315 317 | + event.disallow(PlayerLoginEvent.Result.KICK_BANNED, s); |
316 318 | } else if (!this.isWhitelisted(gameprofile)) { |
317 319 | - return "You are not white-listed on this server!"; |
318 320 | - } else if (this.l.isBanned(socketaddress)) { |
319 321 | + // return "You are not white-listed on this server!"; |
320 322 | + event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "You are not white-listed on this server!"); |
321 323 | + } else if (getIPBans().isBanned(socketaddress) && !getIPBans().get(socketaddress).hasExpired()) { |
322 324 | IpBanEntry ipbanentry = this.l.get(socketaddress); |
323 325 | |
324 326 | s = "Your IP address is banned from this server!\nReason: " + ipbanentry.getReason(); |
325 - | |
327 + | |
326 328 | s = s + "\nYour ban will be removed on " + PlayerList.g.format(ipbanentry.getExpires()); |
327 329 | } |
328 330 | |
329 331 | - return s; |
330 332 | + // return s; |
331 333 | + event.disallow(PlayerLoginEvent.Result.KICK_BANNED, s); |
332 334 | } else { |
333 335 | - return this.players.size() >= this.maxPlayers && !this.f(gameprofile) ? "The server is full!" : null; |
334 336 | + // return this.players.size() >= this.maxPlayers && !this.f(gameprofile) ? "The server is full!" : null; |
335 337 | + if (this.players.size() >= this.maxPlayers && !this.f(gameprofile)) { |
344 346 | } |
345 347 | + return entity; |
346 348 | } |
347 349 | |
348 350 | - public EntityPlayer processLogin(GameProfile gameprofile) { |
349 351 | + public EntityPlayer processLogin(GameProfile gameprofile, EntityPlayer player) { // CraftBukkit - added EntityPlayer |
350 352 | + /* CraftBukkit startMoved up |
351 353 | UUID uuid = EntityHuman.a(gameprofile); |
352 354 | ArrayList arraylist = Lists.newArrayList(); |
353 355 | |
354 - | |
356 + | |
355 357 | } |
356 358 | |
357 359 | return new EntityPlayer(this.server, this.server.getWorldServer(0), gameprofile, (PlayerInteractManager) object); |
358 360 | + */ |
359 361 | + return player; |
360 - | + // CraftBukkit end |
362 + | + // CraftBukkit end |
361 363 | } |
362 364 | |
363 365 | + // CraftBukkit start |
364 366 | public EntityPlayer moveToWorld(EntityPlayer entityplayer, int i, boolean flag) { |
365 367 | + return this.moveToWorld(entityplayer, i, flag, null, true); |
366 368 | + } |
367 369 | + |
368 370 | + public EntityPlayer moveToWorld(EntityPlayer entityplayer, int i, boolean flag, Location location, boolean avoidSuffocation) { |
369 371 | entityplayer.x().getTracker().untrackPlayer(entityplayer); |
370 372 | - entityplayer.x().getTracker().untrackEntity(entityplayer); |
371 373 | + // entityplayer.x().getTracker().untrackEntity(entityplayer); // CraftBukkit |
372 374 | entityplayer.x().getPlayerChunkMap().removePlayer(entityplayer); |
373 375 | this.players.remove(entityplayer); |
374 376 | this.server.getWorldServer(entityplayer.dimension).removeEntity(entityplayer); |
375 377 | BlockPosition blockposition = entityplayer.getBed(); |
376 378 | boolean flag1 = entityplayer.isRespawnForced(); |
377 379 | |
378 380 | + /* CraftBukkit start |
379 381 | entityplayer.dimension = i; |
380 382 | Object object; |
381 383 | |
382 - | |
384 + | |
383 385 | } |
384 386 | |
385 387 | EntityPlayer entityplayer1 = new EntityPlayer(this.server, this.server.getWorldServer(entityplayer.dimension), entityplayer.getProfile(), (PlayerInteractManager) object); |
386 388 | + // */ |
387 389 | + EntityPlayer entityplayer1 = entityplayer; |
388 390 | + org.bukkit.World fromWorld = entityplayer.getBukkitEntity().getWorld(); |
389 391 | + entityplayer.viewingCredits = false; |
390 392 | + // CraftBukkit end |
391 393 | |
392 394 | entityplayer1.playerConnection = entityplayer.playerConnection; |
393 395 | entityplayer1.copyTo(entityplayer, flag); |
394 - | |
396 + | |
395 397 | entityplayer1.a(s); |
396 398 | } |
397 399 | |
398 400 | - WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); |
399 401 | + // WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); // CraftBukkit - handled later |
400 402 | |
401 403 | - this.a(entityplayer1, entityplayer, worldserver); |
402 404 | + // this.a(entityplayer1, entityplayer, worldserver); // CraftBukkit - removed |
403 405 | BlockPosition blockposition1; |
404 406 | |
549 551 | + |
550 552 | + org.bukkit.event.player.PlayerTeleportEvent tpEvent = new org.bukkit.event.player.PlayerTeleportEvent(entityplayer.getBukkitEntity(), enter, exit, cause); |
551 553 | + Bukkit.getServer().getPluginManager().callEvent(tpEvent); |
552 554 | + if (tpEvent.isCancelled() || tpEvent.getTo() == null) { |
553 555 | + return; |
554 556 | + } |
555 557 | + |
556 558 | + Vector velocity = entityplayer.getBukkitEntity().getVelocity(); |
557 559 | + exitWorld.getTravelAgent().adjustExit(entityplayer, exit, velocity); |
558 560 | + |
559 - | + |
560 561 | + entityplayer.worldChangeInvuln = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds |
561 562 | + this.moveToWorld(entityplayer, exitWorld.dimension, true, exit, false); // Vanilla doesn't check for suffocation when handling portals, so neither should we |
562 563 | + if (entityplayer.motX != velocity.getX() || entityplayer.motY != velocity.getY() || entityplayer.motZ != velocity.getZ()) { |
563 564 | + entityplayer.getBukkitEntity().setVelocity(velocity); |
564 565 | + } |
565 566 | + } |
566 567 | + |
567 568 | public void f(EntityPlayer entityplayer) { |
568 569 | GameProfile gameprofile = entityplayer.getProfile(); |
569 570 | int i = this.isOp(gameprofile) ? this.operators.a(gameprofile) : 0; |
570 - | |
571 + | |
571 572 | } |
572 573 | |
573 574 | public void changeWorld(Entity entity, int i, WorldServer worldserver, WorldServer worldserver1) { |
574 575 | + // CraftBukkit start - Split into modular functions |
575 576 | + Location exit = calculateTarget(entity.getBukkitEntity().getLocation(), worldserver1); |
576 577 | + repositionEntity(entity, exit, true); |
577 578 | + } |
578 579 | + |
579 580 | + // Copy of original changeWorld(Entity, int, WorldServer, WorldServer) method with only location calculation logic |
580 581 | + public Location calculateTarget(Location enter, World target) { |
672 673 | + worldserver.methodProfiler.a("moving"); |
673 674 | + */ |
674 675 | + entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch()); |
675 676 | + if (entity.isAlive()) { |
676 677 | + worldserver.entityJoinedWorld(entity, false); |
677 678 | + } |
678 679 | + /* |
679 680 | if (entity.dimension == -1) { |
680 681 | d0 = MathHelper.a(d0 / 8.0D, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D); |
681 682 | d1 = MathHelper.a(d1 / 8.0D, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D); |
682 - | |
683 + | |
683 684 | BlockPosition blockposition; |
684 685 | |
685 686 | if (i == 1) { |
686 687 | + // use default NORMAL world spawn instead of target |
687 688 | + worldserver1 = this.server.worlds.get(0); |
688 689 | blockposition = worldserver1.getSpawn(); |
689 690 | } else { |
690 691 | blockposition = worldserver1.getDimensionSpawn(); |
691 - | |
692 + | |
692 693 | worldserver.entityJoinedWorld(entity, false); |
693 694 | } |
694 695 | } |
695 696 | + */ |
696 697 | |
697 698 | worldserver.methodProfiler.b(); |
698 699 | if (i != 1) { |
699 700 | worldserver.methodProfiler.a("placing"); |
700 701 | + /* |
701 702 | d0 = (double) MathHelper.clamp((int) d0, -29999872, 29999872); |
712 713 | + worldserver1.getTravelAgent().adjustExit(entity, exit, velocity); |
713 714 | + entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch()); |
714 715 | + if (entity.motX != velocity.getX() || entity.motY != velocity.getY() || entity.motZ != velocity.getZ()) { |
715 716 | + entity.getBukkitEntity().setVelocity(velocity); |
716 717 | + } |
717 718 | + } |
718 719 | + // worldserver1.addEntity(entity); |
719 720 | worldserver1.entityJoinedWorld(entity, false); |
720 721 | } |
721 722 | |
722 - | |
723 + | |
723 724 | } |
724 725 | |
725 726 | entity.spawnIn(worldserver1); |
726 727 | + // CraftBukkit end |
727 728 | } |
728 729 | |
729 730 | public void tick() { |
730 - | |
731 + | |
731 732 | |
732 733 | } |
733 734 | |
734 735 | + // CraftBukkit start - add a world/entity limited version |
735 736 | + public void sendAll(Packet packet, EntityHuman entityhuman) { |
736 737 | + for (int i = 0; i < this.players.size(); ++i) { |
737 738 | + EntityPlayer entityplayer = this.players.get(i); |
738 739 | + if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) { |
739 740 | + continue; |
740 741 | + } |
746 747 | + for (int i = 0; i < world.players.size(); ++i) { |
747 748 | + ((EntityPlayer) world.players.get(i)).playerConnection.sendPacket(packet); |
748 749 | + } |
749 750 | + |
750 751 | + } |
751 752 | + // CraftBukkit end |
752 753 | + |
753 754 | public void a(Packet<?> packet, int i) { |
754 755 | for (int j = 0; j < this.players.size(); ++j) { |
755 756 | EntityPlayer entityplayer = (EntityPlayer) this.players.get(j); |
756 - | |
757 + | |
757 758 | |
758 759 | this.operators.add(new OpListEntry(gameprofile, this.server.q(), this.operators.b(gameprofile))); |
759 760 | this.b(this.a(gameprofile.getId()), i); |
760 761 | + // CraftBukkit start |
761 762 | + Player player = server.server.getPlayer(gameprofile.getId()); |
762 763 | + if (player != null) { |
763 764 | + player.recalculatePermissions(); |
764 765 | + } |
765 766 | + // CraftBukkit end |
766 767 | } |
770 771 | this.b(this.a(gameprofile.getId()), 0); |
771 772 | + // CraftBukkit start |
772 773 | + Player player = server.server.getPlayer(gameprofile.getId()); |
773 774 | + if (player != null) { |
774 775 | + player.recalculatePermissions(); |
775 776 | + } |
776 777 | + // CraftBukkit end |
777 778 | } |
778 779 | |
779 780 | private void b(EntityPlayer entityplayer, int i) { |
780 - | |
781 + | |
781 782 | } |
782 783 | |
783 784 | public boolean isOp(GameProfile gameprofile) { |
784 785 | - return this.operators.d(gameprofile) || this.server.R() && this.server.worldServer[0].getWorldData().u() && this.server.Q().equalsIgnoreCase(gameprofile.getName()) || this.t; |
785 786 | + return this.operators.d(gameprofile) || this.server.R() && this.server.worlds.get(0).getWorldData().u() && this.server.Q().equalsIgnoreCase(gameprofile.getName()) || this.t; // CraftBukkit |
786 787 | } |
787 788 | |
788 789 | @Nullable |
789 - | |
790 + | |
790 791 | for (int j = 0; j < this.players.size(); ++j) { |
791 792 | EntityPlayer entityplayer = (EntityPlayer) this.players.get(j); |
792 793 | |
793 794 | + // CraftBukkit start - Test if player receiving packet can see the source of the packet |
794 795 | + if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) { |
795 796 | + continue; |
796 797 | + } |
797 798 | + // CraftBukkit end |
798 799 | + |
799 800 | if (entityplayer != entityhuman && entityplayer.dimension == i) { |
800 801 | double d4 = d0 - entityplayer.locX; |
801 802 | double d5 = d1 - entityplayer.locY; |
802 - | |
803 + | |
803 804 | public void reloadWhitelist() {} |
804 805 | |
805 806 | public void b(EntityPlayer entityplayer, WorldServer worldserver) { |
806 807 | - WorldBorder worldborder = this.server.worldServer[0].getWorldBorder(); |
807 808 | + WorldBorder worldborder = entityplayer.world.getWorldBorder(); // CraftBukkit |
808 809 | |
809 810 | entityplayer.playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE)); |
810 811 | entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean("doDaylightCycle"))); |
811 812 | if (worldserver.W()) { |
812 813 | - entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(1, 0.0F)); |
824 825 | } |
825 826 | |
826 827 | public void updateClient(EntityPlayer entityplayer) { |
827 828 | entityplayer.updateInventory(entityplayer.defaultContainer); |
828 829 | - entityplayer.triggerHealthUpdate(); |
829 830 | + // entityplayer.triggerHealthUpdate(); |
830 831 | + entityplayer.getBukkitEntity().updateScaledHealth(); // CraftBukkit - Update scaled health on respawn and worldchange |
831 832 | entityplayer.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(entityplayer.inventory.itemInHandIndex)); |
832 833 | } |
833 834 | |
834 - | |
835 + | |
835 836 | } |
836 837 | |
837 838 | public String[] getSeenPlayers() { |
838 839 | - return this.server.worldServer[0].getDataManager().getPlayerFileData().getSeenPlayers(); |
839 840 | + return this.server.worlds.get(0).getDataManager().getPlayerFileData().getSeenPlayers(); // CraftBukkit |
840 841 | } |
841 842 | |
842 843 | public boolean getHasWhitelist() { |
843 - | |
844 + | |
844 845 | |
845 846 | public void u() { |
846 847 | for (int i = 0; i < this.players.size(); ++i) { |
847 848 | - ((EntityPlayer) this.players.get(i)).playerConnection.disconnect("Server closed"); |
848 849 | + ((EntityPlayer) this.players.get(i)).playerConnection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message |
849 850 | } |
850 851 | |
851 852 | } |
852 853 | |
853 854 | + // CraftBukkit start |
862 863 | this.server.sendMessage(ichatbasecomponent); |
863 864 | int i = flag ? 1 : 0; |
864 865 | |
865 866 | - this.sendAll(new PacketPlayOutChat(ichatbasecomponent, (byte) i)); |
866 867 | + // CraftBukkit start - we run this through our processor first so we can get web links etc |
867 868 | + this.sendAll(new PacketPlayOutChat(CraftChatMessage.fixComponent(ichatbasecomponent), (byte) i)); |
868 869 | + // CraftBukkit end |
869 870 | } |
870 871 | |
871 872 | public void sendMessage(IChatBaseComponent ichatbasecomponent) { |
872 - | |
873 + | |
873 874 | WorldServer[] aworldserver = this.server.worldServer; |
874 875 | int j = aworldserver.length; |
875 876 | |
876 877 | - for (int k = 0; k < j; ++k) { |
877 878 | - WorldServer worldserver = aworldserver[k]; |
878 879 | + // CraftBukkit start |
879 880 | + for (int k = 0; k < server.worlds.size(); ++k) { |
880 881 | + WorldServer worldserver = server.worlds.get(0); |
881 882 | + // CraftBukkit end |
882 883 | |