mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 09:08:01 +01:00
* Attempts to implement #1682 - TPARequestEvent Awaiting further feedback. I've implemented the event, and elected to send a message to the requester of the TPA when the event gets cancelled. * Fix formatting * Fix up l18s errors, remove todos * Clean up for merge
This commit is contained in:
parent
a08832cfc8
commit
e4cc78a750
@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Teleport;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.events.TPARequestEvent;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
@ -35,7 +36,7 @@ public class Commandtpa extends EssentialsCommand {
|
||||
}
|
||||
// Don't let sender request teleport twice to the same player.
|
||||
if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout
|
||||
&& player.isTpRequestHere() == false) { // Make sure the last teleport request was actually tpa and not tpahere
|
||||
&& !player.isTpRequestHere()) { // Make sure the last teleport request was actually tpa and not tpahere
|
||||
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
|
||||
}
|
||||
if (player.isAutoTeleportEnabled() && !player.isIgnoredPlayer(user)) {
|
||||
@ -49,6 +50,11 @@ public class Commandtpa extends EssentialsCommand {
|
||||
}
|
||||
|
||||
if (!player.isIgnoredPlayer(user)) {
|
||||
TPARequestEvent tpaEvent = new TPARequestEvent(user.getSource(), player, false);
|
||||
ess.getServer().getPluginManager().callEvent(tpaEvent);
|
||||
if (tpaEvent.isCancelled()) {
|
||||
throw new Exception(tl("teleportRequestCancelled", player.getDisplayName()));
|
||||
}
|
||||
player.requestTeleport(user, false);
|
||||
player.sendMessage(tl("teleportRequest", user.getDisplayName()));
|
||||
player.sendMessage(tl("typeTpaccept"));
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.events.TPARequestEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -42,6 +43,12 @@ public class Commandtpaall extends EssentialsCommand {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
TPARequestEvent tpaEvent = new TPARequestEvent(sender, player, true);
|
||||
ess.getServer().getPluginManager().callEvent(tpaEvent);
|
||||
if (tpaEvent.isCancelled()) {
|
||||
sender.sendMessage(tl("teleportRequestCancelled", player.getDisplayName()));
|
||||
continue;
|
||||
}
|
||||
player.requestTeleport(target, true);
|
||||
player.sendMessage(tl("teleportHereRequest", target.getDisplayName()));
|
||||
player.sendMessage(tl("typeTpaccept"));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.events.TPARequestEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -32,10 +33,15 @@ public class Commandtpahere extends EssentialsCommand {
|
||||
}
|
||||
// Don't let sender request teleport twice to the same player.
|
||||
if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout
|
||||
&& player.isTpRequestHere() == true) { // Make sure the last teleport request was actually tpahere and not tpa
|
||||
&& player.isTpRequestHere()) { // Make sure the last teleport request was actually tpahere and not tpa
|
||||
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
|
||||
}
|
||||
if (!player.isIgnoredPlayer(user)) {
|
||||
TPARequestEvent tpaEvent = new TPARequestEvent(user.getSource(), player, true);
|
||||
ess.getServer().getPluginManager().callEvent(tpaEvent);
|
||||
if (tpaEvent.isCancelled()) {
|
||||
throw new Exception(tl("teleportRequestCancelled", player.getDisplayName()));
|
||||
}
|
||||
player.requestTeleport(user, true);
|
||||
player.sendMessage(tl("teleportHereRequest", user.getDisplayName()));
|
||||
player.sendMessage(tl("typeTpaccept"));
|
||||
|
@ -517,6 +517,7 @@ teleportInvalidLocation=Value of coordinates cannot be over 30000000
|
||||
teleportNewPlayerError=\u00a74Failed to teleport new player\!
|
||||
teleportRequest=\u00a7c{0}\u00a76 has requested to teleport to you.
|
||||
teleportRequestAllCancelled=\u00a76All outstanding teleport requests cancelled.
|
||||
teleportRequestCancelled=\u00a76Your teleport request to \u00a7c{0}\u00a76 was cancelled.
|
||||
teleportRequestSpecificCancelled=\u00a76Outstanding teleport request with\u00a7c {0}\u00a76 cancelled.
|
||||
teleportRequestTimeoutInfo=\u00a76This request will timeout after\u00a7c {0} seconds\u00a76.
|
||||
teleportTop=\u00a76Teleporting to top.
|
||||
|
53
Essentials/src/net/ess3/api/events/TPARequestEvent.java
Normal file
53
Essentials/src/net/ess3/api/events/TPARequestEvent.java
Normal file
@ -0,0 +1,53 @@
|
||||
package net.ess3.api.events;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
public class TPARequestEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private CommandSource requester;
|
||||
private IUser target;
|
||||
private boolean cancelled = false, requestToTPAHere = false;
|
||||
|
||||
public TPARequestEvent(CommandSource requester, IUser target, boolean tpaHere) {
|
||||
super();
|
||||
this.requester = requester;
|
||||
this.target = target;
|
||||
this.requestToTPAHere = tpaHere;
|
||||
}
|
||||
|
||||
public CommandSource getRequester() {
|
||||
return requester;
|
||||
}
|
||||
|
||||
public IUser getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public boolean isTeleportHere() {
|
||||
return requestToTPAHere;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user