Files
CatServer/patches/net/minecraft/entity/player/EntityPlayer.java.patch

388 lines
16 KiB
Diff

--- ../src-base/minecraft/net/minecraft/entity/player/EntityPlayer.java
+++ ../src-work/minecraft/net/minecraft/entity/player/EntityPlayer.java
@@ -9,8 +9,6 @@
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
-import net.minecraft.block.BlockBed;
-import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
@@ -32,7 +30,6 @@
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.projectile.EntityFishHook;
-import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
@@ -96,6 +93,17 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.entity.CraftItem;
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.player.PlayerBedEnterEvent;
+import org.bukkit.event.player.PlayerBedLeaveEvent;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerVelocityEvent;
+// CraftBukkit end
+
@SuppressWarnings("incomplete-switch")
public abstract class EntityPlayer extends EntityLivingBase
{
@@ -112,7 +120,7 @@
private InventoryEnderChest theInventoryEnderChest = new InventoryEnderChest();
public Container inventoryContainer;
public Container openContainer;
- protected FoodStats foodStats = new FoodStats();
+ protected FoodStats foodStats = new FoodStats(this);
protected int flyToggleTimer;
public float prevCameraYaw;
public float cameraYaw;
@@ -147,7 +155,17 @@
private ItemStack itemStackMainHand;
private final CooldownTracker cooldownTracker = this.createCooldownTracker();
public EntityFishHook fishEntity;
-
+ // CraftBukkit start
+ public boolean fauxSleeping;
+ public String spawnWorld = "";
+ public int oldLevel = -1;
+
+ @Override
+ public CraftHumanEntity getBukkitEntity() {
+ return (CraftHumanEntity) super.getBukkitEntity();
+ }
+ // CraftBukkit end
+
protected CooldownTracker createCooldownTracker()
{
return new CooldownTracker();
@@ -164,6 +182,9 @@
this.setLocationAndAngles((double)blockpos.getX() + 0.5D, (double)(blockpos.getY() + 1), (double)blockpos.getZ() + 0.5D, 0.0F, 0.0F);
this.unused180 = 180.0F;
this.fireResistance = 20;
+
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this));
+ super.capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities((Entity)this);
}
protected void applyEntityAttributes()
@@ -437,6 +458,10 @@
{
return this.getHealth() <= 0.0F || this.isPlayerSleeping();
}
+
+ public boolean isMovementBlockedCB() {
+ return isMovementBlocked();
+ }
public void closeScreen()
{
@@ -498,7 +523,8 @@
{
if (this.getHealth() < this.getMaxHealth() && this.ticksExisted % 20 == 0)
{
- this.heal(1.0F);
+ // CraftBukkit - added regain reason of "REGEN" for filtering purposes.
+ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
}
if (this.foodStats.needFood() && this.ticksExisted % 10 == 0)
@@ -649,12 +675,13 @@
if (entityIn != this)
{
this.addScore(amount);
- Collection<ScoreObjective> collection = this.getWorldScoreboard().getObjectivesFromCriteria(IScoreCriteria.TOTAL_KILL_COUNT);
+ // CraftBukkit - Get our scores instead
+ Collection<Score> collection = this.worldObj.getServer().getScoreboardManager().getScoreboardScores(IScoreCriteria.TOTAL_KILL_COUNT, this.getName(), new java.util.ArrayList<Score>());;
if (entityIn instanceof EntityPlayer)
{
this.addStat(StatList.PLAYER_KILLS);
- collection.addAll(this.getWorldScoreboard().getObjectivesFromCriteria(IScoreCriteria.PLAYER_KILL_COUNT));
+ this.worldObj.getServer().getScoreboardManager().getScoreboardScores(IScoreCriteria.PLAYER_KILL_COUNT, this.getName(), collection);
}
else
{
@@ -663,14 +690,14 @@
collection.addAll(this.giveTeamKillScores(entityIn));
- for (ScoreObjective scoreobjective : collection)
+ for (Score score : collection)
{
- this.getWorldScoreboard().getOrCreateScore(this.getName(), scoreobjective).incrementScore();
+ score.incrementScore();
}
}
}
- private Collection<ScoreObjective> giveTeamKillScores(Entity p_175137_1_)
+ private Collection<Score> giveTeamKillScores(Entity p_175137_1_)
{
String s = p_175137_1_ instanceof EntityPlayer ? p_175137_1_.getName() : p_175137_1_.getCachedUniqueIdString();
ScorePlayerTeam scoreplayerteam = this.getWorldScoreboard().getPlayersTeam(this.getName());
@@ -697,11 +724,11 @@
if (j >= 0 && j < IScoreCriteria.TEAM_KILL.length)
{
- return this.getWorldScoreboard().getObjectivesFromCriteria(IScoreCriteria.TEAM_KILL[j]);
+ return this.worldObj.getServer().getScoreboardManager().getScoreboardScores(IScoreCriteria.TEAM_KILL[j], this.getName(), new java.util.ArrayList<Score>());
}
}
- return Lists.<ScoreObjective>newArrayList();
+ return Lists.<Score>newArrayList();
}
@Nullable
@@ -771,7 +798,31 @@
entityitem.motionY += (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F);
entityitem.motionZ += Math.sin((double)f3) * (double)f2;
}
-
+ // CraftBukkit start
+ Player player = (Player)getBukkitEntity();
+ CraftItem drop = new CraftItem(this.worldObj.getServer(), entityitem);
+
+ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
+ this.worldObj.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled())
+ {
+ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
+ if ((traceItem) && ((cur == null) || (cur.getAmount() == 0)))
+ {
+ player.getInventory().setItemInHand(drop.getItemStack());
+ }
+ else if ((traceItem) && (cur.isSimilar(drop.getItemStack())) && (drop.getItemStack().getAmount() == 1))
+ {
+ cur.setAmount(cur.getAmount() + 1);
+ player.getInventory().setItemInHand(cur);
+ }
+ else
+ {
+ player.getInventory().addItem(new org.bukkit.inventory.ItemStack[] { drop.getItemStack() });
+ }
+ return null;
+ }
+ // CraftBukkit end
ItemStack itemstack = this.dropItemAndGetStack(entityitem);
if (traceItem)
@@ -905,6 +956,13 @@
this.wakeUpPlayer(true, true, false);
}
+ // CraftBukkit start
+ this.spawnWorld = compound.getString("SpawnWorld");
+ if ("".equals(spawnWorld)) {
+ this.spawnWorld = this.worldObj.getServer().getWorlds().get(0).getName();
+ }
+ // CraftBukkit end
+
if (compound.hasKey("SpawnX", 99) && compound.hasKey("SpawnY", 99) && compound.hasKey("SpawnZ", 99))
{
this.spawnChunk = new BlockPos(compound.getInteger("SpawnX"), compound.getInteger("SpawnY"), compound.getInteger("SpawnZ"));
@@ -973,6 +1031,7 @@
this.foodStats.writeNBT(compound);
this.capabilities.writeCapabilitiesToNBT(compound);
compound.setTag("EnderItems", this.theInventoryEnderChest.saveInventoryToNBT());
+ compound.setString("SpawnWorld", spawnWorld); // CraftBukkit - fixes bed spawns for multiworld worlds
}
public boolean attackEntityFrom(DamageSource source, float amount)
@@ -1078,14 +1137,17 @@
return (float)i / (float)this.inventory.armorInventory.length;
}
- protected void damageEntity(DamageSource damageSrc, float damageAmount)
- {
+ protected void damageEntity(DamageSource damageSrc, float damageAmount) {
+ this.damageEntity0(damageSrc,damageAmount);
+ }
+ protected boolean damageEntity0(DamageSource damageSrc, float damageAmount){
+ if (true) return super.damageEntity0(damageSrc, damageAmount); // CraftBukkit
if (!this.isEntityInvulnerable(damageSrc))
{
damageAmount = net.minecraftforge.common.ForgeHooks.onLivingHurt(this, damageSrc, damageAmount);
- if (damageAmount <= 0) return;
+ if (damageAmount <= 0) return false;
damageAmount = net.minecraftforge.common.ISpecialArmor.ArmorProperties.applyArmor(this, inventory.armorInventory, damageSrc, damageAmount);
- if (damageAmount <= 0) return;
+ if (damageAmount <= 0) return false;
damageAmount = this.applyPotionDamageCalculations(damageSrc, damageAmount);
float f = damageAmount;
damageAmount = Math.max(damageAmount - this.getAbsorptionAmount(), 0.0F);
@@ -1104,6 +1166,7 @@
}
}
}
+ return true;
}
public void openEditSign(TileEntitySign signTile)
@@ -1282,8 +1345,15 @@
if (j > 0 && !targetEntity.isBurning())
{
- flag4 = true;
- targetEntity.setFire(1);
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), targetEntity.getBukkitEntity(), 1);
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+
+ if (!combustEvent.isCancelled()) {
+ flag4 = true;
+ targetEntity.setFire(combustEvent.getDuration());
+ }
+ // CraftBukkit end
}
}
@@ -1316,8 +1386,11 @@
{
if (entitylivingbase != this && entitylivingbase != targetEntity && !this.isOnSameTeam(entitylivingbase) && this.getDistanceSqToEntity(entitylivingbase) < 9.0D)
{
+ // CraftBukkit start - Only apply knockback if the damage hits
+ if (entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage(this), 1.0F)) {
entitylivingbase.knockBack(this, 0.4F, (double)MathHelper.sin(this.rotationYaw * 0.017453292F), (double)(-MathHelper.cos(this.rotationYaw * 0.017453292F)));
- entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage(this), 1.0F);
+ }
+ // CraftBukkit end
}
}
@@ -1327,11 +1400,28 @@
if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged)
{
+ // CraftBukkit start - Add Velocity Event
+ boolean cancelled = false;
+ Player player = (Player) targetEntity.getBukkitEntity();
+ org.bukkit.util.Vector velocity = new org.bukkit.util.Vector( d1, d2, d3 );
+
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
+ worldObj.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+
+ if (!cancelled) {
((EntityPlayerMP)targetEntity).connection.sendPacket(new SPacketEntityVelocity(targetEntity));
targetEntity.velocityChanged = false;
targetEntity.motionX = d1;
targetEntity.motionY = d2;
targetEntity.motionZ = d3;
+ }
+ // CraftBukkit end
}
if (flag2)
@@ -1424,7 +1514,14 @@
if (j > 0)
{
- targetEntity.setFire(j * 4);
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), j * 4);
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+
+ if (!combustEvent.isCancelled()) {
+ targetEntity.setFire(combustEvent.getDuration());
+ }
+ // CraftBukkit end
}
if (this.worldObj instanceof WorldServer && f5 > 2.0F)
@@ -1434,7 +1531,7 @@
}
}
- this.addExhaustion(0.3F);
+ this.addExhaustion(worldObj.spigotConfig.combatExhaustion); // Spigot - Change to use configurable value
}
else
{
@@ -1541,6 +1638,20 @@
this.dismountRidingEntity();
}
+ // CraftBukkit start - fire PlayerBedEnterEvent
+ if (this.getBukkitEntity() instanceof Player) {
+ Player player = (Player) this.getBukkitEntity();
+ org.bukkit.block.Block bed = this.worldObj.getWorld().getBlockAt(bedLocation.getX(), bedLocation.getY(), bedLocation.getZ());
+
+ PlayerBedEnterEvent event = new PlayerBedEnterEvent(player, bed);
+ this.worldObj.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return SleepResult.OTHER_PROBLEM;
+ }
+ }
+ // CraftBukkit end
+
this.setSize(0.2F, 0.2F);
IBlockState state = null;
@@ -1639,6 +1750,23 @@
this.worldObj.updateAllPlayersSleepingFlag();
}
+ // CraftBukkit start - fire PlayerBedLeaveEvent
+ if (this.getBukkitEntity() instanceof Player) {
+ Player player = (Player) this.getBukkitEntity();
+
+ org.bukkit.block.Block bed;
+ BlockPos blockpos = this.bedLocation;
+ if (blockpos != null) {
+ bed = this.worldObj.getWorld().getBlockAt(blockpos.getX(), blockpos.getY(), blockpos.getZ());
+ } else {
+ bed = this.worldObj.getWorld().getBlockAt(player.getLocation());
+ }
+
+ PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed);
+ this.worldObj.getServer().getPluginManager().callEvent(event);
+ }
+ // CraftBukkit end
+
this.sleepTimer = immediately ? 0 : 100;
if (setSpawn)
@@ -1745,11 +1873,13 @@
{
this.spawnChunk = pos;
this.spawnForced = forced;
+ this.spawnWorld = this.worldObj.worldInfo.getWorldName(); // CraftBukkit
}
else
{
this.spawnChunk = null;
this.spawnForced = false;
+ this.spawnWorld = "";
}
}
@@ -1778,11 +1908,11 @@
if (this.isSprinting())
{
- this.addExhaustion(0.8F);
+ this.addExhaustion(worldObj.spigotConfig.sprintExhaustion); // Spigot - Change to use configurable value
}
else
{
- this.addExhaustion(0.2F);
+ this.addExhaustion(worldObj.spigotConfig.walkExhaustion); // Spigot - Change to use configurable value
}
}