Improved fake player handling of offline players
This commit is contained in:
parent
154ea3f6b5
commit
bcead39bf0
2 changed files with 39 additions and 16 deletions
|
@ -11,6 +11,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
|
@ -20,6 +21,7 @@ import net.minecraftforge.common.util.FakePlayerFactory;
|
|||
import net.minecraftforge.event.world.BlockEvent;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public abstract class CommonProxy {
|
||||
|
@ -36,7 +38,20 @@ public abstract class CommonProxy {
|
|||
// client side only
|
||||
}
|
||||
|
||||
private EntityPlayer getFakePlayer(EntityPlayer entityPlayer, WorldServer world, int x, int y, int z) {
|
||||
private static EntityPlayerMP getPlayer(final UUID uuidPlayer) {
|
||||
for (Object object : MinecraftServer.getServer().getConfigurationManager().playerEntityList) {
|
||||
if (object instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) object;
|
||||
if (entityPlayerMP.getUniqueID() == uuidPlayer) {
|
||||
return entityPlayerMP;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static EntityPlayer getFakePlayer(final UUID uuidPlayer, WorldServer world, final double x, final double y, final double z) {
|
||||
EntityPlayer entityPlayer = uuidPlayer == null ? null : getPlayer(uuidPlayer);
|
||||
GameProfile gameProfile = entityPlayer == null ? WarpDrive.gameProfile : entityPlayer.getGameProfile();
|
||||
WeakReference<EntityPlayer> weakFakePlayer = fakePlayers.get(gameProfile);
|
||||
EntityPlayer entityFakePlayer = (weakFakePlayer == null) ? null : weakFakePlayer.get();
|
||||
|
@ -55,13 +70,20 @@ public abstract class CommonProxy {
|
|||
return entityFakePlayer;
|
||||
}
|
||||
|
||||
public boolean isBlockBreakCanceled(EntityPlayer entityPlayer, int sourceX, int sourceY, int sourceZ,
|
||||
World world, int eventX, int eventY, int eventZ) {
|
||||
if (world.isRemote) {
|
||||
public static EntityPlayer getFakePlayer(final UUID uuidPlayer, World world, final double x, final double y, final double z) {
|
||||
if (world.isRemote || !(world instanceof WorldServer)) {
|
||||
return null;
|
||||
}
|
||||
return getFakePlayer(uuidPlayer, (WorldServer) world, x, y, z);
|
||||
}
|
||||
|
||||
public static boolean isBlockBreakCanceled(final UUID uuidPlayer, final int sourceX, final int sourceY, final int sourceZ,
|
||||
World world, final int eventX, final int eventY, final int eventZ) {
|
||||
if (world.isRemote || !(world instanceof WorldServer)) {
|
||||
return false;
|
||||
}
|
||||
if (WarpDriveConfig.LOGGING_BREAK_PLACE) {
|
||||
WarpDrive.logger.info("isBlockBreakCanceled by " + entityPlayer + " at " + sourceX + " " + sourceY + " " + sourceZ
|
||||
WarpDrive.logger.info("isBlockBreakCanceled by " + uuidPlayer + " at " + sourceX + " " + sourceY + " " + sourceZ
|
||||
+ " to " + world.provider.getDimensionName() + " " + eventX + " " + eventY + " " + eventZ);
|
||||
}
|
||||
|
||||
|
@ -69,7 +91,7 @@ public abstract class CommonProxy {
|
|||
if (!block.isAir(world, eventX, eventY, eventZ)) {
|
||||
BlockEvent.BreakEvent breakEvent = new BlockEvent.BreakEvent(eventX, eventY, eventZ, world,
|
||||
world.getBlock(eventX, eventY, eventZ), world.getBlockMetadata(eventX, eventY, eventZ),
|
||||
WarpDrive.proxy.getFakePlayer(entityPlayer, (WorldServer) world, sourceX, sourceY, sourceZ));
|
||||
getFakePlayer(uuidPlayer, (WorldServer) world, sourceX + 0.5D, sourceY + 0.5D, sourceZ + 0.5D));
|
||||
MinecraftForge.EVENT_BUS.post(breakEvent);
|
||||
if (WarpDriveConfig.LOGGING_BREAK_PLACE) {
|
||||
WarpDrive.logger.info("isBlockBreakCanceled player " + breakEvent.getPlayer()
|
||||
|
@ -80,18 +102,18 @@ public abstract class CommonProxy {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean isBlockPlaceCanceled(EntityPlayer entityPlayer, int sourceX, int sourceY, int sourceZ,
|
||||
World world, int eventX, int eventY, int eventZ, Block block, int metadata) {
|
||||
if (world.isRemote) {
|
||||
public static boolean isBlockPlaceCanceled(final UUID uuidPlayer, final int sourceX, final int sourceY, final int sourceZ,
|
||||
World world, final int eventX, final int eventY, final int eventZ, final Block block, final int metadata) {
|
||||
if (world.isRemote || !(world instanceof WorldServer)) {
|
||||
return false;
|
||||
}
|
||||
if (WarpDriveConfig.LOGGING_BREAK_PLACE) {
|
||||
WarpDrive.logger.info("isBlockPlaceCanceled by " + entityPlayer + " at " + sourceX + " " + sourceY + " " + sourceZ
|
||||
WarpDrive.logger.info("isBlockPlaceCanceled by " + uuidPlayer + " at " + sourceX + " " + sourceY + " " + sourceZ
|
||||
+ " to " + world.provider.getDimensionName() + " " + eventX + " " + eventY + " " + eventZ + " of " + Block.blockRegistry.getNameForObject(block) + ":" + metadata);
|
||||
}
|
||||
BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent(
|
||||
new BlockSnapshot(world, eventX, eventY, eventZ, block, metadata), Blocks.air,
|
||||
WarpDrive.proxy.getFakePlayer(entityPlayer, (WorldServer) world, sourceX, sourceY, sourceZ) );
|
||||
getFakePlayer(uuidPlayer, (WorldServer) world, sourceX + 0.5D, sourceY + 0.5D, sourceZ + 0.5D) );
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(placeEvent);
|
||||
if (WarpDriveConfig.LOGGING_BREAK_PLACE) {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package cr0s.warpdrive.block;
|
||||
|
||||
import cr0s.warpdrive.CommonProxy;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockUpdateDetector;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.VectorI;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class TileEntityAbstractBase extends TileEntity implements IBlockUpdateDetector {
|
||||
private boolean isFirstTick = true;
|
||||
|
@ -293,12 +294,12 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
|
|||
|
||||
|
||||
// area protection
|
||||
protected boolean isBlockBreakCanceled(EntityPlayer entityPlayer, World world, int eventX, int eventY, int eventZ) {
|
||||
return WarpDrive.proxy.isBlockBreakCanceled(entityPlayer, xCoord, yCoord, zCoord, world, eventX, eventY, eventZ);
|
||||
protected boolean isBlockBreakCanceled(final UUID uuidPlayer, World world, final int eventX, final int eventY, final int eventZ) {
|
||||
return CommonProxy.isBlockBreakCanceled(uuidPlayer, xCoord, yCoord, zCoord, world, eventX, eventY, eventZ);
|
||||
}
|
||||
|
||||
protected boolean isBlockPlaceCanceled(EntityPlayer entityPlayer, World world, int eventX, int eventY, int eventZ, Block block, int metadata) {
|
||||
return WarpDrive.proxy.isBlockPlaceCanceled(entityPlayer, xCoord, yCoord, zCoord, world, eventX, eventY, eventZ, block, metadata);
|
||||
protected boolean isBlockPlaceCanceled(final UUID uuidPlayer, World world, final int eventX, final int eventY, final int eventZ, final Block block, final int metadata) {
|
||||
return CommonProxy.isBlockPlaceCanceled(uuidPlayer, xCoord, yCoord, zCoord, world, eventX, eventY, eventZ, block, metadata);
|
||||
}
|
||||
|
||||
// saved properties
|
||||
|
|
Loading…
Add table
Reference in a new issue