use of cavern.api.IPlayerData in project Cavern2 by kegare.
the class CaveEventHooks method onPlayerSleepInBed.
@SubscribeEvent
public void onPlayerSleepInBed(PlayerSleepInBedEvent event) {
EntityPlayer player = event.getEntityPlayer();
if (!CavernAPI.dimension.isInCaveDimensions(player)) {
return;
}
SleepResult result = null;
World world = player.world;
if (!world.isRemote) {
IPlayerData data = PlayerData.get(player);
long worldTime = world.getTotalWorldTime();
long sleepTime = data.getLastSleepTime();
if (sleepTime <= 0L) {
sleepTime = worldTime;
data.setLastSleepTime(sleepTime);
}
long requireTime = GeneralConfig.sleepWaitTime * 20;
if (sleepTime + requireTime > worldTime) {
result = SleepResult.OTHER_PROBLEM;
long remainTime = requireTime - (worldTime - sleepTime);
int min = MathHelper.ceil(remainTime / 20 / 60 + 1);
player.sendStatusMessage(new TextComponentTranslation("cavern.message.sleep.still", min), true);
}
}
if (result == null) {
result = PlayerHelper.trySleep(player, event.getPos());
}
if (!world.isRemote && result == SleepResult.OK) {
PlayerData.get(player).setLastSleepTime(world.getTotalWorldTime());
}
event.setResult(result);
}
use of cavern.api.IPlayerData in project Cavern2 by kegare.
the class CaveCapabilities method onPlayerClone.
@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone event) {
EntityPlayer player = event.getEntityPlayer();
if (player.world.isRemote) {
return;
}
EntityPlayer original = event.getOriginal();
IPortalCache originalPortalCache = getCapability(original, PORTAL_CACHE);
IPortalCache portalCache = getCapability(player, PORTAL_CACHE);
if (originalPortalCache != null && portalCache != null) {
NBTTagCompound nbt = new NBTTagCompound();
originalPortalCache.writeToNBT(nbt);
portalCache.readFromNBT(nbt);
}
IPlayerData originalPlayerData = getCapability(original, PLAYER_DATA);
IPlayerData playerData = getCapability(player, PLAYER_DATA);
if (originalPlayerData != null && playerData != null) {
NBTTagCompound nbt = new NBTTagCompound();
originalPlayerData.writeToNBT(nbt);
playerData.readFromNBT(nbt);
}
IMinerStats originalMinerStats = getCapability(original, MINER_STATS);
IMinerStats minerStats = getCapability(player, MINER_STATS);
if (originalMinerStats != null && minerStats != null) {
NBTTagCompound nbt = new NBTTagCompound();
originalMinerStats.writeToNBT(nbt);
minerStats.readFromNBT(nbt);
}
}
Aggregations