diff options
Diffstat (limited to 'src/main/java/net/minecraft/server/EntityPlayer.java')
-rw-r--r-- | src/main/java/net/minecraft/server/EntityPlayer.java | 257 |
1 files changed, 160 insertions, 97 deletions
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 8d61ca63..52fd5612 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -4,6 +4,8 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -28,14 +30,14 @@ public class EntityPlayer extends EntityHuman implements ICrafting { public double e; public final List chunkCoordIntPairQueue = new LinkedList(); public final List removeQueue = new LinkedList(); - private int cl = -99999999; private int cm = -99999999; - private boolean cn = true; + private int cn = -99999999; + private boolean co = true; public int lastSentExp = -99999999; // CraftBukkit - private -> public public int invulnerableTicks = 60; // CraftBukkit - private -> public - private int cq = 0; private int cr = 0; - private boolean cs = true; + private int cs = 0; + private boolean ct = true; private int containerCounter = 0; public boolean h; public int ping; @@ -54,7 +56,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { super(world); playerinteractmanager.player = this; this.playerInteractManager = playerinteractmanager; - this.cq = minecraftserver.getPlayerList().o(); + this.cr = minecraftserver.getPlayerList().o(); ChunkCoordinates chunkcoordinates = world.getSpawn(); int i = chunkcoordinates.x; int j = chunkcoordinates.z; @@ -68,14 +70,21 @@ public class EntityPlayer extends EntityHuman implements ICrafting { k = world.i(i, j); } - this.setPositionRotation((double) i + 0.5D, (double) k, (double) j + 0.5D, 0.0F, 0.0F); this.server = minecraftserver; - this.X = 0.0F; + this.Y = 0.0F; this.name = s; this.height = 0.0F; - this.displayName = this.name; // CraftBukkit - this.listName = this.name; // CraftBukkit - this.canPickUpLoot = true; // CraftBukkit + this.setPositionRotation((double) i + 0.5D, (double) k, (double) j + 0.5D, 0.0F, 0.0F); + + while (!world.getCubes(this, this.boundingBox).isEmpty()) { + this.setPosition(this.locX, this.locY + 1.0D, this.locZ); + } + + // CraftBukkit start + this.displayName = this.name; + this.listName = this.name; + this.canPickUpLoot = true; + // CraftBukkit end } public void a(NBTTagCompound nbttagcompound) { @@ -134,7 +143,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { return 1.62F; } - public void j_() { + public void l_() { this.playerInteractManager.a(); --this.invulnerableTicks; this.activeContainer.b(); @@ -170,7 +179,6 @@ public class EntityPlayer extends EntityHuman implements ICrafting { if (!arraylist.isEmpty()) { this.playerConnection.sendPacket(new Packet56MapChunkBulk(arraylist)); - Iterator iterator2 = arraylist1.iterator(); while (iterator2.hasNext()) { @@ -184,50 +192,70 @@ public class EntityPlayer extends EntityHuman implements ICrafting { while (iterator2.hasNext()) { Chunk chunk = (Chunk) iterator2.next(); - this.p().getTracker().a(this, chunk); + this.o().getTracker().a(this, chunk); } } } } + public void setHealth(int i) { + super.setHealth(i); + Collection collection = this.getScoreboard().a(IObjective.f); + Iterator iterator = collection.iterator(); + + while (iterator.hasNext()) { + ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next(); + + this.getScoreboard().a(this.getLocalizedName(), scoreboardobjective).a(Arrays.asList(new EntityHuman[] { this})); + } + } + public void g() { - super.j_(); + try { + super.l_(); - for (int i = 0; i < this.inventory.getSize(); ++i) { - ItemStack itemstack = this.inventory.getItem(i); + for (int i = 0; i < this.inventory.getSize(); ++i) { + ItemStack itemstack = this.inventory.getItem(i); - if (itemstack != null && Item.byId[itemstack.id].f() && this.playerConnection.lowPriorityCount() <= 5) { - Packet packet = ((ItemWorldMapBase) Item.byId[itemstack.id]).c(itemstack, this.world, this); + if (itemstack != null && Item.byId[itemstack.id].f() && this.playerConnection.lowPriorityCount() <= 5) { + Packet packet = ((ItemWorldMapBase) Item.byId[itemstack.id]).c(itemstack, this.world, this); - if (packet != null) { - this.playerConnection.sendPacket(packet); + if (packet != null) { + this.playerConnection.sendPacket(packet); + } } } - } - if (this.getHealth() != this.cl || this.cm != this.foodData.a() || this.foodData.e() == 0.0F != this.cn) { - // CraftBukkit - this.getHealth() -> this.getScaledHealth() - this.playerConnection.sendPacket(new Packet8UpdateHealth(this.getScaledHealth(), this.foodData.a(), this.foodData.e())); - this.cl = this.getHealth(); - this.cm = this.foodData.a(); - this.cn = this.foodData.e() == 0.0F; - } + if (this.getHealth() != this.cm || this.cn != this.foodData.a() || this.foodData.e() == 0.0F != this.co) { + // CraftBukkit - this.getHealth() -> this.getScaledHealth() + this.playerConnection.sendPacket(new Packet8UpdateHealth(this.getScaledHealth(), this.foodData.a(), this.foodData.e())); + this.cm = this.getHealth(); + this.cn = this.foodData.a(); + this.co = this.foodData.e() == 0.0F; + } - if (this.expTotal != this.lastSentExp) { - this.lastSentExp = this.expTotal; - this.playerConnection.sendPacket(new Packet43SetExperience(this.exp, this.expTotal, this.expLevel)); - } + if (this.expTotal != this.lastSentExp) { + this.lastSentExp = this.expTotal; + this.playerConnection.sendPacket(new Packet43SetExperience(this.exp, this.expTotal, this.expLevel)); + } - // CraftBukkit start - if (this.oldLevel == -1) { - this.oldLevel = this.expLevel; - } + // CraftBukkit start + 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"); - if (this.oldLevel != this.expLevel) { - CraftEventFactory.callPlayerLevelChangeEvent(this.world.getServer().getPlayer((EntityPlayer) this), this.oldLevel, this.expLevel); - this.oldLevel = this.expLevel; + this.a(crashreportsystemdetails); + throw new ReportedException(crashreport); } - // CraftBukkit end } public void die(DamageSource damagesource) { @@ -253,7 +281,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } } - org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, damagesource.getLocalizedDeathMessage(this)); + org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, this.bt.b()); String deathMessage = event.getDeathMessage(); @@ -273,10 +301,23 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } this.closeInventory(); - - // Update effects on player death - this.updateEffects = true; // CraftBukkit end + + Collection collection = this.world.getScoreboard().a(IObjective.c); + Iterator iterator = collection.iterator(); + + while (iterator.hasNext()) { + ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next(); + ScoreboardScore scoreboardscore = this.getScoreboard().a(this.getLocalizedName(), scoreboardobjective); + + scoreboardscore.a(); + } + + EntityLiving entityliving = this.bN(); + + if (entityliving != null) { + entityliving.c(this, this.aM); + } } public boolean damageEntity(DamageSource damagesource, int i) { @@ -289,18 +330,17 @@ public class EntityPlayer extends EntityHuman implements ICrafting { if (!flag && this.invulnerableTicks > 0 && damagesource != DamageSource.OUT_OF_WORLD) { return false; } else { - // CraftBukkit - this.server.getPvP() -> this.world.pvpMode - if (!this.world.pvpMode && damagesource instanceof EntityDamageSource) { + if (damagesource instanceof EntityDamageSource) { Entity entity = damagesource.getEntity(); - if (entity instanceof EntityHuman) { + if (entity instanceof EntityHuman && !this.a((EntityHuman) entity)) { return false; } if (entity instanceof EntityArrow) { EntityArrow entityarrow = (EntityArrow) entity; - if (entityarrow.shooter instanceof EntityHuman) { + if (entityarrow.shooter instanceof EntityHuman && !this.a((EntityHuman) entityarrow.shooter)) { return false; } } @@ -311,11 +351,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } } - protected boolean h() { - return this.server.getPvP(); + public boolean a(EntityHuman entityhuman) { + // CraftBukkit - this.server.getPvP() -> this.world.pvpMode + return !this.world.pvpMode ? false : super.a(entityhuman); } - public void b(int i) { + public void c(int i) { if (this.dimension == 1 && i == 1) { this.a((Statistic) AchievementList.C); this.world.kill(this); @@ -329,7 +370,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { ChunkCoordinates chunkcoordinates = this.server.getWorldServer(i).getDimensionSpawn(); if (chunkcoordinates != null) { - this.netServerHandler.a((double) chunkcoordinates.x, (double) chunkcoordinates.y, (double) chunkcoordinates.z, 0.0F, 0.0F); + this.playerConnection.a((double) chunkcoordinates.x, (double) chunkcoordinates.y, (double) chunkcoordinates.z, 0.0F, 0.0F); } i = 1; @@ -344,8 +385,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting { this.server.getPlayerList().changeDimension(this, i, cause); // CraftBukkit end this.lastSentExp = -1; - this.cl = -1; this.cm = -1; + this.cn = -1; } } @@ -370,7 +411,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { if (enumbedresult == EnumBedResult.OK) { Packet17EntityLocationAction packet17entitylocationaction = new Packet17EntityLocationAction(this, 0, i, j, k); - this.p().getTracker().a((Entity) this, (Packet) packet17entitylocationaction); + this.o().getTracker().a((Entity) this, (Packet) packet17entitylocationaction); this.playerConnection.a(this.locX, this.locY, this.locZ, this.yaw, this.pitch); this.playerConnection.sendPacket(packet17entitylocationaction); } @@ -382,7 +423,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { if (this.fauxSleeping && !this.sleeping) return; // CraftBukkit - Can't leave bed if not in one! if (this.isSleeping()) { - this.p().getTracker().sendPacketToEntity(this, new Packet18ArmAnimation(this, 3)); + this.o().getTracker().sendPacketToEntity(this, new Packet18ArmAnimation(this, 3)); } super.a(flag, flag1, flag2); @@ -425,20 +466,20 @@ public class EntityPlayer extends EntityHuman implements ICrafting { // CraftBukkit end this.nextContainerCounter(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 1, "Crafting", 9)); + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 1, "Crafting", 9, true)); this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); } - public void startEnchanting(int i, int j, int k) { + public void startEnchanting(int i, int j, int k, String s) { // CraftBukkit start - inventory open hook Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerEnchantTable(this.inventory, this.world, i, j, k)); if(container == null) return; // CraftBukkit end this.nextContainerCounter(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 4, "Enchanting", 9)); + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 4, s == null ? "" : s, 9, s != null)); this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); @@ -451,8 +492,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting { // CraftBukkit end this.nextContainerCounter(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 8, "Repairing", 9)); - this.activeContainer = container; // CraftBukkit - use container we passed to event + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 8, "Repairing", 9, true)); + this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); } @@ -468,8 +509,34 @@ public class EntityPlayer extends EntityHuman implements ICrafting { // CraftBukkit end this.nextContainerCounter(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 0, iinventory.getName(), iinventory.getSize())); - this.activeContainer = container; // CraftBukkit - Use container passed to event + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 0, iinventory.getName(), iinventory.getSize(), iinventory.c())); + this.activeContainer = container; // CraftBukkit - Use container we passed to event + this.activeContainer.windowId = this.containerCounter; + this.activeContainer.addSlotListener(this); + } + + public void openHopper(TileEntityHopper tileentityhopper) { + // CraftBukkit start - inventory open hook + Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerHopper(this.inventory, tileentityhopper)); + if(container == null) return; + // CraftBukkit end + + this.nextContainerCounter(); + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 9, tileentityhopper.getName(), tileentityhopper.getSize(), tileentityhopper.c())); + this.activeContainer = container; // CraftBukkit - Use container we passed to event + this.activeContainer.windowId = this.containerCounter; + this.activeContainer.addSlotListener(this); + } + + public void openMinecartHopper(EntityMinecartHopper entityminecarthopper) { + // CraftBukkit start - inventory open hook + Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerHopper(this.inventory, entityminecarthopper)); + if(container == null) return; + // CraftBukkit end + + this.nextContainerCounter(); + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 9, entityminecarthopper.getName(), entityminecarthopper.getSize(), entityminecarthopper.c())); + this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); } @@ -481,8 +548,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting { // CraftBukkit end this.nextContainerCounter(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 2, tileentityfurnace.getName(), tileentityfurnace.getSize())); - this.activeContainer = container; // CraftBukkit - Use container passed to event + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 2, tileentityfurnace.getName(), tileentityfurnace.getSize(), tileentityfurnace.c())); + this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); } @@ -494,8 +561,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting { // CraftBukkit end this.nextContainerCounter(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 3, tileentitydispenser.getName(), tileentitydispenser.getSize())); - this.activeContainer = container; // CraftBukkit - Use container passed to event + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, tileentitydispenser instanceof TileEntityDropper ? 10 : 3, tileentitydispenser.getName(), tileentitydispenser.getSize(), tileentitydispenser.c())); + this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); } @@ -507,8 +574,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting { // CraftBukkit end this.nextContainerCounter(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 5, tileentitybrewingstand.getName(), tileentitybrewingstand.getSize())); - this.activeContainer = container; // CraftBukkit - Use container passed to event + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 5, tileentitybrewingstand.getName(), tileentitybrewingstand.getSize(), tileentitybrewingstand.c())); + this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); } @@ -520,25 +587,25 @@ public class EntityPlayer extends EntityHuman implements ICrafting { // CraftBukkit end this.nextContainerCounter(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 7, tileentitybeacon.getName(), tileentitybeacon.getSize())); - this.activeContainer = container; // CraftBukkit - Use container passed to event + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 7, tileentitybeacon.getName(), tileentitybeacon.getSize(), tileentitybeacon.c())); + this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); } - public void openTrade(IMerchant imerchant) { + public void openTrade(IMerchant imerchant, String s) { // 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 = container; // CraftBukkit - Use container passed to event + this.activeContainer = container; // CraftBukkit - Use container we passed to event this.activeContainer.windowId = this.containerCounter; this.activeContainer.addSlotListener(this); InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).getMerchantInventory(); - this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 6, inventorymerchant.getName(), inventorymerchant.getSize())); + this.playerConnection.sendPacket(new Packet100OpenWindow(this.containerCounter, 6, s == null ? "" : s, inventorymerchant.getSize(), s != null)); MerchantRecipeList merchantrecipelist = imerchant.getOffers(this); if (merchantrecipelist != null) { @@ -583,7 +650,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { public void closeInventory() { this.playerConnection.sendPacket(new Packet101CloseWindow(this.activeContainer.windowId)); - this.k(); + this.j(); } public void broadcastCarriedItem() { @@ -592,8 +659,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } } - public void k() { - this.activeContainer.b(this); + public void j() { + this.activeContainer.b((EntityHuman) this); this.activeContainer = this.defaultContainer; } @@ -610,11 +677,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } } - public void l() { - if (this.vehicle != null) { - this.mount(this.vehicle); - } - + public void k() { if (this.passenger != null) { this.passenger.mount(this); } @@ -625,34 +688,34 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } public void triggerHealthUpdate() { - this.cl = -99999999; + this.cm = -99999999; this.lastSentExp = -1; // CraftBukkit - Added to reset } public void b(String s) { LocaleLanguage localelanguage = LocaleLanguage.a(); - String s1 = localelanguage.b(s); + String s1 = localelanguage.a(s); this.playerConnection.sendPacket(new Packet3Chat(s1)); } - protected void n() { + protected void m() { this.playerConnection.sendPacket(new Packet38EntityStatus(this.id, (byte) 9)); - super.n(); + super.m(); } public void a(ItemStack itemstack, int i) { super.a(itemstack, i); - if (itemstack != null && itemstack.getItem() != null && itemstack.getItem().b_(itemstack) == EnumAnimation.b) { - this.p().getTracker().sendPacketToEntity(this, new Packet18ArmAnimation(this, 5)); + if (itemstack != null && itemstack.getItem() != null && itemstack.getItem().b_(itemstack) == EnumAnimation.EAT) { + this.o().getTracker().sendPacketToEntity(this, new Packet18ArmAnimation(this, 5)); } } public void copyTo(EntityHuman entityhuman, boolean flag) { super.copyTo(entityhuman, flag); this.lastSentExp = -1; - this.cl = -1; this.cm = -1; + this.cn = -1; this.removeQueue.addAll(((EntityPlayer) entityhuman).removeQueue); } @@ -676,11 +739,11 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } public void b(Entity entity) { - this.p().getTracker().sendPacketToEntity(this, new Packet18ArmAnimation(entity, 6)); + this.o().getTracker().sendPacketToEntity(this, new Packet18ArmAnimation(entity, 6)); } public void c(Entity entity) { - this.p().getTracker().sendPacketToEntity(this, new Packet18ArmAnimation(entity, 7)); + this.o().getTracker().sendPacketToEntity(this, new Packet18ArmAnimation(entity, 7)); } public void updateAbilities() { @@ -689,7 +752,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } } - public WorldServer p() { + public WorldServer o() { return (WorldServer) this.world; } @@ -706,7 +769,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { return "seed".equals(s) && !this.server.T() ? true : (!"tell".equals(s) && !"help".equals(s) && !"me".equals(s) ? this.server.getPlayerList().isOp(this.name) : true); } - public String q() { + public String p() { String s = this.playerConnection.networkManager.getSocketAddress().toString(); s = s.substring(s.indexOf("/") + 1); @@ -716,17 +779,17 @@ public class EntityPlayer extends EntityHuman implements ICrafting { public void a(Packet204LocaleAndViewDistance packet204localeandviewdistance) { if (this.locale.b().containsKey(packet204localeandviewdistance.d())) { - this.locale.a(packet204localeandviewdistance.d()); + this.locale.a(packet204localeandviewdistance.d(), false); } int i = 256 >> packet204localeandviewdistance.f(); if (i > 3 && i < 15) { - this.cq = i; + this.cr = i; } - this.cr = packet204localeandviewdistance.g(); - this.cs = packet204localeandviewdistance.h(); + this.cs = packet204localeandviewdistance.g(); + this.ct = packet204localeandviewdistance.h(); if (this.server.I() && this.server.H().equals(this.name)) { this.server.c(packet204localeandviewdistance.i()); } @@ -739,7 +802,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } public int getChatFlags() { - return this.cr; + return this.cs; } public void a(String s, int i) { |