3
0

Implement ReverseClonner, which should fix all issues with teleportation/inventories/crashed after respawning

This commit is contained in:
Sergey Shatunov
2016-02-06 04:29:03 +07:00
parent 313adcfbb0
commit 0b251c5440
10 changed files with 69 additions and 65 deletions

View File

@ -0,0 +1,24 @@
package kcauldron;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
public enum ReverseClonner {
;
public static EntityPlayerMP clone(EntityPlayerMP player, boolean wasDeath) {
EntityPlayerMP shadowCopy = new EntityPlayerMP(player.mcServer, (WorldServer) player.worldObj,
player.getGameProfile(), new ItemInWorldManager(player.worldObj));
shadowCopy.clonePlayer(player, true);
if (wasDeath) {
player.inventory.clearInventory(null, -1);
player.inventoryContainer = new ContainerPlayer(player.inventory, !player.worldObj.isRemote, player);
}
MinecraftForge.EVENT_BUS.post(new PlayerEvent.Clone(player, shadowCopy, wasDeath));
return player;
}
}

View File

@ -27,8 +27,6 @@ import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import net.minecraft.entity.EntityLivingBase;
public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
private CraftInventoryPlayer inventory;
private CraftInventory enderChest;
@ -40,13 +38,6 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
super(server, entity);
mode = server.getDefaultGameMode();
}
@Override
public void updateEntity(EntityLivingBase entity) {
super.updateEntity(entity);
if (inventory != null) inventory.updateInventory(((net.minecraft.entity.player.EntityPlayer) entity).inventory);
if (enderChest != null) enderChest.updateInventory(((net.minecraft.entity.player.EntityPlayer) entity).getInventoryEnderChest());
}
public String getName() {
return getHandle().getCommandSenderName();

View File

@ -48,18 +48,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
public Class<? extends net.minecraft.entity.EntityLivingBase> entityClass;
public String entityName;
// Cauldron end
public void updateEntity(net.minecraft.entity.EntityLivingBase entity) {
super.entity = entity;
public CraftLivingEntity(final CraftServer server, final net.minecraft.entity.EntityLivingBase entity) {
super(server, entity);
// Cauldron start
this.entityClass = entity.getClass();
this.entityName = EntityRegistry.getCustomEntityTypeName(entityClass);
if (entityName == null)
entityName = entity.getCommandSenderName();
}
public CraftLivingEntity(final CraftServer server, final net.minecraft.entity.EntityLivingBase entity) {
super(server, entity);
updateEntity(entity); // KCauldron
// Cauldron end
if (entity instanceof net.minecraft.entity.EntityLiving) {
equipment = new CraftEntityEquipment(this);

View File

@ -55,6 +55,7 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerRegisterChannelEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerUnregisterChannelEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.InventoryView.Property;
import org.bukkit.map.MapView;
import org.bukkit.metadata.MetadataValue;
@ -503,7 +504,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (fromWorld == toWorld) {
entity.playerNetServerHandler.teleport(to);
} else {
server.getHandle().respawnPlayer(entity, toWorld.dimension, false, to, cause); // Cauldron
server.getHandle().respawnPlayer(entity, toWorld.dimension, cause, to); // Cauldron
}
return true;
}
@ -1324,7 +1325,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
{
if ( getHealth() <= 0 && isOnline() )
{
server.getServer().getConfigurationManager().respawnPlayer( getHandle(), 0, false );
server.getServer().getConfigurationManager().respawnPlayer( getHandle(), 0, TeleportCause.DEATH, null );
}
}

View File

@ -17,15 +17,11 @@ import org.bukkit.Material;
public class CraftInventory implements Inventory {
protected net.minecraft.inventory.IInventory inventory;
protected final net.minecraft.inventory.IInventory inventory;
public CraftInventory(net.minecraft.inventory.IInventory inventory) {
this.inventory = inventory;
}
public void updateInventory(net.minecraft.inventory.IInventory inventory) {
this.inventory = inventory;
}
public net.minecraft.inventory.IInventory getInventory() {
return inventory;

View File

@ -11,7 +11,7 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
public CraftInventoryPlayer(net.minecraft.entity.player.InventoryPlayer inventory) {
super(inventory);
}
@Override
public net.minecraft.entity.player.InventoryPlayer getInventory() {
return (net.minecraft.entity.player.InventoryPlayer) inventory;