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());
}
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations