Search in sources :

Example 6 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.

the class ClientProxy method onDrawScreen.

@SubscribeEvent
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
    if (event.getGui() instanceof GuiInventory && buttonWarp != null && buttonWarp.isHovered()) {
        tmpTooltip.clear();
        long timeSince = System.currentTimeMillis() - PlayerWaystoneHelper.getLastFreeWarp(FMLClientHandler.instance().getClientPlayerEntity());
        int secondsLeft = (int) ((WaystoneConfig.general.teleportButtonCooldown * 1000 - timeSince) / 1000);
        if (WaystoneConfig.general.teleportButtonReturnOnly) {
            tmpTooltip.add(TextFormatting.YELLOW + I18n.format("tooltip.waystones:returnToWaystone"));
            WaystoneEntry lastEntry = PlayerWaystoneHelper.getLastWaystone(FMLClientHandler.instance().getClientPlayerEntity());
            if (lastEntry != null) {
                tmpTooltip.add(TextFormatting.GRAY + I18n.format("tooltip.waystones:boundTo", TextFormatting.DARK_AQUA + lastEntry.getName()));
            } else {
                tmpTooltip.add(TextFormatting.GRAY + I18n.format("tooltip.waystones:boundTo", I18n.format("tooltip.waystones:none")));
            }
            if (secondsLeft > 0) {
                tmpTooltip.add("");
                tmpTooltip.add(TextFormatting.GRAY + I18n.format("tooltip.waystones:cooldownLeft", secondsLeft));
            }
        } else {
            tmpTooltip.add(TextFormatting.YELLOW + I18n.format("tooltip.waystones:openWaystoneMenu"));
            if (secondsLeft > 0) {
                tmpTooltip.add(TextFormatting.GRAY + I18n.format("tooltip.waystones:cooldownLeft", secondsLeft));
            }
        }
        event.getGui().drawHoveringText(tmpTooltip, event.getMouseX(), event.getMouseY());
    }
}
Also used : WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) GuiInventory(net.minecraft.client.gui.inventory.GuiInventory) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.

the class GuiWaystoneList method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    if (button == btnNextPage) {
        pageOffset++;
        updateList();
    } else if (button == btnPrevPage) {
        pageOffset--;
        updateList();
    } else if (button instanceof GuiButtonWaystoneEntry) {
        NetworkHandler.channel.sendToServer(new MessageTeleportToWaystone(((GuiButtonWaystoneEntry) button).getWaystone(), warpMode, hand, fromWaystone));
        mc.displayGuiScreen(null);
    } else if (button instanceof GuiButtonSortWaystone) {
        WaystoneEntry waystoneEntry = ((GuiButtonSortWaystone) button).getWaystone();
        int index = ArrayUtils.indexOf(entries, waystoneEntry);
        int sortDir = ((GuiButtonSortWaystone) button).getSortDir();
        int otherIndex = index + sortDir;
        if (index == -1 || otherIndex < 0 || otherIndex >= entries.length) {
            return;
        }
        WaystoneEntry swap = entries[index];
        entries[index] = entries[otherIndex];
        entries[otherIndex] = swap;
        NetworkHandler.channel.sendToServer(new MessageSortWaystone(index, otherIndex));
        updateList();
    } else if (button instanceof GuiButtonRemoveWaystone) {
        WaystoneEntry waystoneEntry = ((GuiButtonRemoveWaystone) button).getWaystone();
        int index = ArrayUtils.indexOf(entries, waystoneEntry);
        entries = ArrayUtils.remove(entries, index);
        NetworkHandler.channel.sendToServer(new MessageRemoveWaystone(index));
        updateList();
    }
}
Also used : WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) MessageRemoveWaystone(net.blay09.mods.waystones.network.message.MessageRemoveWaystone) MessageTeleportToWaystone(net.blay09.mods.waystones.network.message.MessageTeleportToWaystone) MessageSortWaystone(net.blay09.mods.waystones.network.message.MessageSortWaystone)

Example 8 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.

the class HandlerEditWaystone method onMessage.

@Override
@Nullable
public IMessage onMessage(final MessageEditWaystone message, final MessageContext ctx) {
    NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
        EntityPlayer entityPlayer = ctx.getServerHandler().player;
        if (WaystoneConfig.general.creativeModeOnly && !entityPlayer.capabilities.isCreativeMode) {
            return;
        }
        World world = entityPlayer.getEntityWorld();
        BlockPos pos = message.getPos();
        if (entityPlayer.getDistance(pos.getX(), pos.getY(), pos.getZ()) > 10) {
            return;
        }
        GlobalWaystones globalWaystones = GlobalWaystones.get(ctx.getServerHandler().player.world);
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof TileWaystone) {
            TileWaystone tileWaystone = ((TileWaystone) tileEntity).getParent();
            if (globalWaystones.getGlobalWaystone(tileWaystone.getWaystoneName()) != null && !ctx.getServerHandler().player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
                return;
            }
            if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(ctx.getServerHandler().player)) {
                ctx.getServerHandler().player.sendMessage(new TextComponentTranslation("waystones:notTheOwner"));
                return;
            }
            if (globalWaystones.getGlobalWaystone(message.getName()) != null && !ctx.getServerHandler().player.capabilities.isCreativeMode) {
                ctx.getServerHandler().player.sendMessage(new TextComponentTranslation("waystones:nameOccupied", message.getName()));
                return;
            }
            WaystoneEntry oldWaystone = new WaystoneEntry(tileWaystone);
            globalWaystones.removeGlobalWaystone(oldWaystone);
            tileWaystone.setWaystoneName(message.getName());
            WaystoneEntry newWaystone = new WaystoneEntry(tileWaystone);
            if (message.isGlobal() && (ctx.getServerHandler().player.capabilities.isCreativeMode || WaystoneConfig.general.allowEveryoneGlobal)) {
                tileWaystone.setGlobal(true);
                newWaystone.setGlobal(true);
                globalWaystones.addGlobalWaystone(newWaystone);
                for (Object obj : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers()) {
                    WaystoneManager.sendPlayerWaystones((EntityPlayer) obj);
                }
            }
        }
    });
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) GlobalWaystones(net.blay09.mods.waystones.GlobalWaystones) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) TileWaystone(net.blay09.mods.waystones.block.TileWaystone) Nullable(javax.annotation.Nullable)

Example 9 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.

the class HandlerFreeWarpReturn method onMessage.

@Override
@Nullable
public IMessage onMessage(MessageWarpReturn message, final MessageContext ctx) {
    NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
        if (!WaystoneConfig.general.teleportButton) {
            return;
        }
        EntityPlayer entityPlayer = ctx.getServerHandler().player;
        if (!PlayerWaystoneHelper.canFreeWarp(entityPlayer)) {
            return;
        }
        WaystoneEntry lastWaystone = PlayerWaystoneHelper.getLastWaystone(entityPlayer);
        if (lastWaystone != null && WaystoneManager.teleportToWaystone(entityPlayer, lastWaystone)) {
            PlayerWaystoneHelper.setLastFreeWarp(entityPlayer, System.currentTimeMillis());
        }
        WaystoneManager.sendPlayerWaystones(entityPlayer);
    });
    return null;
}
Also used : WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Nullable(javax.annotation.Nullable)

Example 10 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry 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)

Aggregations

WaystoneEntry (net.blay09.mods.waystones.util.WaystoneEntry)17 Nullable (javax.annotation.Nullable)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 NBTTagList (net.minecraft.nbt.NBTTagList)5 TileWaystone (net.blay09.mods.waystones.block.TileWaystone)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 PlayerWaystoneData (net.blay09.mods.waystones.PlayerWaystoneData)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 GlobalWaystones (net.blay09.mods.waystones.GlobalWaystones)1 GuiWaystoneList (net.blay09.mods.waystones.client.gui.GuiWaystoneList)1 MessageConfig (net.blay09.mods.waystones.network.message.MessageConfig)1 MessageRemoveWaystone (net.blay09.mods.waystones.network.message.MessageRemoveWaystone)1 MessageSortWaystone (net.blay09.mods.waystones.network.message.MessageSortWaystone)1 MessageTeleportToWaystone (net.blay09.mods.waystones.network.message.MessageTeleportToWaystone)1 GuiInventory (net.minecraft.client.gui.inventory.GuiInventory)1 ItemStack (net.minecraft.item.ItemStack)1