Essentials/Essentials/src/main/java/com/earth2me/essentials/IUser.java

338 lines
9.2 KiB
Java
Raw Normal View History

package com.earth2me.essentials;
Reduce sync loads for teleporting (#3102) This PR reduces the number of sync loads occurring on any teleport caused by essentials. Fixes #2861 Fixes #2287 Fixes #3274 Fixes #3201 Fixes #2120 Before this PR, essentials would get a block multiple times causing sync loads to check if it was safe to teleport to. Now, the target block's chunk if fetched async with PaperLib and passed along to `LocationUtil#isBlockUnsafeForUser` (which internally calls other LocationUtil methods what that chunk object) resulting in the chunk only loading once, off the main thread. The only operations remaining on the main thread is `LocationUtil#getSafeDestination`. This is due to the method's recursion which would be a pain to move async. **However:** since the chunk was already loaded async, `LocationUtil#getSafeDestination` most of the time won't cause sync chunk loads. The only time it would cause sync chunk loads is with an unsafe location near a chunk border. ----------------------------------------- * Reduce sync teleporting loads * Avoid argument re-assigning * Remove async teleports when unnecessary * Make exceptions cleaner * Async all the things Made an async version of every method with fallbacks for deprecated methods. * Remove old now fallback method * Migrate everything to the new async teleport API * Update ITeleport javadocs * Fix invoking via async context * Fix /jail using deprecated method * Fix jail join handler using deprecated method * Rename all teleport classes to indicate async * Remove deprecated methods * Add (and deprecate) old teleport api * Revert TimedTeleport.java * Reduce Diff * Add legacy sendToJail method * Reduce Diff Further * Use getNewExceptionFuture in Commandtpo * Use getNewExceptionFuture everywhere * Fix even more usages * Revert LocationUtil.java * Fix issue causing unsafe locations to not work properly * Add deprecated notice in IUser implementation * Use CompletableFuture#completeExceptionally for exceptions * Use Essentials' logger in EssentialsCommand#showError * Return implementation rather than interface * Avoid possible deadlocks with entity ejections * Nuke some sync loads with homes Took 7 hours and 2 PRs to paper but it's here! * Fix ABI and make the codestyle worse * Make the codestyle worse because muh diff * Further ruin the codestyle * Fix error messages not showing in TimedTeleports * Improve messages around beds for /home * Fix #3274 Allow unsafe locations for different worlds + spectator mode * Fix fly safety operators
2020-06-24 10:52:25 +02:00
import com.earth2me.essentials.api.IAsyncTeleport;
import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.config.entities.CommandCooldown;
import net.ess3.api.ITeleport;
import net.ess3.api.MaxMoneyException;
2020-03-13 03:08:11 +01:00
import net.ess3.api.events.AfkStatusChangeEvent;
import net.essentialsx.api.v2.services.mail.MailMessage;
import net.essentialsx.api.v2.services.mail.MailSender;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.Nullable;
2015-04-15 06:06:16 +02:00
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
2015-04-15 06:06:16 +02:00
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
2015-04-15 06:06:16 +02:00
2020-10-04 18:03:52 +02:00
/**
* Provides access to the user abstraction and stored data. Maintainers should add methods to <i>this interface</i>.
*
* @deprecated External plugins should use {@link net.ess3.api.IUser} instead of this interface, in case future APIs are added.
*/
@Deprecated
2015-04-15 06:06:16 +02:00
public interface IUser {
boolean isAuthorized(String node);
2015-04-15 06:06:16 +02:00
boolean isAuthorized(IEssentialsCommand cmd);
2015-04-15 06:06:16 +02:00
boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix);
boolean isPermissionSet(String node);
2015-04-15 06:06:16 +02:00
void healCooldown() throws Exception;
2015-04-15 06:06:16 +02:00
void giveMoney(BigDecimal value) throws MaxMoneyException;
2015-04-15 06:06:16 +02:00
void giveMoney(final BigDecimal value, final CommandSource initiator) throws MaxMoneyException;
2015-04-15 06:06:16 +02:00
void payUser(final User reciever, final BigDecimal value) throws Exception;
2015-04-15 06:06:16 +02:00
void takeMoney(BigDecimal value);
2015-04-15 06:06:16 +02:00
void takeMoney(final BigDecimal value, final CommandSource initiator);
2015-04-15 06:06:16 +02:00
boolean canAfford(BigDecimal value);
Boolean canSpawnItem(final Material material);
2015-04-15 06:06:16 +02:00
void setLastLocation();
2015-04-15 06:06:16 +02:00
void setLogoutLocation();
2015-04-15 06:06:16 +02:00
void requestTeleport(final User player, final boolean here);
2013-07-14 13:41:27 +02:00
/**
* Returns whether this user has an outstanding teleport request to deal with.
*
* @deprecated The teleport request system has been moved into a multi-user teleport request queue.
* @see IUser#hasPendingTpaRequests(boolean, boolean)
* @return whether there is a teleport request
*/
@Deprecated
boolean hasOutstandingTeleportRequest();
Reduce sync loads for teleporting (#3102) This PR reduces the number of sync loads occurring on any teleport caused by essentials. Fixes #2861 Fixes #2287 Fixes #3274 Fixes #3201 Fixes #2120 Before this PR, essentials would get a block multiple times causing sync loads to check if it was safe to teleport to. Now, the target block's chunk if fetched async with PaperLib and passed along to `LocationUtil#isBlockUnsafeForUser` (which internally calls other LocationUtil methods what that chunk object) resulting in the chunk only loading once, off the main thread. The only operations remaining on the main thread is `LocationUtil#getSafeDestination`. This is due to the method's recursion which would be a pain to move async. **However:** since the chunk was already loaded async, `LocationUtil#getSafeDestination` most of the time won't cause sync chunk loads. The only time it would cause sync chunk loads is with an unsafe location near a chunk border. ----------------------------------------- * Reduce sync teleporting loads * Avoid argument re-assigning * Remove async teleports when unnecessary * Make exceptions cleaner * Async all the things Made an async version of every method with fallbacks for deprecated methods. * Remove old now fallback method * Migrate everything to the new async teleport API * Update ITeleport javadocs * Fix invoking via async context * Fix /jail using deprecated method * Fix jail join handler using deprecated method * Rename all teleport classes to indicate async * Remove deprecated methods * Add (and deprecate) old teleport api * Revert TimedTeleport.java * Reduce Diff * Add legacy sendToJail method * Reduce Diff Further * Use getNewExceptionFuture in Commandtpo * Use getNewExceptionFuture everywhere * Fix even more usages * Revert LocationUtil.java * Fix issue causing unsafe locations to not work properly * Add deprecated notice in IUser implementation * Use CompletableFuture#completeExceptionally for exceptions * Use Essentials' logger in EssentialsCommand#showError * Return implementation rather than interface * Avoid possible deadlocks with entity ejections * Nuke some sync loads with homes Took 7 hours and 2 PRs to paper but it's here! * Fix ABI and make the codestyle worse * Make the codestyle worse because muh diff * Further ruin the codestyle * Fix error messages not showing in TimedTeleports * Improve messages around beds for /home * Fix #3274 Allow unsafe locations for different worlds + spectator mode * Fix fly safety operators
2020-06-24 10:52:25 +02:00
/**
* @deprecated This API is not asynchronous. Use {@link com.earth2me.essentials.api.IAsyncTeleport IAsyncTeleport} with {@link IUser#getAsyncTeleport()}
*/
@Deprecated
2015-04-15 06:06:16 +02:00
ITeleport getTeleport();
2013-07-14 13:41:27 +02:00
Reduce sync loads for teleporting (#3102) This PR reduces the number of sync loads occurring on any teleport caused by essentials. Fixes #2861 Fixes #2287 Fixes #3274 Fixes #3201 Fixes #2120 Before this PR, essentials would get a block multiple times causing sync loads to check if it was safe to teleport to. Now, the target block's chunk if fetched async with PaperLib and passed along to `LocationUtil#isBlockUnsafeForUser` (which internally calls other LocationUtil methods what that chunk object) resulting in the chunk only loading once, off the main thread. The only operations remaining on the main thread is `LocationUtil#getSafeDestination`. This is due to the method's recursion which would be a pain to move async. **However:** since the chunk was already loaded async, `LocationUtil#getSafeDestination` most of the time won't cause sync chunk loads. The only time it would cause sync chunk loads is with an unsafe location near a chunk border. ----------------------------------------- * Reduce sync teleporting loads * Avoid argument re-assigning * Remove async teleports when unnecessary * Make exceptions cleaner * Async all the things Made an async version of every method with fallbacks for deprecated methods. * Remove old now fallback method * Migrate everything to the new async teleport API * Update ITeleport javadocs * Fix invoking via async context * Fix /jail using deprecated method * Fix jail join handler using deprecated method * Rename all teleport classes to indicate async * Remove deprecated methods * Add (and deprecate) old teleport api * Revert TimedTeleport.java * Reduce Diff * Add legacy sendToJail method * Reduce Diff Further * Use getNewExceptionFuture in Commandtpo * Use getNewExceptionFuture everywhere * Fix even more usages * Revert LocationUtil.java * Fix issue causing unsafe locations to not work properly * Add deprecated notice in IUser implementation * Use CompletableFuture#completeExceptionally for exceptions * Use Essentials' logger in EssentialsCommand#showError * Return implementation rather than interface * Avoid possible deadlocks with entity ejections * Nuke some sync loads with homes Took 7 hours and 2 PRs to paper but it's here! * Fix ABI and make the codestyle worse * Make the codestyle worse because muh diff * Further ruin the codestyle * Fix error messages not showing in TimedTeleports * Improve messages around beds for /home * Fix #3274 Allow unsafe locations for different worlds + spectator mode * Fix fly safety operators
2020-06-24 10:52:25 +02:00
IAsyncTeleport getAsyncTeleport();
2015-04-15 06:06:16 +02:00
BigDecimal getMoney();
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
void setMoney(final BigDecimal value) throws MaxMoneyException;
2013-07-14 13:41:27 +02:00
2020-03-13 03:08:11 +01:00
void setAfk(final boolean set, final AfkStatusChangeEvent.Cause cause);
2015-04-15 06:06:16 +02:00
/**
* 'Hidden' Represents when a player is hidden from others. This status includes when the player is hidden via other
* supported plugins. Use isVanished() if you want to check if a user is vanished by Essentials.
*
* @return If the user is hidden or not
* @see IUser#isVanished()
2015-04-15 06:06:16 +02:00
*/
boolean isHidden();
/**
* Whether the user was hidden before leaving the server.
*
* @return true if the user was hidden.
*/
boolean isLeavingHidden();
void setLeavingHidden(boolean leavingHidden);
2015-04-15 06:06:16 +02:00
void setHidden(boolean vanish);
2015-04-15 06:06:16 +02:00
boolean isGodModeEnabled();
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
String getGroup();
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
boolean inGroup(final String group);
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
boolean canBuild();
2013-07-14 13:41:27 +02:00
/**
* @deprecated The teleport request system has been moved into a multi-user teleport request queue.
* @see IUser#getNextTpaRequest(boolean, boolean, boolean)
*/
@Deprecated
2015-04-15 06:06:16 +02:00
long getTeleportRequestTime();
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
void enableInvulnerabilityAfterTeleport();
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
void resetInvulnerabilityAfterTeleport();
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
boolean hasInvulnerabilityAfterTeleport();
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
/**
* 'Vanished' Represents when a player is hidden from others by Essentials. This status does NOT include when the
* player is hidden via other plugins. Use isHidden() if you want to check if a user is vanished by any supported
* plugin.
*
* @return If the user is vanished or not
* @see IUser#isHidden()
2015-04-15 06:06:16 +02:00
*/
boolean isVanished();
2015-04-15 06:06:16 +02:00
void setVanished(boolean vanish);
2015-04-15 06:06:16 +02:00
boolean isIgnoreExempt();
2015-06-03 22:11:56 +02:00
void sendMessage(String message);
2015-04-15 06:06:16 +02:00
/*
* UserData
*/
Location getHome(String name) throws Exception;
2015-04-15 06:06:16 +02:00
Location getHome(Location loc) throws Exception;
2015-04-15 06:06:16 +02:00
List<String> getHomes();
2015-04-15 06:06:16 +02:00
void setHome(String name, Location loc);
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
void delHome(String name) throws Exception;
2015-04-15 06:06:16 +02:00
boolean hasHome();
2015-04-15 06:06:16 +02:00
Location getLastLocation();
2015-04-15 06:06:16 +02:00
Location getLogoutLocation();
2015-04-15 06:06:16 +02:00
long getLastTeleportTimestamp();
2013-07-14 13:41:27 +02:00
2015-04-15 06:06:16 +02:00
void setLastTeleportTimestamp(long time);
2015-04-15 06:06:16 +02:00
String getJail();
2015-04-15 06:06:16 +02:00
void setJail(String jail);
String getFormattedJailTime();
@Deprecated
2015-04-15 06:06:16 +02:00
List<String> getMails();
@Deprecated
2015-04-15 06:06:16 +02:00
void addMail(String mail);
void sendMail(MailSender sender, String message);
void sendMail(MailSender sender, String message, long expireAt);
ArrayList<MailMessage> getMailMessages();
void setMailList(ArrayList<MailMessage> messages);
int getMailAmount();
2015-04-15 06:06:16 +02:00
boolean isAfk();
2020-10-03 19:46:05 +02:00
@Deprecated
void setAfk(final boolean set);
2015-07-29 03:45:33 +02:00
boolean isIgnoreMsg();
2020-10-03 19:46:05 +02:00
void setIgnoreMsg(boolean ignoreMsg);
@Deprecated
2015-04-15 06:06:16 +02:00
void setConfigProperty(String node, Object object);
2015-04-15 06:06:16 +02:00
Set<String> getConfigKeys();
2015-04-15 06:06:16 +02:00
Map<String, Object> getConfigMap();
2015-04-15 06:06:16 +02:00
Map<String, Object> getConfigMap(String node);
2020-10-03 19:46:05 +02:00
@Deprecated
Map<Pattern, Long> getCommandCooldowns();
List<CommandCooldown> getCooldownsList();
Date getCommandCooldownExpiry(String label);
2020-10-03 19:46:05 +02:00
void addCommandCooldown(Pattern pattern, Date expiresAt, boolean save);
2020-10-03 19:46:05 +02:00
boolean clearCommandCooldown(Pattern pattern);
2015-04-15 06:06:16 +02:00
/*
* PlayerExtension
*/
Player getBase();
2015-04-15 06:06:16 +02:00
CommandSource getSource();
2015-06-03 22:11:56 +02:00
String getName();
2016-06-18 22:38:20 +02:00
UUID getUUID();
String getDisplayName();
2021-03-29 19:07:55 +02:00
String getFormattedNickname();
String getAfkMessage();
void setAfkMessage(final String message);
2020-10-03 19:46:05 +02:00
long getAfkSince();
2020-10-03 19:46:05 +02:00
boolean isAcceptingPay();
2020-10-03 19:46:05 +02:00
void setAcceptingPay(boolean acceptingPay);
2020-10-03 19:46:05 +02:00
boolean isPromptingPayConfirm();
2020-10-03 19:46:05 +02:00
void setPromptingPayConfirm(boolean prompt);
2020-10-03 19:46:05 +02:00
boolean isPromptingClearConfirm();
2020-10-03 19:46:05 +02:00
void setPromptingClearConfirm(boolean prompt);
boolean isLastMessageReplyRecipient();
void setLastMessageReplyRecipient(boolean enabled);
Map<User, BigDecimal> getConfirmingPayments();
Block getTargetBlock(int maxDistance);
void setToggleShout(boolean toggleShout);
boolean isToggleShout();
/**
* Gets information about the most-recently-made, non-expired TPA request in the tpa queue of this {@link IUser}.
* <p>
* The TPA Queue is Last-In-First-Out queue which stores all the active pending teleport
* requests of this {@link IUser}. Timeout calculations are also done during the
* iteration process of this method, ensuring that teleport requests made past the timeout
* period are removed from queue and therefore not returned here. The maximum size of this
* queue is determined by {@link ISettings#getTpaMaxRequests()}.
*
* @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration.
* @param ignoreExpirations true if this method should not process expirations for the entire queue and stop execution on the first unexpired request.
* @param excludeHere true if /tphere requests should be ignored in fetching the next tpa request.
* @return A {@link TpaRequest} corresponding to the next available request or null if no valid request is present.
*/
@Nullable TpaRequest getNextTpaRequest(boolean inform, boolean ignoreExpirations, boolean excludeHere);
/**
* Whether or not this {@link IUser} has any valid TPA requests in queue.
*
* @param inform true if the user should be informed if a request expires during iteration.
* @param excludeHere true if /tpahere requests should be ignored in checking if a tpa request is available.
* @return true if the user has an available pending request in queue.
*/
boolean hasPendingTpaRequests(boolean inform, boolean excludeHere);
class TpaRequest {
private final String name;
private final UUID requesterUuid;
private boolean here;
private Location location;
private long time;
public TpaRequest(String name, UUID requesterUuid) {
this.name = name;
this.requesterUuid = requesterUuid;
}
public String getName() {
return name;
}
public UUID getRequesterUuid() {
return requesterUuid;
}
public boolean isHere() {
return here;
}
public void setHere(boolean here) {
this.here = here;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
}
List<String> getPastUsernames();
void addPastUsername(String username);
}