use of com.easterlyn.util.Request in project Easterlyn by Easterlyn.
the class Transportalizer method getFailureMessage.
@Nullable
private String getFailureMessage(Player player, Entity entity, boolean push, Location from, Location to, ConfigurationSection storage, int cost) {
if (push && entity instanceof Player) {
// Sender must have button access to send players
if (!ProtectionUtil.canUseButtonsAt(player, to)) {
return ChatColor.RED + "You do not have access to the location specified!";
}
return null;
}
if (!push && entity instanceof Player) {
RegisteredServiceProvider<EasterlynCore> registration = getMachines().getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return "Easterlyn core plugin not loaded! Cannot pull players.";
}
if (player.getUniqueId().equals(entity.getUniqueId())) {
return null;
}
User target = registration.getProvider().getUserManager().getUser(entity.getUniqueId());
User issuer = registration.getProvider().getUserManager().getUser(player.getUniqueId());
if (target.setPendingRequest(new Request() {
@Override
public void accept() {
if (getFuel(storage) < cost) {
target.sendMessage("Transportalizer is too low on fuel! Ask " + issuer.getDisplayName() + " to add more!");
}
Player localTarget = target.getPlayer();
if (localTarget == null) {
return;
}
teleport(entity, from, to);
setFuel(storage, getFuel(storage) - cost);
}
@Override
public void decline() {
target.sendMessage("Request declined!");
}
})) {
target.sendMessage(issuer.getUniqueId(), issuer.getDisplayName() + " is requesting to transportalize you!\n" + "Use /accept or /decline to manage the request.");
// Blank message won't actually send, but will preclude immediate transportalization.
return "";
}
return null;
}
// Ender dragon or ender dragon parts
if (entity instanceof ComplexLivingEntity || entity instanceof ComplexEntityPart) {
return ChatColor.RED + "Great effort, but you can't transportalize a dragon.";
}
if (entity instanceof ArmorStand) {
// Armor stand manipulation requires the ability to build
if (!ProtectionUtil.canBuildAt(player, from) || !ProtectionUtil.canBuildAt(player, to)) {
return ChatColor.RED + "You do not have access to the location specified!";
}
return null;
}
if (entity instanceof Monster || entity instanceof Explosive || entity instanceof ExplosiveMinecart) {
// Hostiles, TNT, wither projectiles, fireballs, etc. require build permissions
if (!ProtectionUtil.canOpenChestsAt(player, from) || !ProtectionUtil.canBuildAt(player, to)) {
return ChatColor.RED + "You do not have access to the location specified!";
}
return null;
}
// Generic push/pull requires chest access in send location and full access in arrival location
if (!ProtectionUtil.canOpenChestsAt(player, from) || !ProtectionUtil.canMobsSpawn(to) && !ProtectionUtil.canBuildAt(player, to)) {
return ChatColor.RED + "You do not have access to the location specified!";
}
return null;
}
use of com.easterlyn.util.Request in project Easterlyn by Easterlyn.
the class ManageRequestCommand method accept.
@CommandAlias("accept|yes|y|tpyes|tpaccept")
@Description("{@@sink.module.request.accept.description}")
@CommandCompletion("")
@Syntax("")
@CommandPermission("easterlyn.command.request")
public void accept(@Flags(CoreContexts.SELF) User user) {
Request request = user.pollPendingRequest();
if (request == null) {
core.getLocaleManager().sendMessage(user.getPlayer(), "sink.module.request.error.no_pending");
return;
}
request.accept();
}
use of com.easterlyn.util.Request in project Easterlyn by Easterlyn.
the class ManageRequestCommand method decline.
@CommandAlias("decline|no|n|tpno|tpdeny")
@Description("{@@sink.module.request.decline.description}")
@CommandCompletion("")
@Syntax("")
@CommandPermission("easterlyn.command.request")
public void decline(@Flags(CoreContexts.SELF) User user) {
Request request = user.pollPendingRequest();
if (request == null) {
core.getLocaleManager().sendMessage(user.getPlayer(), "sink.module.request.error.no_pending");
return;
}
request.decline();
}
use of com.easterlyn.util.Request in project Easterlyn by Easterlyn.
the class User method pollPendingRequest.
/**
* Gets and clears the pending request, if any.
*
* @return the Request or null if not present
*/
@Nullable
public Request pollPendingRequest() {
Object stored = tempStore.remove("core.request");
if (!(stored instanceof Request)) {
return null;
}
Request request = (Request) stored;
return request.getExpiry() > System.currentTimeMillis() ? request : null;
}
use of com.easterlyn.util.Request in project Easterlyn by Easterlyn.
the class TeleportRequestCommand method tpRequest.
private void tpRequest(User issuer, User requested, boolean to) {
long nextTPA = issuer.getStorage().getLong(TPREQUEST_COOLDOWN);
if (nextTPA > System.currentTimeMillis()) {
SimpleDateFormat format = new SimpleDateFormat("m:ss");
core.getLocaleManager().sendMessage(issuer.getPlayer(), "sink.module.tprequest.error.cooldown", "{value}", format.format(new Date(nextTPA - System.currentTimeMillis())));
return;
}
issuer.getStorage().set(TPREQUEST_COOLDOWN, System.currentTimeMillis() + sink.getConfig().getLong(CONFIG_IGNORE));
Player issuingPlayer = issuer.getPlayer();
Player requestedPlayer = requested.getPlayer();
if (issuingPlayer == null || requestedPlayer == null) {
core.getLocaleManager().sendMessage(issuingPlayer, "sink.module.tprequest.error.offline");
return;
}
if (requested.setPendingRequest(new Request() {
@Override
public void accept() {
Player localIssuer = issuer.getPlayer();
Player localRequested = requested.getPlayer();
if (localIssuer == null || localRequested == null) {
core.getLocaleManager().sendMessage(localRequested, "sink.module.tprequest.error.offline");
return;
}
Player destination = to ? localRequested : localIssuer;
Player teleportee = to ? localIssuer : localRequested;
if (teleportee.teleport(destination.getLocation().add(0, 0.1, 0), PlayerTeleportEvent.TeleportCause.PLUGIN)) {
core.getLocaleManager().sendMessage(localRequested, "sink.module.tprequest.common.accept");
core.getLocaleManager().sendMessage(localIssuer, "sink.module.tprequest.common.accepted", "{value}", localRequested.getName());
}
}
@Override
public void decline() {
core.getLocaleManager().sendMessage(requestedPlayer, "sink.module.tprequest.common.decline");
core.getLocaleManager().sendMessage(issuingPlayer, "sink.module.tprequest.common.declined", "{value}", requestedPlayer.getName());
issuer.getStorage().set(TPREQUEST_COOLDOWN, issuer.getStorage().getLong(TPREQUEST_COOLDOWN) - sink.getConfig().getLong(CONFIG_IGNORE) + sink.getConfig().getLong(CONFIG_ACCEPT));
}
})) {
core.getLocaleManager().sendMessage(issuingPlayer, "sink.module.tprequest.common.issued");
String requestMessage = core.getLocaleManager().getValue(to ? "sink.module.tprequest.to.request" : "sink.module.tprequest.pull.request", core.getLocaleManager().getLocale(requestedPlayer), "{value}", issuingPlayer.getName());
requested.sendMessage(issuer.getUniqueId(), requestMessage);
} else {
core.getLocaleManager().sendMessage(issuingPlayer, "sink.module.tprequest.error.popular", "{value}", requestedPlayer.getName());
}
}
Aggregations