public static void teleport(EntityPlayerMP player, WarpPoint point) { if (point.getWorld() == null) { DimensionManager.initDimension(point.getDimension()); if (point.getWorld() == null) { ChatOutputHandler.chatError( player, Translator.translate("Unable to teleport! Target dimension does not exist")); return; } } // Check permissions UserIdent ident = UserIdent.get(player); if (!APIRegistry.perms.checkPermission(player, TELEPORT_FROM)) throw new TranslatedCommandException("You are not allowed to teleport from here."); if (!APIRegistry.perms.checkUserPermission(ident, point.toWorldPoint(), TELEPORT_TO)) throw new TranslatedCommandException("You are not allowed to teleport to that location."); if (player.dimension != point.getDimension() && !APIRegistry.perms.checkUserPermission(ident, point.toWorldPoint(), TELEPORT_CROSSDIM)) throw new TranslatedCommandException("You are not allowed to teleport across dimensions."); // Get and check teleport cooldown int teleportCooldown = ServerUtil.parseIntDefault( APIRegistry.perms.getUserPermissionProperty(ident, TELEPORT_COOLDOWN), 0) * 1000; if (teleportCooldown > 0) { PlayerInfo pi = PlayerInfo.get(player); long cooldownDuration = (pi.getLastTeleportTime() + teleportCooldown) - System.currentTimeMillis(); if (cooldownDuration >= 0) { ChatOutputHandler.chatNotification( player, Translator.format("Cooldown still active. %d seconds to go.", cooldownDuration / 1000)); return; } } // Get and check teleport warmup int teleportWarmup = ServerUtil.parseIntDefault( APIRegistry.perms.getUserPermissionProperty(ident, TELEPORT_WARMUP), 0); if (teleportWarmup <= 0) { checkedTeleport(player, point); return; } if (!canTeleportTo(point)) { ChatOutputHandler.chatError( player, Translator.translate("Unable to teleport! Target location obstructed.")); return; } // Setup timed teleport tpInfos.put(player.getPersistentID(), new TeleportInfo(player, point, teleportWarmup * 1000)); ChatOutputHandler.chatNotification( player, Translator.format( "Teleporting. Please stand still for %s.", ChatOutputHandler.formatTimeDurationReadable(teleportWarmup, true))); }
public static void checkedTeleport(EntityPlayerMP player, WarpPoint point) { if (!canTeleportTo(point)) { ChatOutputHandler.chatError( player, Translator.translate("Unable to teleport! Target location obstructed.")); return; } PlayerInfo pi = PlayerInfo.get(player); pi.setLastTeleportOrigin(new WarpPoint(player)); pi.setLastTeleportTime(System.currentTimeMillis()); pi.setLastDeathLocation(null); doTeleport(player, point); }
@Override public void error(String message) { if (!isTabCompletion) ChatOutputHandler.chatError(sender, "Error: " + message); }