use of net.blay09.mods.waystones.network.message.MessageSortWaystone 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();
}
}
use of net.blay09.mods.waystones.network.message.MessageSortWaystone 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;
}
Aggregations