mirror of
https://github.com/EssentialsX/Essentials.git
synced 2026-11-05 09:10:17 -05:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8244dbd80 |
No files matched your search
@@ -1,7 +1,6 @@
|
||||
name: Report bug
|
||||
description: Report a bug in EssentialsX.
|
||||
labels: 'bug: unconfirmed'
|
||||
type: Bug
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
name: Request a feature
|
||||
description: Suggest a feature you want to see in EssentialsX!
|
||||
labels: 'type: enhancement'
|
||||
type: Feature
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
|
||||
@@ -11,9 +11,6 @@ on:
|
||||
- mc/*
|
||||
- dev/*
|
||||
|
||||
permissions:
|
||||
checks: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and upload
|
||||
|
||||
@@ -10,13 +10,13 @@ dependencies {
|
||||
|
||||
api 'io.papermc:paperlib:1.0.6'
|
||||
|
||||
implementation 'org.spongepowered:configurate-yaml:4.2.0'
|
||||
implementation 'org.checkerframework:checker-qual:3.49.0'
|
||||
implementation 'org.spongepowered:configurate-yaml:4.1.2'
|
||||
implementation 'org.checkerframework:checker-qual:3.21.0'
|
||||
implementation 'nu.studer:java-ordered-properties:1.0.4'
|
||||
|
||||
implementation 'net.kyori:adventure-api:4.19.0'
|
||||
implementation 'net.kyori:adventure-text-minimessage:4.19.0'
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.3.4'
|
||||
implementation 'net.kyori:adventure-api:4.17.0'
|
||||
implementation 'net.kyori:adventure-text-minimessage:4.17.0'
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.3.3'
|
||||
|
||||
// Providers
|
||||
api project(':providers:BaseProviders')
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -33,7 +31,7 @@ public class AlternativeCommandsHandler {
|
||||
if (plugin.getDescription().getMain().contains("com.earth2me.essentials") || plugin.getDescription().getMain().contains("net.essentialsx")) {
|
||||
return;
|
||||
}
|
||||
for (final Map.Entry<String, Command> entry : getPluginCommands(plugin)) {
|
||||
for (final Map.Entry<String, Command> entry : getPluginCommands(plugin).entrySet()) {
|
||||
final String[] commandSplit = entry.getKey().split(":", 2);
|
||||
final String commandName = commandSplit.length > 1 ? commandSplit[1] : entry.getKey();
|
||||
final Command command = entry.getValue();
|
||||
@@ -66,23 +64,14 @@ public class AlternativeCommandsHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map.Entry<String, Command>> getPluginCommands(Plugin plugin) {
|
||||
private Map<String, Command> getPluginCommands(Plugin plugin) {
|
||||
final Map<String, Command> commands = new HashMap<>();
|
||||
for (final Map.Entry<String, Command> entry : ess.provider(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
if (entry.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) entry.getValue()).getPlugin().equals(plugin)) {
|
||||
commands.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
// Try to use non-namespaced commands first if we can, some Commands may not like being registered under a
|
||||
// different label than their getName() returns, so avoid doing that when we can
|
||||
return commands.entrySet().stream().sorted((o1, o2) -> {
|
||||
if (o1.getKey().contains(":") && !o2.getKey().contains(":")) {
|
||||
return 1;
|
||||
} else if (!o1.getKey().contains(":") && o2.getKey().contains(":")) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}).collect(Collectors.toList());
|
||||
return commands;
|
||||
}
|
||||
|
||||
public void removePlugin(final Plugin plugin) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.earth2me.essentials.utils.LocationUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.InvalidWorldException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.UserWarpEvent;
|
||||
import net.ess3.api.events.teleport.PreTeleportEvent;
|
||||
@@ -423,7 +424,7 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
final Location loc;
|
||||
try {
|
||||
loc = ess.getWarps().getWarp(warp);
|
||||
} catch (final WarpNotFoundException e) {
|
||||
} catch (final WarpNotFoundException | InvalidWorldException e) {
|
||||
future.completeExceptionally(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,11 +59,27 @@ import net.ess3.nms.refl.providers.ReflServerStateProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSpawnEggProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSpawnerBlockProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSyncCommandsProvider;
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import net.ess3.provider.BiomeKeyProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.InventoryViewProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.MaterialTagProvider;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.PlayerLocaleProvider;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import net.ess3.provider.ProviderListener;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import net.ess3.provider.ServerStateProvider;
|
||||
import net.ess3.provider.SignDataProvider;
|
||||
import net.ess3.provider.SpawnEggProvider;
|
||||
import net.ess3.provider.SpawnerBlockProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import net.ess3.provider.SyncCommandsProvider;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.ess3.provider.providers.BaseBannerDataProvider;
|
||||
import net.ess3.provider.providers.BaseInventoryViewProvider;
|
||||
import net.ess3.provider.providers.BaseLoggerProvider;
|
||||
@@ -86,7 +102,6 @@ import net.ess3.provider.providers.ModernPersistentDataProvider;
|
||||
import net.ess3.provider.providers.ModernPlayerLocaleProvider;
|
||||
import net.ess3.provider.providers.ModernPotionMetaProvider;
|
||||
import net.ess3.provider.providers.ModernSignDataProvider;
|
||||
import net.ess3.provider.providers.ModernSyncCommandsProvider;
|
||||
import net.ess3.provider.providers.PaperBiomeKeyProvider;
|
||||
import net.ess3.provider.providers.PaperContainerProvider;
|
||||
import net.ess3.provider.providers.PaperKnownCommandsProvider;
|
||||
@@ -94,7 +109,6 @@ 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.ess3.provider.providers.PaperTickCountProvider;
|
||||
import net.ess3.provider.providers.PrehistoricPotionMetaProvider;
|
||||
import net.essentialsx.api.v2.services.BalanceTop;
|
||||
import net.essentialsx.api.v2.services.mail.MailService;
|
||||
@@ -140,7 +154,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
@@ -157,7 +170,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private final transient TNTExplodeListener tntListener = new TNTExplodeListener();
|
||||
private final transient Set<String> vanishedPlayers = new LinkedHashSet<>();
|
||||
private final transient Map<String, IEssentialsCommand> commandMap = new HashMap<>();
|
||||
private final transient ProviderFactory providerFactory = new ProviderFactory(this);
|
||||
private transient ISettings settings;
|
||||
private transient Jails jails;
|
||||
private transient Warps warps;
|
||||
@@ -177,7 +189,28 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private transient I18n i18n;
|
||||
private transient MetricsWrapper metrics;
|
||||
private transient EssentialsTimer timer;
|
||||
private transient SpawnerItemProvider spawnerItemProvider;
|
||||
private transient SpawnerBlockProvider spawnerBlockProvider;
|
||||
private transient SpawnEggProvider spawnEggProvider;
|
||||
private transient PotionMetaProvider potionMetaProvider;
|
||||
private transient BannerDataProvider bannerDataProvider;
|
||||
private transient ServerStateProvider serverStateProvider;
|
||||
private transient ContainerProvider containerProvider;
|
||||
private transient SerializationProvider serializationProvider;
|
||||
private transient KnownCommandsProvider knownCommandsProvider;
|
||||
private transient FormattedCommandAliasProvider formattedCommandAliasProvider;
|
||||
private transient ProviderListener recipeBookEventProvider;
|
||||
private transient MaterialTagProvider materialTagProvider;
|
||||
private transient SyncCommandsProvider syncCommandsProvider;
|
||||
private transient PersistentDataProvider persistentDataProvider;
|
||||
private transient ReflOnlineModeProvider onlineModeProvider;
|
||||
private transient ItemUnbreakableProvider unbreakableProvider;
|
||||
private transient WorldInfoProvider worldInfoProvider;
|
||||
private transient PlayerLocaleProvider playerLocaleProvider;
|
||||
private transient SignDataProvider signDataProvider;
|
||||
private transient DamageEventProvider damageEventProvider;
|
||||
private transient BiomeKeyProvider biomeKeyProvider;
|
||||
private transient InventoryViewProvider inventoryViewProvider;
|
||||
private transient Kits kits;
|
||||
private transient RandomTeleport randomTeleport;
|
||||
private transient UpdateChecker updateChecker;
|
||||
@@ -324,10 +357,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
upgrade.convertKits();
|
||||
execTimer.mark("Kits");
|
||||
|
||||
randomTeleport = new RandomTeleport(this);
|
||||
confList.add(randomTeleport);
|
||||
execTimer.mark("Init(RandomTeleport)");
|
||||
|
||||
upgrade.afterSettings();
|
||||
execTimer.mark("Upgrade3");
|
||||
|
||||
@@ -343,6 +372,13 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
confList.add(itemDb);
|
||||
execTimer.mark("Init(ItemDB)");
|
||||
|
||||
randomTeleport = new RandomTeleport(this);
|
||||
if (randomTeleport.getPreCache()) {
|
||||
randomTeleport.cacheRandomLocations(randomTeleport.getCenter(), randomTeleport.getMinRange(), randomTeleport.getMaxRange());
|
||||
}
|
||||
confList.add(randomTeleport);
|
||||
execTimer.mark("Init(RandomTeleport)");
|
||||
|
||||
customItemResolver = new CustomItemResolver(this);
|
||||
try {
|
||||
itemDb.registerResolver(this, "custom_items", customItemResolver);
|
||||
@@ -358,77 +394,53 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
execTimer.mark("Init(Jails)");
|
||||
|
||||
EconomyLayers.onEnable(this);
|
||||
execTimer.mark("Init(EconomyLayers)");
|
||||
|
||||
// Spawner item provider only uses one, but it's here for legacy...
|
||||
providerFactory.registerProvider(BlockMetaSpawnerItemProvider.class);
|
||||
//Spawner item provider only uses one but it's here for legacy...
|
||||
spawnerItemProvider = new BlockMetaSpawnerItemProvider();
|
||||
|
||||
// Spawner block providers
|
||||
providerFactory.registerProvider(ReflSpawnerBlockProvider.class, BukkitSpawnerBlockProvider.class);
|
||||
//Spawner block providers
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_12_0_R01)) {
|
||||
spawnerBlockProvider = new ReflSpawnerBlockProvider();
|
||||
} else {
|
||||
spawnerBlockProvider = new BukkitSpawnerBlockProvider();
|
||||
}
|
||||
|
||||
// Spawn Egg Providers
|
||||
providerFactory.registerProvider(LegacySpawnEggProvider.class, ReflSpawnEggProvider.class, FlatSpawnEggProvider.class);
|
||||
//Spawn Egg Providers
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
spawnEggProvider = new LegacySpawnEggProvider();
|
||||
} else if (VersionUtil.getServerBukkitVersion().isLowerThanOrEqualTo(VersionUtil.v1_12_2_R01)) {
|
||||
spawnEggProvider = new ReflSpawnEggProvider();
|
||||
} else {
|
||||
spawnEggProvider = new FlatSpawnEggProvider();
|
||||
}
|
||||
|
||||
//Potion Meta Provider
|
||||
providerFactory.registerProvider(PrehistoricPotionMetaProvider.class, LegacyPotionMetaProvider.class, ModernPotionMetaProvider.class);
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) {
|
||||
potionMetaProvider = new ModernPotionMetaProvider();
|
||||
} else if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
potionMetaProvider = new PrehistoricPotionMetaProvider();
|
||||
} else {
|
||||
potionMetaProvider = new LegacyPotionMetaProvider();
|
||||
}
|
||||
|
||||
//Banner Meta Provider
|
||||
providerFactory.registerProvider(LegacyBannerDataProvider.class, BaseBannerDataProvider.class);
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) {
|
||||
bannerDataProvider = new BaseBannerDataProvider();
|
||||
} else {
|
||||
bannerDataProvider = new LegacyBannerDataProvider();
|
||||
}
|
||||
|
||||
// Server State Provider
|
||||
providerFactory.registerProvider(ReflServerStateProvider.class, PaperServerStateProvider.class);
|
||||
//Server State Provider
|
||||
//Container Provider
|
||||
if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01)) {
|
||||
serverStateProvider = new PaperServerStateProvider();
|
||||
containerProvider = new PaperContainerProvider();
|
||||
serializationProvider = new PaperSerializationProvider();
|
||||
} else {
|
||||
serverStateProvider = new ReflServerStateProvider();
|
||||
}
|
||||
|
||||
// Container Provider
|
||||
providerFactory.registerProvider(PaperContainerProvider.class);
|
||||
|
||||
// Serialization Provider
|
||||
providerFactory.registerProvider(PaperSerializationProvider.class);
|
||||
|
||||
// Known Commands Provider
|
||||
providerFactory.registerProvider(ReflKnownCommandsProvider.class, PaperKnownCommandsProvider.class);
|
||||
|
||||
// Command Aliases Provider
|
||||
providerFactory.registerProvider(ReflFormattedCommandAliasProvider.class);
|
||||
|
||||
// Material Tag Providers
|
||||
providerFactory.registerProvider(BukkitMaterialTagProvider.class, PaperMaterialTagProvider.class);
|
||||
|
||||
// Sync Commands Provider
|
||||
providerFactory.registerProvider(ReflSyncCommandsProvider.class, ModernSyncCommandsProvider.class);
|
||||
|
||||
// Persistent Data Provider
|
||||
providerFactory.registerProvider(ReflPersistentDataProvider.class, ModernPersistentDataProvider.class);
|
||||
|
||||
// Online Mode Provider
|
||||
providerFactory.registerProvider(ReflOnlineModeProvider.class);
|
||||
|
||||
// Unbreakable Provider
|
||||
providerFactory.registerProvider(LegacyItemUnbreakableProvider.class, ModernItemUnbreakableProvider.class);
|
||||
|
||||
// World Info Provider
|
||||
providerFactory.registerProvider(FixedHeightWorldInfoProvider.class, ReflDataWorldInfoProvider.class, ModernDataWorldInfoProvider.class);
|
||||
|
||||
// Sign Data Provider
|
||||
providerFactory.registerProvider(ModernSignDataProvider.class);
|
||||
|
||||
// Player Locale Provider
|
||||
providerFactory.registerProvider(ModernPlayerLocaleProvider.class, LegacyPlayerLocaleProvider.class);
|
||||
|
||||
// Damage Event Provider
|
||||
providerFactory.registerProvider(ModernDamageEventProvider.class, LegacyDamageEventProvider.class);
|
||||
|
||||
// Inventory View Provider
|
||||
providerFactory.registerProvider(LegacyInventoryViewProvider.class, BaseInventoryViewProvider.class);
|
||||
|
||||
// Biome Key Provider
|
||||
providerFactory.registerProvider(PaperBiomeKeyProvider.class);
|
||||
|
||||
// Tick Count Provider
|
||||
providerFactory.registerProvider(PaperTickCountProvider.class);
|
||||
|
||||
providerFactory.finalizeRegistration();
|
||||
|
||||
// Event Providers
|
||||
//Event Providers
|
||||
if (PaperLib.isPaper()) {
|
||||
try {
|
||||
Class.forName("com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent");
|
||||
@@ -437,13 +449,76 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
((Cancellable) event).setCancelled(true);
|
||||
}
|
||||
});
|
||||
if (getSettings().isDebug()) {
|
||||
LOGGER.log(Level.INFO, "Registered Paper Recipe Book Event Listener");
|
||||
}
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
//Known Commands Provider
|
||||
if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01)) {
|
||||
knownCommandsProvider = new PaperKnownCommandsProvider();
|
||||
} else {
|
||||
knownCommandsProvider = new ReflKnownCommandsProvider();
|
||||
}
|
||||
|
||||
// Command aliases provider
|
||||
formattedCommandAliasProvider = new ReflFormattedCommandAliasProvider(PaperLib.isPaper());
|
||||
|
||||
// Material Tag Providers
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_13_0_R01)) {
|
||||
materialTagProvider = PaperLib.isPaper() ? new PaperMaterialTagProvider() : new BukkitMaterialTagProvider();
|
||||
}
|
||||
|
||||
// Sync Commands Provider
|
||||
syncCommandsProvider = new ReflSyncCommandsProvider();
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01)) {
|
||||
persistentDataProvider = new ModernPersistentDataProvider(this);
|
||||
} else {
|
||||
persistentDataProvider = new ReflPersistentDataProvider(this);
|
||||
}
|
||||
|
||||
onlineModeProvider = new ReflOnlineModeProvider();
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01)) {
|
||||
unbreakableProvider = new ModernItemUnbreakableProvider();
|
||||
} else {
|
||||
unbreakableProvider = new LegacyItemUnbreakableProvider();
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_17_1_R01)) {
|
||||
worldInfoProvider = new ModernDataWorldInfoProvider();
|
||||
} else if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_5_R01)) {
|
||||
worldInfoProvider = new ReflDataWorldInfoProvider();
|
||||
} else {
|
||||
worldInfoProvider = new FixedHeightWorldInfoProvider();
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01)) {
|
||||
signDataProvider = new ModernSignDataProvider(this);
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_12_2_R01)) {
|
||||
playerLocaleProvider = new ModernPlayerLocaleProvider();
|
||||
} else {
|
||||
playerLocaleProvider = new LegacyPlayerLocaleProvider();
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_4_R01)) {
|
||||
damageEventProvider = new ModernDamageEventProvider();
|
||||
} else {
|
||||
damageEventProvider = new LegacyDamageEventProvider();
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_R01)) {
|
||||
inventoryViewProvider = new BaseInventoryViewProvider();
|
||||
} else {
|
||||
inventoryViewProvider = new LegacyInventoryViewProvider();
|
||||
}
|
||||
|
||||
if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_19_4_R01)) {
|
||||
biomeKeyProvider = new PaperBiomeKeyProvider();
|
||||
}
|
||||
|
||||
execTimer.mark("Init(Providers)");
|
||||
reload();
|
||||
|
||||
@@ -547,14 +622,9 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
jails.resetListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderFactory getProviders() {
|
||||
return providerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
final boolean stopping = provider(ServerStateProvider.class).isStopping();
|
||||
final boolean stopping = getServerStateProvider().isStopping();
|
||||
if (!stopping) {
|
||||
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("serverReloading")));
|
||||
}
|
||||
@@ -613,8 +683,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
for (final String commandName : this.getDescription().getCommands().keySet()) {
|
||||
final Command command = this.getCommand(commandName);
|
||||
if (command != null) {
|
||||
command.setDescription(AdventureUtil.miniToLegacy(tlLiteral(commandName + "CommandDescription")));
|
||||
command.setUsage(AdventureUtil.miniToLegacy(tlLiteral(commandName + "CommandUsage")));
|
||||
command.setDescription(tlLiteral(commandName + "CommandDescription"));
|
||||
command.setUsage(tlLiteral(commandName + "CommandUsage"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,9 +745,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
// Check for disabled commands
|
||||
if (getSettings().isCommandDisabled(commandLabel)) {
|
||||
final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
|
||||
if (newCmd != null && (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this)) {
|
||||
return newCmd.tabComplete(cSender, commandLabel, args);
|
||||
if (getKnownCommandsProvider().getKnownCommands().containsKey(commandLabel)) {
|
||||
final Command newCmd = getKnownCommandsProvider().getKnownCommands().get(commandLabel);
|
||||
if (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this) {
|
||||
return newCmd.tabComplete(cSender, commandLabel, args);
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -740,8 +812,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
} catch (final Exception ex) {
|
||||
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
|
||||
if (cSender instanceof Player) {
|
||||
final PlayerLocaleProvider localeProvider = provider(PlayerLocaleProvider.class);
|
||||
getBukkitAudience().sender(cSender).sendMessage(AdventureUtil.miniMessage().deserialize(tlLocale(I18n.getLocale(localeProvider.getLocale((Player) cSender)), "internalError")));
|
||||
cSender.sendMessage(tlLocale(I18n.getLocale(getPlayerLocaleProvider().getLocale((Player) cSender)), "internalError"));
|
||||
} else {
|
||||
cSender.sendMessage(tlLiteral("internalError"));
|
||||
}
|
||||
@@ -784,9 +855,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
// Check for disabled commands
|
||||
if (getSettings().isCommandDisabled(commandLabel)) {
|
||||
final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
|
||||
if (newCmd != null && (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin()))) {
|
||||
return newCmd.execute(cSender, commandLabel, args);
|
||||
if (getKnownCommandsProvider().getKnownCommands().containsKey(commandLabel)) {
|
||||
final Command newCmd = getKnownCommandsProvider().getKnownCommands().get(commandLabel);
|
||||
if (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin())) {
|
||||
return newCmd.execute(cSender, commandLabel, args);
|
||||
}
|
||||
}
|
||||
sender.sendTl("commandDisabled", commandLabel);
|
||||
return true;
|
||||
@@ -830,11 +903,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
} catch (final NotEnoughArgumentsException ex) {
|
||||
if (getSettings().isVerboseCommandUsages() && !cmd.getUsageStrings().isEmpty()) {
|
||||
sender.sendTl("commandHelpLine1", commandLabel);
|
||||
String description = command.getDescription();
|
||||
try {
|
||||
description = sender.tl(command.getName() + "CommandDescription");
|
||||
} catch (MissingResourceException ignored) {}
|
||||
sender.sendTl("commandHelpLine2", description);
|
||||
sender.sendTl("commandHelpLine2", command.getDescription());
|
||||
sender.sendTl("commandHelpLine3");
|
||||
for (Map.Entry<String, String> usage : cmd.getUsageStrings().entrySet()) {
|
||||
sender.sendTl("commandHelpLineUsage", AdventureUtil.parsed(usage.getKey().replace("<command>", commandLabel)), AdventureUtil.parsed(usage.getValue()));
|
||||
@@ -868,17 +937,16 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
}
|
||||
|
||||
public void cleanupOpenInventories() {
|
||||
final InventoryViewProvider provider = provider(InventoryViewProvider.class);
|
||||
for (final User user : getOnlineUsers()) {
|
||||
if (user.isRecipeSee()) {
|
||||
final InventoryView view = user.getBase().getOpenInventory();
|
||||
|
||||
provider.getTopInventory(view).clear();
|
||||
provider.close(view);
|
||||
inventoryViewProvider.getTopInventory(view).clear();
|
||||
inventoryViewProvider.close(view);
|
||||
user.setRecipeSee(false);
|
||||
}
|
||||
if (user.isInvSee() || user.isEnderSee()) {
|
||||
provider.close(user.getBase().getOpenInventory());
|
||||
inventoryViewProvider.close(user.getBase().getOpenInventory());
|
||||
user.setInvSee(false);
|
||||
user.setEnderSee(false);
|
||||
}
|
||||
@@ -1305,11 +1373,115 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return onlineUsers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerItemProvider getSpawnerItemProvider() {
|
||||
return spawnerItemProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerBlockProvider getSpawnerBlockProvider() {
|
||||
return spawnerBlockProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnEggProvider getSpawnEggProvider() {
|
||||
return spawnEggProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionMetaProvider getPotionMetaProvider() {
|
||||
return potionMetaProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BannerDataProvider getBannerDataProvider() {
|
||||
return bannerDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryViewProvider getInventoryViewProvider() {
|
||||
return inventoryViewProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomItemResolver getCustomItemResolver() {
|
||||
return customItemResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerStateProvider getServerStateProvider() {
|
||||
return serverStateProvider;
|
||||
}
|
||||
|
||||
public MaterialTagProvider getMaterialTagProvider() {
|
||||
return materialTagProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerProvider getContainerProvider() {
|
||||
return containerProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnownCommandsProvider getKnownCommandsProvider() {
|
||||
return knownCommandsProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerializationProvider getSerializationProvider() {
|
||||
return serializationProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormattedCommandAliasProvider getFormattedCommandAliasProvider() {
|
||||
return formattedCommandAliasProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SyncCommandsProvider getSyncCommandsProvider() {
|
||||
return syncCommandsProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentDataProvider getPersistentDataProvider() {
|
||||
return persistentDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReflOnlineModeProvider getOnlineModeProvider() {
|
||||
return onlineModeProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUnbreakableProvider getItemUnbreakableProvider() {
|
||||
return unbreakableProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldInfoProvider getWorldInfoProvider() {
|
||||
return worldInfoProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocaleProvider getPlayerLocaleProvider() {
|
||||
return playerLocaleProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageEventProvider getDamageEventProvider() {
|
||||
return damageEventProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeKeyProvider getBiomeKeyProvider() {
|
||||
return biomeKeyProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignDataProvider getSignDataProvider() {
|
||||
return signDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginCommand getPluginCommand(final String cmd) {
|
||||
return this.getCommand(cmd);
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
@@ -28,11 +26,11 @@ public class EssentialsBlockListener implements Listener {
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
final ItemStack is = event.getItemInHand();
|
||||
|
||||
if (is.getType() == MaterialUtil.SPAWNER && ess.provider(PersistentDataProvider.class).getString(is, "convert") != null) {
|
||||
if (is.getType() == MaterialUtil.SPAWNER && ess.getPersistentDataProvider().getString(is, "convert") != null) {
|
||||
final BlockState blockState = event.getBlockPlaced().getState();
|
||||
if (blockState instanceof CreatureSpawner) {
|
||||
final CreatureSpawner spawner = (CreatureSpawner) blockState;
|
||||
final EntityType type = ess.provider(SpawnerItemProvider.class).getEntityType(event.getItemInHand());
|
||||
final EntityType type = ess.getSpawnerItemProvider().getEntityType(event.getItemInHand());
|
||||
if (type != null && Mob.fromBukkitType(type) != null) {
|
||||
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) {
|
||||
spawner.setSpawnedType(type);
|
||||
|
||||
@@ -190,15 +190,7 @@ public class EssentialsEntityListener implements Listener {
|
||||
final User user = ess.getUser(event.getEntity());
|
||||
if (user.isAuthorized("essentials.keepinv")) {
|
||||
event.setKeepInventory(true);
|
||||
// We don't do getDrops().clear() here because it would remove any loot tables that were added by other plugins/datapacks.
|
||||
// Instead, we remove the items from the drops that are in the player's inventory. This way, the loot tables can still drop items.
|
||||
// This is the same behavior as the vanilla /gamerule keepInventory.
|
||||
final ItemStack[] inventory = Inventories.getInventory(event.getEntity(), true);
|
||||
for (final ItemStack item : inventory) {
|
||||
if (item != null) {
|
||||
event.getDrops().remove(item);
|
||||
}
|
||||
}
|
||||
event.getDrops().clear();
|
||||
final ISettings.KeepInvPolicy vanish = ess.getSettings().getVanishingItemsPolicy();
|
||||
final ISettings.KeepInvPolicy bind = ess.getSettings().getBindingItemsPolicy();
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01) && (vanish != ISettings.KeepInvPolicy.KEEP || bind != ISettings.KeepInvPolicy.KEEP)) {
|
||||
|
||||
@@ -17,10 +17,6 @@ import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.ess3.provider.CommandSendListenerProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.InventoryViewProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.TickCountProvider;
|
||||
import net.ess3.provider.providers.BukkitCommandSendListenerProvider;
|
||||
import net.ess3.provider.providers.PaperCommandSendListenerProvider;
|
||||
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
|
||||
@@ -69,6 +65,7 @@ import java.lang.management.ManagementFactory;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -302,7 +299,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
}
|
||||
user.setLogoutLocation();
|
||||
if (user.isRecipeSee()) {
|
||||
ess.provider(InventoryViewProvider.class).getTopInventory(user.getBase().getOpenInventory()).clear();
|
||||
ess.getInventoryViewProvider().getTopInventory(user.getBase().getOpenInventory()).clear();
|
||||
}
|
||||
|
||||
final ArrayList<HumanEntity> viewers = new ArrayList<>(user.getBase().getInventory().getViewers());
|
||||
@@ -589,21 +586,6 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
if (ess.getSettings().isTeleportInvulnerability()) {
|
||||
user.enableInvulnerabilityAfterTeleport();
|
||||
}
|
||||
|
||||
// Mitigation for https://github.com/EssentialsX/Essentials/issues/4325
|
||||
final TickCountProvider tickCountProvider = ess.provider(TickCountProvider.class);
|
||||
if (tickCountProvider != null && ess.getSettings().isWorldChangePreserveFlying() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_17_R01)) {
|
||||
if (user.isAuthorized("essentials.fly")) {
|
||||
//noinspection DataFlowIssue - not real
|
||||
if (event.getFrom().getWorld() != event.getTo().getWorld() && player.getAllowFlight()) {
|
||||
// If the player is not flying but has the ability to fly, we set the sign of the tick count to -1
|
||||
// Later on in the PlayerChangedWorldEvent, we will set the player's flying state to true if the tick count is positive.
|
||||
// If the tick count is negative, we simply just set the player's flight ability to true.
|
||||
final int tick = player.isFlying() ? tickCountProvider.getTickCount() : -tickCountProvider.getTickCount();
|
||||
user.setFlightTick(tick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
@@ -627,17 +609,17 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
final String cmd = event.getMessage().split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final String cmd = event.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final int argStartIndex = event.getMessage().indexOf(" ");
|
||||
final String args = argStartIndex == -1 ? "" // No arguments present
|
||||
: event.getMessage().substring(argStartIndex); // arguments start at argStartIndex; substring from there.
|
||||
|
||||
// If the plugin command does not exist, check if it is an alias from commands.yml
|
||||
if (ess.getServer().getPluginCommand(cmd) == null) {
|
||||
final Command knownCommand = ess.provider(KnownCommandsProvider.class).getKnownCommands().get(cmd);
|
||||
final Command knownCommand = ess.getKnownCommandsProvider().getKnownCommands().get(cmd);
|
||||
if (knownCommand instanceof FormattedCommandAlias) {
|
||||
final FormattedCommandAlias command = (FormattedCommandAlias) knownCommand;
|
||||
for (String fullCommand : ess.provider(FormattedCommandAliasProvider.class).createCommands(command, event.getPlayer(), args.split(" "))) {
|
||||
for (String fullCommand : ess.getFormattedCommandAliasProvider().createCommands(command, event.getPlayer(), args.split(" "))) {
|
||||
handlePlayerCommandPreprocess(event, fullCommand);
|
||||
}
|
||||
return;
|
||||
@@ -650,7 +632,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent event, final String effectiveCommand) {
|
||||
final Player player = event.getPlayer();
|
||||
final String cmd = effectiveCommand.split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final String cmd = effectiveCommand.toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final PluginCommand pluginCommand = ess.getServer().getPluginCommand(cmd);
|
||||
|
||||
if (ess.getSettings().getSocialSpyCommands().contains(cmd) || ess.getSettings().getSocialSpyCommands().contains("*")) {
|
||||
@@ -723,17 +705,21 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
// If so, no need to check for (and write) new ones.
|
||||
boolean cooldownFound = false;
|
||||
|
||||
for (final Entry<Pattern, Long> entry : user.getCommandCooldowns().entrySet()) {
|
||||
// Iterate over a copy of getCommandCooldowns in case of concurrent modifications
|
||||
for (final Entry<Pattern, Long> entry : new HashMap<>(user.getCommandCooldowns()).entrySet()) {
|
||||
// Remove any expired cooldowns
|
||||
if (entry.getValue() <= System.currentTimeMillis()) {
|
||||
user.clearCommandCooldown(entry.getKey());
|
||||
// Don't break in case there are other command cooldowns left to clear.
|
||||
} else if (entry.getKey().matcher(fullCommand).matches()) {
|
||||
// User's current cooldown hasn't expired, inform and terminate cooldown code.
|
||||
final String commandCooldownTime = DateUtil.formatDateDiff(entry.getValue());
|
||||
user.sendTl("commandCooldown", commandCooldownTime);
|
||||
cooldownFound = true;
|
||||
event.setCancelled(true);
|
||||
if (entry.getValue() > System.currentTimeMillis()) {
|
||||
final String commandCooldownTime = DateUtil.formatDateDiff(entry.getValue());
|
||||
user.sendTl("commandCooldown", commandCooldownTime);
|
||||
cooldownFound = true;
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -757,7 +743,8 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
if (ess.getSettings().isWorldChangeFlyResetEnabled()) {
|
||||
if (user.getBase().getGameMode() != GameMode.CREATIVE
|
||||
&& user.getBase().getGameMode() != GameMode.SPECTATOR
|
||||
// COMPAT: String compare for 1.7.10
|
||||
&& !user.getBase().getGameMode().name().equals("SPECTATOR")
|
||||
&& !user.isAuthorized("essentials.fly")) {
|
||||
user.getBase().setFallDistance(0f);
|
||||
user.getBase().setAllowFlight(false);
|
||||
@@ -780,16 +767,6 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final TickCountProvider tickCountProvider = ess.provider(TickCountProvider.class);
|
||||
final int flightTick = user.getFlightTick();
|
||||
if (tickCountProvider != null && Math.abs(flightTick) == tickCountProvider.getTickCount() && user.isAuthorized("essentials.fly")) {
|
||||
user.getBase().setAllowFlight(true);
|
||||
if (flightTick > 0) {
|
||||
user.getBase().setFlying(true);
|
||||
}
|
||||
}
|
||||
user.setFlightTick(-1);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@@ -920,15 +897,14 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onInventoryClickEvent(final InventoryClickEvent event) {
|
||||
Player refreshPlayer = null;
|
||||
final InventoryViewProvider provider = ess.provider(InventoryViewProvider.class);
|
||||
final Inventory top = provider.getTopInventory(event.getView());
|
||||
final Inventory top = ess.getInventoryViewProvider().getTopInventory(event.getView());
|
||||
final InventoryType type = top.getType();
|
||||
|
||||
final Inventory clickedInventory;
|
||||
if (event.getRawSlot() < 0) {
|
||||
clickedInventory = null;
|
||||
} else {
|
||||
clickedInventory = event.getRawSlot() < top.getSize() ? top : provider.getBottomInventory(event.getView());
|
||||
clickedInventory = event.getRawSlot() < top.getSize() ? top : ess.getInventoryViewProvider().getBottomInventory(event.getView());
|
||||
}
|
||||
|
||||
final User user = ess.getUser((Player) event.getWhoClicked());
|
||||
@@ -987,8 +963,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryCloseEvent(final InventoryCloseEvent event) {
|
||||
Player refreshPlayer = null;
|
||||
final InventoryViewProvider provider = ess.provider(InventoryViewProvider.class);
|
||||
final Inventory top = provider.getTopInventory(event.getView());
|
||||
final Inventory top = ess.getInventoryViewProvider().getTopInventory(event.getView());
|
||||
final InventoryType type = top.getType();
|
||||
if (type == InventoryType.PLAYER) {
|
||||
final User user = ess.getUser((Player) event.getPlayer());
|
||||
@@ -1002,7 +977,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
final User user = ess.getUser((Player) event.getPlayer());
|
||||
if (user.isRecipeSee()) {
|
||||
user.setRecipeSee(false);
|
||||
provider.getTopInventory(event.getView()).clear();
|
||||
ess.getInventoryViewProvider().getTopInventory(event.getView()).clear();
|
||||
refreshPlayer = user.getBase();
|
||||
}
|
||||
} else if (type == InventoryType.CHEST && top.getSize() == 9) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.config.ConfigurateUtil;
|
||||
import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.config.EssentialsUserConfiguration;
|
||||
import com.earth2me.essentials.config.entities.LazyLocation;
|
||||
import com.earth2me.essentials.craftbukkit.BanLookup;
|
||||
import com.earth2me.essentials.userstorage.ModernUUIDCache;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
@@ -157,41 +156,6 @@ public class EssentialsUpgrade {
|
||||
ess.getLogger().info("To rerun the conversion type /essentials uuidconvert");
|
||||
}
|
||||
|
||||
public void updateRandomTeleport() {
|
||||
if (doneFile.getBoolean("updateRandomTeleport", false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EssentialsConfiguration config = ess.getRandomTeleport().getConfig();
|
||||
|
||||
if (config.getRootNode() != null) {
|
||||
final LazyLocation center = config.getLocation("center");
|
||||
final Location centerLoc = center != null ? center.location() : null;
|
||||
if (center != null && centerLoc != null) {
|
||||
final double minRange = config.getDouble("min-range", Double.MIN_VALUE);
|
||||
final double maxRange = config.getDouble("max-range", Double.MIN_VALUE);
|
||||
for (final World world : ess.getServer().getWorlds()) {
|
||||
final String propPrefix = "locations." + world.getName() + ".";
|
||||
config.setProperty(propPrefix + "center", centerLoc);
|
||||
|
||||
if (minRange != Double.MIN_VALUE) {
|
||||
config.setProperty(propPrefix + "min-range", minRange);
|
||||
}
|
||||
if (maxRange != Double.MIN_VALUE) {
|
||||
config.setProperty(propPrefix + "max-range", maxRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
config.removeProperty("center");
|
||||
|
||||
config.blockingSave();
|
||||
}
|
||||
|
||||
doneFile.setProperty("updateRandomTeleport", true);
|
||||
doneFile.save();
|
||||
ess.getLogger().info("Done converting random teleport config.");
|
||||
}
|
||||
|
||||
public void convertMailList() {
|
||||
if (doneFile.getBoolean("updateUsersMailList", false)) {
|
||||
return;
|
||||
@@ -1104,6 +1068,5 @@ public class EssentialsUpgrade {
|
||||
convertStupidCamelCaseUserdataKeys();
|
||||
convertMailList();
|
||||
purgeBrokenNpcAccounts();
|
||||
updateRandomTeleport();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,25 @@ import com.earth2me.essentials.commands.PlayerNotFoundException;
|
||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||
import com.earth2me.essentials.updatecheck.UpdateChecker;
|
||||
import com.earth2me.essentials.userstorage.IUserMap;
|
||||
import net.ess3.provider.Provider;
|
||||
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import net.ess3.provider.BiomeKeyProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.InventoryViewProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.MaterialTagProvider;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.PlayerLocaleProvider;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import net.ess3.provider.ServerStateProvider;
|
||||
import net.ess3.provider.SignDataProvider;
|
||||
import net.ess3.provider.SpawnerBlockProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import net.ess3.provider.SyncCommandsProvider;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.essentialsx.api.v2.services.BalanceTop;
|
||||
import net.essentialsx.api.v2.services.mail.MailService;
|
||||
import org.bukkit.Server;
|
||||
@@ -139,11 +157,43 @@ public interface IEssentials extends Plugin {
|
||||
|
||||
Iterable<User> getOnlineUsers();
|
||||
|
||||
SpawnerItemProvider getSpawnerItemProvider();
|
||||
|
||||
SpawnerBlockProvider getSpawnerBlockProvider();
|
||||
|
||||
ServerStateProvider getServerStateProvider();
|
||||
|
||||
MaterialTagProvider getMaterialTagProvider();
|
||||
|
||||
ContainerProvider getContainerProvider();
|
||||
|
||||
KnownCommandsProvider getKnownCommandsProvider();
|
||||
|
||||
SerializationProvider getSerializationProvider();
|
||||
|
||||
FormattedCommandAliasProvider getFormattedCommandAliasProvider();
|
||||
|
||||
SyncCommandsProvider getSyncCommandsProvider();
|
||||
|
||||
PersistentDataProvider getPersistentDataProvider();
|
||||
|
||||
ReflOnlineModeProvider getOnlineModeProvider();
|
||||
|
||||
ItemUnbreakableProvider getItemUnbreakableProvider();
|
||||
|
||||
WorldInfoProvider getWorldInfoProvider();
|
||||
|
||||
SignDataProvider getSignDataProvider();
|
||||
|
||||
PlayerLocaleProvider getPlayerLocaleProvider();
|
||||
|
||||
DamageEventProvider getDamageEventProvider();
|
||||
|
||||
BiomeKeyProvider getBiomeKeyProvider();
|
||||
|
||||
BannerDataProvider getBannerDataProvider();
|
||||
|
||||
InventoryViewProvider getInventoryViewProvider();
|
||||
|
||||
PluginCommand getPluginCommand(String cmd);
|
||||
|
||||
ProviderFactory getProviders();
|
||||
|
||||
default <P extends Provider> P provider(final Class<P> providerClass) {
|
||||
return getProviders().get(providerClass);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import net.essentialsx.api.v2.ChatType;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -38,8 +37,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
String getChatFormat(String group);
|
||||
|
||||
String getChatFormat(String group, ChatType chatType);
|
||||
|
||||
String getWorldAlias(String world);
|
||||
|
||||
int getChatRadius();
|
||||
@@ -56,8 +53,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean isChatQuestionEnabled();
|
||||
|
||||
boolean isUsePaperChatEvent();
|
||||
|
||||
BigDecimal getCommandCost(IEssentialsCommand cmd);
|
||||
|
||||
BigDecimal getCommandCost(String label);
|
||||
@@ -105,18 +100,12 @@ public interface ISettings extends IConf {
|
||||
|
||||
List<Material> getProtectList(final String configName);
|
||||
|
||||
List<String> getProtectListRaw(final String configName);
|
||||
|
||||
boolean getProtectPreventSpawn(final String creatureName);
|
||||
|
||||
String getProtectString(final String configName);
|
||||
|
||||
boolean getRespawnAtHome();
|
||||
|
||||
String getRandomSpawnLocation();
|
||||
|
||||
String getRandomRespawnLocation();
|
||||
|
||||
boolean isRespawnAtAnchor();
|
||||
|
||||
Set getMultipleHomes();
|
||||
@@ -348,8 +337,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean isWorldChangeFlyResetEnabled();
|
||||
|
||||
boolean isWorldChangePreserveFlying();
|
||||
|
||||
boolean isWorldChangeSpeedResetEnabled();
|
||||
|
||||
long getCommandCooldownMs(String label);
|
||||
@@ -424,20 +411,12 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean showZeroBaltop();
|
||||
|
||||
String getNickRegex();
|
||||
|
||||
BigDecimal getMultiplier(final User user);
|
||||
|
||||
int getMaxItemLore();
|
||||
|
||||
Tag getPrimaryColor();
|
||||
|
||||
Tag getSecondaryColor();
|
||||
|
||||
BigDecimal getBaltopMinBalance();
|
||||
|
||||
long getBaltopMinPlaytime();
|
||||
|
||||
enum KeepInvPolicy {
|
||||
KEEP,
|
||||
DELETE,
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.earth2me.essentials;
|
||||
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;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.essentialsx.api.v2.services.mail.MailMessage;
|
||||
@@ -69,9 +70,13 @@ public interface IUser {
|
||||
* @return whether there is a teleport request
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean hasOutstandingTeleportRequest() {
|
||||
return getNextTpaRequest(false, false, false) != null;
|
||||
}
|
||||
boolean hasOutstandingTeleportRequest();
|
||||
|
||||
/**
|
||||
* @deprecated This API is not asynchronous. Use {@link com.earth2me.essentials.api.IAsyncTeleport IAsyncTeleport} with {@link IUser#getAsyncTeleport()}
|
||||
*/
|
||||
@Deprecated
|
||||
ITeleport getTeleport();
|
||||
|
||||
IAsyncTeleport getAsyncTeleport();
|
||||
|
||||
@@ -177,17 +182,6 @@ public interface IUser {
|
||||
|
||||
String getFormattedJailTime();
|
||||
|
||||
/**
|
||||
* Returns last activity time.
|
||||
* <p>
|
||||
* It is used internally to determine if user's afk status should be set to
|
||||
* true because of ACTIVITY {@link AfkStatusChangeEvent.Cause}, or the player
|
||||
* should be kicked for being afk too long.
|
||||
*
|
||||
* @return Last activity time (Epoch Milliseconds)
|
||||
*/
|
||||
long getLastActivityTime();
|
||||
|
||||
@Deprecated
|
||||
List<String> getMails();
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.logging.Level;
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
|
||||
public class Jails implements net.ess3.api.IJails {
|
||||
private static boolean enabled = false;
|
||||
private static transient boolean enabled = false;
|
||||
private final IEssentials ess;
|
||||
private final EssentialsConfiguration config;
|
||||
private final Map<String, LazyLocation> jails = new HashMap<>();
|
||||
@@ -142,6 +142,28 @@ public class Jails implements net.ess3.api.IJails {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method does not use asynchronous teleportation. Use {@link Jails#sendToJail(IUser, String, CompletableFuture)}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
public void sendToJail(final IUser user, String jail) throws Exception {
|
||||
if (jail == null || jail.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
jail = jail.toLowerCase(Locale.ENGLISH);
|
||||
synchronized (jails) {
|
||||
if (jails.containsKey(jail)) {
|
||||
if (user.getBase().isOnline()) {
|
||||
user.getTeleport().now(getJail(jail), false, TeleportCause.COMMAND);
|
||||
}
|
||||
user.setJail(jail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToJail(final IUser user, final String jailName, final CompletableFuture<Boolean> future) throws Exception {
|
||||
if (jailName == null || jailName.isEmpty()) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.KitClaimEvent;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import net.essentialsx.api.v2.events.KitPreExpandItemsEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -192,14 +191,13 @@ public class Kit {
|
||||
}
|
||||
|
||||
final ItemStack stack;
|
||||
final SerializationProvider serializationProvider = ess.provider(SerializationProvider.class);
|
||||
|
||||
if (kitItem.startsWith("@")) {
|
||||
if (serializationProvider == null) {
|
||||
if (ess.getSerializationProvider() == null) {
|
||||
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("kitError3", kitName, user.getName())));
|
||||
continue;
|
||||
}
|
||||
stack = serializationProvider.deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
|
||||
stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
|
||||
} else {
|
||||
final String[] parts = kitItem.split(" +");
|
||||
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
|
||||
@@ -242,10 +240,10 @@ public class Kit {
|
||||
|
||||
for (final ItemStack itemStack : leftover.values()) {
|
||||
int spillAmount = itemStack.getAmount();
|
||||
if (maxStackSize != 0) {
|
||||
itemStack.setAmount(Math.min(spillAmount, itemStack.getMaxStackSize()));
|
||||
}
|
||||
while (spillAmount > 0) {
|
||||
if (maxStackSize != 0) {
|
||||
itemStack.setAmount(Math.min(spillAmount, itemStack.getMaxStackSize()));
|
||||
}
|
||||
user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
|
||||
spillAmount -= itemStack.getAmount();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.textreader.BookInput;
|
||||
import com.earth2me.essentials.textreader.BookPager;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
@@ -10,9 +11,6 @@ import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
@@ -216,6 +214,8 @@ public class MetaItemStack {
|
||||
return;
|
||||
}
|
||||
|
||||
final Material WRITTEN_BOOK = EnumUtil.getMaterial("WRITTEN_BOOK");
|
||||
|
||||
if (split.length > 1 && split[0].equalsIgnoreCase("name") && hasMetaPermission(sender, "name", false, true, ess)) {
|
||||
final String displayName = FormatUtil.replaceFormat(split[1].replaceAll("(?<!\\\\)_", " ").replace("\\_", "_"));
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
@@ -251,7 +251,7 @@ public class MetaItemStack {
|
||||
final IText input = new BookInput("book", true, ess);
|
||||
final BookPager pager = new BookPager(input);
|
||||
// This fix only applies to written books - which require an author and a title. https://bugs.mojang.com/browse/MC-59153
|
||||
if (stack.getType() == Material.WRITTEN_BOOK) {
|
||||
if (stack.getType() == WRITTEN_BOOK) {
|
||||
if (!meta.hasAuthor()) {
|
||||
// The sender can be null when this method is called from {@link com.earth2me.essentials.signs.EssentialsSign#getItemMeta(ItemStack, String, IEssentials)}
|
||||
meta.setAuthor(sender == null ? Console.getInstance().getDisplayName() : sender.getPlayer().getName());
|
||||
@@ -264,12 +264,12 @@ public class MetaItemStack {
|
||||
final List<String> pages = pager.getPages(split[1]);
|
||||
meta.setPages(pages);
|
||||
stack.setItemMeta(meta);
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "author", false, true, ess)) {
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == WRITTEN_BOOK && hasMetaPermission(sender, "author", false, true, ess)) {
|
||||
final String author = FormatUtil.replaceFormat(split[1]);
|
||||
final BookMeta meta = (BookMeta) stack.getItemMeta();
|
||||
meta.setAuthor(author);
|
||||
stack.setItemMeta(meta);
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "title", false, true, ess)) {
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == WRITTEN_BOOK && hasMetaPermission(sender, "title", false, true, ess)) {
|
||||
final String title = FormatUtil.replaceFormat(split[1].replaceAll("(?<!\\\\)_", " ").replace("\\_", "_"));
|
||||
final BookMeta meta = (BookMeta) stack.getItemMeta();
|
||||
meta.setTitle(title);
|
||||
@@ -565,7 +565,7 @@ public class MetaItemStack {
|
||||
}
|
||||
pmeta.addCustomEffect(pEffect, true);
|
||||
stack.setItemMeta(pmeta);
|
||||
ess.provider(PotionMetaProvider.class).setSplashPotion(stack, isSplashPotion);
|
||||
ess.getPotionMetaProvider().setSplashPotion(stack, isSplashPotion);
|
||||
resetPotionMeta();
|
||||
}
|
||||
}
|
||||
@@ -655,7 +655,7 @@ public class MetaItemStack {
|
||||
final BannerMeta meta = (BannerMeta) stack.getItemMeta();
|
||||
if (split[0].equalsIgnoreCase("basecolor")) {
|
||||
final Color color = Color.fromRGB(Integer.parseInt(split[1]));
|
||||
ess.provider(BannerDataProvider.class).setBaseColor(stack, DyeColor.getByColor(color));
|
||||
ess.getBannerDataProvider().setBaseColor(stack, DyeColor.getByColor(color));
|
||||
} else if (patternType != null) {
|
||||
//noinspection removal
|
||||
final PatternType type = PatternType.getByIdentifier(split[0]);
|
||||
@@ -718,7 +718,7 @@ public class MetaItemStack {
|
||||
|
||||
private void setUnbreakable(final IEssentials ess, final ItemStack is, final boolean unbreakable) {
|
||||
final ItemMeta meta = is.getItemMeta();
|
||||
ess.provider(ItemUnbreakableProvider.class).setUnbreakable(meta, unbreakable);
|
||||
ess.getItemUnbreakableProvider().setUnbreakable(meta, unbreakable);
|
||||
is.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
@@ -50,16 +50,7 @@ public enum Mob {
|
||||
WITHER("Wither", Enemies.ENEMY, EntityType.WITHER),
|
||||
BAT("Bat", Enemies.FRIENDLY, EntityType.BAT),
|
||||
WITCH("Witch", Enemies.ENEMY, EntityType.WITCH),
|
||||
BOAT("Boat", Enemies.NEUTRAL, MobCompat.OAK_BOAT),
|
||||
ACACIA_BOAT("AcaciaBoat", Enemies.NEUTRAL, "ACACIA_BOAT"),
|
||||
DARK_OAK_BOAT("DarkOakBoat", Enemies.NEUTRAL, "DARK_OAK_BOAT"),
|
||||
BIRCH_BOAT("BirchBoat", Enemies.NEUTRAL, "BIRCH_BOAT"),
|
||||
JUNGLE_BOAT("JungleBoat", Enemies.NEUTRAL, "JUNGLE_BOAT"),
|
||||
SPRUCE_BOAT("SpruceBoat", Enemies.NEUTRAL, "SPRUCE_BOAT"),
|
||||
MANGROVE_BOAT("MangroveBoat", Enemies.NEUTRAL, "MANGROVE_BOAT"),
|
||||
CHERRY_BOAT("CherryBoat", Enemies.NEUTRAL, "CHERRY_BOAT"),
|
||||
BAMBOO_RAFT("BambooRaft", Enemies.NEUTRAL, "BAMBOO_RAFT"),
|
||||
PALE_OAK_BOAT("PaleOakBoat", Enemies.NEUTRAL, "PALE_OAK_BOAT"),
|
||||
BOAT("Boat", Enemies.NEUTRAL, EntityType.BOAT),
|
||||
MINECART("Minecart", Enemies.NEUTRAL, EntityType.MINECART),
|
||||
MINECART_CHEST("ChestMinecart", Enemies.NEUTRAL, MobCompat.CHEST_MINECART),
|
||||
MINECART_FURNACE("FurnaceMinecart", Enemies.NEUTRAL, MobCompat.FURNACE_MINECART),
|
||||
@@ -124,7 +115,6 @@ public enum Mob {
|
||||
ARMADILLO("Armadillo", Enemies.FRIENDLY, "ARMADILLO"),
|
||||
BREEZE("Breeze", Enemies.ENEMY, "BREEZE"),
|
||||
BOGGED("Bogged", Enemies.ENEMY, "BOGGED"),
|
||||
CREAKING("Creaking", Enemies.ENEMY, "CREAKING")
|
||||
;
|
||||
|
||||
private static final Map<String, Mob> hashMap = new HashMap<>();
|
||||
|
||||
@@ -9,8 +9,6 @@ import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.entity.Axolotl;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Camel;
|
||||
import org.bukkit.entity.Chicken;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fox;
|
||||
@@ -20,17 +18,12 @@ import org.bukkit.entity.MushroomCow;
|
||||
import org.bukkit.entity.Ocelot;
|
||||
import org.bukkit.entity.Panda;
|
||||
import org.bukkit.entity.Parrot;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Salmon;
|
||||
import org.bukkit.entity.TropicalFish;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static com.earth2me.essentials.utils.EnumUtil.getEntityType;
|
||||
@@ -38,21 +31,8 @@ import static com.earth2me.essentials.utils.EnumUtil.getEntityType;
|
||||
public final class MobCompat {
|
||||
|
||||
// Constants for mob interfaces added in later versions
|
||||
public static final Class<?> RAIDER = ReflUtil.getClassCached("org.bukkit.entity.Raider");
|
||||
|
||||
// Stupid hacks to avoid Commodore rewrites.
|
||||
private static final Class<?> COW = ReflUtil.getClassCached("org.bukkit.entity.Cow");
|
||||
private static final Class<?> COW_VARIANT = ReflUtil.getClassCached("org.bukkit.entity.Cow$Variant");
|
||||
private static final MethodHandle COW_VARIANT_HANDLE;
|
||||
|
||||
static {
|
||||
MethodHandle handle = null;
|
||||
try {
|
||||
handle = MethodHandles.lookup().findVirtual(COW, "setVariant", MethodType.methodType(void.class, COW_VARIANT));
|
||||
} catch (final Throwable ignored) {
|
||||
}
|
||||
COW_VARIANT_HANDLE = handle;
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Class RAIDER = ReflUtil.getClassCached("org.bukkit.entity.Raider");
|
||||
|
||||
// Constants for mobs added in later versions
|
||||
public static final EntityType LLAMA = getEntityType("LLAMA");
|
||||
@@ -68,7 +48,6 @@ public final class MobCompat {
|
||||
public static final EntityType GOAT = getEntityType("GOAT");
|
||||
public static final EntityType FROG = getEntityType("FROG");
|
||||
public static final EntityType CAMEL = getEntityType("CAMEL");
|
||||
public static final EntityType SALMON = getEntityType("SALMON");
|
||||
|
||||
// Constants for mobs that have changed since earlier versions
|
||||
public static final EntityType CAT = getEntityType("CAT", "OCELOT");
|
||||
@@ -82,7 +61,6 @@ public final class MobCompat {
|
||||
public static final EntityType SPAWNER_MINECART = getEntityType("SPAWNER_MINECART", "MINECART_MOB_SPAWNER");
|
||||
public static final EntityType END_CRYSTAL = getEntityType("END_CRYSTAL", "ENDER_CRYSTAL");
|
||||
public static final EntityType FIREWORK_ROCKET = getEntityType("FIREWORK_ROCKET", "FIREWORK");
|
||||
public static final EntityType OAK_BOAT = getEntityType("BOAT", "OAK_BOAT");
|
||||
|
||||
private MobCompat() {
|
||||
}
|
||||
@@ -216,7 +194,7 @@ public final class MobCompat {
|
||||
}
|
||||
|
||||
public static void setBoatVariant(final Entity entity, final BoatVariant variant) {
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_3_R01) || VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
return;
|
||||
}
|
||||
final Boat boat;
|
||||
@@ -229,7 +207,6 @@ public final class MobCompat {
|
||||
//noinspection deprecation
|
||||
boat.setWoodType(TreeSpecies.valueOf(variant.getTreeSpecies()));
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
boat.setBoatType(Boat.Type.valueOf(variant.getBoatType()));
|
||||
}
|
||||
}
|
||||
@@ -259,51 +236,6 @@ public final class MobCompat {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSalmonSize(Entity spawned, String s) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_3_R01)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawned instanceof org.bukkit.entity.Salmon) {
|
||||
((Salmon) spawned).setVariant(Salmon.Variant.valueOf(s));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCowVariant(final Entity spawned, final String variant) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01) || COW_VARIANT_HANDLE == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawned instanceof Cow) {
|
||||
try {
|
||||
COW_VARIANT_HANDLE.invoke(spawned, RegistryUtil.valueOf(COW_VARIANT, variant));
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setChickenVariant(final Entity spawned, final String variant) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawned instanceof Chicken) {
|
||||
//noinspection DataFlowIssue
|
||||
((Chicken) spawned).setVariant(RegistryUtil.valueOf(Chicken.Variant.class, variant));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPigVariant(final Entity spawned, final String variant) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_5_R01)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawned instanceof Pig) {
|
||||
//noinspection DataFlowIssue
|
||||
((Pig) spawned).setVariant(RegistryUtil.valueOf(Pig.Variant.class, variant));
|
||||
}
|
||||
}
|
||||
|
||||
public enum CatType {
|
||||
// These are (loosely) Mojang names for the cats
|
||||
SIAMESE("SIAMESE", "SIAMESE_CAT"),
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Chicken;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -219,18 +218,6 @@ public enum MobData {
|
||||
WOODS_WOLF("woods", EntityType.WOLF, "wolf:WOODS", true),
|
||||
CHESTNUT_WOLF("chestnut", EntityType.WOLF, "wolf:CHESTNUT", true),
|
||||
STRIPED_WOLF("striped", EntityType.WOLF, "wolf:STRIPED", true),
|
||||
SMALL_SALMON("small", MobCompat.SALMON, "salmon:SMALL", true),
|
||||
MEDIUM_SALMON("medium", MobCompat.SALMON, "salmon:MEDIUM", true),
|
||||
LARGE_SALMON("large", MobCompat.SALMON, "salmon:LARGE", true),
|
||||
TEMPERATE_COW("temperate", EntityType.COW.getEntityClass(), "cow:TEMPERATE", true),
|
||||
WARM_COW("warm", EntityType.COW.getEntityClass(), "cow:WARM", true),
|
||||
COLD_COW("cold", EntityType.COW.getEntityClass(), "cow:COLD", true),
|
||||
TEMPERATE_CHICKEN("temperate", Chicken.class, "chicken:TEMPERATE", true),
|
||||
WARM_CHICKEN("warm", Chicken.class, "chicken:WARM", true),
|
||||
COLD_CHICKEN("cold", Chicken.class, "chicken:COLD", true),
|
||||
TEMPERATE_PIG("temperate", Pig.class, "pig:TEMPERATE", true),
|
||||
WARM_PIG("warm", Pig.class, "pig:WARM", true),
|
||||
COLD_PIG("cold", Pig.class, "pig:COLD", true),
|
||||
;
|
||||
|
||||
final private String nickname;
|
||||
@@ -449,18 +436,6 @@ public enum MobData {
|
||||
case "wolf":
|
||||
MobCompat.setWolfVariant(spawned, split[1]);
|
||||
break;
|
||||
case "salmon":
|
||||
MobCompat.setSalmonSize(spawned, split[1]);
|
||||
break;
|
||||
case "cow":
|
||||
MobCompat.setCowVariant(spawned, split[1]);
|
||||
break;
|
||||
case "chicken":
|
||||
MobCompat.setChickenVariant(spawned, split[1]);
|
||||
break;
|
||||
case "pig":
|
||||
MobCompat.setPigVariant(spawned, split[1]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Essentials.getWrappedLogger().warning("Unknown mob data type: " + this.toString());
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.provider.Provider;
|
||||
import net.essentialsx.providers.NullableProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ProviderFactory {
|
||||
private final Map<Class<? extends Provider>, Provider> providers = new HashMap<>();
|
||||
private final Map<Class<? extends Provider>, List<Class<? extends Provider>>> registeredProviders = new HashMap<>();
|
||||
private final Essentials essentials;
|
||||
|
||||
public ProviderFactory(final Essentials essentials) {
|
||||
this.essentials = essentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the provider which has been selected for the given type.
|
||||
* @param providerClass The provider type.
|
||||
* @return the provider or null if no provider could be selected for that type.
|
||||
*/
|
||||
public <P extends Provider> P get(final Class<P> providerClass) {
|
||||
final Provider provider = providers.get(providerClass);
|
||||
if (provider == null) {
|
||||
return null;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (P) provider;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public final void registerProvider(final Class<? extends Provider>... toRegister) {
|
||||
for (final Class<? extends Provider> provider : toRegister) {
|
||||
final Class<?> superclass = provider.getInterfaces().length > 0 ? provider.getInterfaces()[0] : provider.getSuperclass();
|
||||
if (Provider.class.isAssignableFrom(superclass)) {
|
||||
//noinspection unchecked
|
||||
registeredProviders.computeIfAbsent((Class<? extends Provider>) superclass, k -> new ArrayList<>()).add(provider);
|
||||
if (essentials.getSettings().isDebug()) {
|
||||
essentials.getLogger().info("Registered provider " + provider.getSimpleName() + " for " + superclass.getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void finalizeRegistration() {
|
||||
for (final Map.Entry<Class<? extends Provider>, List<Class<? extends Provider>>> entry : registeredProviders.entrySet()) {
|
||||
final Class<? extends Provider> providerClass = entry.getKey();
|
||||
final boolean nullable = providerClass.isAnnotationPresent(NullableProvider.class);
|
||||
Class<? extends Provider> highestProvider = null;
|
||||
ProviderData highestProviderData = null;
|
||||
int highestWeight = -1;
|
||||
for (final Class<? extends Provider> provider : entry.getValue()) {
|
||||
try {
|
||||
final ProviderData providerData = provider.getAnnotation(ProviderData.class);
|
||||
if (providerData.weight() > highestWeight && testProvider(provider)) {
|
||||
highestWeight = providerData.weight();
|
||||
highestProvider = provider;
|
||||
highestProviderData = providerData;
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
essentials.getLogger().log(Level.SEVERE, "Failed to initialize provider " + provider.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (highestProvider != null) {
|
||||
essentials.getLogger().info("Selected " + highestProviderData.description() + " as the provider for " + providerClass.getSimpleName());
|
||||
providers.put(providerClass, getProviderInstance(highestProvider));
|
||||
} else if (!nullable) {
|
||||
throw new IllegalStateException("No provider found for " + providerClass.getName());
|
||||
} else {
|
||||
essentials.getLogger().info("No provider found for " + providerClass.getSimpleName() + ", but it is nullable");
|
||||
}
|
||||
}
|
||||
registeredProviders.clear();
|
||||
}
|
||||
|
||||
private boolean testProvider(final Class<?> providerClass) throws InvocationTargetException, IllegalAccessException {
|
||||
try {
|
||||
for (final Method method : providerClass.getMethods()) {
|
||||
if (method.isAnnotationPresent(ProviderTest.class)) {
|
||||
return (Boolean) method.invoke(null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (final NoClassDefFoundError ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private <P extends Provider> P getProviderInstance(final Class<P> provider) {
|
||||
try {
|
||||
final Constructor<?> constructor = provider.getConstructors()[0];
|
||||
if (constructor.getParameterTypes().length == 0) {
|
||||
//noinspection unchecked
|
||||
return (P) constructor.newInstance();
|
||||
}
|
||||
final Object[] args = new Object[constructor.getParameterTypes().length];
|
||||
|
||||
/*
|
||||
Providers can have constructors with any of the following types, and this code will automatically supply them;
|
||||
- Plugin - The Essentials instance will be passed
|
||||
- boolean - True will be passed if this server is running Paper, otherwise false.
|
||||
*/
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
final Class<?> paramType = constructor.getParameterTypes()[i];
|
||||
if (paramType.isAssignableFrom(Plugin.class)) {
|
||||
args[i] = essentials;
|
||||
} else if (paramType.isAssignableFrom(boolean.class)) {
|
||||
args[i] = PaperLib.isPaper();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported parameter type " + paramType.getName());
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return (P) constructor.newInstance(args);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
try {
|
||||
return provider.getConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ex) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,17 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.config.ConfigurateUtil;
|
||||
import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.config.entities.LazyLocation;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.InvalidWorldException;
|
||||
import net.ess3.provider.BiomeKeyProvider;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
@@ -29,73 +23,58 @@ public class RandomTeleport implements IConf {
|
||||
private static final int HIGHEST_BLOCK_Y_OFFSET = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_R01) ? 1 : 0;
|
||||
private final IEssentials ess;
|
||||
private final EssentialsConfiguration config;
|
||||
private final Map<String, ConcurrentLinkedQueue<Location>> cachedLocations = new HashMap<>();
|
||||
private WorldInfoProvider worldInfoProvider;
|
||||
private final ConcurrentLinkedQueue<Location> cachedLocations = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public RandomTeleport(final IEssentials essentials) {
|
||||
this.ess = essentials;
|
||||
config = new EssentialsConfiguration(new File(essentials.getDataFolder(), "tpr.yml"), "/tpr.yml",
|
||||
"Configuration for the random teleport command.\nUse the /settpr command in-game to set random teleport locations.");
|
||||
}
|
||||
|
||||
public EssentialsConfiguration getConfig() {
|
||||
return config;
|
||||
"Configuration for the random teleport command.\nSome settings may be defaulted, and can be changed via the /settpr command in-game.");
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
worldInfoProvider = ess.provider(WorldInfoProvider.class);
|
||||
config.load();
|
||||
cachedLocations.clear();
|
||||
}
|
||||
|
||||
public boolean hasLocation(final String name) {
|
||||
return config.hasProperty("locations." + name);
|
||||
}
|
||||
|
||||
public Location getCenter(final String name) {
|
||||
final LazyLocation center = config.getLocation(locationKey(name, "center"));
|
||||
if (center != null && center.location() != null) {
|
||||
return center.location();
|
||||
public Location getCenter() {
|
||||
try {
|
||||
final LazyLocation center = config.getLocation("center");
|
||||
if (center != null && center.location() != null) {
|
||||
return center.location();
|
||||
}
|
||||
} catch (final InvalidWorldException ignored) {
|
||||
}
|
||||
|
||||
final Location worldCenter = ess.getServer().getWorlds().get(0).getWorldBorder().getCenter();
|
||||
worldCenter.setY(worldCenter.getWorld().getHighestBlockYAt(worldCenter) + HIGHEST_BLOCK_Y_OFFSET);
|
||||
setCenter(name, worldCenter);
|
||||
return worldCenter;
|
||||
final Location center = ess.getServer().getWorlds().get(0).getWorldBorder().getCenter();
|
||||
center.setY(center.getWorld().getHighestBlockYAt(center) + HIGHEST_BLOCK_Y_OFFSET);
|
||||
setCenter(center);
|
||||
return center;
|
||||
}
|
||||
|
||||
public void setCenter(final String name, final Location center) {
|
||||
config.setProperty(locationKey(name, "center"), center);
|
||||
public void setCenter(final Location center) {
|
||||
config.setProperty("center", center);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public double getMinRange(final String name) {
|
||||
return config.getDouble(locationKey(name, "min-range"), 0d);
|
||||
public double getMinRange() {
|
||||
return config.getDouble("min-range", 0d);
|
||||
}
|
||||
|
||||
public void setMinRange(final String name, final double minRange) {
|
||||
config.setProperty(locationKey(name, "min-range"), minRange);
|
||||
public void setMinRange(final double minRange) {
|
||||
config.setProperty("min-range", minRange);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public double getMaxRange(final String name) {
|
||||
return config.getDouble(locationKey(name, "max-range"), getCenter(name).getWorld().getWorldBorder().getSize() / 2);
|
||||
public double getMaxRange() {
|
||||
return config.getDouble("max-range", getCenter().getWorld().getWorldBorder().getSize() / 2);
|
||||
}
|
||||
|
||||
public void setMaxRange(final String name, final double maxRange) {
|
||||
config.setProperty(locationKey(name, "max-range"), maxRange);
|
||||
public void setMaxRange(final double maxRange) {
|
||||
config.setProperty("max-range", maxRange);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public String getDefaultLocation() {
|
||||
return config.getString("default-location", "{world}");
|
||||
}
|
||||
|
||||
public boolean isPerLocationPermission() {
|
||||
return config.getBoolean("per-location-permission", false);
|
||||
}
|
||||
|
||||
public Set<String> getExcludedBiomes() {
|
||||
final Set<String> excludedBiomes = new HashSet<>();
|
||||
for (final String key : config.getList("excluded-biomes", String.class)) {
|
||||
@@ -112,48 +91,39 @@ public class RandomTeleport implements IConf {
|
||||
return config.getInt("cache-threshold", 10);
|
||||
}
|
||||
|
||||
public List<String> listLocations() {
|
||||
return new ArrayList<>(ConfigurateUtil.getKeys(config.getRootNode().node("locations")));
|
||||
public boolean getPreCache() {
|
||||
return config.getBoolean("pre-cache", false);
|
||||
}
|
||||
|
||||
public Queue<Location> getCachedLocations(final String name) {
|
||||
this.cachedLocations.computeIfAbsent(name, x -> new ConcurrentLinkedQueue<>());
|
||||
return cachedLocations.get(name);
|
||||
public Queue<Location> getCachedLocations() {
|
||||
return cachedLocations;
|
||||
}
|
||||
|
||||
// Get a named random teleport location; cached if possible, otherwise on demand.
|
||||
public CompletableFuture<Location> getRandomLocation(final String name) {
|
||||
final Queue<Location> cached = this.getCachedLocations(name);
|
||||
// Get a random location; cached if possible. Otherwise on demand.
|
||||
public CompletableFuture<Location> getRandomLocation(final Location center, final double minRange, final double maxRange) {
|
||||
final int findAttempts = this.getFindAttempts();
|
||||
final Queue<Location> cachedLocations = this.getCachedLocations();
|
||||
// Try to build up the cache if it is below the threshold
|
||||
if (cached.size() < this.getCacheThreshold()) {
|
||||
cacheRandomLocations(name);
|
||||
if (cachedLocations.size() < this.getCacheThreshold()) {
|
||||
cacheRandomLocations(center, minRange, maxRange);
|
||||
}
|
||||
final CompletableFuture<Location> future = new CompletableFuture<>();
|
||||
// Return a random location immediately if one is available, otherwise try to find one now
|
||||
if (cached.isEmpty()) {
|
||||
final int findAttempts = this.getFindAttempts();
|
||||
final Location center = this.getCenter(name);
|
||||
final double minRange = this.getMinRange(name);
|
||||
final double maxRange = this.getMaxRange(name);
|
||||
if (cachedLocations.isEmpty()) {
|
||||
attemptRandomLocation(findAttempts, center, minRange, maxRange).thenAccept(future::complete);
|
||||
} else {
|
||||
future.complete(cached.poll());
|
||||
future.complete(cachedLocations.poll());
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
// Get a random location with specific parameters (note: not cached).
|
||||
public CompletableFuture<Location> getRandomLocation(final Location center, final double minRange, final double maxRange) {
|
||||
return attemptRandomLocation(this.getFindAttempts(), center, minRange, maxRange);
|
||||
}
|
||||
|
||||
// Prompts caching random valid locations, up to a maximum number of attempts.
|
||||
public void cacheRandomLocations(final String name) {
|
||||
// Prompts caching random valid locations, up to a maximum number of attempts
|
||||
public void cacheRandomLocations(final Location center, final double minRange, final double maxRange) {
|
||||
ess.getServer().getScheduler().scheduleSyncDelayedTask(ess, () -> {
|
||||
for (int i = 0; i < this.getFindAttempts(); ++i) {
|
||||
calculateRandomLocation(getCenter(name), getMinRange(name), getMaxRange(name)).thenAccept(location -> {
|
||||
calculateRandomLocation(center, minRange, maxRange).thenAccept(location -> {
|
||||
if (isValidRandomLocation(location)) {
|
||||
this.getCachedLocations(name).add(location);
|
||||
this.getCachedLocations().add(location);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -202,7 +172,7 @@ public class RandomTeleport implements IConf {
|
||||
final Location location = new Location(
|
||||
center.getWorld(),
|
||||
center.getX() + offsetX,
|
||||
worldInfoProvider.getMaxHeight(center.getWorld()),
|
||||
ess.getWorldInfoProvider().getMaxHeight(center.getWorld()),
|
||||
center.getZ() + offsetZ,
|
||||
360 * RANDOM.nextFloat() - 180,
|
||||
0
|
||||
@@ -218,22 +188,18 @@ public class RandomTeleport implements IConf {
|
||||
return future;
|
||||
}
|
||||
|
||||
// Returns an appropriate elevation for a given location in the nether, or MIN_VALUE if none is found
|
||||
// Returns an appropriate elevation for a given location in the nether, or -1 if none is found
|
||||
private double getNetherYAt(final Location location) {
|
||||
final World world = location.getWorld();
|
||||
for (int y = 32; y < worldInfoProvider.getMaxHeight(world); ++y) {
|
||||
if (Material.BEDROCK.equals(world.getBlockAt(location.getBlockX(), y, location.getBlockZ()).getType())) {
|
||||
break;
|
||||
}
|
||||
if (!LocationUtil.isBlockUnsafe(ess, world, location.getBlockX(), y, location.getBlockZ())) {
|
||||
for (int y = 32; y < ess.getWorldInfoProvider().getMaxHeight(location.getWorld()); ++y) {
|
||||
if (!LocationUtil.isBlockUnsafe(ess, location.getWorld(), location.getBlockX(), y, location.getBlockZ())) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return Double.MIN_VALUE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private boolean isValidRandomLocation(final Location location) {
|
||||
return location.getBlockY() > worldInfoProvider.getMinHeight(location.getWorld()) && !isExcludedBiome(location);
|
||||
return location.getBlockY() > ess.getWorldInfoProvider().getMinHeight(location.getWorld()) && !isExcludedBiome(location);
|
||||
}
|
||||
|
||||
// Exclude biome if enum or namespaced key matches
|
||||
@@ -249,7 +215,7 @@ public class RandomTeleport implements IConf {
|
||||
return false;
|
||||
}
|
||||
final String biomeKey;
|
||||
final BiomeKeyProvider biomeKeyProvider = ess.provider(BiomeKeyProvider.class);
|
||||
final BiomeKeyProvider biomeKeyProvider = ess.getBiomeKeyProvider();
|
||||
if (biomeKeyProvider != null) {
|
||||
// Works with custom biome keys
|
||||
biomeKey = biomeKeyProvider.getBiomeKey(location.getBlock()).toString();
|
||||
@@ -260,10 +226,6 @@ public class RandomTeleport implements IConf {
|
||||
return excluded.contains(biomeKey);
|
||||
}
|
||||
|
||||
private String locationKey(final String name, final String key) {
|
||||
return "locations." + name + "." + key;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return config.getFile();
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@ import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.SyncCommandsProvider;
|
||||
import net.essentialsx.api.v2.ChatType;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
@@ -26,7 +23,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
|
||||
import java.io.File;
|
||||
@@ -38,7 +34,6 @@ import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -49,7 +44,6 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
@@ -64,7 +58,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
private final transient EssentialsConfiguration config;
|
||||
private final transient IEssentials ess;
|
||||
private final transient AtomicInteger reloadCount = new AtomicInteger(0);
|
||||
private final ChatFormats chatFormats = new ChatFormats();
|
||||
private final Map<String, String> chatFormats = Collections.synchronizedMap(new HashMap<>());
|
||||
private int chatRadius = 0;
|
||||
// #easteregg
|
||||
private char chatShout = '!';
|
||||
@@ -151,8 +145,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
private Map<String, String> worldAliases;
|
||||
private Tag primaryColor = DEFAULT_PRIMARY_COLOR;
|
||||
private Tag secondaryColor = DEFAULT_SECONDARY_COLOR;
|
||||
private Set<String> multiplierPerms;
|
||||
private BigDecimal defaultMultiplier;
|
||||
|
||||
public Settings(final IEssentials ess) {
|
||||
this.ess = ess;
|
||||
@@ -170,16 +162,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getBoolean("respawn-at-home", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomSpawnLocation() {
|
||||
return config.getString("random-spawn-location", "none");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomRespawnLocation() {
|
||||
return config.getString("random-respawn-location", "none");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRespawnAtAnchor() {
|
||||
return config.getBoolean("respawn-at-anchor", false);
|
||||
@@ -206,7 +188,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
final Set<String> homeList = getMultipleHomes();
|
||||
if (homeList != null) {
|
||||
for (final String set : homeList) {
|
||||
if (user.isAuthorized("essentials.sethome.multiple." + set) && limit < getHomeLimit(set)) {
|
||||
if (user.isAuthorized("essentials.sethome.multiple." + set) && (limit < getHomeLimit(set))) {
|
||||
limit = getHomeLimit(set);
|
||||
}
|
||||
}
|
||||
@@ -266,11 +248,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getBoolean("chat.question-enabled", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsePaperChatEvent() {
|
||||
return config.getBoolean("chat.paper-chat-events", true);
|
||||
}
|
||||
|
||||
public boolean _isTeleportSafetyEnabled() {
|
||||
return config.getBoolean("teleport-safety", true);
|
||||
}
|
||||
@@ -345,11 +322,9 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
private void _addAlternativeCommand(final String label, final Command current) {
|
||||
final KnownCommandsProvider knownCommandsProvider = ess.provider(KnownCommandsProvider.class);
|
||||
|
||||
Command cmd = ess.getAlternativeCommandsHandler().getAlternative(label);
|
||||
if (cmd == null) {
|
||||
for (final Map.Entry<String, Command> entry : knownCommandsProvider.getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
final String[] split = entry.getKey().split(":");
|
||||
if (entry.getValue() != current && split[split.length - 1].equals(label)) {
|
||||
cmd = entry.getValue();
|
||||
@@ -359,7 +334,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
if (cmd != null) {
|
||||
knownCommandsProvider.getKnownCommands().put(label, cmd);
|
||||
ess.getKnownCommandsProvider().getKnownCommands().put(label, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,132 +579,32 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
|
||||
@Override
|
||||
public String getChatFormat(final String group) {
|
||||
return getChatFormat(group, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChatFormat(final String group, final ChatType chatType) {
|
||||
final String mFormat = chatFormats.getFormat(group, chatType, new ChatFormatConfigSupplier(group, chatType));
|
||||
String mFormat = chatFormats.get(group);
|
||||
if (mFormat == null) {
|
||||
mFormat = config.getString("chat.group-formats." + (group == null ? "Default" : group), config.getString("chat.format", "&7[{GROUP}]&r {DISPLAYNAME}&7:&r {MESSAGE}"));
|
||||
mFormat = FormatUtil.replaceFormat(mFormat);
|
||||
mFormat = mFormat.replace("{DISPLAYNAME}", "%1$s");
|
||||
mFormat = mFormat.replace("{MESSAGE}", "%2$s");
|
||||
mFormat = mFormat.replace("{GROUP}", "{0}");
|
||||
mFormat = mFormat.replace("{WORLD}", "{1}");
|
||||
mFormat = mFormat.replace("{WORLDNAME}", "{1}");
|
||||
mFormat = mFormat.replace("{SHORTWORLDNAME}", "{2}");
|
||||
mFormat = mFormat.replace("{TEAMPREFIX}", "{3}");
|
||||
mFormat = mFormat.replace("{TEAMSUFFIX}", "{4}");
|
||||
mFormat = mFormat.replace("{TEAMNAME}", "{5}");
|
||||
mFormat = mFormat.replace("{PREFIX}", "{6}");
|
||||
mFormat = mFormat.replace("{SUFFIX}", "{7}");
|
||||
mFormat = mFormat.replace("{USERNAME}", "{8}");
|
||||
mFormat = mFormat.replace("{NICKNAME}", "{9}");
|
||||
mFormat = "§r".concat(mFormat);
|
||||
chatFormats.put(group, mFormat);
|
||||
}
|
||||
if (isDebug()) {
|
||||
ess.getLogger().info(String.format("Found format '%s' for group '%s'", mFormat, group));
|
||||
}
|
||||
return mFormat;
|
||||
}
|
||||
|
||||
private class ChatFormatConfigSupplier implements Supplier<String> {
|
||||
private final String group;
|
||||
private final ChatType chatType;
|
||||
|
||||
ChatFormatConfigSupplier(String group, ChatType chatType) {
|
||||
this.group = group;
|
||||
this.chatType = chatType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
final String chatKey = chatType.key();
|
||||
|
||||
final String groupPath = "chat.group-formats." + (group == null ? "Default" : group);
|
||||
String configFormat = config.getString(groupPath + "." + chatKey, null);
|
||||
|
||||
if (configFormat == null) {
|
||||
configFormat = config.getString(groupPath, null);
|
||||
}
|
||||
|
||||
final String formatPath = "chat.format";
|
||||
if (configFormat == null) {
|
||||
configFormat = config.getString(formatPath + "." + chatKey, null);
|
||||
}
|
||||
|
||||
if (configFormat == null) {
|
||||
configFormat = config.getString(formatPath, null);
|
||||
}
|
||||
|
||||
if (configFormat == null) {
|
||||
configFormat = "&7[{GROUP}]&r {DISPLAYNAME}&7:&r {MESSAGE}";
|
||||
}
|
||||
|
||||
configFormat = FormatUtil.replaceFormat(configFormat);
|
||||
configFormat = configFormat.replace("{DISPLAYNAME}", "%1$s");
|
||||
configFormat = configFormat.replace("{MESSAGE}", "%2$s");
|
||||
configFormat = configFormat.replace("{GROUP}", "{0}");
|
||||
configFormat = configFormat.replace("{WORLD}", "{1}");
|
||||
configFormat = configFormat.replace("{WORLDNAME}", "{1}");
|
||||
configFormat = configFormat.replace("{SHORTWORLDNAME}", "{2}");
|
||||
configFormat = configFormat.replace("{TEAMPREFIX}", "{3}");
|
||||
configFormat = configFormat.replace("{TEAMSUFFIX}", "{4}");
|
||||
configFormat = configFormat.replace("{TEAMNAME}", "{5}");
|
||||
configFormat = configFormat.replace("{PREFIX}", "{6}");
|
||||
configFormat = configFormat.replace("{SUFFIX}", "{7}");
|
||||
configFormat = configFormat.replace("{USERNAME}", "{8}");
|
||||
configFormat = configFormat.replace("{NICKNAME}", "{9}");
|
||||
configFormat = "§r".concat(configFormat);
|
||||
return configFormat;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ChatFormats {
|
||||
|
||||
private final Map<String, TypedChatFormat> groupFormats;
|
||||
private TypedChatFormat defaultFormat;
|
||||
|
||||
ChatFormats() {
|
||||
defaultFormat = null;
|
||||
groupFormats = new HashMap<>();
|
||||
}
|
||||
|
||||
public String getFormat(String group, ChatType type, Supplier<String> configSupplier) {
|
||||
// With such a large synchronize block, we synchronize a potential config deserialization
|
||||
// It does not matter as it needs to be done. It's even better as we ensure to do it once
|
||||
// TypedChatFormat is also synchronized
|
||||
synchronized (this) {
|
||||
final TypedChatFormat typedChatFormat;
|
||||
if (group == null) {
|
||||
if (defaultFormat == null) {
|
||||
defaultFormat = new TypedChatFormat();
|
||||
}
|
||||
typedChatFormat = defaultFormat;
|
||||
} else {
|
||||
typedChatFormat = groupFormats.computeIfAbsent(group, s -> new TypedChatFormat());
|
||||
}
|
||||
return typedChatFormat.getFormat(type, configSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
synchronized (this) {
|
||||
defaultFormat = null;
|
||||
groupFormats.clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class TypedChatFormat {
|
||||
|
||||
private final Map<ChatType, String> typedFormats;
|
||||
private String defaultFormat;
|
||||
|
||||
TypedChatFormat() {
|
||||
defaultFormat = null;
|
||||
typedFormats = new EnumMap<>(ChatType.class);
|
||||
}
|
||||
|
||||
public String getFormat(ChatType type, Supplier<String> configSupplier) {
|
||||
final String format;
|
||||
if (type == null) {
|
||||
if (defaultFormat == null) {
|
||||
defaultFormat = configSupplier.get();
|
||||
}
|
||||
format = defaultFormat;
|
||||
} else {
|
||||
format = typedFormats.computeIfAbsent(type, c -> configSupplier.get());
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWorldAlias(String world) {
|
||||
return worldAliases.getOrDefault(world.toLowerCase(), world);
|
||||
@@ -818,32 +693,18 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
overriddenCommands = _getOverriddenCommands();
|
||||
playerCommands = _getPlayerCommands();
|
||||
|
||||
final KnownCommandsProvider knownCommandsProvider = ess.provider(KnownCommandsProvider.class);
|
||||
|
||||
// This will be late loaded
|
||||
if (knownCommandsProvider != null) {
|
||||
if (ess.getKnownCommandsProvider() != null) {
|
||||
boolean mapModified = false;
|
||||
if (!disabledBukkitCommands.isEmpty()) {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!");
|
||||
}
|
||||
knownCommandsProvider.getKnownCommands().putAll(disabledBukkitCommands);
|
||||
ess.getKnownCommandsProvider().getKnownCommands().putAll(disabledBukkitCommands);
|
||||
disabledBukkitCommands.clear();
|
||||
mapModified = true;
|
||||
}
|
||||
|
||||
if (reloadCount.get() < 2) {
|
||||
// on startup: add plugins again in case they registered commands with the new API
|
||||
// we need to schedule this task before any of the below tasks using _addAlternativeCommand.
|
||||
ess.scheduleSyncDelayedTask(() -> {
|
||||
for (final Plugin plugin : ess.getServer().getPluginManager().getPlugins()) {
|
||||
if (plugin.isEnabled()) {
|
||||
ess.getAlternativeCommandsHandler().addPlugin(plugin);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (final String command : disabledCommands) {
|
||||
final String effectiveAlias = command.toLowerCase(Locale.ENGLISH);
|
||||
final Command toDisable = ess.getPluginCommand(effectiveAlias);
|
||||
@@ -851,7 +712,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias);
|
||||
}
|
||||
final Command removed = knownCommandsProvider.getKnownCommands().remove(effectiveAlias);
|
||||
final Command removed = ess.getKnownCommandsProvider().getKnownCommands().remove(effectiveAlias);
|
||||
if (removed != null) {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!");
|
||||
@@ -869,16 +730,14 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
}
|
||||
|
||||
final SyncCommandsProvider syncCommandsProvider = ess.provider(SyncCommandsProvider.class);
|
||||
|
||||
if (mapModified) {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Syncing commands");
|
||||
}
|
||||
if (reloadCount.get() < 2) {
|
||||
ess.scheduleSyncDelayedTask(syncCommandsProvider::syncCommands);
|
||||
ess.scheduleSyncDelayedTask(() -> ess.getSyncCommandsProvider().syncCommands());
|
||||
} else {
|
||||
syncCommandsProvider.syncCommands();
|
||||
ess.getSyncCommandsProvider().syncCommands();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -936,8 +795,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
worldAliases = _getWorldAliases();
|
||||
primaryColor = _getPrimaryColor();
|
||||
secondaryColor = _getSecondaryColor();
|
||||
multiplierPerms = _getMultiplierPerms();
|
||||
defaultMultiplier = _getDefaultMultiplier();
|
||||
|
||||
reloadCount.incrementAndGet();
|
||||
}
|
||||
@@ -1096,23 +953,14 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getProtectListRaw(String configName) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
public List<Material> getProtectList(final String configName) {
|
||||
final List<Material> list = new ArrayList<>();
|
||||
for (String itemName : config.getString(configName, "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list.add(itemName);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getProtectList(final String configName) {
|
||||
final List<Material> list = new ArrayList<>();
|
||||
for (String itemName : getProtectListRaw(configName)) {
|
||||
Material mat = EnumUtil.getMaterial(itemName.toUpperCase());
|
||||
|
||||
if (mat == null) {
|
||||
@@ -1933,11 +1781,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getBoolean("world-change-fly-reset", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldChangePreserveFlying() {
|
||||
return config.getBoolean("world-change-preserve-flying", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldChangeSpeedResetEnabled() {
|
||||
return config.getBoolean("world-change-speed-reset", true);
|
||||
@@ -1945,7 +1788,9 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
|
||||
private List<String> _getDefaultEnabledConfirmCommands() {
|
||||
final List<String> commands = config.getList("default-enabled-confirm-commands", String.class);
|
||||
commands.replaceAll(String::toLowerCase);
|
||||
for (int i = 0; i < commands.size(); i++) {
|
||||
commands.set(i, commands.get(i).toLowerCase());
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
@@ -2121,38 +1966,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNickRegex() {
|
||||
return config.getString("allowed-nicks-regex", "^[a-zA-Z_0-9§]+$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getMultiplier(final User user) {
|
||||
BigDecimal multiplier = defaultMultiplier;
|
||||
if (multiplierPerms == null) {
|
||||
return defaultMultiplier;
|
||||
}
|
||||
|
||||
for (final String multiplierPerm : multiplierPerms) {
|
||||
if (user.isAuthorized("essentials.sell.multiplier." + multiplierPerm)) {
|
||||
final BigDecimal value = config.getBigDecimal("sell-multipliers." + multiplierPerm, BigDecimal.ZERO);
|
||||
if (value.compareTo(multiplier) > 0) {
|
||||
multiplier = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
private BigDecimal _getDefaultMultiplier() {
|
||||
return config.getBigDecimal("sell-multipliers.default", BigDecimal.ONE);
|
||||
}
|
||||
|
||||
private Set<String> _getMultiplierPerms() {
|
||||
final CommentedConfigurationNode section = config.getSection("sell-multipliers");
|
||||
return section == null ? null : ConfigurateUtil.getKeys(section);
|
||||
}
|
||||
|
||||
public int getMaxItemLore() {
|
||||
return config.getInt("max-itemlore-lines", 10);
|
||||
}
|
||||
@@ -2194,14 +2007,4 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getBaltopMinBalance() {
|
||||
return config.getBigDecimal("baltop-requirements.minimum-balance", BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBaltopMinPlaytime() {
|
||||
return config.getLong("baltop-requirements.minimum-playtime", 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.ITeleport;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.UserWarpEvent;
|
||||
import net.ess3.api.events.teleport.PreTeleportEvent;
|
||||
import net.ess3.api.events.teleport.TeleportWarmupEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
/**
|
||||
* @deprecated This API is not asynchronous. Use {@link com.earth2me.essentials.AsyncTeleport AsyncTeleport}
|
||||
*/
|
||||
@Deprecated
|
||||
public class Teleport implements ITeleport {
|
||||
private final IUser teleportOwner;
|
||||
private final IEssentials ess;
|
||||
private TimedTeleport timedTeleport;
|
||||
|
||||
private TeleportType tpType;
|
||||
|
||||
@Deprecated
|
||||
public Teleport(final IUser user, final IEssentials ess) {
|
||||
this.teleportOwner = user;
|
||||
this.ess = ess;
|
||||
tpType = TeleportType.NORMAL;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void cooldown(final boolean check) throws Exception {
|
||||
final Calendar time = new GregorianCalendar();
|
||||
if (teleportOwner.getLastTeleportTimestamp() > 0) {
|
||||
// Take the current time, and remove the delay from it.
|
||||
final double cooldown = ess.getSettings().getTeleportCooldown();
|
||||
final Calendar earliestTime = new GregorianCalendar();
|
||||
earliestTime.add(Calendar.SECOND, -(int) cooldown);
|
||||
earliestTime.add(Calendar.MILLISECOND, -(int) ((cooldown * 1000.0) % 1000.0));
|
||||
// This value contains the most recent time a teleportPlayer could have been used that would allow another use.
|
||||
final long earliestLong = earliestTime.getTimeInMillis();
|
||||
|
||||
// When was the last teleportPlayer used?
|
||||
final long lastTime = teleportOwner.getLastTeleportTimestamp();
|
||||
|
||||
if (lastTime > time.getTimeInMillis()) {
|
||||
// This is to make sure time didn't get messed up on last teleportPlayer use.
|
||||
// If this happens, let's give the user the benifit of the doubt.
|
||||
teleportOwner.setLastTeleportTimestamp(time.getTimeInMillis());
|
||||
return;
|
||||
} else if (lastTime > earliestLong
|
||||
&& cooldownApplies()) {
|
||||
time.setTimeInMillis(lastTime);
|
||||
time.add(Calendar.SECOND, (int) cooldown);
|
||||
time.add(Calendar.MILLISECOND, (int) ((cooldown * 1000.0) % 1000.0));
|
||||
throw new TranslatableException("timeBeforeTeleport", DateUtil.formatDateDiff(time.getTimeInMillis()));
|
||||
}
|
||||
}
|
||||
// if justCheck is set, don't update lastTeleport; we're just checking
|
||||
if (!check) {
|
||||
teleportOwner.setLastTeleportTimestamp(time.getTimeInMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private boolean cooldownApplies() {
|
||||
boolean applies = true;
|
||||
final String globalBypassPerm = "essentials.teleport.cooldown.bypass";
|
||||
switch (tpType) {
|
||||
case NORMAL:
|
||||
applies = !teleportOwner.isAuthorized(globalBypassPerm);
|
||||
break;
|
||||
case BACK:
|
||||
applies = !(teleportOwner.isAuthorized(globalBypassPerm) &&
|
||||
teleportOwner.isAuthorized("essentials.teleport.cooldown.bypass.back"));
|
||||
break;
|
||||
case TPA:
|
||||
applies = !(teleportOwner.isAuthorized(globalBypassPerm) &&
|
||||
teleportOwner.isAuthorized("essentials.teleport.cooldown.bypass.tpa"));
|
||||
break;
|
||||
}
|
||||
return applies;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void warnUser(final IUser user, final double delay) {
|
||||
final Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.SECOND, (int) delay);
|
||||
c.add(Calendar.MILLISECOND, (int) ((delay * 1000.0) % 1000.0));
|
||||
user.sendTl("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis()));
|
||||
}
|
||||
|
||||
//The now function is used when you want to skip tp delay when teleporting someone to a location or player.
|
||||
@Override
|
||||
@Deprecated
|
||||
public void now(final Location loc, final boolean cooldown, final TeleportCause cause) throws Exception {
|
||||
if (cooldown) {
|
||||
cooldown(false);
|
||||
}
|
||||
final ITarget target = new LocationTarget(loc);
|
||||
now(teleportOwner, target, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void now(final Player entity, final boolean cooldown, final TeleportCause cause) throws Exception {
|
||||
if (cooldown) {
|
||||
cooldown(false);
|
||||
}
|
||||
final ITarget target = new PlayerTarget(entity);
|
||||
now(teleportOwner, target, cause);
|
||||
teleportOwner.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void now(final IUser teleportee, final ITarget target, final TeleportCause cause) throws Exception {
|
||||
cancel(false);
|
||||
Location loc = target.getLocation();
|
||||
|
||||
final PreTeleportEvent event = new PreTeleportEvent(teleportee, cause, target);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (teleportee.isAuthorized("essentials.back.onteleport")) {
|
||||
teleportee.setLastLocation();
|
||||
}
|
||||
|
||||
if (!teleportee.getBase().isEmpty()) {
|
||||
if (!ess.getSettings().isTeleportPassengerDismount()) {
|
||||
throw new TranslatableException("passengerTeleportFail");
|
||||
}
|
||||
teleportee.getBase().eject();
|
||||
}
|
||||
|
||||
if (LocationUtil.isBlockUnsafeForUser(ess, teleportee, loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
|
||||
if (ess.getSettings().isTeleportSafetyEnabled()) {
|
||||
if (ess.getSettings().isForceDisableTeleportSafety()) {
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
} else {
|
||||
PaperLib.teleportAsync(teleportee.getBase(), LocationUtil.getSafeDestination(ess, teleportee, loc), cause);
|
||||
}
|
||||
} else {
|
||||
throw new TranslatableException("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
} else {
|
||||
if (ess.getSettings().isForceDisableTeleportSafety()) {
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
} else {
|
||||
if (ess.getSettings().isTeleportToCenterLocation()) {
|
||||
loc = LocationUtil.getRoundedDestination(loc);
|
||||
}
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//The teleportPlayer function is used when you want to normally teleportPlayer someone to a location or player.
|
||||
//This method is nolonger used internally and will be removed.
|
||||
@Deprecated
|
||||
@Override
|
||||
public void teleport(final Location loc, final Trade chargeFor) throws Exception {
|
||||
teleport(loc, chargeFor, TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void teleport(final Location loc, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
teleport(teleportOwner, new LocationTarget(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
//This is used when teleporting to a player
|
||||
@Override
|
||||
@Deprecated
|
||||
public void teleport(final Player entity, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
final ITarget target = new PlayerTarget(entity);
|
||||
teleportOwner.sendTl("teleportToPlayer", entity.getDisplayName());
|
||||
teleport(teleportOwner, target, chargeFor, cause);
|
||||
}
|
||||
|
||||
//This is used when teleporting to stored location
|
||||
@Override
|
||||
@Deprecated
|
||||
public void teleportPlayer(final IUser teleportee, final Location loc, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
teleport(teleportee, new LocationTarget(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
//This is used on /tphere
|
||||
@Override
|
||||
@Deprecated
|
||||
public void teleportPlayer(final IUser teleportee, final Player entity, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
final ITarget target = new PlayerTarget(entity);
|
||||
teleport(teleportee, target, chargeFor, cause);
|
||||
teleportee.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ());
|
||||
teleportOwner.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void teleport(final IUser teleportee, final ITarget target, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
final TeleportWarmupEvent event = new TeleportWarmupEvent(teleportee, cause, target, delay);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
delay = event.getDelay();
|
||||
|
||||
Trade cashCharge = chargeFor;
|
||||
|
||||
if (chargeFor != null) {
|
||||
chargeFor.isAffordableFor(teleportOwner);
|
||||
|
||||
//This code is to make sure that commandcosts are checked in the initial world, and not in the resulting world.
|
||||
if (!chargeFor.getCommandCost(teleportOwner).equals(BigDecimal.ZERO)) {
|
||||
//By converting a command cost to a regular cost, the command cost permission isn't checked when executing the charge after teleport.
|
||||
cashCharge = new Trade(chargeFor.getCommandCost(teleportOwner), ess);
|
||||
}
|
||||
}
|
||||
|
||||
cooldown(true);
|
||||
if (delay <= 0 || teleportOwner.isAuthorized("essentials.teleport.timer.bypass") || teleportee.isAuthorized("essentials.teleport.timer.bypass")) {
|
||||
cooldown(false);
|
||||
now(teleportee, target, cause);
|
||||
if (cashCharge != null) {
|
||||
cashCharge.charge(teleportOwner);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cancel(false);
|
||||
warnUser(teleportee, delay);
|
||||
initTimer((long) (delay * 1000.0), teleportee, target, cashCharge, cause, false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void teleportOther(final IUser teleporter, final IUser teleportee, final ITarget target, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
final TeleportWarmupEvent event = new TeleportWarmupEvent(teleporter, teleportee, cause, target, delay);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
delay = event.getDelay();
|
||||
|
||||
Trade cashCharge = chargeFor;
|
||||
|
||||
if (teleporter != null && chargeFor != null) {
|
||||
chargeFor.isAffordableFor(teleporter);
|
||||
|
||||
//This code is to make sure that commandcosts are checked in the initial world, and not in the resulting world.
|
||||
if (!chargeFor.getCommandCost(teleporter).equals(BigDecimal.ZERO)) {
|
||||
//By converting a command cost to a regular cost, the command cost permission isn't checked when executing the charge after teleport.
|
||||
cashCharge = new Trade(chargeFor.getCommandCost(teleporter), ess);
|
||||
}
|
||||
}
|
||||
|
||||
cooldown(true);
|
||||
if (delay <= 0 || teleporter == null
|
||||
|| teleporter.isAuthorized("essentials.teleport.timer.bypass")
|
||||
|| teleportOwner.isAuthorized("essentials.teleport.timer.bypass")
|
||||
|| teleportee.isAuthorized("essentials.teleport.timer.bypass")) {
|
||||
cooldown(false);
|
||||
now(teleportee, target, cause);
|
||||
if (teleporter != null && cashCharge != null) {
|
||||
cashCharge.charge(teleporter);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cancel(false);
|
||||
warnUser(teleportee, delay);
|
||||
initTimer((long) (delay * 1000.0), teleportee, target, cashCharge, cause, false);
|
||||
}
|
||||
|
||||
//The respawn function is a wrapper used to handle tp fallback, on /jail and /home
|
||||
@Override
|
||||
@Deprecated
|
||||
public void respawn(final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
final TeleportWarmupEvent event = new TeleportWarmupEvent(teleportOwner, cause, null, delay);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
delay = event.getDelay();
|
||||
|
||||
if (chargeFor != null) {
|
||||
chargeFor.isAffordableFor(teleportOwner);
|
||||
}
|
||||
cooldown(true);
|
||||
if (delay <= 0 || teleportOwner.isAuthorized("essentials.teleport.timer.bypass")) {
|
||||
cooldown(false);
|
||||
respawnNow(teleportOwner, cause);
|
||||
if (chargeFor != null) {
|
||||
chargeFor.charge(teleportOwner);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cancel(false);
|
||||
warnUser(teleportOwner, delay);
|
||||
initTimer((long) (delay * 1000.0), teleportOwner, null, chargeFor, cause, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
void respawnNow(final IUser teleportee, final TeleportCause cause) throws Exception {
|
||||
final Player player = teleportee.getBase();
|
||||
final Location bed = player.getBedSpawnLocation();
|
||||
if (bed != null) {
|
||||
now(teleportee, new LocationTarget(bed), cause);
|
||||
} else {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("Could not find bed spawn, forcing respawn event.");
|
||||
}
|
||||
final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false);
|
||||
ess.getServer().getPluginManager().callEvent(pre);
|
||||
now(teleportee, new LocationTarget(pre.getRespawnLocation()), cause);
|
||||
}
|
||||
}
|
||||
|
||||
//The warp function is a wrapper used to teleportPlayer a player to a /warp
|
||||
@Override
|
||||
@Deprecated
|
||||
public void warp(final IUser teleportee, String warp, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
final UserWarpEvent event = new UserWarpEvent(teleportee, warp, chargeFor);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
warp = event.getWarp();
|
||||
final Location loc = ess.getWarps().getWarp(warp);
|
||||
teleportee.sendTl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
if (!teleportee.equals(teleportOwner)) {
|
||||
teleportOwner.sendTl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
teleport(teleportee, new LocationTarget(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
//The back function is a wrapper used to teleportPlayer a player /back to their previous location.
|
||||
@Override
|
||||
@Deprecated
|
||||
public void back(final Trade chargeFor) throws Exception {
|
||||
back(teleportOwner, chargeFor);
|
||||
}
|
||||
|
||||
//This function is a wrapper over the other back function for cases where another player performs back for them
|
||||
@Override
|
||||
@Deprecated
|
||||
public void back(final IUser teleporter, final Trade chargeFor) throws Exception {
|
||||
tpType = TeleportType.BACK;
|
||||
final Location loc = teleportOwner.getLastLocation();
|
||||
teleportOwner.sendTl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
teleportOther(teleporter, teleportOwner, new LocationTarget(loc), chargeFor, TeleportCause.COMMAND);
|
||||
}
|
||||
|
||||
//This function is used to throw a user back after a jail sentence
|
||||
@Override
|
||||
@Deprecated
|
||||
public void back() throws Exception {
|
||||
now(teleportOwner, new LocationTarget(teleportOwner.getLastLocation()), TeleportCause.COMMAND);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setTpType(final TeleportType tpType) {
|
||||
this.tpType = tpType;
|
||||
}
|
||||
|
||||
//If we need to cancelTimer a pending teleportPlayer call this method
|
||||
@Deprecated
|
||||
private void cancel(final boolean notifyUser) {
|
||||
if (timedTeleport != null) {
|
||||
timedTeleport.cancelTimer(notifyUser);
|
||||
timedTeleport = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void initTimer(final long delay, final IUser teleportUser, final ITarget target, final Trade chargeFor, final TeleportCause cause, final boolean respawn) {
|
||||
timedTeleport = new TimedTeleport(teleportOwner, ess, this, delay, teleportUser, target, chargeFor, cause, respawn);
|
||||
}
|
||||
|
||||
public enum TeleportType {
|
||||
TPA,
|
||||
BACK,
|
||||
NORMAL
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Deprecated
|
||||
public class TimedTeleport implements Runnable {
|
||||
private static final double MOVE_CONSTANT = 0.3;
|
||||
private final IUser teleportOwner;
|
||||
private final IEssentials ess;
|
||||
private final Teleport teleport;
|
||||
private final UUID timer_teleportee;
|
||||
private final long timer_started; // time this task was initiated
|
||||
private final long timer_delay; // how long to delay the teleportPlayer
|
||||
// note that I initially stored a clone of the location for reference, but...
|
||||
// when comparing locations, I got incorrect mismatches (rounding errors, looked like)
|
||||
// so, the X/Y/Z values are stored instead and rounded off
|
||||
private final long timer_initX;
|
||||
private final long timer_initY;
|
||||
private final long timer_initZ;
|
||||
private final ITarget timer_teleportTarget;
|
||||
private final boolean timer_respawn;
|
||||
private final boolean timer_canMove;
|
||||
private final Trade timer_chargeFor;
|
||||
private final TeleportCause timer_cause;
|
||||
private int timer_task;
|
||||
private double timer_health;
|
||||
|
||||
TimedTeleport(final IUser user, final IEssentials ess, final Teleport teleport, final long delay, final IUser teleportUser, final ITarget target, final Trade chargeFor, final TeleportCause cause, final boolean respawn) {
|
||||
this.teleportOwner = user;
|
||||
this.ess = ess;
|
||||
this.teleport = teleport;
|
||||
this.timer_started = System.currentTimeMillis();
|
||||
this.timer_delay = delay;
|
||||
this.timer_health = teleportUser.getBase().getHealth();
|
||||
this.timer_initX = Math.round(teleportUser.getBase().getLocation().getX() * MOVE_CONSTANT);
|
||||
this.timer_initY = Math.round(teleportUser.getBase().getLocation().getY() * MOVE_CONSTANT);
|
||||
this.timer_initZ = Math.round(teleportUser.getBase().getLocation().getZ() * MOVE_CONSTANT);
|
||||
this.timer_teleportee = teleportUser.getBase().getUniqueId();
|
||||
this.timer_teleportTarget = target;
|
||||
this.timer_chargeFor = chargeFor;
|
||||
this.timer_cause = cause;
|
||||
this.timer_respawn = respawn;
|
||||
this.timer_canMove = user.isAuthorized("essentials.teleport.timer.move");
|
||||
|
||||
timer_task = ess.runTaskTimerAsynchronously(this, 20, 20).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (teleportOwner == null || !teleportOwner.getBase().isOnline() || teleportOwner.getBase().getLocation() == null) {
|
||||
cancelTimer(false);
|
||||
return;
|
||||
}
|
||||
|
||||
final IUser teleportUser = ess.getUser(this.timer_teleportee);
|
||||
|
||||
if (teleportUser == null || !teleportUser.getBase().isOnline()) {
|
||||
cancelTimer(false);
|
||||
return;
|
||||
}
|
||||
|
||||
final Location currLocation = teleportUser.getBase().getLocation();
|
||||
if (currLocation == null) {
|
||||
cancelTimer(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!timer_canMove && (Math.round(currLocation.getX() * MOVE_CONSTANT) != timer_initX || Math.round(currLocation.getY() * MOVE_CONSTANT) != timer_initY || Math.round(currLocation.getZ() * MOVE_CONSTANT) != timer_initZ || teleportUser.getBase().getHealth() < timer_health)) {
|
||||
// user moved, cancelTimer teleportPlayer
|
||||
cancelTimer(true);
|
||||
return;
|
||||
}
|
||||
|
||||
class DelayedTeleportTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
timer_health = teleportUser.getBase().getHealth(); // in case user healed, then later gets injured
|
||||
final long now = System.currentTimeMillis();
|
||||
if (now > timer_started + timer_delay) {
|
||||
try {
|
||||
teleport.cooldown(false);
|
||||
} catch (final Exception ex) {
|
||||
teleportOwner.sendTl("cooldownWithMessage", ex.getMessage());
|
||||
if (teleportOwner != teleportUser) {
|
||||
teleportUser.sendTl("cooldownWithMessage", ex.getMessage());
|
||||
}
|
||||
}
|
||||
try {
|
||||
cancelTimer(false);
|
||||
teleportUser.sendTl("teleportationCommencing");
|
||||
|
||||
if (timer_chargeFor != null) {
|
||||
timer_chargeFor.isAffordableFor(teleportOwner);
|
||||
}
|
||||
if (timer_respawn) {
|
||||
teleport.respawnNow(teleportUser, timer_cause);
|
||||
} else {
|
||||
teleport.now(teleportUser, timer_teleportTarget, timer_cause);
|
||||
}
|
||||
if (timer_chargeFor != null) {
|
||||
timer_chargeFor.charge(teleportOwner);
|
||||
}
|
||||
|
||||
} catch (final Exception ex) {
|
||||
ess.showError(teleportOwner.getSource(), ex, "\\ teleport");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ess.scheduleSyncDelayedTask(new DelayedTeleportTask());
|
||||
}
|
||||
|
||||
//If we need to cancelTimer a pending teleportPlayer call this method
|
||||
void cancelTimer(final boolean notifyUser) {
|
||||
if (timer_task == -1) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ess.getServer().getScheduler().cancelTask(timer_task);
|
||||
if (notifyUser) {
|
||||
teleportOwner.sendTl("pendingTeleportCancelled");
|
||||
if (timer_teleportee != null && !timer_teleportee.equals(teleportOwner.getBase().getUniqueId())) {
|
||||
ess.getUser(timer_teleportee).sendTl("pendingTeleportCancelled");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
timer_task = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
@@ -192,7 +191,7 @@ public class Trade {
|
||||
}
|
||||
|
||||
if (getMoney() != null && getMoney().signum() > 0 && !user.canAfford(getMoney())) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess))));
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -203,7 +202,7 @@ public class Trade {
|
||||
|
||||
final BigDecimal money;
|
||||
if (command != null && !command.isEmpty() && (money = getCommandCost(user)).signum() > 0 && !user.canAfford(money)) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(money, ess))));
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(money, ess)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -242,8 +241,8 @@ public class Trade {
|
||||
} else {
|
||||
for (final ItemStack itemStack : leftover.values()) {
|
||||
int spillAmount = itemStack.getAmount();
|
||||
itemStack.setAmount(Math.min(spillAmount, itemStack.getMaxStackSize()));
|
||||
while (spillAmount > 0) {
|
||||
itemStack.setAmount(Math.min(spillAmount, itemStack.getMaxStackSize()));
|
||||
user.getBase().getWorld().dropItemNaturally(user.getBase().getLocation(), itemStack);
|
||||
spillAmount -= itemStack.getAmount();
|
||||
}
|
||||
@@ -286,7 +285,7 @@ public class Trade {
|
||||
ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString());
|
||||
}
|
||||
if (!user.canAfford(getMoney()) && getMoney().signum() > 0) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess))));
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess)));
|
||||
return;
|
||||
}
|
||||
user.takeMoney(getMoney());
|
||||
@@ -305,7 +304,7 @@ public class Trade {
|
||||
if (command != null) {
|
||||
final BigDecimal cost = getCommandCost(user);
|
||||
if (!user.canAfford(cost) && cost.signum() > 0) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(cost, ess))));
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(cost, ess)));
|
||||
return;
|
||||
}
|
||||
user.takeMoney(cost);
|
||||
|
||||
@@ -21,7 +21,6 @@ import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.ess3.api.events.JailStatusChangeEvent;
|
||||
import net.ess3.api.events.MuteStatusChangeEvent;
|
||||
import net.ess3.api.events.UserBalanceUpdateEvent;
|
||||
import net.ess3.provider.PlayerLocaleProvider;
|
||||
import net.essentialsx.api.v2.events.TransactionEvent;
|
||||
import net.essentialsx.api.v2.services.mail.MailSender;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -63,6 +62,8 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
// User modules
|
||||
private final IMessageRecipient messageRecipient;
|
||||
private transient final AsyncTeleport teleport;
|
||||
@SuppressWarnings("deprecation")
|
||||
private transient final Teleport legacyTeleport;
|
||||
|
||||
// User command confirmation strings
|
||||
private final Map<User, BigDecimal> confirmingPayments = new WeakHashMap<>();
|
||||
@@ -100,13 +101,14 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
// Misc
|
||||
private transient final List<String> signCopy = Lists.newArrayList("", "", "", "");
|
||||
private transient long lastVanishTime = System.currentTimeMillis();
|
||||
private transient int flightTick = -1;
|
||||
private String lastLocaleString;
|
||||
private Locale playerLocale;
|
||||
|
||||
public User(final Player base, final IEssentials ess) {
|
||||
super(base, ess);
|
||||
teleport = new AsyncTeleport(this, ess);
|
||||
//noinspection deprecation
|
||||
legacyTeleport = new Teleport(this, ess);
|
||||
if (isAfk()) {
|
||||
afkPosition = this.getLocation();
|
||||
}
|
||||
@@ -245,9 +247,9 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
return;
|
||||
}
|
||||
setMoney(getMoney().add(value), cause);
|
||||
sendTl("addedToAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)));
|
||||
sendTl("addedToAccount", NumberUtil.displayCurrency(value, ess));
|
||||
if (initiator != null) {
|
||||
initiator.sendTl("addedToOthersAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess)));
|
||||
initiator.sendTl("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,12 +266,12 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
if (canAfford(value)) {
|
||||
setMoney(getMoney().subtract(value), cause);
|
||||
reciever.setMoney(reciever.getMoney().add(value), cause);
|
||||
sendTl("moneySentTo", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), reciever.getDisplayName());
|
||||
reciever.sendTl("moneyRecievedFrom", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName());
|
||||
sendTl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName());
|
||||
reciever.sendTl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName());
|
||||
final TransactionEvent transactionEvent = new TransactionEvent(this.getSource(), reciever, value);
|
||||
ess.getServer().getPluginManager().callEvent(transactionEvent);
|
||||
} else {
|
||||
throw new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)));
|
||||
throw new ChargeException("notEnoughMoney", NumberUtil.displayCurrency(value, ess));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,9 +294,9 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
} catch (final MaxMoneyException ex) {
|
||||
ess.getLogger().log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex);
|
||||
}
|
||||
sendTl("takenFromAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)));
|
||||
sendTl("takenFromAccount", NumberUtil.displayCurrency(value, ess));
|
||||
if (initiator != null) {
|
||||
initiator.sendTl("takenFromOthersAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess)));
|
||||
initiator.sendTl("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,6 +375,13 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
teleportRequestQueue.put(request.getName(), request);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean hasOutstandingTeleportRequest() {
|
||||
return getNextTpaRequest(false, false, false) != null;
|
||||
}
|
||||
|
||||
public Collection<String> getPendingTpaKeys() {
|
||||
return teleportRequestQueue.keySet();
|
||||
}
|
||||
@@ -556,6 +565,16 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
return teleport;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This API is not asynchronous. Use {@link User#getAsyncTeleport()}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
public Teleport getTeleport() {
|
||||
return legacyTeleport;
|
||||
}
|
||||
|
||||
public long getLastOnlineActivity() {
|
||||
return lastOnlineActivity;
|
||||
}
|
||||
@@ -775,11 +794,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastActivityTime() {
|
||||
return this.lastActivity;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void updateActivity(final boolean broadcast) {
|
||||
updateActivity(broadcast, AfkStatusChangeEvent.Cause.UNKNOWN);
|
||||
@@ -1074,8 +1088,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
@Override
|
||||
public String playerTl(String tlKey, Object... args) {
|
||||
if (ess.getSettings().isPerPlayerLocale()) {
|
||||
final PlayerLocaleProvider provider = ess.provider(PlayerLocaleProvider.class);
|
||||
return tlLocale(getPlayerLocale(provider.getLocale(base)), tlKey, args);
|
||||
return tlLocale(getPlayerLocale(ess.getPlayerLocaleProvider().getLocale(base)), tlKey, args);
|
||||
}
|
||||
return tlLiteral(tlKey, args);
|
||||
}
|
||||
@@ -1284,12 +1297,4 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
return toggleShout == null ? toggleShout = ess.getSettings().isShoutDefault() : toggleShout;
|
||||
}
|
||||
|
||||
public int getFlightTick() {
|
||||
return flightTick;
|
||||
}
|
||||
|
||||
public void setFlightTick(int flightTick) {
|
||||
this.flightTick = flightTick;
|
||||
}
|
||||
}
|
||||
@@ -348,17 +348,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
||||
}
|
||||
|
||||
public int getMailAmount() {
|
||||
if (holder.mail() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int amount = 0;
|
||||
for (MailMessage element : holder.mail()) {
|
||||
if (!element.isExpired()) {
|
||||
amount++;
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
return holder.mail() == null ? 0 : holder.mail().size();
|
||||
}
|
||||
|
||||
public int getUnreadMailAmount() {
|
||||
@@ -368,7 +358,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
||||
|
||||
int unread = 0;
|
||||
for (MailMessage element : holder.mail()) {
|
||||
if (!element.isRead() && !element.isExpired()) {
|
||||
if (!element.isRead()) {
|
||||
unread++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import net.ess3.api.InvalidNameException;
|
||||
import net.ess3.api.InvalidWorldException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class Warps implements IConf, net.ess3.api.IWarps {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getWarp(final String warp) throws WarpNotFoundException {
|
||||
public Location getWarp(final String warp) throws WarpNotFoundException, InvalidWorldException {
|
||||
final EssentialsConfiguration conf = warpPoints.get(new StringIgnoreCase(warp));
|
||||
if (conf == null) {
|
||||
throw new WarpNotFoundException();
|
||||
@@ -78,7 +79,7 @@ public class Warps implements IConf, net.ess3.api.IWarps {
|
||||
if (conf == null) {
|
||||
final File confFile = new File(warpsFolder, filename + ".yml");
|
||||
if (confFile.exists()) {
|
||||
throw new TranslatableException("similarWarpExist");
|
||||
throw new Exception(user == null ? tlLiteral("similarWarpExist") : user.playerTl("similarWarpExist"));
|
||||
}
|
||||
conf = new EssentialsConfiguration(confFile);
|
||||
conf.load();
|
||||
|
||||
@@ -46,6 +46,17 @@ public interface IJails extends IConf {
|
||||
*/
|
||||
void removeJail(String jail) throws Exception;
|
||||
|
||||
/**
|
||||
* Attempts to send the given user to the given jail
|
||||
*
|
||||
* @param user the user to send to jail
|
||||
* @param jail the jail to send the user to
|
||||
* @throws Exception if the user is offline or jail does not exist
|
||||
* @deprecated Use {@link IJails#sendToJail(IUser, String, CompletableFuture)}
|
||||
*/
|
||||
@Deprecated
|
||||
void sendToJail(IUser user, String jail) throws Exception;
|
||||
|
||||
/**
|
||||
* Attempts to send the given user to the given jail
|
||||
*
|
||||
|
||||
@@ -22,8 +22,9 @@ public interface IWarps extends IConf {
|
||||
* @param warp - Warp name
|
||||
* @return - Location the warp is set to
|
||||
* @throws WarpNotFoundException When the warp is not found
|
||||
* @throws net.ess3.api.InvalidWorldException When the world the warp is in is not found
|
||||
*/
|
||||
Location getWarp(String warp) throws WarpNotFoundException;
|
||||
Location getWarp(String warp) throws WarpNotFoundException, net.ess3.api.InvalidWorldException;
|
||||
|
||||
/**
|
||||
* Checks if the provided name is a warp.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
public class Commandanvil extends EssentialsCommand {
|
||||
@@ -12,13 +11,11 @@ public class Commandanvil extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openAnvil(user.getBase());
|
||||
ess.getContainerProvider().openAnvil(user.getBase());
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import org.bukkit.Server;
|
||||
|
||||
@@ -21,16 +20,16 @@ public class Commandbalance extends EssentialsCommand {
|
||||
}
|
||||
|
||||
final User target = getPlayer(server, args, 0, false, true);
|
||||
sender.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(target.getMoney(), ess)));
|
||||
sender.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length == 1 && user.isAuthorized("essentials.balance.others")) {
|
||||
final User target = getPlayer(server, args, 0, true, true);
|
||||
user.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(target.getMoney(), ess)));
|
||||
user.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess));
|
||||
} else if (args.length < 2) {
|
||||
user.sendTl("balance", AdventureUtil.parsed(NumberUtil.displayCurrency(user.getMoney(), ess)));
|
||||
user.sendTl("balance", NumberUtil.displayCurrency(user.getMoney(), ess));
|
||||
} else {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.essentialsx.api.v2.services.BalanceTop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -115,38 +110,17 @@ public class Commandbalancetop extends EssentialsCommand {
|
||||
future.thenRun(() -> {
|
||||
if (fresh) {
|
||||
final SimpleTextInput newCache = new SimpleTextInput();
|
||||
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("serverTotal", AdventureUtil.parsed(NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess)))));
|
||||
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("serverTotal", NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess))));
|
||||
int pos = 1;
|
||||
for (final Map.Entry<UUID, BalanceTop.Entry> entry : ess.getBalanceTop().getBalanceTopCache().entrySet()) {
|
||||
final BigDecimal balance = entry.getValue().getBalance();
|
||||
final User user = ess.getUser(entry.getKey());
|
||||
|
||||
final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
|
||||
final boolean offlineStatisticSupported = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01);
|
||||
final long playtime;
|
||||
if (user.getBase() == null || !user.getBase().isOnline()) {
|
||||
if (offlineStatisticSupported) {
|
||||
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
|
||||
} else {
|
||||
playtime = -1;
|
||||
}
|
||||
} else {
|
||||
playtime = user.getBase().getStatistic(PLAY_ONE_TICK);
|
||||
}
|
||||
// Play time in seconds
|
||||
final long playTimeSecs = Math.max(playtime / 20, 0);
|
||||
|
||||
// Checking if player meets the requirements of minimum balance and minimum playtime to be listed in baltop list
|
||||
if ((ess.getSettings().showZeroBaltop() || balance.compareTo(BigDecimal.ZERO) > 0)
|
||||
&& balance.compareTo(ess.getSettings().getBaltopMinBalance()) >= 0 &&
|
||||
// Skip playtime check for offline players on versions below 1.15.2
|
||||
(playtime == -1 || playTimeSecs >= ess.getSettings().getBaltopMinPlaytime())) {
|
||||
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(balance, ess)))));
|
||||
if (ess.getSettings().showZeroBaltop() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
||||
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess))));
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
cache = newCache;
|
||||
}
|
||||
|
||||
outputCache(sender, page);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,14 +4,12 @@ import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.WritableBookMeta;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -52,14 +50,7 @@ public class Commandbook extends EssentialsCommand {
|
||||
} else {
|
||||
if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others")) {
|
||||
final ItemStack newItem = new ItemStack(WRITABLE_BOOK, item.getAmount());
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) {
|
||||
final WritableBookMeta wbmeta = (WritableBookMeta) newItem.getItemMeta();
|
||||
//noinspection DataFlowIssue
|
||||
wbmeta.setPages(bmeta.getPages());
|
||||
newItem.setItemMeta(wbmeta);
|
||||
} else {
|
||||
newItem.setItemMeta(bmeta);
|
||||
}
|
||||
newItem.setItemMeta(bmeta);
|
||||
Inventories.setItemInMainHand(user.getBase(), newItem);
|
||||
user.sendTl("editBookContents");
|
||||
} else {
|
||||
@@ -72,15 +63,7 @@ public class Commandbook extends EssentialsCommand {
|
||||
bmeta.setAuthor(player);
|
||||
}
|
||||
final ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount());
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) {
|
||||
final BookMeta real = (BookMeta) newItem.getItemMeta();
|
||||
real.setAuthor(bmeta.getAuthor());
|
||||
real.setTitle(bmeta.getTitle());
|
||||
real.setPages(bmeta.getPages());
|
||||
newItem.setItemMeta(real);
|
||||
} else {
|
||||
newItem.setItemMeta(bmeta);
|
||||
}
|
||||
newItem.setItemMeta(bmeta);
|
||||
Inventories.setItemInMainHand(user.getBase(), newItem);
|
||||
user.sendTl("bookLocked");
|
||||
} else {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
@@ -22,7 +21,7 @@ public class Commandbottom extends EssentialsCommand {
|
||||
final int bottomZ = user.getLocation().getBlockZ();
|
||||
final float pitch = user.getLocation().getPitch();
|
||||
final float yaw = user.getLocation().getYaw();
|
||||
final Location unsafe = new Location(user.getWorld(), bottomX, ess.provider(WorldInfoProvider.class).getMinHeight(user.getWorld()), bottomZ, yaw, pitch);
|
||||
final Location unsafe = new Location(user.getWorld(), bottomX, ess.getWorldInfoProvider().getMinHeight(user.getWorld()), bottomZ, yaw, pitch);
|
||||
final Location safe = LocationUtil.getSafeDestination(ess, unsafe);
|
||||
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
|
||||
future.thenAccept(success -> {
|
||||
|
||||
+1
-2
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Server;
|
||||
@@ -54,7 +53,7 @@ public class Commandbroadcastworld extends EssentialsCommand {
|
||||
if (message.isEmpty()) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
ess.broadcastTl(null, u -> !u.getBase().getWorld().equals(world), true, "broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), AdventureUtil.parsed(AdventureUtil.legacyToMini(name)));
|
||||
ess.broadcastTl(null, u -> !u.getBase().getWorld().equals(world), true, "broadcast", message, AdventureUtil.parsed(AdventureUtil.legacyToMini(name)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-5
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
public class Commandcartographytable extends EssentialsCommand {
|
||||
@@ -12,13 +11,11 @@ public class Commandcartographytable extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openCartographyTable(user.getBase());
|
||||
ess.getContainerProvider().openCartographyTable(user.getBase());
|
||||
}
|
||||
}
|
||||
+2
-7
@@ -6,7 +6,6 @@ import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -81,7 +80,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
}
|
||||
}
|
||||
|
||||
protected void clearHandler(final CommandSource sender, final Player player, final String[] args, final int offset, final boolean showExtended) throws TranslatableException {
|
||||
protected void clearHandler(final CommandSource sender, final Player player, final String[] args, final int offset, final boolean showExtended) {
|
||||
ClearHandlerType type = ClearHandlerType.ALL_EXCEPT_ARMOR;
|
||||
final Set<Item> items = new HashSet<>();
|
||||
int amount = -1;
|
||||
@@ -125,11 +124,6 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
stack.setDurability(item.getData());
|
||||
}
|
||||
|
||||
// can't remove a negative amount of items. (it adds them)
|
||||
if (amount < -1) {
|
||||
throw new TranslatableException("cannotRemoveNegativeItems");
|
||||
}
|
||||
|
||||
// amount -1 means all items will be cleared
|
||||
if (amount == -1) {
|
||||
final int removedAmount = Inventories.removeItemSimilar(player, stack, true);
|
||||
@@ -137,6 +131,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
sender.sendTl("inventoryClearingStack", removedAmount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName());
|
||||
}
|
||||
} else {
|
||||
stack.setAmount(amount < 0 ? 1 : amount);
|
||||
if (Inventories.removeItemAmount(player, stack, amount)) {
|
||||
sender.sendTl("inventoryClearingStack", amount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName());
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.PasteUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -43,10 +42,9 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
final ItemStack[] items = Inventories.getInventory(user.getBase(), true);
|
||||
final List<String> list = new ArrayList<>();
|
||||
|
||||
final SerializationProvider serializationProvider = ess.provider(SerializationProvider.class);
|
||||
boolean useSerializationProvider = ess.getSettings().isUseBetterKits();
|
||||
|
||||
if (useSerializationProvider && serializationProvider == null) {
|
||||
if (useSerializationProvider && ess.getSerializationProvider() == null) {
|
||||
ess.showError(user.getSource(), new TranslatableException("createKitUnsupported"), commandLabel);
|
||||
useSerializationProvider = false;
|
||||
}
|
||||
@@ -55,7 +53,7 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
if (is != null && is.getType() != null && is.getType() != Material.AIR) {
|
||||
final String serialized;
|
||||
if (useSerializationProvider) {
|
||||
serialized = "@" + Base64Coder.encodeLines(serializationProvider.serializeItem(is));
|
||||
serialized = "@" + Base64Coder.encodeLines(ess.getSerializationProvider().serializeItem(is));
|
||||
} else {
|
||||
serialized = ess.getItemDb().serialize(is);
|
||||
}
|
||||
|
||||
@@ -18,24 +18,6 @@ public class Commanddelhome extends EssentialsCommand {
|
||||
super("delhome");
|
||||
}
|
||||
|
||||
private void deleteHome(CommandSource sender, User user, String home) {
|
||||
final HomeModifyEvent event = new HomeModifyEvent(sender.getUser(), user, home, user.getHome(home), false);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("HomeModifyEvent canceled for /delhome execution by " + sender.getDisplayName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
user.delHome(home);
|
||||
sender.sendTl("deleteHome", home);
|
||||
} catch (Exception e) {
|
||||
sender.sendTl("invalidHome", home);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length < 1) {
|
||||
@@ -63,19 +45,21 @@ public class Commanddelhome extends EssentialsCommand {
|
||||
name = expandedArg[0].toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
switch (name) {
|
||||
case "bed":
|
||||
throw new TranslatableException("invalidHomeName");
|
||||
case "*":
|
||||
final List<String> homes = user.getHomes();
|
||||
for (String home : homes) {
|
||||
deleteHome(sender, user, home);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
deleteHome(sender, user, name);
|
||||
break;
|
||||
if (name.equals("bed")) {
|
||||
throw new TranslatableException("invalidHomeName");
|
||||
}
|
||||
|
||||
final HomeModifyEvent event = new HomeModifyEvent(sender.getUser(), user, name, user.getHome(name), false);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("HomeModifyEvent canceled for /delhome execution by " + sender.getDisplayName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
user.delHome(name);
|
||||
sender.sendTl("deleteHome", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +81,6 @@ public class Commanddelhome extends EssentialsCommand {
|
||||
return homes;
|
||||
}
|
||||
otherUser.getHomes().forEach(home -> homes.add(namePart + ":" + home));
|
||||
homes.add(namePart + ":" + "*");
|
||||
}
|
||||
}
|
||||
return homes;
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
@@ -54,7 +53,7 @@ public class Commandeco extends EssentialsLoopCommand {
|
||||
if (player.getMoney().subtract(userAmount).compareTo(ess.getSettings().getMinMoney()) >= 0) {
|
||||
player.takeMoney(userAmount, sender, UserBalanceUpdateEvent.Cause.COMMAND_ECO);
|
||||
} else {
|
||||
ess.showError(sender, new TranslatableException("minimumBalanceError", AdventureUtil.parsed(NumberUtil.displayCurrency(ess.getSettings().getMinMoney(), ess))), commandLabel);
|
||||
ess.showError(sender, new TranslatableException("minimumBalanceError", NumberUtil.displayCurrency(ess.getSettings().getMinMoney(), ess)), commandLabel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -65,8 +64,8 @@ public class Commandeco extends EssentialsLoopCommand {
|
||||
final boolean underMin = userAmount.compareTo(minBal) < 0;
|
||||
final boolean aboveMax = userAmount.compareTo(maxBal) > 0;
|
||||
player.setMoney(underMin ? minBal : aboveMax ? maxBal : userAmount, UserBalanceUpdateEvent.Cause.COMMAND_ECO);
|
||||
player.sendTl("setBal", AdventureUtil.parsed(NumberUtil.displayCurrency(player.getMoney(), ess)));
|
||||
sender.sendTl("setBalOthers", player.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(player.getMoney(), ess)));
|
||||
player.sendTl("setBal", NumberUtil.displayCurrency(player.getMoney(), ess));
|
||||
sender.sendTl("setBalOthers", player.getDisplayName(), NumberUtil.displayCurrency(player.getMoney(), ess));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import com.earth2me.essentials.userstorage.ModernUserMap;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.CommandMapUtil;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FloatUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.PasteUtil;
|
||||
import com.earth2me.essentials.utils.RegistryUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -22,8 +22,6 @@ import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.OnlineModeProvider;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -69,8 +67,8 @@ import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
// This command has 4 undocumented behaviours #EasterEgg
|
||||
public class Commandessentials extends EssentialsCommand {
|
||||
|
||||
private static final Sound NOTE_HARP = RegistryUtil.valueOf(Sound.class, "BLOCK_NOTE_BLOCK_HARP", "BLOCK_NOTE_HARP", "NOTE_PIANO");
|
||||
private static final Sound MOO_SOUND = RegistryUtil.valueOf(Sound.class, "COW_IDLE", "ENTITY_COW_MILK");
|
||||
private static final Sound NOTE_HARP = EnumUtil.valueOf(Sound.class, "BLOCK_NOTE_BLOCK_HARP", "BLOCK_NOTE_HARP", "NOTE_PIANO");
|
||||
private static final Sound MOO_SOUND = EnumUtil.valueOf(Sound.class, "COW_IDLE", "ENTITY_COW_MILK");
|
||||
|
||||
private static final String HOMES_USAGE = "/<command> homes (fix | delete [world])";
|
||||
|
||||
@@ -265,7 +263,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
serverData.addProperty("bukkit-version", Bukkit.getBukkitVersion());
|
||||
serverData.addProperty("server-version", Bukkit.getVersion());
|
||||
serverData.addProperty("server-brand", Bukkit.getName());
|
||||
serverData.addProperty("online-mode", ess.provider(OnlineModeProvider.class).getOnlineModeString());
|
||||
serverData.addProperty("online-mode", ess.getOnlineModeProvider().getOnlineModeString());
|
||||
final JsonObject supportStatus = new JsonObject();
|
||||
final VersionUtil.SupportStatus status = VersionUtil.getServerSupportStatus();
|
||||
supportStatus.addProperty("status", status.name());
|
||||
@@ -336,7 +334,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
final Plugin essDiscordLink = Bukkit.getPluginManager().getPlugin("EssentialsDiscordLink");
|
||||
final Plugin essSpawn = Bukkit.getPluginManager().getPlugin("EssentialsSpawn");
|
||||
|
||||
final Map<String, Command> knownCommandsCopy = new HashMap<>(ess.provider(KnownCommandsProvider.class).getKnownCommands());
|
||||
final Map<String, Command> knownCommandsCopy = new HashMap<>(ess.getKnownCommandsProvider().getKnownCommands());
|
||||
final Map<String, String> disabledCommandsCopy = new HashMap<>(ess.getAlternativeCommandsHandler().disabledCommands());
|
||||
|
||||
// Further operations will be heavy IO
|
||||
@@ -461,14 +459,12 @@ public class Commandessentials extends EssentialsCommand {
|
||||
final CompletableFuture<PasteUtil.PasteResult> future = PasteUtil.createPaste(files);
|
||||
future.thenAccept(result -> {
|
||||
if (result != null) {
|
||||
final String dumpUrl = "https://essentialsx.net/dump.html?bytebin=" + result.getPasteId();
|
||||
final String dumpUrl = "https://essentialsx.net/dump.html?id=" + result.getPasteId();
|
||||
sender.sendTl("dumpUrl", dumpUrl);
|
||||
// pastes.dev doesn't support deletion keys
|
||||
//sender.sendTl("dumpDeleteKey", result.getDeletionKey());
|
||||
sender.sendTl("dumpDeleteKey", result.getDeletionKey());
|
||||
if (sender.isPlayer()) {
|
||||
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpConsoleUrl", dumpUrl)));
|
||||
// pastes.dev doesn't support deletion keys
|
||||
//ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
|
||||
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
|
||||
}
|
||||
}
|
||||
files.clear();
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.entity.SplashPotion;
|
||||
import org.bukkit.entity.ThrownExpBottle;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.entity.WindCharge;
|
||||
import org.bukkit.entity.WitherSkull;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -56,10 +55,6 @@ public class Commandfireball extends EssentialsCommand {
|
||||
builder.put("trident", Trident.class);
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_R01)) {
|
||||
builder.put("windcharge", WindCharge.class);
|
||||
}
|
||||
|
||||
types = builder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
public class Commandgrindstone extends EssentialsCommand {
|
||||
@@ -12,13 +11,11 @@ public class Commandgrindstone extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openGrindstone(user.getBase());
|
||||
ess.getContainerProvider().openGrindstone(user.getBase());
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import com.earth2me.essentials.textreader.TextInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
@@ -19,7 +18,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
public class Commandhelp extends EssentialsCommand {
|
||||
public Commandhelp() {
|
||||
@@ -37,27 +35,20 @@ public class Commandhelp extends EssentialsCommand {
|
||||
if (input.getLines().isEmpty()) {
|
||||
if (pageStr != null && pageStr.startsWith("/")) {
|
||||
final String cmd = pageStr.substring(1);
|
||||
for (final Map.Entry<String, Command> knownCmd : ess.provider(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> knownCmd : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
if (knownCmd.getKey().equalsIgnoreCase(cmd)) {
|
||||
final Command bukkit = knownCmd.getValue();
|
||||
final boolean isEssCommand = bukkit instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) bukkit).getPlugin().equals(ess);
|
||||
final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(bukkit.getName()) : null;
|
||||
user.sendTl("commandHelpLine1", cmd);
|
||||
String description = bukkit.getDescription();
|
||||
if (essCommand != null) {
|
||||
try {
|
||||
description = user.playerTl(bukkit.getName() + "CommandDescription");
|
||||
} catch (MissingResourceException ignored) {}
|
||||
}
|
||||
user.sendTl("commandHelpLine2", description);
|
||||
user.sendTl("commandHelpLine4", bukkit.getAliases().toString());
|
||||
user.sendTl("commandHelpLine2", knownCmd.getValue().getDescription());
|
||||
user.sendTl("commandHelpLine4", knownCmd.getValue().getAliases().toString());
|
||||
user.sendTl("commandHelpLine3");
|
||||
final boolean isEssCommand = knownCmd.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) knownCmd.getValue()).getPlugin().equals(ess);
|
||||
final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(knownCmd.getValue().getName()) : null;
|
||||
if (essCommand != null && !essCommand.getUsageStrings().isEmpty()) {
|
||||
for (Map.Entry<String, String> usage : essCommand.getUsageStrings().entrySet()) {
|
||||
user.sendTl("commandHelpLineUsage", AdventureUtil.parsed(usage.getKey().replace("<command>", cmd)), AdventureUtil.parsed(usage.getValue()));
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(bukkit.getUsage());
|
||||
user.sendMessage(knownCmd.getValue().getUsage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
@@ -30,9 +29,7 @@ public class Commandkill extends EssentialsLoopCommand {
|
||||
if (sender.isPlayer() && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
|
||||
throw new PlayerExemptException("killExempt", matchPlayer.getDisplayName());
|
||||
}
|
||||
final DamageEventProvider provider = ess.provider(DamageEventProvider.class);
|
||||
|
||||
final EntityDamageEvent ede = provider.callDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Float.MAX_VALUE);
|
||||
final EntityDamageEvent ede = ess.getDamageEventProvider().callDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Float.MAX_VALUE);
|
||||
if (ede.isCancelled() && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Mob;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.RegistryUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Cat;
|
||||
@@ -22,12 +21,8 @@ public class Commandkittycannon extends EssentialsCommand {
|
||||
|
||||
private static Ocelot spawnOcelot(final Server server, final User user) throws Mob.MobException {
|
||||
final Ocelot ocelot = (Ocelot) Mob.OCELOT.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
|
||||
//noinspection deprecation
|
||||
final Object[] values = RegistryUtil.values(Ocelot.Type.class);
|
||||
|
||||
final int i = random.nextInt(values.length);
|
||||
//noinspection deprecation
|
||||
ocelot.setCatType((Ocelot.Type) values[i]);
|
||||
final int i = random.nextInt(Ocelot.Type.values().length);
|
||||
ocelot.setCatType(Ocelot.Type.values()[i]);
|
||||
((Tameable) ocelot).setTamed(true);
|
||||
ocelot.setBaby();
|
||||
ocelot.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));
|
||||
@@ -36,10 +31,8 @@ public class Commandkittycannon extends EssentialsCommand {
|
||||
|
||||
private static Entity spawnCat(final Server server, final User user) throws Mob.MobException {
|
||||
final Cat cat = (Cat) Mob.CAT.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
|
||||
final Object[] values = RegistryUtil.values(Cat.Type.class);
|
||||
|
||||
final int i = random.nextInt(values.length);
|
||||
cat.setCatType((Cat.Type) values[i]);
|
||||
final int i = random.nextInt(Cat.Type.values().length);
|
||||
cat.setCatType(Cat.Type.values()[i]);
|
||||
cat.setTamed(true);
|
||||
cat.setBaby();
|
||||
cat.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
public class Commandloom extends EssentialsCommand {
|
||||
@@ -12,13 +11,11 @@ public class Commandloom extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openLoom(user.getBase());
|
||||
ess.getContainerProvider().openLoom(user.getBase());
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class Commandnick extends EssentialsLoopCommand {
|
||||
|
||||
private String formatNickname(final User user, final String nick) throws Exception {
|
||||
final String newNick = user == null ? FormatUtil.replaceFormat(nick) : FormatUtil.formatString(user, "essentials.nick", nick);
|
||||
if (!newNick.matches(ess.getSettings().getNickRegex()) && user != null && !user.isAuthorized("essentials.nick.allowunsafe")) {
|
||||
if (!newNick.matches("^[a-zA-Z_0-9" + ChatColor.COLOR_CHAR + "]+$") && user != null && !user.isAuthorized("essentials.nick.allowunsafe")) {
|
||||
throw new TranslatableException("nickNamesAlpha");
|
||||
} else if (getNickLength(newNick) > ess.getSettings().getMaxNickLength()) {
|
||||
throw new TranslatableException("nickTooLong");
|
||||
|
||||
@@ -3,14 +3,12 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.UserBalanceUpdateEvent;
|
||||
import net.ess3.provider.PlayerLocaleProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -19,6 +17,11 @@ import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class Commandpay extends EssentialsLoopCommand {
|
||||
private static final BigDecimal THOUSAND = new BigDecimal(1000);
|
||||
private static final BigDecimal MILLION = new BigDecimal(1_000_000);
|
||||
private static final BigDecimal BILLION = new BigDecimal(1_000_000_000);
|
||||
private static final BigDecimal TRILLION = new BigDecimal(1_000_000_000_000L);
|
||||
|
||||
public Commandpay() {
|
||||
super("pay");
|
||||
}
|
||||
@@ -41,16 +44,33 @@ public class Commandpay extends EssentialsLoopCommand {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final BigDecimal amount;
|
||||
if (ess.getSettings().isPerPlayerLocale()) {
|
||||
final String playerLocale = ess.provider(PlayerLocaleProvider.class).getLocale(user.getBase());
|
||||
amount = NumberUtil.parseStringToBDecimal(ogStr, user.getPlayerLocale(playerLocale));
|
||||
} else {
|
||||
amount = NumberUtil.parseStringToBDecimal(ogStr);
|
||||
BigDecimal tempAmount = new BigDecimal(sanitizedString);
|
||||
switch (Character.toLowerCase(ogStr.charAt(ogStr.length() - 1))) {
|
||||
case 'k': {
|
||||
tempAmount = tempAmount.multiply(THOUSAND);
|
||||
break;
|
||||
}
|
||||
case 'm': {
|
||||
tempAmount = tempAmount.multiply(MILLION);
|
||||
break;
|
||||
}
|
||||
case 'b': {
|
||||
tempAmount = tempAmount.multiply(BILLION);
|
||||
break;
|
||||
}
|
||||
case 't': {
|
||||
tempAmount = tempAmount.multiply(TRILLION);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final BigDecimal amount = tempAmount;
|
||||
|
||||
if (amount.compareTo(ess.getSettings().getMinimumPayAmount()) < 0) { // Check if amount is less than minimum-pay-amount
|
||||
throw new TranslatableException("minimumPayAmount", AdventureUtil.parsed(NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess)));
|
||||
throw new TranslatableException("minimumPayAmount", NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess));
|
||||
}
|
||||
final AtomicBoolean informToConfirm = new AtomicBoolean(false);
|
||||
final boolean canPayOffline = user.isAuthorized("essentials.pay.offline");
|
||||
@@ -97,7 +117,7 @@ public class Commandpay extends EssentialsLoopCommand {
|
||||
});
|
||||
if (informToConfirm.get()) {
|
||||
final String cmd = "/" + commandLabel + " " + StringUtil.joinList(" ", args);
|
||||
user.sendTl("confirmPayment", AdventureUtil.parsed(NumberUtil.displayCurrency(amount, ess)), cmd);
|
||||
user.sendTl("confirmPayment", NumberUtil.displayCurrency(amount, ess), cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,10 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.InventoryViewProvider;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.FurnaceRecipe;
|
||||
@@ -134,7 +131,7 @@ public class Commandrecipe extends EssentialsCommand {
|
||||
if (VersionUtil.PRE_FLATTENING && item.getDurability() == Short.MAX_VALUE) {
|
||||
item.setDurability((short) 0);
|
||||
}
|
||||
ess.provider(InventoryViewProvider.class).getTopInventory(view).setItem(j * 3 + k + 1, item);
|
||||
ess.getInventoryViewProvider().getTopInventory(view).setItem(j * 3 + k + 1, item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -153,28 +150,18 @@ public class Commandrecipe extends EssentialsCommand {
|
||||
materials[j][k] = item == null ? null : item.getType();
|
||||
}
|
||||
}
|
||||
sender.sendTl("recipeGrid", colorTag(colorMap, materials, 0, 0), colorTag(colorMap, materials, 0, 1), colorTag(colorMap, materials, 0, 2));
|
||||
sender.sendTl("recipeGrid", colorTag(colorMap, materials, 1, 0), colorTag(colorMap, materials, 1, 1), colorTag(colorMap, materials, 1, 2));
|
||||
sender.sendTl("recipeGrid", colorTag(colorMap, materials, 2, 0), colorTag(colorMap, materials, 2, 1), colorTag(colorMap, materials, 2, 2));
|
||||
sender.sendTl("recipeGrid", colorMap.get(materials[0][0]), colorMap.get(materials[0][1]), colorMap.get(materials[0][2]));
|
||||
sender.sendTl("recipeGrid", colorMap.get(materials[1][0]), colorMap.get(materials[1][1]), colorMap.get(materials[1][2]));
|
||||
sender.sendTl("recipeGrid", colorMap.get(materials[2][0]), colorMap.get(materials[2][1]), colorMap.get(materials[2][2]));
|
||||
|
||||
final StringBuilder s = new StringBuilder();
|
||||
for (final Material items : colorMap.keySet().toArray(new Material[0])) {
|
||||
s.append(sender.tl("recipeGridItem", colorMap.get(items), getMaterialName(sender, items))).append(" ");
|
||||
s.append(sender.tl("recipeGridItem", colorMap.get(items), getMaterialName(sender, items)));
|
||||
}
|
||||
sender.sendTl("recipeWhere", AdventureUtil.parsed(s.toString()));
|
||||
sender.sendTl("recipeWhere", s.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private AdventureUtil.ParsedPlaceholder colorTag(final Map<Material, String> colorMap, final Material[][] materials, final int x, final int y) {
|
||||
final char colorChar = colorMap.get(materials[x][y]).charAt(0);
|
||||
final NamedTextColor namedTextColor = AdventureUtil.fromChar(colorChar);
|
||||
if (namedTextColor == null) {
|
||||
throw new IllegalStateException("Illegal amount of materials in recipe");
|
||||
}
|
||||
|
||||
return AdventureUtil.parsed("<" + namedTextColor + ">" + colorChar);
|
||||
}
|
||||
|
||||
public void shapelessRecipe(final CommandSource sender, final ShapelessRecipe recipe, final boolean showWindow) {
|
||||
final List<ItemStack> ingredients = recipe.getIngredientList();
|
||||
if (showWindow) {
|
||||
@@ -187,7 +174,7 @@ public class Commandrecipe extends EssentialsCommand {
|
||||
if (VersionUtil.PRE_FLATTENING && item.getDurability() == Short.MAX_VALUE) {
|
||||
item.setDurability((short) 0);
|
||||
}
|
||||
ess.provider(InventoryViewProvider.class).setItem(view, i + 1, item);
|
||||
ess.getInventoryViewProvider().setItem(view, i + 1, item);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -216,7 +216,7 @@ public class Commandseen extends EssentialsCommand {
|
||||
|
||||
if (matches.size() > 0) {
|
||||
sender.sendTl("matchingIPAddress");
|
||||
sender.sendTl("matchingAccounts", StringUtil.joinList(matches));
|
||||
sender.sendMessage(StringUtil.joinList(matches));
|
||||
} else {
|
||||
sender.sendTl("noMatchingPlayers");
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class Commandsell extends EssentialsCommand {
|
||||
ess.showError(user.getSource(), new TranslatableException("cannotSellTheseNamedItems", String.join(ChatColor.RESET + ", ", names)), commandLabel);
|
||||
}
|
||||
if (count != 1) {
|
||||
final AdventureUtil.ParsedPlaceholder totalWorthStr = AdventureUtil.parsed(NumberUtil.displayCurrency(totalWorth, ess));
|
||||
final String totalWorthStr = NumberUtil.displayCurrency(totalWorth, ess);
|
||||
if (args[0].equalsIgnoreCase("blocks")) {
|
||||
user.sendTl("totalWorthBlocks", totalWorthStr, totalWorthStr);
|
||||
} else {
|
||||
@@ -93,8 +93,7 @@ public class Commandsell extends EssentialsCommand {
|
||||
|
||||
private BigDecimal sellItem(final User user, final ItemStack is, final String[] args, final boolean isBulkSell) throws Exception {
|
||||
final int amount = ess.getWorth().getAmount(ess, user, is, args, isBulkSell);
|
||||
final BigDecimal originalWorth = ess.getWorth().getPrice(ess, is);
|
||||
final BigDecimal worth = originalWorth == null ? null : originalWorth.multiply(ess.getSettings().getMultiplier(user));
|
||||
final BigDecimal worth = ess.getWorth().getPrice(ess, is);
|
||||
|
||||
if (worth == null) {
|
||||
throw new TranslatableException("itemCannotBeSold");
|
||||
@@ -102,7 +101,7 @@ public class Commandsell extends EssentialsCommand {
|
||||
|
||||
if (amount <= 0) {
|
||||
if (!isBulkSell) {
|
||||
user.sendTl("itemSold", AdventureUtil.parsed(NumberUtil.displayCurrency(BigDecimal.ZERO, ess)), BigDecimal.ZERO, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess));
|
||||
user.sendTl("itemSold", NumberUtil.displayCurrency(BigDecimal.ZERO, ess), BigDecimal.ZERO, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess));
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
@@ -121,9 +120,9 @@ public class Commandsell extends EssentialsCommand {
|
||||
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), user.getMoney(), ess);
|
||||
user.giveMoney(result, null, UserBalanceUpdateEvent.Cause.COMMAND_SELL);
|
||||
final String typeName = is.getType().toString().toLowerCase(Locale.ENGLISH);
|
||||
final AdventureUtil.ParsedPlaceholder worthDisplay = AdventureUtil.parsed(NumberUtil.displayCurrency(worth, ess));
|
||||
user.sendTl("itemSold", AdventureUtil.parsed(NumberUtil.displayCurrency(result, ess)), amount, typeName, worthDisplay);
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("itemSoldConsole", user.getName(), typeName, AdventureUtil.miniToLegacy(NumberUtil.displayCurrency(result, ess)), amount, AdventureUtil.miniToLegacy(worthDisplay.toString()), user.getDisplayName())));
|
||||
final String worthDisplay = NumberUtil.displayCurrency(worth, ess);
|
||||
user.sendTl("itemSold", NumberUtil.displayCurrency(result, ess), amount, typeName, worthDisplay);
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("itemSoldConsole", user.getName(), typeName, NumberUtil.displayCurrency(result, ess), amount, worthDisplay, user.getDisplayName())));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,10 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.RandomTeleport;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Commandsettpr extends EssentialsCommand {
|
||||
public Commandsettpr() {
|
||||
@@ -17,20 +15,22 @@ public class Commandsettpr extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
if (args.length == 0) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final RandomTeleport randomTeleport = ess.getRandomTeleport();
|
||||
if ("center".equalsIgnoreCase(args[1])) {
|
||||
randomTeleport.setCenter(args[0], user.getLocation());
|
||||
randomTeleport.getCachedLocations().clear();
|
||||
if ("center".equalsIgnoreCase(args[0])) {
|
||||
randomTeleport.setCenter(user.getLocation());
|
||||
user.sendTl("settpr");
|
||||
} else if (args.length > 2) {
|
||||
if ("minrange".equalsIgnoreCase(args[1])) {
|
||||
randomTeleport.setMinRange(args[0], Double.parseDouble(args[2]));
|
||||
} else if ("maxrange".equalsIgnoreCase(args[1])) {
|
||||
randomTeleport.setMaxRange(args[0], Double.parseDouble(args[2]));
|
||||
} else if (args.length > 1) {
|
||||
if ("minrange".equalsIgnoreCase(args[0])) {
|
||||
randomTeleport.setMinRange(Double.parseDouble(args[1]));
|
||||
} else if ("maxrange".equalsIgnoreCase(args[0])) {
|
||||
randomTeleport.setMaxRange(Double.parseDouble(args[1]));
|
||||
}
|
||||
user.sendTl("settprValue", args[1].toLowerCase(), args[2].toLowerCase());
|
||||
user.sendTl("settprValue", args[0].toLowerCase(), args[1].toLowerCase());
|
||||
} else {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
@@ -39,8 +39,6 @@ public class Commandsettpr extends EssentialsCommand {
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
return user.getServer().getWorlds().stream().map(World::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 2) {
|
||||
return Arrays.asList("center", "minrange", "maxrange");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.api.IWarps;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import net.ess3.api.InvalidWorldException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.essentialsx.api.v2.events.WarpModifyEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -30,7 +31,7 @@ public class Commandsetwarp extends EssentialsCommand {
|
||||
|
||||
try {
|
||||
warpLoc = warps.getWarp(args[0]);
|
||||
} catch (final WarpNotFoundException ignored) {
|
||||
} catch (final WarpNotFoundException | InvalidWorldException ignored) {
|
||||
}
|
||||
if (warpLoc == null) {
|
||||
final WarpModifyEvent event = new WarpModifyEvent(user, args[0], null, user.getLocation(), WarpModifyEvent.WarpModifyCause.CREATE);
|
||||
|
||||
@@ -48,14 +48,7 @@ public class Commandskull extends EssentialsCommand {
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final String owner;
|
||||
final User player;
|
||||
if (args.length == 2) {
|
||||
player = getPlayer(server, args, 1, false, false);
|
||||
} else {
|
||||
player = user;
|
||||
}
|
||||
|
||||
if (args.length > 0 && player.isAuthorized("essentials.skull.others")) {
|
||||
if (args.length > 0 && user.isAuthorized("essentials.skull.others")) {
|
||||
if (BASE_64_PATTERN.matcher(args[0]).matches()) {
|
||||
try {
|
||||
final String decoded = new String(Base64.getDecoder().decode(args[0]));
|
||||
@@ -87,9 +80,9 @@ public class Commandskull extends EssentialsCommand {
|
||||
final SkullMeta metaSkull;
|
||||
boolean spawn = false;
|
||||
|
||||
if (itemSkull != null && MaterialUtil.isPlayerHead(itemSkull) && user == player) {
|
||||
if (itemSkull != null && MaterialUtil.isPlayerHead(itemSkull)) {
|
||||
metaSkull = (SkullMeta) itemSkull.getItemMeta();
|
||||
} else if (user == player ? user.isAuthorized("essentials.skull.spawn") : user.isAuthorized("essentials.skull.spawn.others")) {
|
||||
} else if (user.isAuthorized("essentials.skull.spawn")) {
|
||||
itemSkull = new ItemStack(SKULL_ITEM, 1, (byte) 3);
|
||||
metaSkull = (SkullMeta) itemSkull.getItemMeta();
|
||||
spawn = true;
|
||||
@@ -101,10 +94,10 @@ public class Commandskull extends EssentialsCommand {
|
||||
throw new TranslatableException("noPermissionSkull");
|
||||
}
|
||||
|
||||
editSkull(user, player, itemSkull, metaSkull, owner, spawn);
|
||||
editSkull(user, itemSkull, metaSkull, owner, spawn);
|
||||
}
|
||||
|
||||
private void editSkull(final User user, final User receive, final ItemStack stack, final SkullMeta skullMeta, final String owner, final boolean spawn) {
|
||||
private void editSkull(final User user, final ItemStack stack, final SkullMeta skullMeta, final String owner, final boolean spawn) {
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
// Run this stuff async because it causes an HTTP request
|
||||
|
||||
@@ -138,11 +131,8 @@ public class Commandskull extends EssentialsCommand {
|
||||
ess.scheduleSyncDelayedTask(() -> {
|
||||
stack.setItemMeta(skullMeta);
|
||||
if (spawn) {
|
||||
Inventories.addItem(receive.getBase(), stack);
|
||||
receive.sendTl("givenSkull", shortOwnerName);
|
||||
if (user != receive) {
|
||||
user.sendTl("givenSkullOther", receive.getDisplayName(), shortOwnerName);
|
||||
}
|
||||
Inventories.addItem(user.getBase(), stack);
|
||||
user.sendTl("givenSkull", shortOwnerName);
|
||||
return;
|
||||
}
|
||||
user.sendTl("skullChanged", shortOwnerName);
|
||||
@@ -158,12 +148,6 @@ public class Commandskull extends EssentialsCommand {
|
||||
} else {
|
||||
return Lists.newArrayList(user.getName());
|
||||
}
|
||||
} else if (args.length == 2){
|
||||
if (user.isAuthorized("essentials.skull.others")) {
|
||||
return getPlayers(server, user);
|
||||
} else {
|
||||
return Lists.newArrayList(user.getName());
|
||||
}
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
public class Commandsmithingtable extends EssentialsCommand {
|
||||
@@ -12,13 +11,11 @@ public class Commandsmithingtable extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openSmithingTable(user.getBase());
|
||||
ess.getContainerProvider().openSmithingTable(user.getBase());
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class Commandspawner extends EssentialsCommand {
|
||||
final CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
|
||||
spawner.setSpawnedType(mob.getType());
|
||||
if (delay > 0) {
|
||||
final SpawnerBlockProvider spawnerBlockProvider = ess.provider(SpawnerBlockProvider.class);
|
||||
final SpawnerBlockProvider spawnerBlockProvider = ess.getSpawnerBlockProvider();
|
||||
spawnerBlockProvider.setMinSpawnDelay(spawner, 1);
|
||||
spawnerBlockProvider.setMaxSpawnDelay(spawner, Integer.MAX_VALUE);
|
||||
spawnerBlockProvider.setMinSpawnDelay(spawner, delay);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
public class Commandstonecutter extends EssentialsCommand {
|
||||
@@ -12,13 +11,11 @@ public class Commandstonecutter extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openStonecutter(user.getBase());
|
||||
ess.getContainerProvider().openStonecutter(user.getBase());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
@@ -15,9 +14,7 @@ public class Commandsuicide extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final DamageEventProvider provider = ess.provider(DamageEventProvider.class);
|
||||
|
||||
final EntityDamageEvent ede = provider.callDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Float.MAX_VALUE);
|
||||
final EntityDamageEvent ede = ess.getDamageEventProvider().callDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Float.MAX_VALUE);
|
||||
ede.getEntity().setLastDamageCause(ede);
|
||||
user.getBase().setHealth(0);
|
||||
user.sendTl("suicideMessage");
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
@@ -21,7 +20,7 @@ public class Commandtop extends EssentialsCommand {
|
||||
final int topZ = user.getLocation().getBlockZ();
|
||||
final float pitch = user.getLocation().getPitch();
|
||||
final float yaw = user.getLocation().getYaw();
|
||||
final Location unsafe = new Location(user.getWorld(), topX, ess.provider(WorldInfoProvider.class).getMaxHeight(user.getWorld()), topZ, yaw, pitch);
|
||||
final Location unsafe = new Location(user.getWorld(), topX, ess.getWorldInfoProvider().getMaxHeight(user.getWorld()), topZ, yaw, pitch);
|
||||
final Location safe = LocationUtil.getSafeDestination(ess, unsafe);
|
||||
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
|
||||
future.thenAccept(success -> {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.RandomTeleport;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.UserRandomTeleportEvent;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
@@ -12,7 +10,6 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Commandtpr extends EssentialsCommand {
|
||||
|
||||
@@ -25,67 +22,25 @@ public class Commandtpr extends EssentialsCommand {
|
||||
final Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
final RandomTeleport randomTeleport = ess.getRandomTeleport();
|
||||
final String defaultLocation = randomTeleport.getDefaultLocation().replace("{world}", user.getLocation().getWorld().getName());
|
||||
final String name = args.length > 0 ? args[0] : defaultLocation;
|
||||
final User userToTeleport = args.length > 1 && user.isAuthorized("essentials.tpr.others") ? getPlayer(server, user, args, 1) : user;
|
||||
if (randomTeleport.isPerLocationPermission() && !user.isAuthorized("essentials.tpr.location." + name)) {
|
||||
throw new TranslatableException("warpUsePermission");
|
||||
}
|
||||
final UserRandomTeleportEvent event = new UserRandomTeleportEvent(userToTeleport, name, randomTeleport.getCenter(name), randomTeleport.getMinRange(name), randomTeleport.getMaxRange(name));
|
||||
final UserRandomTeleportEvent event = new UserRandomTeleportEvent(user, randomTeleport.getCenter(), randomTeleport.getMinRange(), randomTeleport.getMaxRange());
|
||||
server.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
(event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(name))
|
||||
.thenAccept(location -> {
|
||||
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
userToTeleport.sendTl("tprSuccess");
|
||||
}
|
||||
});
|
||||
userToTeleport.getAsyncTeleport().teleport(location, charge, PlayerTeleportEvent.TeleportCause.COMMAND, future);
|
||||
});
|
||||
randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()).thenAccept(location -> {
|
||||
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
|
||||
user.getAsyncTeleport().teleport(location, charge, PlayerTeleportEvent.TeleportCause.COMMAND, future);
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
user.sendTl("tprSuccess");
|
||||
}
|
||||
});
|
||||
});
|
||||
throw new NoChargeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
final RandomTeleport randomTeleport = ess.getRandomTeleport();
|
||||
final User userToTeleport = getPlayer(server, sender, args, 1);
|
||||
final String name = args[0];
|
||||
final UserRandomTeleportEvent event = new UserRandomTeleportEvent(userToTeleport, name, randomTeleport.getCenter(name), randomTeleport.getMinRange(name), randomTeleport.getMaxRange(name));
|
||||
server.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
(event.isModified() ? randomTeleport.getRandomLocation(event.getCenter(), event.getMinRange(), event.getMaxRange()) : randomTeleport.getRandomLocation(name))
|
||||
.thenAccept(location -> {
|
||||
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
userToTeleport.sendTl("tprSuccess");
|
||||
}
|
||||
});
|
||||
userToTeleport.getAsyncTeleport().now(location, false, PlayerTeleportEvent.TeleportCause.COMMAND, future);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
final RandomTeleport randomTeleport = ess.getRandomTeleport();
|
||||
if (args.length == 1) {
|
||||
if (randomTeleport.isPerLocationPermission()) {
|
||||
return randomTeleport.listLocations().stream().filter(name -> sender.isAuthorized("essentials.tpr.location." + name)).collect(Collectors.toList());
|
||||
} else {
|
||||
return randomTeleport.listLocations();
|
||||
}
|
||||
} else if (args.length == 2 && sender.isAuthorized("essentials.tpr.others")) {
|
||||
return getPlayers(server, sender);
|
||||
}
|
||||
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class Commandwhois extends EssentialsCommand {
|
||||
final long playtimeMs = System.currentTimeMillis() - (user.getBase().getStatistic(PLAY_ONE_TICK) * 50L);
|
||||
sender.sendTl("whoisPlaytime", DateUtil.formatDateDiff(playtimeMs));
|
||||
if (!ess.getSettings().isEcoDisabled()) {
|
||||
sender.sendTl("whoisMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(user.getMoney(), ess)));
|
||||
sender.sendTl("whoisMoney", NumberUtil.displayCurrency(user.getMoney(), ess));
|
||||
}
|
||||
if (!sender.isPlayer() || ess.getUser(sender.getPlayer()).isAuthorized("essentials.whois.ip")) {
|
||||
sender.sendTl("whoisIPAddress", user.getBase().getAddress().getAddress().toString());
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -46,7 +45,7 @@ public class Commandworth extends EssentialsCommand {
|
||||
}
|
||||
}
|
||||
if (count > 1) {
|
||||
final AdventureUtil.ParsedPlaceholder totalWorthStr = AdventureUtil.parsed(NumberUtil.displayCurrency(totalWorth, ess));
|
||||
final String totalWorthStr = NumberUtil.displayCurrency(totalWorth, ess);
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("blocks")) {
|
||||
user.sendTl("totalSellableBlocks", totalWorthStr, totalWorthStr);
|
||||
return;
|
||||
@@ -89,8 +88,8 @@ public class Commandworth extends EssentialsCommand {
|
||||
|
||||
final BigDecimal result = worth.multiply(BigDecimal.valueOf(amount));
|
||||
final String typeName = is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||
final AdventureUtil.ParsedPlaceholder resultDisplay = AdventureUtil.parsed(NumberUtil.displayCurrency(result, ess));
|
||||
final AdventureUtil.ParsedPlaceholder worthDisplay = AdventureUtil.parsed(NumberUtil.displayCurrency(worth, ess));
|
||||
final String resultDisplay = NumberUtil.displayCurrency(result, ess);
|
||||
final String worthDisplay = NumberUtil.displayCurrency(worth, ess);
|
||||
if (MaterialUtil.getDamage(is) != 0) {
|
||||
sender.sendTl("worthMeta", typeName, MaterialUtil.getDamage(is), resultDisplay, amount, worthDisplay);
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -278,7 +277,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand {
|
||||
* Lists all commands.
|
||||
*/
|
||||
protected final List<String> getCommands(Server server) {
|
||||
final Map<String, Command> commandMap = Maps.newHashMap(this.ess.provider(KnownCommandsProvider.class).getKnownCommands());
|
||||
final Map<String, Command> commandMap = Maps.newHashMap(this.ess.getKnownCommandsProvider().getKnownCommands());
|
||||
final List<String> commands = Lists.newArrayListWithCapacity(commandMap.size());
|
||||
for (final Command command : commandMap.values()) {
|
||||
if (!(command instanceof PluginIdentifiableCommand)) {
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import net.ess3.api.TranslatableException;
|
||||
|
||||
public class InvalidModifierException extends TranslatableException {
|
||||
public InvalidModifierException() {
|
||||
super("invalidModifier");
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -13,6 +13,7 @@ import com.earth2me.essentials.config.serializers.LocationTypeSerializer;
|
||||
import com.earth2me.essentials.config.serializers.MailMessageSerializer;
|
||||
import com.earth2me.essentials.config.serializers.MaterialTypeSerializer;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import net.ess3.api.InvalidWorldException;
|
||||
import net.essentialsx.api.v2.services.mail.MailMessage;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -122,7 +123,7 @@ public class EssentialsConfiguration {
|
||||
setInternal(path, LazyLocation.fromLocation(location));
|
||||
}
|
||||
|
||||
public LazyLocation getLocation(final String path) {
|
||||
public LazyLocation getLocation(final String path) throws InvalidWorldException {
|
||||
final CommentedConfigurationNode node = path == null ? getRootNode() : getSection(path);
|
||||
if (node == null) {
|
||||
return null;
|
||||
|
||||
@@ -243,10 +243,6 @@ public final class Inventories {
|
||||
}
|
||||
|
||||
public static boolean removeItemAmount(final Player player, final ItemStack toRemove, int amount) {
|
||||
if (amount < 0) {
|
||||
throw new IllegalArgumentException("Amount cannot be negative.");
|
||||
}
|
||||
|
||||
final List<Integer> clearSlots = new ArrayList<>();
|
||||
final ItemStack[] items = player.getInventory().getContents();
|
||||
|
||||
|
||||
+1
-2
@@ -5,7 +5,6 @@ import com.earth2me.essentials.OfflinePlayerStub;
|
||||
import com.earth2me.essentials.api.NoLoanPermittedException;
|
||||
import com.earth2me.essentials.api.UserDoesNotExistException;
|
||||
import com.earth2me.essentials.config.EssentialsUserConfiguration;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.google.common.base.Charsets;
|
||||
@@ -62,7 +61,7 @@ public class VaultEconomyProvider implements Economy {
|
||||
|
||||
@Override
|
||||
public String format(double amount) {
|
||||
return AdventureUtil.miniToLegacy(NumberUtil.displayCurrency(BigDecimal.valueOf(amount), ess));
|
||||
return NumberUtil.displayCurrency(BigDecimal.valueOf(amount), ess);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,8 +9,6 @@ import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.PluginKey;
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
@@ -286,9 +284,8 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
|
||||
serializeEffectMeta(sb, fireworkEffectMeta.getEffect());
|
||||
}
|
||||
} else if (MaterialUtil.isPotion(material)) {
|
||||
final PotionMetaProvider provider = ess.provider(PotionMetaProvider.class);
|
||||
final boolean splash = provider.isSplashPotion(is);
|
||||
final Collection<PotionEffect> effects = provider.getCustomEffects(is);
|
||||
final boolean splash = ess.getPotionMetaProvider().isSplashPotion(is);
|
||||
final Collection<PotionEffect> effects = ess.getPotionMetaProvider().getCustomEffects(is);
|
||||
|
||||
for (final PotionEffect e : effects) {
|
||||
// long but needs to be effect:speed power:2 duration:120 in that order.
|
||||
@@ -319,7 +316,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
|
||||
} else {
|
||||
final BannerMeta bannerMeta = (BannerMeta) is.getItemMeta();
|
||||
if (bannerMeta != null) {
|
||||
DyeColor baseDyeColor = ess.provider(BannerDataProvider.class).getBaseColor(is);
|
||||
DyeColor baseDyeColor = ess.getBannerDataProvider().getBaseColor(is);
|
||||
if (baseDyeColor == null) {
|
||||
baseDyeColor = MaterialUtil.getColorOf(material);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,7 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -134,7 +132,7 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
final ItemData.EssentialPotionData potionData = data.getPotionData();
|
||||
|
||||
if (potionData != null && stack.getItemMeta() instanceof PotionMeta) {
|
||||
ess.provider(PotionMetaProvider.class).setBasePotionType(stack, potionData.getType(), potionData.isExtended(), potionData.isUpgraded());
|
||||
ess.getPotionMetaProvider().setBasePotionType(stack, potionData.getType(), potionData.isExtended(), potionData.isUpgraded());
|
||||
}
|
||||
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
@@ -152,8 +150,8 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
// setItemMeta to prevent a race condition
|
||||
final EntityType entity = data.getEntity();
|
||||
if (entity != null && material.toString().contains("SPAWNER")) {
|
||||
ess.provider(SpawnerItemProvider.class).setEntityType(stack, entity);
|
||||
ess.provider(PersistentDataProvider.class).set(stack, "convert", "true");
|
||||
ess.getSpawnerItemProvider().setEntityType(stack, entity);
|
||||
ess.getPersistentDataProvider().set(stack, "convert", "true");
|
||||
}
|
||||
|
||||
return stack;
|
||||
@@ -208,10 +206,10 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
final Material type = is.getType();
|
||||
|
||||
if (MaterialUtil.isPotion(type) && is.getItemMeta() instanceof PotionMeta) {
|
||||
final PotionMetaProvider provider = ess.provider(PotionMetaProvider.class);
|
||||
final PotionMetaProvider provider = ess.getPotionMetaProvider();
|
||||
return new ItemData(type, new ItemData.EssentialPotionData(provider.getBasePotionType(is), provider.isUpgraded(is), provider.isExtended(is)));
|
||||
} else if (type.toString().contains("SPAWNER")) {
|
||||
final EntityType entity = ess.provider(SpawnerItemProvider.class).getEntityType(is);
|
||||
final EntityType entity = ess.getSpawnerItemProvider().getEntityType(is);
|
||||
return new ItemData(type, entity);
|
||||
} else {
|
||||
return new ItemData(type);
|
||||
|
||||
@@ -7,10 +7,6 @@ import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import net.ess3.provider.SpawnEggProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -191,8 +187,8 @@ public class LegacyItemDb extends AbstractItemDb {
|
||||
if (mat == MOB_SPAWNER) {
|
||||
if (metaData == 0) metaData = EntityType.PIG.getTypeId();
|
||||
try {
|
||||
retval = ess.provider(SpawnerItemProvider.class).setEntityType(retval, EntityType.fromId(metaData));
|
||||
ess.provider(PersistentDataProvider.class).set(retval, "convert", "true");
|
||||
retval = ess.getSpawnerItemProvider().setEntityType(retval, EntityType.fromId(metaData));
|
||||
ess.getPersistentDataProvider().set(retval, "convert", "true");
|
||||
} catch (final IllegalArgumentException e) {
|
||||
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
|
||||
}
|
||||
@@ -203,10 +199,10 @@ public class LegacyItemDb extends AbstractItemDb {
|
||||
} catch (final IllegalArgumentException e) {
|
||||
throw new Exception("Can't spawn entity ID " + metaData + " from spawn eggs.");
|
||||
}
|
||||
retval = ess.provider(SpawnEggProvider.class).createEggItem(type);
|
||||
retval = ess.getSpawnEggProvider().createEggItem(type);
|
||||
} else if (mat.name().endsWith("POTION")
|
||||
&& VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_11_R01)) { // Only apply this to pre-1.11 as items.csv might only work in 1.11
|
||||
retval = ess.provider(PotionMetaProvider.class).createPotionItem(mat, metaData);
|
||||
retval = ess.getPotionMetaProvider().createPotionItem(mat, metaData);
|
||||
} else {
|
||||
retval.setDurability(metaData);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.perm;
|
||||
|
||||
import com.earth2me.essentials.commands.Commandhat;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -10,16 +11,16 @@ import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public final class PermissionsDefaults {
|
||||
|
||||
|
||||
private PermissionsDefaults() {
|
||||
}
|
||||
|
||||
|
||||
public static void registerAllBackDefaults() {
|
||||
for (final World world : Bukkit.getWorlds()) {
|
||||
registerBackDefaultFor(world);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void registerBackDefaultFor(final World w) {
|
||||
final String permName = "essentials.back.into." + w.getName();
|
||||
|
||||
@@ -41,7 +42,7 @@ public final class PermissionsDefaults {
|
||||
}
|
||||
|
||||
final ImmutableMap.Builder<String, Boolean> children = ImmutableMap.builder();
|
||||
for (final Material mat : Material.values()) {
|
||||
for (final Material mat : MaterialUtil.getKnownMaterials()) {
|
||||
final String matPerm = Commandhat.PERM_PREFIX + mat.name().toLowerCase();
|
||||
children.put(matPerm, true);
|
||||
pluginManager.addPermission(new Permission(matPerm, "Prevent using " + mat + " as a type of hat.", PermissionDefault.FALSE));
|
||||
|
||||
@@ -12,11 +12,9 @@ import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.SignBreakEvent;
|
||||
import net.ess3.api.events.SignCreateEvent;
|
||||
import net.ess3.api.events.SignInteractEvent;
|
||||
import net.ess3.provider.SignDataProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -168,26 +166,24 @@ public class EssentialsSign {
|
||||
}
|
||||
|
||||
public void setOwnerData(final IEssentials ess, final User user, final ISign signProvider) {
|
||||
final SignDataProvider dataProvider = ess.provider(SignDataProvider.class);
|
||||
if (dataProvider == null) {
|
||||
if (ess.getSignDataProvider() == null) {
|
||||
return;
|
||||
}
|
||||
final Sign sign = (Sign) signProvider.getBlock().getState();
|
||||
dataProvider.setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString());
|
||||
ess.getSignDataProvider().setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString());
|
||||
}
|
||||
|
||||
public boolean isOwner(final IEssentials ess, final User user, final ISign signProvider, final int nameIndex, final String namePrefix) {
|
||||
final SignDataProvider dataProvider = ess.provider(SignDataProvider.class);
|
||||
final Sign sign = (Sign) signProvider.getBlock().getState();
|
||||
if (dataProvider == null || dataProvider.getSignData(sign, SIGN_OWNER_KEY) == null) {
|
||||
if (ess.getSignDataProvider() == null || ess.getSignDataProvider().getSignData(sign, SIGN_OWNER_KEY) == null) {
|
||||
final boolean isLegacyOwner = FormatUtil.stripFormat(signProvider.getLine(nameIndex)).equalsIgnoreCase(getUsername(user));
|
||||
if (dataProvider != null && isLegacyOwner) {
|
||||
dataProvider.setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString());
|
||||
if (ess.getSignDataProvider() != null && isLegacyOwner) {
|
||||
ess.getSignDataProvider().setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString());
|
||||
}
|
||||
return isLegacyOwner;
|
||||
}
|
||||
|
||||
if (user.getUUID().toString().equals(dataProvider.getSignData(sign, SIGN_OWNER_KEY))) {
|
||||
if (user.getUUID().toString().equals(ess.getSignDataProvider().getSignData(sign, SIGN_OWNER_KEY))) {
|
||||
signProvider.setLine(nameIndex, namePrefix + getUsername(user));
|
||||
return true;
|
||||
}
|
||||
@@ -412,10 +408,6 @@ public class EssentialsSign {
|
||||
item.setAmount(quantity);
|
||||
return item;
|
||||
} catch (final Exception ex) {
|
||||
if (ex instanceof TranslatableException) {
|
||||
final TranslatableException te = (TranslatableException) ex;
|
||||
throw new SignException(ex, te.getTlKey(), te.getArgs());
|
||||
}
|
||||
throw new SignException(ex, "errorWithMessage", ex.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -558,11 +550,9 @@ public class EssentialsSign {
|
||||
|
||||
static class BlockSign implements ISign {
|
||||
private final transient Block block;
|
||||
private transient Sign sign;
|
||||
|
||||
BlockSign(final Block block) {
|
||||
this.block = block;
|
||||
this.sign = getSign();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -579,7 +569,7 @@ public class EssentialsSign {
|
||||
|
||||
@Override
|
||||
public final void setLine(final int index, final String text) {
|
||||
sign.setLine(index, text);
|
||||
getSign().setLine(index, text);
|
||||
updateSign();
|
||||
}
|
||||
|
||||
@@ -596,8 +586,7 @@ public class EssentialsSign {
|
||||
|
||||
@Override
|
||||
public final void updateSign() {
|
||||
sign.update();
|
||||
sign = getSign();
|
||||
getSign().update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
public class SignAnvil extends EssentialsSign {
|
||||
public SignAnvil() {
|
||||
@@ -11,7 +10,7 @@ public class SignAnvil extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.provider(ContainerProvider.class) == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
player.sendTl("unsupportedBrand");
|
||||
return false;
|
||||
}
|
||||
@@ -20,7 +19,7 @@ public class SignAnvil extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.provider(ContainerProvider.class).openAnvil(player.getBase());
|
||||
ess.getContainerProvider().openAnvil(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
|
||||
@@ -12,7 +11,7 @@ public class SignBalance extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException {
|
||||
player.sendTl("balance", AdventureUtil.parsed(NumberUtil.displayCurrency(player.getMoney(), ess)));
|
||||
player.sendTl("balance", NumberUtil.displayCurrency(player.getMoney(), ess));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials.signs;
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.events.SignTransactionEvent;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -46,12 +45,6 @@ public class SignBuy extends EssentialsSign {
|
||||
}
|
||||
|
||||
charge.isAffordableFor(player);
|
||||
final SignTransactionEvent signTransactionEvent = new SignTransactionEvent(sign, this, player, items.getItemStack(), SignTransactionEvent.TransactionType.BUY, charge.getMoney());
|
||||
|
||||
ess.getServer().getPluginManager().callEvent(signTransactionEvent);
|
||||
if (signTransactionEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
if (!items.pay(player)) {
|
||||
throw new ChargeException("inventoryFull");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
public class SignCartography extends EssentialsSign {
|
||||
public SignCartography() {
|
||||
@@ -11,7 +10,7 @@ public class SignCartography extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.provider(ContainerProvider.class) == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
player.sendTl("unsupportedBrand");
|
||||
return false;
|
||||
}
|
||||
@@ -20,7 +19,7 @@ public class SignCartography extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.provider(ContainerProvider.class).openCartographyTable(player.getBase());
|
||||
ess.getContainerProvider().openCartographyTable(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class SignEnchant extends EssentialsSign {
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
|
||||
final ItemStack stack;
|
||||
final String itemName = sign.getLine(1);
|
||||
final MaterialTagProvider tagProvider = ess.provider(MaterialTagProvider.class);
|
||||
final MaterialTagProvider tagProvider = ess.getMaterialTagProvider();
|
||||
try {
|
||||
stack = itemName.equals("*") || itemName.equalsIgnoreCase("any") || (tagProvider != null && tagProvider.tagExists(itemName)) ? null : getItemStack(sign.getLine(1), 1, ess);
|
||||
} catch (final SignException e) {
|
||||
@@ -66,7 +66,7 @@ public class SignEnchant extends EssentialsSign {
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
|
||||
final ItemStack playerHand = Inventories.getItemInHand(player.getBase());
|
||||
final MaterialTagProvider tagProvider = ess.provider(MaterialTagProvider.class);
|
||||
final MaterialTagProvider tagProvider = ess.getMaterialTagProvider();
|
||||
final String itemName = sign.getLine(1);
|
||||
final ItemStack search = itemName.equals("*") || itemName.equalsIgnoreCase("any") || (tagProvider != null && tagProvider.tagExists(itemName) && tagProvider.isTagged(itemName, playerHand.getType())) ? null : getItemStack(itemName, 1, ess);
|
||||
final Trade charge = getTrade(sign, 3, ess);
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
public class SignGrindstone extends EssentialsSign {
|
||||
public SignGrindstone() {
|
||||
@@ -11,7 +10,7 @@ public class SignGrindstone extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.provider(ContainerProvider.class) == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
player.sendTl("unsupportedBrand");
|
||||
return false;
|
||||
}
|
||||
@@ -20,7 +19,7 @@ public class SignGrindstone extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.provider(ContainerProvider.class).openGrindstone(player.getBase());
|
||||
ess.getContainerProvider().openGrindstone(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
public class SignLoom extends EssentialsSign {
|
||||
public SignLoom() {
|
||||
@@ -11,7 +10,7 @@ public class SignLoom extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.provider(ContainerProvider.class) == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
player.sendTl("unsupportedBrand");
|
||||
return false;
|
||||
}
|
||||
@@ -20,7 +19,7 @@ public class SignLoom extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.provider(ContainerProvider.class).openLoom(player.getBase());
|
||||
ess.getContainerProvider().openLoom(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.RandomTeleport;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SignRandomTeleport extends EssentialsSign {
|
||||
public SignRandomTeleport() {
|
||||
super("RandomTeleport");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException, MaxMoneyException {
|
||||
final String name = sign.getLine(1);
|
||||
final RandomTeleport randomTeleport = ess.getRandomTeleport();
|
||||
randomTeleport.getRandomLocation(name).thenAccept(location -> {
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
player.sendTl("tprSuccess");
|
||||
}
|
||||
});
|
||||
player.getAsyncTeleport().now(location, false, PlayerTeleportEvent.TeleportCause.COMMAND, future);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.commands.Commandrepair;
|
||||
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
|
||||
public class SignRepair extends EssentialsSign {
|
||||
public SignRepair() {
|
||||
@@ -43,8 +42,6 @@ public class SignRepair extends EssentialsSign {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
} catch (final TranslatableException ex) {
|
||||
throw new SignException(ex.getTlKey(), ex.getArgs());
|
||||
} catch (final Exception ex) {
|
||||
throw new SignException(ex, "errorWithMessage", ex.getMessage());
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.Trade.OverflowType;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.events.SignTransactionEvent;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -42,19 +41,11 @@ public class SignSell extends EssentialsSign {
|
||||
//noinspection BigDecimalMethodWithoutRoundingCalled
|
||||
BigDecimal pricePerSingleItem = chargeAmount.divide(new BigDecimal(initialItemAmount));
|
||||
pricePerSingleItem = pricePerSingleItem.multiply(new BigDecimal(newItemAmount));
|
||||
pricePerSingleItem = pricePerSingleItem.multiply(ess.getSettings().getMultiplier(player));
|
||||
money = new Trade(pricePerSingleItem, ess);
|
||||
}
|
||||
}
|
||||
|
||||
charge.isAffordableFor(player);
|
||||
|
||||
final SignTransactionEvent signTransactionEvent = new SignTransactionEvent(sign, this, player, charge.getItemStack(), SignTransactionEvent.TransactionType.SELL, money.getMoney());
|
||||
ess.getServer().getPluginManager().callEvent(signTransactionEvent);
|
||||
if (signTransactionEvent.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
money.pay(player, OverflowType.DROP);
|
||||
charge.charge(player);
|
||||
Trade.log("Sign", "Sell", "Interact", username, charge, username, money, sign.getBlock().getLocation(), player.getMoney(), ess);
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
public class SignSmithing extends EssentialsSign {
|
||||
public SignSmithing() {
|
||||
@@ -11,7 +10,7 @@ public class SignSmithing extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.provider(ContainerProvider.class) == null) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
player.sendTl("unsupportedBrand");
|
||||
return false;
|
||||
}
|
||||
@@ -20,7 +19,7 @@ public class SignSmithing extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.provider(ContainerProvider.class).openSmithingTable(player.getBase());
|
||||
ess.getContainerProvider().openSmithingTable(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
//TODO: TL exceptions
|
||||
public class SignTrade extends EssentialsSign {
|
||||
private static final int MAX_STOCK_LINE_LENGTH = 15;
|
||||
|
||||
@@ -46,14 +47,14 @@ public class SignTrade extends EssentialsSign {
|
||||
final Trade stored;
|
||||
try {
|
||||
stored = getTrade(sign, 1, AmountType.TOTAL, true, true, ess);
|
||||
subtractAmount(sign, 1, stored, ess, false);
|
||||
subtractAmount(sign, 1, stored, ess);
|
||||
|
||||
final Map<Integer, ItemStack> withdraw = stored.pay(player, OverflowType.RETURN);
|
||||
|
||||
if (withdraw == null) {
|
||||
Trade.log("Sign", "Trade", "Withdraw", username, store, username, null, sign.getBlock().getLocation(), player.getMoney(), ess);
|
||||
} else {
|
||||
setAmount(sign, 1, BigDecimal.valueOf(withdraw.get(0).getAmount()), ess, false);
|
||||
setAmount(sign, 1, BigDecimal.valueOf(withdraw.get(0).getAmount()), ess);
|
||||
Trade.log("Sign", "Trade", "Withdraw", username, stored, username, new Trade(withdraw.get(0), ess), sign.getBlock().getLocation(), player.getMoney(), ess);
|
||||
}
|
||||
} catch (final SignException e) {
|
||||
@@ -66,16 +67,11 @@ public class SignTrade extends EssentialsSign {
|
||||
final Trade charge = getTrade(sign, 1, AmountType.COST, false, true, ess);
|
||||
final Trade trade = getTrade(sign, 2, AmountType.COST, true, true, ess);
|
||||
charge.isAffordableFor(player);
|
||||
|
||||
// validate addAmount + subtractAmount first to ensure they both do not throw exceptions
|
||||
addAmount(sign, 1, charge, ess, true);
|
||||
subtractAmount(sign, 2, trade, ess, true);
|
||||
|
||||
addAmount(sign, 1, charge, ess, false);
|
||||
subtractAmount(sign, 2, trade, ess, false);
|
||||
addAmount(sign, 1, charge, ess);
|
||||
subtractAmount(sign, 2, trade, ess);
|
||||
if (!trade.pay(player)) {
|
||||
subtractAmount(sign, 1, charge, ess, false);
|
||||
addAmount(sign, 2, trade, ess, false);
|
||||
subtractAmount(sign, 1, charge, ess);
|
||||
addAmount(sign, 2, trade, ess);
|
||||
throw new ChargeException("inventoryFull");
|
||||
}
|
||||
charge.charge(player);
|
||||
@@ -97,7 +93,7 @@ public class SignTrade extends EssentialsSign {
|
||||
stack = stack.clone();
|
||||
stack.setAmount(amount);
|
||||
final Trade store = new Trade(stack, ess);
|
||||
addAmount(sign, 2, store, ess, false);
|
||||
addAmount(sign, 2, store, ess);
|
||||
store.charge(player);
|
||||
return store;
|
||||
}
|
||||
@@ -131,10 +127,10 @@ public class SignTrade extends EssentialsSign {
|
||||
return true;
|
||||
}
|
||||
|
||||
setAmount(sign, 1, BigDecimal.valueOf(withdraw1 == null ? 0L : withdraw1.get(0).getAmount()), ess, false);
|
||||
setAmount(sign, 1, BigDecimal.valueOf(withdraw1 == null ? 0L : withdraw1.get(0).getAmount()), ess);
|
||||
Trade.log("Sign", "Trade", "Withdraw", signOwner.substring(2), stored1, username, withdraw1 == null ? null : new Trade(withdraw1.get(0), ess), sign.getBlock().getLocation(), player.getMoney(), ess);
|
||||
|
||||
setAmount(sign, 2, BigDecimal.valueOf(withdraw2 == null ? 0L : withdraw2.get(0).getAmount()), ess, false);
|
||||
setAmount(sign, 2, BigDecimal.valueOf(withdraw2 == null ? 0L : withdraw2.get(0).getAmount()), ess);
|
||||
Trade.log("Sign", "Trade", "Withdraw", signOwner.substring(2), stored2, username, withdraw2 == null ? null : new Trade(withdraw2.get(0), ess), sign.getBlock().getLocation(), player.getMoney(), ess);
|
||||
|
||||
sign.updateSign();
|
||||
@@ -271,37 +267,38 @@ public class SignTrade extends EssentialsSign {
|
||||
throw new SignException("invalidSignLine", index + 1);
|
||||
}
|
||||
|
||||
protected final void subtractAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess, final boolean validationRun) throws SignException {
|
||||
protected final void subtractAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException {
|
||||
final BigDecimal money = trade.getMoney();
|
||||
if (money != null) {
|
||||
changeAmount(sign, index, money.negate(), ess, validationRun);
|
||||
changeAmount(sign, index, money.negate(), ess);
|
||||
}
|
||||
final ItemStack item = trade.getItemStack();
|
||||
if (item != null) {
|
||||
changeAmount(sign, index, BigDecimal.valueOf(-item.getAmount()), ess, validationRun);
|
||||
changeAmount(sign, index, BigDecimal.valueOf(-item.getAmount()), ess);
|
||||
}
|
||||
final Integer exp = trade.getExperience();
|
||||
if (exp != null) {
|
||||
changeAmount(sign, index, BigDecimal.valueOf(-exp), ess, validationRun);
|
||||
changeAmount(sign, index, BigDecimal.valueOf(-exp), ess);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void addAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess, final boolean validationRun) throws SignException {
|
||||
protected final void addAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException {
|
||||
final BigDecimal money = trade.getMoney();
|
||||
if (money != null) {
|
||||
changeAmount(sign, index, money, ess, validationRun);
|
||||
changeAmount(sign, index, money, ess);
|
||||
}
|
||||
final ItemStack item = trade.getItemStack();
|
||||
if (item != null) {
|
||||
changeAmount(sign, index, BigDecimal.valueOf(item.getAmount()), ess, validationRun);
|
||||
changeAmount(sign, index, BigDecimal.valueOf(item.getAmount()), ess);
|
||||
}
|
||||
final Integer exp = trade.getExperience();
|
||||
if (exp != null) {
|
||||
changeAmount(sign, index, BigDecimal.valueOf(exp), ess, validationRun);
|
||||
changeAmount(sign, index, BigDecimal.valueOf(exp), ess);
|
||||
}
|
||||
}
|
||||
|
||||
private void changeAmount(final ISign sign, final int index, final BigDecimal value, final IEssentials ess, final boolean validationRun) throws SignException {
|
||||
//TODO: Translate these exceptions.
|
||||
private void changeAmount(final ISign sign, final int index, final BigDecimal value, final IEssentials ess) throws SignException {
|
||||
final String line = sign.getLine(index).trim();
|
||||
if (line.isEmpty()) {
|
||||
throw new SignException("emptySignLine", index + 1);
|
||||
@@ -310,18 +307,20 @@ public class SignTrade extends EssentialsSign {
|
||||
|
||||
if (split.length == 2) {
|
||||
final BigDecimal amount = getBigDecimal(split[1], ess).add(value);
|
||||
setAmount(sign, index, amount, ess, validationRun);
|
||||
setAmount(sign, index, amount, ess);
|
||||
return;
|
||||
}
|
||||
if (split.length == 3) {
|
||||
final BigDecimal amount = getBigDecimal(split[2], ess).add(value);
|
||||
setAmount(sign, index, amount, ess, validationRun);
|
||||
setAmount(sign, index, amount, ess);
|
||||
return;
|
||||
}
|
||||
throw new SignException("invalidSignLine", index + 1);
|
||||
}
|
||||
|
||||
private void setAmount(final ISign sign, final int index, final BigDecimal value, final IEssentials ess, final boolean validationRun) throws SignException {
|
||||
//TODO: Translate these exceptions.
|
||||
private void setAmount(final ISign sign, final int index, final BigDecimal value, final IEssentials ess) throws SignException {
|
||||
|
||||
final String line = sign.getLine(index).trim();
|
||||
if (line.isEmpty()) {
|
||||
throw new SignException("emptySignLine", index + 1);
|
||||
@@ -334,9 +333,7 @@ public class SignTrade extends EssentialsSign {
|
||||
if (money != null && amount != null) {
|
||||
final String newline = NumberUtil.shortCurrency(money, ess) + ":" + NumberUtil.formatAsCurrency(value);
|
||||
validateSignLength(newline);
|
||||
if (!validationRun) {
|
||||
sign.setLine(index, newline);
|
||||
}
|
||||
sign.setLine(index, newline);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -346,16 +343,12 @@ public class SignTrade extends EssentialsSign {
|
||||
if (split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp")) {
|
||||
final String newline = stackAmount + " " + split[1] + ":" + value.intValueExact();
|
||||
validateSignLength(newline);
|
||||
if (!validationRun) {
|
||||
sign.setLine(index, newline);
|
||||
}
|
||||
sign.setLine(index, newline);
|
||||
} else {
|
||||
getItemStack(split[1], stackAmount, ess);
|
||||
final String newline = stackAmount + " " + split[1] + ":" + value.intValueExact();
|
||||
validateSignLength(newline);
|
||||
if (!validationRun) {
|
||||
sign.setLine(index, newline);
|
||||
}
|
||||
sign.setLine(index, newline);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -26,10 +25,6 @@ public class SignWarp extends EssentialsSign {
|
||||
try {
|
||||
ess.getWarps().getWarp(warpName);
|
||||
} catch (final Exception ex) {
|
||||
if (ex instanceof TranslatableException) {
|
||||
final TranslatableException te = (TranslatableException) ex;
|
||||
throw new SignException(ex, te.getTlKey(), te.getArgs());
|
||||
}
|
||||
throw new SignException(ex, "errorWithMessage", ex.getMessage());
|
||||
}
|
||||
final String group = sign.getLine(2);
|
||||
|
||||
@@ -25,8 +25,7 @@ public enum Signs {
|
||||
TRADE(new SignTrade()),
|
||||
WARP(new SignWarp()),
|
||||
WEATHER(new SignWeather()),
|
||||
WORKBENCH(new SignWorkbench()),
|
||||
RANDOMTELEPORT(new SignRandomTeleport());
|
||||
WORKBENCH(new SignWorkbench());
|
||||
private final EssentialsSign sign;
|
||||
|
||||
Signs(final EssentialsSign sign) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -33,7 +32,7 @@ public class HelpInput implements IText {
|
||||
}
|
||||
|
||||
final Multimap<Plugin, Command> pluginCommands = HashMultimap.create();
|
||||
for (final Command command : ess.provider(KnownCommandsProvider.class).getKnownCommands().values()) {
|
||||
for (final Command command : ess.getKnownCommandsProvider().getKnownCommands().values()) {
|
||||
if (!(command instanceof PluginIdentifiableCommand)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.ExecuteTimer;
|
||||
import com.earth2me.essentials.PlayerList;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.DescParseTickFormat;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
@@ -228,7 +227,7 @@ public class KeywordReplacer implements IText {
|
||||
break;
|
||||
case BALANCE:
|
||||
if (user != null) {
|
||||
replacer = AdventureUtil.miniToLegacy(NumberUtil.displayCurrency(user.getMoney(), ess));
|
||||
replacer = NumberUtil.displayCurrency(user.getMoney(), ess);
|
||||
}
|
||||
break;
|
||||
case MAILS:
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.AbstractChatEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.flattener.ComponentFlattener;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.serializer.legacy.CharacterAndFormat;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.Reset;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class AdventureUtil {
|
||||
private static final LegacyComponentSerializer LEGACY_SERIALIZER;
|
||||
@@ -19,10 +25,25 @@ public final class AdventureUtil {
|
||||
private static MiniMessage miniMessageInstance;
|
||||
|
||||
static {
|
||||
final List<CharacterAndFormat> formats = new ArrayList<>();
|
||||
formats.addAll(CharacterAndFormat.defaults());
|
||||
formats.addAll(Arrays.asList(
|
||||
CharacterAndFormat.characterAndFormat('A', NamedTextColor.GREEN),
|
||||
CharacterAndFormat.characterAndFormat('B', NamedTextColor.AQUA),
|
||||
CharacterAndFormat.characterAndFormat('C', NamedTextColor.RED),
|
||||
CharacterAndFormat.characterAndFormat('D', NamedTextColor.LIGHT_PURPLE),
|
||||
CharacterAndFormat.characterAndFormat('E', NamedTextColor.YELLOW),
|
||||
CharacterAndFormat.characterAndFormat('F', NamedTextColor.WHITE),
|
||||
CharacterAndFormat.characterAndFormat('K', TextDecoration.OBFUSCATED),
|
||||
CharacterAndFormat.characterAndFormat('L', TextDecoration.BOLD),
|
||||
CharacterAndFormat.characterAndFormat('M', TextDecoration.STRIKETHROUGH),
|
||||
CharacterAndFormat.characterAndFormat('N', TextDecoration.UNDERLINED),
|
||||
CharacterAndFormat.characterAndFormat('O', TextDecoration.ITALIC),
|
||||
CharacterAndFormat.characterAndFormat('R', Reset.INSTANCE)
|
||||
));
|
||||
final LegacyComponentSerializer.Builder builder = LegacyComponentSerializer.builder()
|
||||
.flattener(ComponentFlattener.basic())
|
||||
.extractUrls(AbstractChatEvent.URL_PATTERN)
|
||||
.hexColors()
|
||||
.formats(formats)
|
||||
.useUnusualXRepeatedCharacterHexFormat();
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_1_R01)) {
|
||||
builder.hexColors();
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.FormattedCommandAlias;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@@ -61,7 +60,7 @@ public final class CommandMapUtil {
|
||||
} else if (value instanceof FormattedCommandAlias) {
|
||||
json.addProperty("source", "commands.yml");
|
||||
final JsonArray formatStrings = new JsonArray();
|
||||
for (final String entry : ess.provider(FormattedCommandAliasProvider.class).getFormatStrings((FormattedCommandAlias) value)) {
|
||||
for (final String entry : ess.getFormattedCommandAliasProvider().getFormatStrings((FormattedCommandAlias) value)) {
|
||||
formatStrings.add(new JsonPrimitive(entry));
|
||||
}
|
||||
json.add("bukkit_aliases", formatStrings);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.provider.AbstractChatEvent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
|
||||
@@ -25,6 +24,7 @@ public final class FormatUtil {
|
||||
private static final Pattern REPLACE_ALL_RGB_PATTERN = Pattern.compile("(&)?&#([0-9a-fA-F]{6})");
|
||||
//Used to prepare xmpp output
|
||||
private static final Pattern LOGCOLOR_PATTERN = Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]");
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-zA-Z]{2,3}(?:/\\S+)?)");
|
||||
//Used to strip ANSI control codes from console
|
||||
private static final Pattern ANSI_CONTROL_PATTERN = Pattern.compile("[\\x1B\\x9B][\\[\\]()#;?]*(?:(?:(?:;[-a-zA-Z\\d/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d/#&.:=?%@~_]*)*)?\\x07|(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~])");
|
||||
private static final Pattern PAPER_CONTROL_PATTERN = Pattern.compile("(?i)" + (char) 0x7f + "[0-9A-FK-ORX]");
|
||||
@@ -297,9 +297,9 @@ public final class FormatUtil {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
String text = AbstractChatEvent.URL_PATTERN.matcher(input).replaceAll("$1 $2");
|
||||
while (AbstractChatEvent.URL_PATTERN.matcher(text).find()) {
|
||||
text = AbstractChatEvent.URL_PATTERN.matcher(text).replaceAll("$1 $2");
|
||||
String text = URL_PATTERN.matcher(input).replaceAll("$1 $2");
|
||||
while (URL_PATTERN.matcher(text).find()) {
|
||||
text = URL_PATTERN.matcher(text).replaceAll("$1 $2");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -15,7 +14,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -38,15 +37,15 @@ public final class LocationUtil {
|
||||
private static final Material FARMLAND = EnumUtil.getMaterial("FARMLAND");
|
||||
|
||||
// The player can stand inside these materials
|
||||
private static final Set<Material> HOLLOW_MATERIALS = EnumSet.noneOf(Material.class);
|
||||
private static final Set<Material> TRANSPARENT_MATERIALS = EnumSet.noneOf(Material.class);
|
||||
private static final Set<Material> HOLLOW_MATERIALS = new HashSet<>();
|
||||
private static final Set<Material> TRANSPARENT_MATERIALS = new HashSet<>();
|
||||
|
||||
static {
|
||||
// If the server is running in a test environment, the isTransparent() method will blow up since
|
||||
// it requires the registry to be initialized. This is a workaround to prevent that from happening.
|
||||
if (!Essentials.TESTING) {
|
||||
// Materials from Material.isTransparent()
|
||||
for (final Material mat : Material.values()) {
|
||||
for (final Material mat : MaterialUtil.getKnownMaterials()) {
|
||||
if (mat.isTransparent()) {
|
||||
HOLLOW_MATERIALS.add(mat);
|
||||
}
|
||||
@@ -114,7 +113,7 @@ public final class LocationUtil {
|
||||
}
|
||||
|
||||
public static boolean isBlockAboveAir(IEssentials ess, final World world, final int x, final int y, final int z) {
|
||||
return y > ess.provider(WorldInfoProvider.class).getMaxHeight(world) || HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType());
|
||||
return y > ess.getWorldInfoProvider().getMaxHeight(world) || HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType());
|
||||
}
|
||||
|
||||
public static boolean isBlockOutsideWorldBorder(final World world, final int x, final int z) {
|
||||
@@ -219,12 +218,10 @@ public final class LocationUtil {
|
||||
if (loc == null || loc.getWorld() == null) {
|
||||
throw new TranslatableException("destinationNotSet");
|
||||
}
|
||||
final WorldInfoProvider worldInfoProvider = ess.provider(WorldInfoProvider.class);
|
||||
|
||||
final World world = loc.getWorld();
|
||||
final int worldMinY = worldInfoProvider.getMinHeight(world);
|
||||
final int worldLogicalY = worldInfoProvider.getLogicalHeight(world);
|
||||
final int worldMaxY = loc.getBlockY() < worldLogicalY ? worldLogicalY : worldInfoProvider.getMaxHeight(world);
|
||||
final int worldMinY = ess.getWorldInfoProvider().getMinHeight(world);
|
||||
final int worldLogicalY = ess.getWorldInfoProvider().getLogicalHeight(world);
|
||||
final int worldMaxY = loc.getBlockY() < worldLogicalY ? worldLogicalY : ess.getWorldInfoProvider().getMaxHeight(world);
|
||||
int x = loc.getBlockX();
|
||||
int y = (int) Math.round(loc.getY());
|
||||
int z = loc.getBlockZ();
|
||||
@@ -281,14 +278,13 @@ public final class LocationUtil {
|
||||
}
|
||||
|
||||
public static boolean shouldFly(IEssentials ess, final Location loc) {
|
||||
final WorldInfoProvider worldInfoProvider = ess.provider(WorldInfoProvider.class);
|
||||
final World world = loc.getWorld();
|
||||
final int x = loc.getBlockX();
|
||||
int y = (int) Math.round(loc.getY());
|
||||
final int z = loc.getBlockZ();
|
||||
int count = 0;
|
||||
// Check whether more than 2 unsafe block are below player.
|
||||
while (LocationUtil.isBlockUnsafe(ess, world, x, y, z) && y >= worldInfoProvider.getMinHeight(world)) {
|
||||
while (LocationUtil.isBlockUnsafe(ess, world, x, y, z) && y >= ess.getWorldInfoProvider().getMinHeight(world)) {
|
||||
y--;
|
||||
count++;
|
||||
if (count > 2) {
|
||||
@@ -297,7 +293,7 @@ public final class LocationUtil {
|
||||
}
|
||||
|
||||
// If not then check if player is in the void
|
||||
return y < worldInfoProvider.getMinHeight(world);
|
||||
return y < ess.getWorldInfoProvider().getMinHeight(world);
|
||||
}
|
||||
|
||||
public static class Vector3D {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.earth2me.essentials.utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.material.MaterialData;
|
||||
@@ -86,7 +87,7 @@ public final class MaterialUtil {
|
||||
"OAK_SIGN", "SPRUCE_SIGN",
|
||||
"CRIMSON_SIGN", "WARPED_SIGN",
|
||||
"MANGROVE_SIGN", "CHERRY_SIGN",
|
||||
"BAMBOO_SIGN", "PALE_OAK_SIGN");
|
||||
"BAMBOO_SIGN");
|
||||
|
||||
WALL_SIGNS = EnumUtil.getAllMatching(Material.class, "WALL_SIGN",
|
||||
"ACACIA_WALL_SIGN", "BIRCH_WALL_SIGN",
|
||||
@@ -94,21 +95,21 @@ public final class MaterialUtil {
|
||||
"OAK_WALL_SIGN", "SPRUCE_WALL_SIGN",
|
||||
"CRIMSON_WALL_SIGN", "WARPED_WALL_SIGN",
|
||||
"MANGROVE_WALL_SIGN", "CHERRY_WALL_SIGN",
|
||||
"BAMBOO_WALL_SIGN", "PALE_OAK_WALL_SIGN");
|
||||
"BAMBOO_WALL_SIGN");
|
||||
|
||||
HANGING_SIGNS = EnumUtil.getAllMatching(Material.class, "ACACIA_HANGING_SIGN", "BIRCH_HANGING_SIGN",
|
||||
"DARK_OAK_HANGING_SIGN", "JUNGLE_HANGING_SIGN",
|
||||
"OAK_HANGING_SIGN", "SPRUCE_HANGING_SIGN",
|
||||
"CRIMSON_HANGING_SIGN", "WARPED_HANGING_SIGN",
|
||||
"MANGROVE_HANGING_SIGN", "CHERRY_HANGING_SIGN",
|
||||
"BAMBOO_HANGING_SIGN", "PALE_OAK_HANGING_SIGN");
|
||||
"BAMBOO_HANGING_SIGN");
|
||||
|
||||
HANGING_WALL_SIGNS = EnumUtil.getAllMatching(Material.class, "ACACIA_WALL_HANGING_SIGN", "BIRCH_WALL_HANGING_SIGN",
|
||||
"DARK_OAK_WALL_HANGING_SIGN", "JUNGLE_WALL_HANGING_SIGN",
|
||||
"OAK_WALL_HANGING_SIGN", "SPRUCE_WALL_HANGING_SIGN",
|
||||
"CRIMSON_WALL_HANGING_SIGN", "WARPED_WALL_HANGING_SIGN",
|
||||
"MANGROVE_WALL_HANGING_SIGN", "CHERRY_WALL_HANGING_SIGN",
|
||||
"BAMBOO_WALL_HANGING_SIGN", "PALE_OAK_WALL_HANGING_SIGN");
|
||||
"BAMBOO_WALL_HANGING_SIGN");
|
||||
}
|
||||
|
||||
private MaterialUtil() {
|
||||
@@ -246,4 +247,11 @@ public final class MaterialUtil {
|
||||
|
||||
return DyeColor.WHITE;
|
||||
}
|
||||
|
||||
public static Material[] getKnownMaterials() {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_14_R01)) {
|
||||
return Material.values();
|
||||
}
|
||||
return Registry.MATERIAL.stream().toArray(Material[]::new);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
|
||||
import com.earth2me.essentials.commands.InvalidModifierException;
|
||||
import net.ess3.api.IEssentials;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -8,25 +7,18 @@ import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
|
||||
public final class NumberUtil {
|
||||
|
||||
private static final BigDecimal THOUSAND = new BigDecimal(1000);
|
||||
private static final BigDecimal MILLION = new BigDecimal(1_000_000);
|
||||
private static final BigDecimal BILLION = new BigDecimal(1_000_000_000);
|
||||
private static final BigDecimal TRILLION = new BigDecimal(1_000_000_000_000L);
|
||||
|
||||
private static final DecimalFormat twoDPlaces = new DecimalFormat("#,###.##");
|
||||
private static final DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
// This field is likely to be modified in com.earth2me.essentials.Settings when loading currency format.
|
||||
// This ensures that we can supply a constant formatting.
|
||||
private static Locale PRETTY_LOCALE = Locale.US;
|
||||
private static NumberFormat PRETTY_FORMAT = NumberFormat.getInstance(PRETTY_LOCALE);
|
||||
private static NumberFormat PRETTY_FORMAT = NumberFormat.getInstance(Locale.US);
|
||||
|
||||
static {
|
||||
twoDPlaces.setRoundingMode(RoundingMode.HALF_UP);
|
||||
@@ -73,22 +65,21 @@ public final class NumberUtil {
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this *can* return MiniMessage, make sure if this is sent to a player that it is wrapped in AdventureUtil#parsed.
|
||||
*/
|
||||
public static String displayCurrency(final BigDecimal value, final IEssentials ess) {
|
||||
return displayCurrency(value, ess, false);
|
||||
String currency = formatAsPrettyCurrency(value);
|
||||
String sign = "";
|
||||
if (value.signum() < 0) {
|
||||
currency = currency.substring(1);
|
||||
sign = "-";
|
||||
}
|
||||
if (ess.getSettings().isCurrencySymbolSuffixed()) {
|
||||
return sign + tlLiteral("currency", currency, ess.getSettings().getCurrencySymbol());
|
||||
}
|
||||
return sign + tlLiteral("currency", ess.getSettings().getCurrencySymbol(), currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this *can* return MiniMessage, make sure if this is sent to a player that it is wrapped in AdventureUtil#parsed.
|
||||
*/
|
||||
public static String displayCurrencyExactly(final BigDecimal value, final IEssentials ess) {
|
||||
return displayCurrency(value, ess, true);
|
||||
}
|
||||
|
||||
private static String displayCurrency(final BigDecimal value, final IEssentials ess, final boolean exact) {
|
||||
String currency = exact ? value.toPlainString() : formatAsPrettyCurrency(value);
|
||||
String currency = value.toPlainString();
|
||||
String sign = "";
|
||||
if (value.signum() < 0) {
|
||||
currency = currency.substring(1);
|
||||
@@ -147,52 +138,6 @@ public final class NumberUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static BigDecimal parseStringToBDecimal(final String sArg, final Locale locale) throws ParseException, InvalidModifierException {
|
||||
if (sArg.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
final String sanitizedString = sArg.replaceAll("[^0-9.,]", "");
|
||||
BigDecimal multiplier = null;
|
||||
|
||||
switch (sArg.replace(sanitizedString, "").toUpperCase()) {
|
||||
case "": {
|
||||
break;
|
||||
}
|
||||
case "K": {
|
||||
multiplier = THOUSAND;
|
||||
break;
|
||||
}
|
||||
case "M": {
|
||||
multiplier = MILLION;
|
||||
break;
|
||||
}
|
||||
case "B": {
|
||||
multiplier = BILLION;
|
||||
break;
|
||||
}
|
||||
case "T": {
|
||||
multiplier = TRILLION;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new InvalidModifierException();
|
||||
}
|
||||
|
||||
final NumberFormat format = NumberFormat.getInstance(locale);
|
||||
final Number parsed = format.parse(sanitizedString);
|
||||
BigDecimal amount = new BigDecimal(parsed.toString());
|
||||
|
||||
if (multiplier != null) {
|
||||
amount = amount.multiply(multiplier);
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static BigDecimal parseStringToBDecimal(final String sArg) throws ParseException, InvalidModifierException {
|
||||
return parseStringToBDecimal(sArg, PRETTY_LOCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backport from Guava.
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.base.Charsets;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -16,11 +17,10 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public final class PasteUtil {
|
||||
private static final String PASTE_URL = "https://pastes.dev/";
|
||||
private static final String PASTE_UPLOAD_URL = "https://api.pastes.dev/post";
|
||||
private static final String PASTE_URL = "https://paste.gg/";
|
||||
private static final String PASTE_UPLOAD_URL = "https://api.paste.gg/v1/pastes";
|
||||
private static final ExecutorService PASTE_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor();
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
@@ -42,8 +42,7 @@ public final class PasteUtil {
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("User-Agent", "EssentialsX plugin");
|
||||
connection.setRequestProperty("Content-Type", "text/json");
|
||||
connection.setRequestProperty("Content-Encoding", "gzip");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
final JsonObject body = new JsonObject();
|
||||
final JsonArray files = new JsonArray();
|
||||
for (final PasteFile page : pages) {
|
||||
@@ -57,22 +56,24 @@ public final class PasteUtil {
|
||||
}
|
||||
body.add("files", files);
|
||||
|
||||
try (final OutputStream os = new GZIPOutputStream(connection.getOutputStream())) {
|
||||
try (final OutputStream os = connection.getOutputStream()) {
|
||||
os.write(body.toString().getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
if (connection.getResponseCode() >= 400) {
|
||||
//noinspection UnstableApiUsage
|
||||
future.completeExceptionally(new Error(CharStreams.toString(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8))));
|
||||
return;
|
||||
}
|
||||
|
||||
// Read URL
|
||||
final JsonObject object = GSON.fromJson(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8), JsonObject.class);
|
||||
final String pasteId = object.get("key").getAsString();
|
||||
final String pasteId = object.get("result").getAsJsonObject().get("id").getAsString();
|
||||
final String pasteUrl = PASTE_URL + pasteId;
|
||||
final JsonElement deletionKey = object.get("result").getAsJsonObject().get("deletion_key");
|
||||
connection.disconnect();
|
||||
|
||||
final PasteResult result = new PasteResult(pasteId, pasteUrl, null);
|
||||
final PasteResult result = new PasteResult(pasteId, pasteUrl, deletionKey != null ? deletionKey.getAsString() : null);
|
||||
future.complete(result);
|
||||
} catch (Exception e) {
|
||||
future.completeExceptionally(e);
|
||||
|
||||
@@ -3,50 +3,12 @@ package com.earth2me.essentials.utils;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class RegistryUtil {
|
||||
private static final Table<Class<?>, String, Object> registryCache = HashBasedTable.create();
|
||||
|
||||
private RegistryUtil() {
|
||||
}
|
||||
|
||||
public static <T> Object[] values(Class<T> registry) {
|
||||
if (registry.getEnumConstants() != null) {
|
||||
return registry.getEnumConstants();
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
final T[] values = (T[]) registryCache.get(registry, "$values");
|
||||
if (values != null) {
|
||||
return values;
|
||||
}
|
||||
|
||||
final List<T> set = new ArrayList<>();
|
||||
|
||||
for (final Field field : registry.getDeclaredFields()) {
|
||||
try {
|
||||
final Object value = field.get(null);
|
||||
if (value != null && registry.isAssignableFrom(value.getClass())) {
|
||||
//noinspection unchecked
|
||||
set.add((T) value);
|
||||
}
|
||||
} catch (NullPointerException | IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
final T[] array = (T[]) new Object[set.size()];
|
||||
for (int i = 0; i < set.size(); i++) {
|
||||
array[i] = set.get(i);
|
||||
}
|
||||
registryCache.put(registry, "$values", array);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public static <T> T valueOf(Class<T> registry, String... names) {
|
||||
for (final String name : names) {
|
||||
//noinspection unchecked
|
||||
|
||||
@@ -38,12 +38,11 @@ public final class VersionUtil {
|
||||
public static final BukkitVersion v1_19_R01 = BukkitVersion.fromString("1.19-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_19_4_R01 = BukkitVersion.fromString("1.19.4-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_20_1_R01 = BukkitVersion.fromString("1.20.1-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_20_4_R01 = BukkitVersion.fromString("1.20.4-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_20_6_R01 = BukkitVersion.fromString("1.20.6-R0.1-SNAPSHOT");
|
||||
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");
|
||||
|
||||
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_R01);
|
||||
|
||||
public static final boolean PRE_FLATTENING = VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01);
|
||||
|
||||
|
||||
Loaded 100 of 245 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user