Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed Jul 5, 2021
2 parents be8bb92 + 8c8c85d commit 7991c13
Show file tree
Hide file tree
Showing 133 changed files with 18,267 additions and 704 deletions.
2 changes: 1 addition & 1 deletion .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<suppressions>
<suppress files=".*[\\/]test[\\/]java[\\/].*" checks="RequireExplicitVisibilityModifier"/>
<!-- TODO: don't suppress I-prefixed API interfaces under com.earth2me.essentials -->
<suppress files="(com[\\/]earth2me[\\/]essentials[\\/]|net[\\/]ess3[\\/])(?:[^\\/]+$|(?!api)[^\\/]+[\\/])" checks="MissingJavadoc(Method|Type)"/>
<suppress files="(com[\\/]earth2me[\\/]essentials[\\/]|net[\\/]ess3[\\/]|net[\\/]essentialsx[\\/])(?:[^\\/]+$|(?!api)[^\\/]+[\\/])" checks="MissingJavadoc(Method|Type)"/>
</suppressions>
1 change: 1 addition & 0 deletions .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
mv Essentials/build/docs/javadoc/ javadocs/
cp -r EssentialsAntiBuild/build/docs/javadoc/ javadocs/EssentialsAntiBuild/
cp -r EssentialsChat/build/docs/javadoc/ javadocs/EssentialsChat/
cp -r EssentialsDiscord/build/docs/javadoc/ javadocs/EssentialsDiscord/
cp -r EssentialsGeoIP/build/docs/javadoc/ javadocs/EssentialsGeoIP/
cp -r EssentialsProtect/build/docs/javadoc/ javadocs/EssentialsProtect/
cp -r EssentialsSpawn/build/docs/javadoc/ javadocs/EssentialsSpawn/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ protected void nowAsync(final IUser teleportee, final ITarget target, final Tele
future.complete(false);
return;
}
teleportee.setLastLocation();

if (!ess.getSettings().isForcePassengerTeleport() && !teleportee.getBase().isEmpty()) {
if (!ess.getSettings().isTeleportPassengerDismount()) {
Expand All @@ -178,7 +177,11 @@ protected void nowAsync(final IUser teleportee, final ITarget target, final Tele
return;
}
}
teleportee.setLastLocation();

if (teleportee.isAuthorized("essentials.back.onteleport")) {
teleportee.setLastLocation();
}

final Location targetLoc = target.getLocation();
if (ess.getSettings().isTeleportSafetyEnabled() && LocationUtil.isBlockOutsideWorldBorder(targetLoc.getWorld(), targetLoc.getBlockX(), targetLoc.getBlockZ())) {
targetLoc.setX(LocationUtil.getXInsideWorldBorder(targetLoc.getWorld(), targetLoc.getBlockX()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ private void calculateBalanceTopMap() {
final BigDecimal userMoney = user.getMoney();
user.updateMoneyCache(userMoney);
newTotal = newTotal.add(userMoney);
final String name = user.isHidden() ? user.getName() : user.getDisplayName();
entries.add(new BalanceTop.Entry(user.getBase().getUniqueId(), name, userMoney));
final String name;
if (user.getBase() instanceof OfflinePlayer) {
name = user.getLastAccountName();
} else if (user.isHidden()) {
name = user.getName();
} else {
name = user.getDisplayName();
}
entries.add(new BalanceTop.Entry(user.getUUID(), name, userMoney));
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.UUID;

import static com.earth2me.essentials.I18n.tl;

public final class Console implements IMessageRecipient {
Expand Down Expand Up @@ -46,6 +48,11 @@ public String getName() {
return Console.NAME;
}

@Override
public UUID getUUID() {
return null;
}

@Override
public String getDisplayName() {
return Console.DISPLAY_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ public static Enchantment getByName(final String name) {
}
Enchantment enchantment = null;
if (isFlat) { // 1.13+ only
enchantment = Enchantment.getByKey(NamespacedKey.minecraft(name.toLowerCase()));
try {
enchantment = Enchantment.getByKey(NamespacedKey.minecraft(name.toLowerCase()));
} catch (IllegalArgumentException ignored) {
// NamespacedKey throws IAE if key does not match regex
}
}

if (enchantment == null) {
Expand Down
115 changes: 114 additions & 1 deletion Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.NoChargeException;
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import com.earth2me.essentials.commands.PlayerNotFoundException;
import com.earth2me.essentials.commands.QuietAbortException;
import com.earth2me.essentials.economy.EconomyLayers;
import com.earth2me.essentials.economy.vault.VaultEconomyProvider;
Expand All @@ -38,6 +39,7 @@
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.updatecheck.UpdateChecker;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.VersionUtil;
import io.papermc.lib.PaperLib;
import net.ess3.api.Economy;
Expand All @@ -58,6 +60,7 @@
import net.ess3.provider.MaterialTagProvider;
import net.ess3.provider.PersistentDataProvider;
import net.ess3.provider.PotionMetaProvider;
import net.ess3.provider.SerializationProvider;
import net.ess3.provider.ProviderListener;
import net.ess3.provider.ServerStateProvider;
import net.ess3.provider.SpawnEggProvider;
Expand All @@ -76,8 +79,10 @@
import net.ess3.provider.providers.PaperKnownCommandsProvider;
import net.ess3.provider.providers.PaperMaterialTagProvider;
import net.ess3.provider.providers.PaperRecipeBookListener;
import net.ess3.provider.providers.PaperSerializationProvider;
import net.ess3.provider.providers.PaperServerStateProvider;
import net.essentialsx.api.v2.services.BalanceTop;
import net.essentialsx.api.v2.services.mail.MailService;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
Expand Down Expand Up @@ -116,6 +121,7 @@
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
Expand All @@ -142,6 +148,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
private transient UserMap userMap;
private transient BalanceTopImpl balanceTop;
private transient ExecuteTimer execTimer;
private transient MailService mail;
private transient I18n i18n;
private transient MetricsWrapper metrics;
private transient EssentialsTimer timer;
Expand All @@ -151,6 +158,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
private transient PotionMetaProvider potionMetaProvider;
private transient ServerStateProvider serverStateProvider;
private transient ContainerProvider containerProvider;
private transient SerializationProvider serializationProvider;
private transient KnownCommandsProvider knownCommandsProvider;
private transient FormattedCommandAliasProvider formattedCommandAliasProvider;
private transient ProviderListener recipeBookEventProvider;
Expand Down Expand Up @@ -198,6 +206,7 @@ public void setupForTesting(final Server server) throws IOException, InvalidDesc
LOGGER.log(Level.INFO, tl("usingTempFolderForTesting"));
LOGGER.log(Level.INFO, dataFolder.toString());
settings = new Settings(this);
mail = new MailServiceImpl(this);
userMap = new UserMap(this);
balanceTop = new BalanceTopImpl(this);
permissionsHandler = new PermissionsHandler(this, false);
Expand Down Expand Up @@ -271,6 +280,9 @@ public void onEnable() {
confList.add(settings);
execTimer.mark("Settings");

mail = new MailServiceImpl(this);
execTimer.mark("Init(Mail)");

userMap = new UserMap(this);
confList.add(userMap);
execTimer.mark("Init(Usermap)");
Expand Down Expand Up @@ -316,6 +328,8 @@ public void onEnable() {
confList.add(jails);
execTimer.mark("Init(Jails)");

EconomyLayers.onEnable(this);

//Spawner item provider only uses one but it's here for legacy...
spawnerItemProvider = new BlockMetaSpawnerItemProvider();

Expand Down Expand Up @@ -347,6 +361,7 @@ public void onEnable() {
if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01)) {
serverStateProvider = new PaperServerStateProvider();
containerProvider = new PaperContainerProvider();
serializationProvider = new PaperSerializationProvider();
} else {
serverStateProvider = new ReflServerStateProvider();
}
Expand Down Expand Up @@ -495,7 +510,7 @@ public void onDisable() {
user.sendMessage(tl("unvanishedReload"));
}
if (stopping) {
user.setLastLocation();
user.setLogoutLocation();
if (!user.isHidden()) {
user.setLastLogout(System.currentTimeMillis());
}
Expand Down Expand Up @@ -888,6 +903,94 @@ public User getOfflineUser(final String name) {
return user;
}

@Override
public User matchUser(final Server server, final User sourceUser, final String searchTerm, final Boolean getHidden, final boolean getOffline) throws PlayerNotFoundException {
final User user;
Player exPlayer;

try {
exPlayer = server.getPlayer(UUID.fromString(searchTerm));
} catch (final IllegalArgumentException ex) {
if (getOffline) {
exPlayer = server.getPlayerExact(searchTerm);
} else {
exPlayer = server.getPlayer(searchTerm);
}
}

if (exPlayer != null) {
user = getUser(exPlayer);
} else {
user = getUser(searchTerm);
}

if (user != null) {
if (!getOffline && !user.getBase().isOnline()) {
throw new PlayerNotFoundException();
}

if (getHidden || canInteractWith(sourceUser, user)) {
return user;
} else { // not looking for hidden and cannot interact (i.e is hidden)
if (getOffline && user.getName().equalsIgnoreCase(searchTerm)) { // if looking for offline and got an exact match
return user;
}
}
throw new PlayerNotFoundException();
}
final List<Player> matches = server.matchPlayer(searchTerm);

if (matches.isEmpty()) {
final String matchText = searchTerm.toLowerCase(Locale.ENGLISH);
for (final User userMatch : getOnlineUsers()) {
if (getHidden || canInteractWith(sourceUser, userMatch)) {
final String displayName = FormatUtil.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH);
if (displayName.contains(matchText)) {
return userMatch;
}
}
}
} else {
for (final Player player : matches) {
final User userMatch = getUser(player);
if (userMatch.getDisplayName().startsWith(searchTerm) && (getHidden || canInteractWith(sourceUser, userMatch))) {
return userMatch;
}
}
final User userMatch = getUser(matches.get(0));
if (getHidden || canInteractWith(sourceUser, userMatch)) {
return userMatch;
}
}
throw new PlayerNotFoundException();
}

@Override
public boolean canInteractWith(final CommandSource interactor, final User interactee) {
if (interactor == null) {
return !interactee.isHidden();
}

if (interactor.isPlayer()) {
return canInteractWith(getUser(interactor.getPlayer()), interactee);
}

return true; // console
}

@Override
public boolean canInteractWith(final User interactor, final User interactee) {
if (interactor == null) {
return !interactee.isHidden();
}

if (interactor.equals(interactee)) {
return true;
}

return interactor.getBase().canSee(interactee.getBase());
}

//This will create a new user if there is not a match.
@Override
public User getUser(final Player base) {
Expand Down Expand Up @@ -1061,6 +1164,11 @@ public EssentialsTimer getTimer() {
return timer;
}

@Override
public MailService getMail() {
return mail;
}

@Override
public List<String> getVanishedPlayers() {
return Collections.unmodifiableList(new ArrayList<>(vanishedPlayers));
Expand Down Expand Up @@ -1129,6 +1237,11 @@ public KnownCommandsProvider getKnownCommandsProvider() {
return knownCommandsProvider;
}

@Override
public SerializationProvider getSerializationProvider() {
return serializationProvider;
}

@Override
public FormattedCommandAliasProvider getFormattedCommandAliasProvider() {
return formattedCommandAliasProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ public void run() {
user.setDisplayNick();
updateCompass(user);

ess.runTaskAsynchronously(() -> ess.getServer().getPluginManager().callEvent(new AsyncUserDataLoadEvent(user)));

if (!ess.getVanishedPlayersNew().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
for (final String p : ess.getVanishedPlayersNew()) {
final Player toVanish = ess.getServer().getPlayerExact(p);
Expand All @@ -328,12 +326,14 @@ public void run() {
user.getBase().setSleepingIgnored(true);
}

final String effectiveMessage;
if (ess.getSettings().allowSilentJoinQuit() && (user.isAuthorized("essentials.silentjoin") || user.isAuthorized("essentials.silentjoin.vanish"))) {
if (user.isAuthorized("essentials.silentjoin.vanish")) {
user.setVanished(true);
}
effectiveMessage = null;
} else if (message == null || hideJoinQuitMessages()) {
//NOOP
effectiveMessage = null;
} else if (ess.getSettings().isCustomJoinMessage()) {
final String msg = ess.getSettings().getCustomJoinMessage()
.replace("{PLAYER}", player.getDisplayName()).replace("{USERNAME}", player.getName())
Expand All @@ -345,10 +345,16 @@ public void run() {
if (!msg.isEmpty()) {
ess.getServer().broadcastMessage(msg);
}
effectiveMessage = msg.isEmpty() ? null : msg;
} else if (ess.getSettings().allowSilentJoinQuit()) {
ess.getServer().broadcastMessage(message);
effectiveMessage = message;
} else {
effectiveMessage = message;
}

ess.runTaskAsynchronously(() -> ess.getServer().getPluginManager().callEvent(new AsyncUserDataLoadEvent(user, effectiveMessage)));

final int motdDelay = ess.getSettings().getMotdDelay() / 50;
final DelayMotdTask motdTask = new DelayMotdTask(user);
if (motdDelay > 0) {
Expand All @@ -358,8 +364,7 @@ public void run() {
}

if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
final List<String> mail = user.getMails();
if (mail.isEmpty()) {
if (user.getUnreadMailAmount() == 0) {
if (ess.getSettings().isNotifyNoNewMail()) {
user.sendMessage(tl("noNewMail")); // Only notify if they want us to.
}
Expand Down
Loading

0 comments on commit 7991c13

Please sign in to comment.