Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ out/
build/
target/
*.class
build-logic/.kotlin/
build-logic/bin/

# Run directory
/run/
18 changes: 11 additions & 7 deletions Essentials/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ dependencies {
implementation 'org.checkerframework:checker-qual:3.49.0'
implementation 'nu.studer:java-ordered-properties:1.0.4'

implementation 'net.kyori:adventure-api:4.21.0'
implementation 'net.kyori:adventure-text-minimessage:4.21.0'
implementation 'net.kyori:adventure-api:4.23.0'
implementation 'net.kyori:adventure-text-minimessage:4.23.0'
implementation 'net.kyori:adventure-platform-bukkit:4.4.0'

// Providers
api project(':providers:BaseProviders')
api project(path: ':providers:PaperProvider', configuration: 'shadow')
api(project(':providers:BaseProviders')) {
exclude(module: 'spigot-api')
}
api(project(path: ':providers:PaperProvider', configuration: 'shadow')){
exclude(module: 'paper-api')
}
api(project(':providers:NMSReflectionProvider')) {
exclude group: "org.bukkit", module: "bukkit"
exclude(module: 'bukkit')
}
api(project(':providers:1_8Provider')) {
exclude group: "org.spigotmc", module: "spigot"
exclude(module: 'spigot-api')
}
api(project(':providers:1_12Provider')) {
exclude group: "org.bukkit", module: "bukkit"
exclude(module: 'bukkit')
}
}

Expand Down
92 changes: 31 additions & 61 deletions Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import net.ess3.provider.ServerStateProvider;
import net.ess3.provider.providers.BaseBannerDataProvider;
import net.ess3.provider.providers.BaseInventoryViewProvider;
import net.ess3.provider.providers.BaseLoggerProvider;
import net.ess3.provider.providers.BlockMetaSpawnerItemProvider;
import net.ess3.provider.providers.BukkitMaterialTagProvider;
import net.ess3.provider.providers.BukkitSpawnerBlockProvider;
Expand Down Expand Up @@ -120,18 +119,13 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -187,52 +181,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
EconomyLayers.init();
}

public Essentials() {
}

protected Essentials(final JavaPluginLoader loader, final PluginDescriptionFile description, final File dataFolder, final File file) {
super(loader, description, dataFolder, file);
}

public Essentials(final Server server) {
super(new JavaPluginLoader(server), new PluginDescriptionFile("Essentials", "", "com.earth2me.essentials.Essentials"), null, null);
}

@Override
public ISettings getSettings() {
return settings;
}

public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException {
TESTING = true;
LOGGER = new BaseLoggerProvider(this, BUKKIT_LOGGER);
final File dataFolder = File.createTempFile("essentialstest", "");
if (!dataFolder.delete()) {
throw new IOException();
}
if (!dataFolder.mkdir()) {
throw new IOException();
}
i18n = new I18n(this);
i18n.onEnable();
i18n.updateLocale("en");
Console.setInstance(this);

LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("usingTempFolderForTesting")));
LOGGER.log(Level.INFO, dataFolder.toString());
settings = new Settings(this);
mail = new MailServiceImpl(this);
userMap = new ModernUserMap(this);
balanceTop = new BalanceTopImpl(this);
permissionsHandler = new PermissionsHandler(this, false);
Economy.setEss(this);
confList = new ArrayList<>();
jails = new Jails(this);
registerListeners(server.getPluginManager());
kits = new Kits(this);
bukkitAudience = BukkitAudiences.create(this);
}

@Override
public void onLoad() {
try {
Expand Down Expand Up @@ -426,7 +379,9 @@ public void onEnable() {
// Tick Count Provider
providerFactory.registerProvider(PaperTickCountProvider.class);

providerFactory.finalizeRegistration();
if (!TESTING) {
providerFactory.finalizeRegistration();
}

// Event Providers
if (PaperLib.isPaper()) {
Expand Down Expand Up @@ -464,15 +419,17 @@ public void onEnable() {
PermissionsDefaults.registerAllBackDefaults();
PermissionsDefaults.registerAllHatDefaults();

updateChecker = new UpdateChecker(this);
runTaskAsynchronously(() -> {
getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("versionFetching")));
for (final Component component : updateChecker.getVersionMessages(false, true, new CommandSource(this, Bukkit.getConsoleSender()))) {
getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, AdventureUtil.adventureToLegacy(component));
}
});
if (!TESTING) {
updateChecker = new UpdateChecker(this);
runTaskAsynchronously(() -> {
getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("versionFetching")));
for (final Component component : updateChecker.getVersionMessages(false, true, new CommandSource(this, Bukkit.getConsoleSender()))) {
getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, AdventureUtil.adventureToLegacy(component));
}
});

metrics = new MetricsWrapper(this, 858, true);
metrics = new MetricsWrapper(this, 858, true);
}

execTimer.mark("Init(External)");

Expand All @@ -486,7 +443,9 @@ public void onEnable() {
handleCrash(ex);
throw ex;
}
getBackup().setPendingShutdown(false);
if (!TESTING) {
getBackup().setPendingShutdown(false);
}
}

// Returns our provider logger if available
Expand Down Expand Up @@ -554,11 +513,19 @@ public ProviderFactory getProviders() {

@Override
public void onDisable() {
final boolean stopping = provider(ServerStateProvider.class).isStopping();
if (bukkitAudience != null) {
bukkitAudience.close();
}

final boolean stopping = TESTING || provider(ServerStateProvider.class).isStopping();
if (!stopping) {
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("serverReloading")));
}
getBackup().setPendingShutdown(true);

if (!TESTING) {
getBackup().setPendingShutdown(true);
}

for (final User user : getOnlineUsers()) {
if (user.isVanished()) {
user.setVanished(false);
Expand All @@ -575,7 +542,7 @@ public void onDisable() {
}
}
cleanupOpenInventories();
if (getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) {
if (!TESTING && getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) {
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("backupInProgress")));
getBackup().getTaskLock().join();
}
Expand All @@ -586,9 +553,12 @@ public void onDisable() {
backup.stopTask();
}

this.getPermissionsHandler().unregisterContexts();
if (!TESTING) {
this.getPermissionsHandler().unregisterContexts();
}

Economy.setEss(null);
AdventureUtil.setEss(null);
Trade.closeLog();
getUsers().shutdown();

Expand Down
3 changes: 2 additions & 1 deletion Essentials/src/main/java/com/earth2me/essentials/Mob.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public enum Mob {
ARMADILLO("Armadillo", Enemies.FRIENDLY, "ARMADILLO"),
BREEZE("Breeze", Enemies.ENEMY, "BREEZE"),
BOGGED("Bogged", Enemies.ENEMY, "BOGGED"),
CREAKING("Creaking", Enemies.ENEMY, "CREAKING")
CREAKING("Creaking", Enemies.ENEMY, "CREAKING"),
HAPPY_GHAST("HappyGhast", Enemies.FRIENDLY, "HAPPY_GHAST")
;

private static final Map<String, Mob> hashMap = new HashMap<>();
Expand Down
8 changes: 8 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public boolean isAuthorized(final IEssentialsCommand cmd, final String permissio

@Override
public boolean isAuthorized(final String node) {
if (Essentials.TESTING) {
return false;
}

final boolean result = isAuthorizedCheck(node);
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result);
Expand All @@ -145,6 +149,10 @@ public boolean isAuthorized(final String node) {

@Override
public boolean isPermissionSet(final String node) {
if (Essentials.TESTING) {
return false;
}

final boolean result = isPermSetCheck(node);
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " (set-explicit) - " + result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public final class VersionUtil {
public static final BukkitVersion v1_21_R01 = BukkitVersion.fromString("1.21-R0.1-SNAPSHOT");
public static final BukkitVersion v1_21_3_R01 = BukkitVersion.fromString("1.21.3-R0.1-SNAPSHOT");
public static final BukkitVersion v1_21_5_R01 = BukkitVersion.fromString("1.21.5-R0.1-SNAPSHOT");
public static final BukkitVersion v1_21_6_R01 = BukkitVersion.fromString("1.21.6-R0.1-SNAPSHOT");

private static final Set<BukkitVersion> supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01, v1_17_1_R01, v1_18_2_R01, v1_19_4_R01, v1_20_6_R01, v1_21_5_R01);
private static final Set<BukkitVersion> supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01, v1_17_1_R01, v1_18_2_R01, v1_19_4_R01, v1_20_6_R01, v1_21_6_R01);

public static final boolean PRE_FLATTENING = VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01);

Expand Down
Loading