Search in sources :

Example 1 with MessageRemoveWaystone

use of net.blay09.mods.waystones.network.message.MessageRemoveWaystone 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 2 with MessageRemoveWaystone

use of net.blay09.mods.waystones.network.message.MessageRemoveWaystone 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)2 Nullable (javax.annotation.Nullable)1 PlayerWaystoneData (net.blay09.mods.waystones.PlayerWaystoneData)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