Search in sources :

Example 1 with PlayerWaystoneData

use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.

the class PlayerWaystoneData method fromPlayer.

public static PlayerWaystoneData fromPlayer(EntityPlayer player) {
    NBTTagCompound tagCompound = PlayerWaystoneHelper.getWaystonesTag(player);
    NBTTagList tagList = tagCompound.getTagList(PlayerWaystoneHelper.WAYSTONE_LIST, Constants.NBT.TAG_COMPOUND);
    WaystoneEntry[] entries = new WaystoneEntry[tagList.tagCount()];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = WaystoneEntry.read(tagList.getCompoundTagAt(i));
    }
    long lastFreeWarp = tagCompound.getLong(PlayerWaystoneHelper.LAST_FREE_WARP);
    long lastWarpStoneUse = tagCompound.getLong(PlayerWaystoneHelper.LAST_WARP_STONE_USE);
    return new PlayerWaystoneData(entries, lastFreeWarp, lastWarpStoneUse);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with PlayerWaystoneData

use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.

the class WaystoneManager method sendPlayerWaystones.

public static void sendPlayerWaystones(EntityPlayer player) {
    if (player instanceof EntityPlayerMP) {
        PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(player);
        NetworkHandler.channel.sendTo(new MessageWaystones(waystoneData.getWaystones(), waystoneData.getLastFreeWarp(), waystoneData.getLastWarpStoneUse()), (EntityPlayerMP) player);
    }
}
Also used : MessageWaystones(net.blay09.mods.waystones.network.message.MessageWaystones) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 3 with PlayerWaystoneData

use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.

the class HandlerRemoveWaystone method onMessage.

@Override
@Nullable
public IMessage onMessage(final MessageRemoveWaystone message, final MessageContext ctx) {
    NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
        PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(ctx.getServerHandler().player);
        WaystoneEntry[] entries = waystoneData.getWaystones();
        int index = message.getIndex();
        if (index < 0 || index >= entries.length) {
            return;
        }
        WaystoneManager.removePlayerWaystone(ctx.getServerHandler().player, entries[index]);
        WaystoneManager.sendPlayerWaystones(ctx.getServerHandler().player);
    });
    return null;
}
Also used : PlayerWaystoneData(net.blay09.mods.waystones.PlayerWaystoneData) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) Nullable(javax.annotation.Nullable)

Example 4 with PlayerWaystoneData

use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.

the class CommonProxy method onPlayerLoggedIn.

@SubscribeEvent
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
    GlobalWaystones globalWaystones = GlobalWaystones.get(event.player.world);
    PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(event.player);
    List<WaystoneEntry> validWaystones = Lists.newArrayList();
    for (WaystoneEntry waystone : waystoneData.getWaystones()) {
        if (waystone.isGlobal()) {
            if (globalWaystones.getGlobalWaystone(waystone.getName()) == null) {
                continue;
            }
        }
        validWaystones.add(waystone);
    }
    for (WaystoneEntry waystone : globalWaystones.getGlobalWaystones()) {
        if (!validWaystones.contains(waystone)) {
            validWaystones.add(waystone);
        }
    }
    PlayerWaystoneHelper.store(event.player, validWaystones.toArray(new WaystoneEntry[validWaystones.size()]), waystoneData.getLastFreeWarp(), waystoneData.getLastWarpStoneUse());
    NetworkHandler.channel.sendTo(new MessageConfig(), (EntityPlayerMP) event.player);
    WaystoneManager.sendPlayerWaystones(event.player);
}
Also used : MessageConfig(net.blay09.mods.waystones.network.message.MessageConfig) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with PlayerWaystoneData

use of net.blay09.mods.waystones.PlayerWaystoneData in project Waystones by blay09.

the class HandlerSortWaystone method onMessage.

@Override
@Nullable
public IMessage onMessage(final MessageSortWaystone message, final MessageContext ctx) {
    NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
        PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(ctx.getServerHandler().player);
        WaystoneEntry[] entries = waystoneData.getWaystones();
        int index = message.getIndex();
        int otherIndex = message.getOtherIndex();
        if (index < 0 || index >= entries.length || otherIndex < 0 || otherIndex >= entries.length) {
            return;
        }
        WaystoneEntry swap = entries[index];
        entries[index] = entries[otherIndex];
        entries[otherIndex] = swap;
        waystoneData.store(ctx.getServerHandler().player);
        WaystoneManager.sendPlayerWaystones(ctx.getServerHandler().player);
    });
    return null;
}
Also used : PlayerWaystoneData(net.blay09.mods.waystones.PlayerWaystoneData) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) Nullable(javax.annotation.Nullable)

Aggregations

WaystoneEntry (net.blay09.mods.waystones.util.WaystoneEntry)4 Nullable (javax.annotation.Nullable)2 PlayerWaystoneData (net.blay09.mods.waystones.PlayerWaystoneData)2 MessageConfig (net.blay09.mods.waystones.network.message.MessageConfig)1 MessageWaystones (net.blay09.mods.waystones.network.message.MessageWaystones)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1