mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-13 06:15:08 +01:00
Rework the provider system
This commit is contained in:
parent
0897ef71f2
commit
9771d160c4
@ -1,5 +1,6 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -52,7 +53,7 @@ public class AlternativeCommandsHandler {
|
||||
|
||||
private Map<String, Command> getPluginCommands(Plugin plugin) {
|
||||
final Map<String, Command> commands = new HashMap<>();
|
||||
for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> entry : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
|
||||
if (entry.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) entry.getValue()).getPlugin().equals(plugin)) {
|
||||
commands.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
@ -56,22 +56,9 @@ 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.ContainerProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.MaterialTagProvider;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
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.BaseLoggerProvider;
|
||||
import net.ess3.provider.providers.BasePotionDataProvider;
|
||||
import net.ess3.provider.providers.BlockMetaSpawnerItemProvider;
|
||||
@ -145,6 +132,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private static Logger LOGGER = null;
|
||||
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
|
||||
private final transient Set<String> vanishedPlayers = new LinkedHashSet<>();
|
||||
private final transient ProviderFactory providerFactory = new ProviderFactory(this);
|
||||
private transient ISettings settings;
|
||||
private transient Jails jails;
|
||||
private transient Warps warps;
|
||||
@ -162,23 +150,7 @@ 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 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 SignDataProvider signDataProvider;
|
||||
private transient Kits kits;
|
||||
private transient RandomTeleport randomTeleport;
|
||||
private transient UpdateChecker updateChecker;
|
||||
@ -353,44 +325,59 @@ 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...
|
||||
spawnerItemProvider = new BlockMetaSpawnerItemProvider();
|
||||
// Spawner item provider only uses one, but it's here for legacy...
|
||||
providerFactory.registerProvider(BlockMetaSpawnerItemProvider.class);
|
||||
|
||||
//Spawner block providers
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_12_0_R01)) {
|
||||
spawnerBlockProvider = new ReflSpawnerBlockProvider();
|
||||
} else {
|
||||
spawnerBlockProvider = new BukkitSpawnerBlockProvider();
|
||||
}
|
||||
// Spawner block providers
|
||||
providerFactory.registerProvider(ReflSpawnerBlockProvider.class, BukkitSpawnerBlockProvider.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();
|
||||
}
|
||||
// Spawn Egg Providers
|
||||
providerFactory.registerProvider(LegacySpawnEggProvider.class, ReflSpawnEggProvider.class, FlatSpawnEggProvider.class);
|
||||
|
||||
//Potion Meta Provider
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
potionMetaProvider = new LegacyPotionMetaProvider();
|
||||
} else {
|
||||
potionMetaProvider = new BasePotionDataProvider();
|
||||
}
|
||||
// Potion Meta Provider
|
||||
providerFactory.registerProvider(LegacyPotionMetaProvider.class, BasePotionDataProvider.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();
|
||||
}
|
||||
// Server State Provider
|
||||
providerFactory.registerProvider(ReflServerStateProvider.class, PaperServerStateProvider.class);
|
||||
|
||||
//Event Providers
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
providerFactory.finalizeRegistration();
|
||||
|
||||
// Event Providers
|
||||
if (PaperLib.isPaper()) {
|
||||
try {
|
||||
Class.forName("com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent");
|
||||
@ -403,50 +390,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
execTimer.mark("Init(Providers)");
|
||||
reload();
|
||||
|
||||
@ -550,9 +493,14 @@ 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 = getServerStateProvider().isStopping();
|
||||
final boolean stopping = getProviders().get(ServerStateProvider.class).isStopping();
|
||||
if (!stopping) {
|
||||
LOGGER.log(Level.SEVERE, tl("serverReloading"));
|
||||
}
|
||||
@ -665,8 +613,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
// Check for disabled commands
|
||||
if (getSettings().isCommandDisabled(commandLabel)) {
|
||||
if (getKnownCommandsProvider().getKnownCommands().containsKey(commandLabel)) {
|
||||
final Command newCmd = getKnownCommandsProvider().getKnownCommands().get(commandLabel);
|
||||
if (getProviders().get(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) {
|
||||
final Command newCmd = getProviders().get(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
|
||||
if (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this) {
|
||||
return newCmd.tabComplete(cSender, commandLabel, args);
|
||||
}
|
||||
@ -771,8 +719,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
// Check for disabled commands
|
||||
if (getSettings().isCommandDisabled(commandLabel)) {
|
||||
if (getKnownCommandsProvider().getKnownCommands().containsKey(commandLabel)) {
|
||||
final Command newCmd = getKnownCommandsProvider().getKnownCommands().get(commandLabel);
|
||||
if (getProviders().get(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) {
|
||||
final Command newCmd = getProviders().get(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
|
||||
if (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin())) {
|
||||
return newCmd.execute(cSender, commandLabel, args);
|
||||
}
|
||||
@ -1251,90 +1199,11 @@ 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 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 SignDataProvider getSignDataProvider() {
|
||||
return signDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginCommand getPluginCommand(final String cmd) {
|
||||
return this.getCommand(cmd);
|
||||
|
@ -2,6 +2,8 @@ package com.earth2me.essentials;
|
||||
|
||||
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;
|
||||
@ -25,11 +27,11 @@ public class EssentialsBlockListener implements Listener {
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
final ItemStack is = event.getItemInHand();
|
||||
|
||||
if (is.getType() == MaterialUtil.SPAWNER && ess.getPersistentDataProvider().getString(is, "convert") != null) {
|
||||
if (is.getType() == MaterialUtil.SPAWNER && ess.getProviders().get(PersistentDataProvider.class).getString(is, "convert") != null) {
|
||||
final BlockState blockState = event.getBlockPlaced().getState();
|
||||
if (blockState instanceof CreatureSpawner) {
|
||||
final CreatureSpawner spawner = (CreatureSpawner) blockState;
|
||||
final EntityType type = ess.getSpawnerItemProvider().getEntityType(event.getItemInHand());
|
||||
final EntityType type = ess.getProviders().get(SpawnerItemProvider.class).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);
|
||||
|
@ -14,6 +14,8 @@ 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.KnownCommandsProvider;
|
||||
import net.ess3.provider.providers.BukkitCommandSendListenerProvider;
|
||||
import net.ess3.provider.providers.PaperCommandSendListenerProvider;
|
||||
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
|
||||
@ -580,10 +582,10 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
// 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.getKnownCommandsProvider().getKnownCommands().get(cmd);
|
||||
final Command knownCommand = ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().get(cmd);
|
||||
if (knownCommand instanceof FormattedCommandAlias) {
|
||||
final FormattedCommandAlias command = (FormattedCommandAlias) knownCommand;
|
||||
for (String fullCommand : ess.getFormattedCommandAliasProvider().createCommands(command, event.getPlayer(), args.split(" "))) {
|
||||
for (String fullCommand : ess.getProviders().get(FormattedCommandAliasProvider.class).createCommands(command, event.getPlayer(), args.split(" "))) {
|
||||
handlePlayerCommandPreprocess(event, fullCommand);
|
||||
}
|
||||
return;
|
||||
|
@ -7,20 +7,6 @@ import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.commands.PlayerNotFoundException;
|
||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||
import com.earth2me.essentials.updatecheck.UpdateChecker;
|
||||
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.MaterialTagProvider;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
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;
|
||||
@ -140,33 +126,7 @@ 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();
|
||||
|
||||
PluginCommand getPluginCommand(String cmd);
|
||||
|
||||
ProviderFactory getProviders();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.events.KitClaimEvent;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -191,11 +192,11 @@ public class Kit {
|
||||
final ItemStack stack;
|
||||
|
||||
if (kitItem.startsWith("@")) {
|
||||
if (ess.getSerializationProvider() == null) {
|
||||
if (ess.getProviders().get(SerializationProvider.class) == null) {
|
||||
ess.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName()));
|
||||
continue;
|
||||
}
|
||||
stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
|
||||
stack = ess.getProviders().get(SerializationProvider.class).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);
|
||||
|
@ -10,6 +10,7 @@ import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
@ -684,7 +685,7 @@ public class MetaItemStack {
|
||||
|
||||
private void setUnbreakable(final IEssentials ess, final ItemStack is, final boolean unbreakable) {
|
||||
final ItemMeta meta = is.getItemMeta();
|
||||
ess.getItemUnbreakableProvider().setUnbreakable(meta, unbreakable);
|
||||
ess.getProviders().get(ItemUnbreakableProvider.class).setUnbreakable(meta, unbreakable);
|
||||
is.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,118 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.provider.Provider;
|
||||
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;
|
||||
}
|
||||
|
||||
public <P extends Provider> P get(final Class<P> providerClass) {
|
||||
if (!this.providers.containsKey(providerClass)) {
|
||||
return null;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (P) providers.get(providerClass);
|
||||
}
|
||||
|
||||
@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();
|
||||
Class<? extends Provider> highestProvider = null;
|
||||
ProviderData highestProviderData = null;
|
||||
int highestWeight = -1;
|
||||
providerLoop:
|
||||
for (final Class<? extends Provider> provider : entry.getValue()) {
|
||||
try {
|
||||
final ProviderData providerData = provider.getAnnotation(ProviderData.class);
|
||||
if (providerData.weight() > highestWeight) {
|
||||
for (final Method method : provider.getMethods()) {
|
||||
if (method.isAnnotationPresent(ProviderTest.class)) {
|
||||
final Boolean result = (Boolean) method.invoke(null);
|
||||
if (!result) {
|
||||
continue providerLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
highestWeight = providerData.weight();
|
||||
highestProvider = provider;
|
||||
highestProviderData = providerData;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
essentials.getLogger().log(Level.SEVERE, "Failed to initialize provider " + provider.getName(), e);
|
||||
}
|
||||
}
|
||||
if (highestProvider == null) {
|
||||
throw new IllegalStateException("No provider found for " + providerClass.getName());
|
||||
}
|
||||
|
||||
essentials.getLogger().info("Selected " + highestProviderData.description() + " as the provider for " + providerClass.getSimpleName());
|
||||
providers.put(providerClass, getProviderInstance(highestProvider));
|
||||
}
|
||||
registeredProviders.clear();
|
||||
}
|
||||
|
||||
private <C extends Provider> C getProviderInstance(final Class<C> provider) {
|
||||
try {
|
||||
final Constructor<?> constructor = provider.getConstructors()[0];
|
||||
if (constructor.getParameterTypes().length == 0) {
|
||||
//noinspection unchecked
|
||||
return (C) constructor.newInstance();
|
||||
}
|
||||
final Object[] args = new Object[constructor.getParameterTypes().length];
|
||||
|
||||
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 (C) 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ 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.WorldInfoProvider;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
@ -177,7 +178,7 @@ public class RandomTeleport implements IConf {
|
||||
final Location location = new Location(
|
||||
center.getWorld(),
|
||||
center.getX() + offsetX,
|
||||
ess.getWorldInfoProvider().getMaxHeight(center.getWorld()),
|
||||
ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(center.getWorld()),
|
||||
center.getZ() + offsetZ,
|
||||
360 * RANDOM.nextFloat() - 180,
|
||||
0
|
||||
@ -195,7 +196,7 @@ public class RandomTeleport implements IConf {
|
||||
|
||||
// Returns an appropriate elevation for a given location in the nether, or -1 if none is found
|
||||
private double getNetherYAt(final Location location) {
|
||||
for (int y = 32; y < ess.getWorldInfoProvider().getMaxHeight(location.getWorld()); ++y) {
|
||||
for (int y = 32; y < ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(location.getWorld()); ++y) {
|
||||
if (!LocationUtil.isBlockUnsafe(ess, location.getWorld(), location.getBlockX(), y, location.getBlockZ())) {
|
||||
return y;
|
||||
}
|
||||
@ -204,7 +205,7 @@ public class RandomTeleport implements IConf {
|
||||
}
|
||||
|
||||
private boolean isValidRandomLocation(final Location location) {
|
||||
return location.getBlockY() > ess.getWorldInfoProvider().getMinHeight(location.getWorld()) && !this.getExcludedBiomes().contains(location.getBlock().getBiome());
|
||||
return location.getBlockY() > ess.getProviders().get(WorldInfoProvider.class).getMinHeight(location.getWorld()) && !this.getExcludedBiomes().contains(location.getBlock().getBiome());
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
|
@ -13,6 +13,8 @@ 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 org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@ -315,7 +317,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
private void _addAlternativeCommand(final String label, final Command current) {
|
||||
Command cmd = ess.getAlternativeCommandsHandler().getAlternative(label);
|
||||
if (cmd == null) {
|
||||
for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> entry : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
|
||||
final String[] split = entry.getKey().split(":");
|
||||
if (entry.getValue() != current && split[split.length - 1].equals(label)) {
|
||||
cmd = entry.getValue();
|
||||
@ -325,7 +327,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
if (cmd != null) {
|
||||
ess.getKnownCommandsProvider().getKnownCommands().put(label, cmd);
|
||||
ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().put(label, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -680,13 +682,13 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
playerCommands = _getPlayerCommands();
|
||||
|
||||
// This will be late loaded
|
||||
if (ess.getKnownCommandsProvider() != null) {
|
||||
if (ess.getProviders().get(KnownCommandsProvider.class) != null) {
|
||||
boolean mapModified = false;
|
||||
if (!disabledBukkitCommands.isEmpty()) {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!");
|
||||
}
|
||||
ess.getKnownCommandsProvider().getKnownCommands().putAll(disabledBukkitCommands);
|
||||
ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().putAll(disabledBukkitCommands);
|
||||
disabledBukkitCommands.clear();
|
||||
mapModified = true;
|
||||
}
|
||||
@ -698,7 +700,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias);
|
||||
}
|
||||
final Command removed = ess.getKnownCommandsProvider().getKnownCommands().remove(effectiveAlias);
|
||||
final Command removed = ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().remove(effectiveAlias);
|
||||
if (removed != null) {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!");
|
||||
@ -721,9 +723,9 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
ess.getLogger().log(Level.INFO, "Syncing commands");
|
||||
}
|
||||
if (reloadCount.get() < 2) {
|
||||
ess.scheduleSyncDelayedTask(() -> ess.getSyncCommandsProvider().syncCommands());
|
||||
ess.scheduleSyncDelayedTask(() -> ess.getProviders().get(SyncCommandsProvider.class).syncCommands());
|
||||
} else {
|
||||
ess.getSyncCommandsProvider().syncCommands();
|
||||
ess.getProviders().get(SyncCommandsProvider.class).syncCommands();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
@ -13,11 +14,11 @@ public class Commandanvil extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
ess.getContainerProvider().openAnvil(user.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openAnvil(user.getBase());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
@ -13,11 +14,11 @@ public class Commandcartographytable extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
ess.getContainerProvider().openCartographyTable(user.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openCartographyTable(user.getBase());
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.PasteUtil;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -42,7 +43,7 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
|
||||
boolean useSerializationProvider = ess.getSettings().isUseBetterKits();
|
||||
|
||||
if (useSerializationProvider && ess.getSerializationProvider() == null) {
|
||||
if (useSerializationProvider && ess.getProviders().get(SerializationProvider.class) == null) {
|
||||
ess.showError(user.getSource(), new Exception(tl("createKitUnsupported")), commandLabel);
|
||||
useSerializationProvider = false;
|
||||
}
|
||||
@ -51,7 +52,7 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
if (is != null && is.getType() != null && is.getType() != Material.AIR) {
|
||||
final String serialized;
|
||||
if (useSerializationProvider) {
|
||||
serialized = "@" + Base64Coder.encodeLines(ess.getSerializationProvider().serializeItem(is));
|
||||
serialized = "@" + Base64Coder.encodeLines(ess.getProviders().get(SerializationProvider.class).serializeItem(is));
|
||||
} else {
|
||||
serialized = ess.getItemDb().serialize(is);
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.OnlineModeProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -202,7 +204,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.getOnlineModeProvider().getOnlineModeString());
|
||||
serverData.addProperty("online-mode", ess.getProviders().get(OnlineModeProvider.class).getOnlineModeString());
|
||||
final JsonObject supportStatus = new JsonObject();
|
||||
final VersionUtil.SupportStatus status = VersionUtil.getServerSupportStatus();
|
||||
supportStatus.addProperty("status", status.name());
|
||||
@ -272,7 +274,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
final Plugin essDiscord = Bukkit.getPluginManager().getPlugin("EssentialsDiscord");
|
||||
final Plugin essSpawn = Bukkit.getPluginManager().getPlugin("EssentialsSpawn");
|
||||
|
||||
final Map<String, Command> knownCommandsCopy = new HashMap<>(ess.getKnownCommandsProvider().getKnownCommands());
|
||||
final Map<String, Command> knownCommandsCopy = new HashMap<>(ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands());
|
||||
final Map<String, String> disabledCommandsCopy = new HashMap<>(ess.getAlternativeCommandsHandler().disabledCommands());
|
||||
|
||||
// Further operations will be heavy IO
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
@ -13,11 +14,11 @@ public class Commandgrindstone extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
ess.getContainerProvider().openGrindstone(user.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openGrindstone(user.getBase());
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.TextInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
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;
|
||||
@ -36,7 +37,7 @@ 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.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> knownCmd : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
|
||||
if (knownCmd.getKey().equalsIgnoreCase(cmd)) {
|
||||
user.sendMessage(tl("commandHelpLine1", cmd));
|
||||
user.sendMessage(tl("commandHelpLine2", knownCmd.getValue().getDescription()));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
@ -13,11 +14,11 @@ public class Commandloom extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
ess.getContainerProvider().openLoom(user.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openLoom(user.getBase());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
@ -13,11 +14,11 @@ public class Commandsmithingtable extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
ess.getContainerProvider().openSmithingTable(user.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openSmithingTable(user.getBase());
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class Commandspawner extends EssentialsCommand {
|
||||
final CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
|
||||
spawner.setSpawnedType(mob.getType());
|
||||
if (delay > 0) {
|
||||
final SpawnerBlockProvider spawnerBlockProvider = ess.getSpawnerBlockProvider();
|
||||
final SpawnerBlockProvider spawnerBlockProvider = ess.getProviders().get(SpawnerBlockProvider.class);
|
||||
spawnerBlockProvider.setMinSpawnDelay(spawner, 1);
|
||||
spawnerBlockProvider.setMaxSpawnDelay(spawner, Integer.MAX_VALUE);
|
||||
spawnerBlockProvider.setMinSpawnDelay(spawner, delay);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
@ -13,11 +14,11 @@ public class Commandstonecutter extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
ess.getContainerProvider().openStonecutter(user.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openStonecutter(user.getBase());
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ 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;
|
||||
@ -22,7 +23,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.getWorldInfoProvider().getMaxHeight(user.getWorld()), topZ, yaw, pitch);
|
||||
final Location unsafe = new Location(user.getWorld(), topX, ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(user.getWorld()), topZ, yaw, pitch);
|
||||
final Location safe = LocationUtil.getSafeDestination(ess, unsafe);
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
future.thenAccept(success -> {
|
||||
|
@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
@ -277,7 +278,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.getKnownCommandsProvider().getKnownCommands());
|
||||
final Map<String, Command> commandMap = Maps.newHashMap(this.ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands());
|
||||
final List<String> commands = Lists.newArrayListWithCapacity(commandMap.size());
|
||||
for (final Command command : commandMap.values()) {
|
||||
if (!(command instanceof PluginIdentifiableCommand)) {
|
||||
|
@ -8,6 +8,8 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -149,8 +151,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.getSpawnerItemProvider().setEntityType(stack, entity);
|
||||
ess.getPersistentDataProvider().set(stack, "convert", "true");
|
||||
ess.getProviders().get(SpawnerItemProvider.class).setEntityType(stack, entity);
|
||||
ess.getProviders().get(PersistentDataProvider.class).set(stack, "convert", "true");
|
||||
}
|
||||
|
||||
return stack;
|
||||
@ -208,7 +210,7 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
final PotionData potion = ((PotionMeta) item.getItemMeta()).getBasePotionData();
|
||||
return new ItemData(type, potion);
|
||||
} else if (type.toString().contains("SPAWNER")) {
|
||||
final EntityType entity = ess.getSpawnerItemProvider().getEntityType(item);
|
||||
final EntityType entity = ess.getProviders().get(SpawnerItemProvider.class).getEntityType(item);
|
||||
return new ItemData(type, entity);
|
||||
} else {
|
||||
return new ItemData(type);
|
||||
|
@ -6,6 +6,10 @@ import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
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;
|
||||
@ -188,8 +192,8 @@ public class LegacyItemDb extends AbstractItemDb {
|
||||
if (mat == MOB_SPAWNER) {
|
||||
if (metaData == 0) metaData = EntityType.PIG.getTypeId();
|
||||
try {
|
||||
retval = ess.getSpawnerItemProvider().setEntityType(retval, EntityType.fromId(metaData));
|
||||
ess.getPersistentDataProvider().set(retval, "convert", "true");
|
||||
retval = ess.getProviders().get(SpawnerItemProvider.class).setEntityType(retval, EntityType.fromId(metaData));
|
||||
ess.getProviders().get(PersistentDataProvider.class).set(retval, "convert", "true");
|
||||
} catch (final IllegalArgumentException e) {
|
||||
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
|
||||
}
|
||||
@ -200,10 +204,10 @@ public class LegacyItemDb extends AbstractItemDb {
|
||||
} catch (final IllegalArgumentException e) {
|
||||
throw new Exception("Can't spawn entity ID " + metaData + " from spawn eggs.");
|
||||
}
|
||||
retval = ess.getSpawnEggProvider().createEggItem(type);
|
||||
retval = ess.getProviders().get(SpawnEggProvider.class).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.getPotionMetaProvider().createPotionItem(mat, metaData);
|
||||
retval = ess.getProviders().get(PotionMetaProvider.class).createPotionItem(mat, metaData);
|
||||
} else {
|
||||
retval.setDurability(metaData);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import net.ess3.api.MaxMoneyException;
|
||||
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;
|
||||
@ -163,24 +164,24 @@ public class EssentialsSign {
|
||||
}
|
||||
|
||||
public void setOwnerData(final IEssentials ess, final User user, final ISign signProvider) {
|
||||
if (ess.getSignDataProvider() == null) {
|
||||
if (ess.getProviders().get(SignDataProvider.class) == null) {
|
||||
return;
|
||||
}
|
||||
final Sign sign = (Sign) signProvider.getBlock().getState();
|
||||
ess.getSignDataProvider().setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString());
|
||||
ess.getProviders().get(SignDataProvider.class).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 Sign sign = (Sign) signProvider.getBlock().getState();
|
||||
if (ess.getSignDataProvider() == null || ess.getSignDataProvider().getSignData(sign, SIGN_OWNER_KEY) == null) {
|
||||
if (ess.getProviders().get(SignDataProvider.class) == null || ess.getProviders().get(SignDataProvider.class).getSignData(sign, SIGN_OWNER_KEY) == null) {
|
||||
final boolean isLegacyOwner = FormatUtil.stripFormat(signProvider.getLine(nameIndex)).equalsIgnoreCase(getUsername(user));
|
||||
if (ess.getSignDataProvider() != null && isLegacyOwner) {
|
||||
ess.getSignDataProvider().setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString());
|
||||
if (ess.getProviders().get(SignDataProvider.class) != null && isLegacyOwner) {
|
||||
ess.getProviders().get(SignDataProvider.class).setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString());
|
||||
}
|
||||
return isLegacyOwner;
|
||||
}
|
||||
|
||||
if (user.getUUID().toString().equals(ess.getSignDataProvider().getSignData(sign, SIGN_OWNER_KEY))) {
|
||||
if (user.getUUID().toString().equals(ess.getProviders().get(SignDataProvider.class).getSignData(sign, SIGN_OWNER_KEY))) {
|
||||
signProvider.setLine(nameIndex, namePrefix + getUsername(user));
|
||||
return true;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
@ -12,7 +13,7 @@ public class SignAnvil extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
player.sendMessage(tl("unsupportedBrand"));
|
||||
return false;
|
||||
}
|
||||
@ -21,7 +22,7 @@ public class SignAnvil extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.getContainerProvider().openAnvil(player.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openAnvil(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
@ -12,7 +13,7 @@ public class SignCartography extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
player.sendMessage(tl("unsupportedBrand"));
|
||||
return false;
|
||||
}
|
||||
@ -21,7 +22,7 @@ public class SignCartography extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.getContainerProvider().openCartographyTable(player.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openCartographyTable(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,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.getMaterialTagProvider();
|
||||
final MaterialTagProvider tagProvider = ess.getProviders().get(MaterialTagProvider.class);
|
||||
try {
|
||||
stack = itemName.equals("*") || itemName.equalsIgnoreCase("any") || (tagProvider != null && tagProvider.tagExists(itemName)) ? null : getItemStack(sign.getLine(1), 1, ess);
|
||||
} catch (final SignException e) {
|
||||
@ -67,7 +67,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 = player.getBase().getItemInHand();
|
||||
final MaterialTagProvider tagProvider = ess.getMaterialTagProvider();
|
||||
final MaterialTagProvider tagProvider = ess.getProviders().get(MaterialTagProvider.class);
|
||||
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,6 +2,7 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
@ -12,7 +13,7 @@ public class SignGrindstone extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
player.sendMessage(tl("unsupportedBrand"));
|
||||
return false;
|
||||
}
|
||||
@ -21,7 +22,7 @@ public class SignGrindstone extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.getContainerProvider().openGrindstone(player.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openGrindstone(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
@ -12,7 +13,7 @@ public class SignLoom extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
player.sendMessage(tl("unsupportedBrand"));
|
||||
return false;
|
||||
}
|
||||
@ -21,7 +22,7 @@ public class SignLoom extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.getContainerProvider().openLoom(player.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openLoom(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
@ -12,7 +13,7 @@ public class SignSmithing extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
if (ess.getContainerProvider() == null) {
|
||||
if (ess.getProviders().get(ContainerProvider.class) == null) {
|
||||
player.sendMessage(tl("unsupportedBrand"));
|
||||
return false;
|
||||
}
|
||||
@ -21,7 +22,7 @@ public class SignSmithing extends EssentialsSign {
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
|
||||
ess.getContainerProvider().openSmithingTable(player.getBase());
|
||||
ess.getProviders().get(ContainerProvider.class).openSmithingTable(player.getBase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.User;
|
||||
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 +34,7 @@ public class HelpInput implements IText {
|
||||
}
|
||||
|
||||
final Multimap<Plugin, Command> pluginCommands = HashMultimap.create();
|
||||
for (final Command command : ess.getKnownCommandsProvider().getKnownCommands().values()) {
|
||||
for (final Command command : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().values()) {
|
||||
if (!(command instanceof PluginIdentifiableCommand)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ 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;
|
||||
@ -60,7 +61,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.getFormattedCommandAliasProvider().getFormatStrings((FormattedCommandAlias) value)) {
|
||||
for (final String entry : ess.getProviders().get(FormattedCommandAliasProvider.class).getFormatStrings((FormattedCommandAlias) value)) {
|
||||
formatStrings.add(new JsonPrimitive(entry));
|
||||
}
|
||||
json.add("bukkit_aliases", formatStrings);
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.utils;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -109,7 +110,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.getWorldInfoProvider().getMaxHeight(world) || HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType());
|
||||
return y > ess.getProviders().get(WorldInfoProvider.class).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) {
|
||||
@ -215,9 +216,9 @@ public final class LocationUtil {
|
||||
throw new Exception(tl("destinationNotSet"));
|
||||
}
|
||||
final World world = loc.getWorld();
|
||||
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);
|
||||
final int worldMinY = ess.getProviders().get(WorldInfoProvider.class).getMinHeight(world);
|
||||
final int worldLogicalY = ess.getProviders().get(WorldInfoProvider.class).getLogicalHeight(world);
|
||||
final int worldMaxY = loc.getBlockY() < worldLogicalY ? worldLogicalY : ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(world);
|
||||
int x = loc.getBlockX();
|
||||
int y = (int) Math.round(loc.getY());
|
||||
int z = loc.getBlockZ();
|
||||
@ -280,7 +281,7 @@ public final class LocationUtil {
|
||||
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 >= ess.getWorldInfoProvider().getMinHeight(world)) {
|
||||
while (LocationUtil.isBlockUnsafe(ess, world, x, y, z) && y >= ess.getProviders().get(WorldInfoProvider.class).getMinHeight(world)) {
|
||||
y--;
|
||||
count++;
|
||||
if (count > 2) {
|
||||
@ -289,7 +290,7 @@ public final class LocationUtil {
|
||||
}
|
||||
|
||||
// If not then check if player is in the void
|
||||
return y < ess.getWorldInfoProvider().getMinHeight(world);
|
||||
return y < ess.getProviders().get(WorldInfoProvider.class).getMinHeight(world);
|
||||
}
|
||||
|
||||
public static class Vector3D {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package net.ess3.api;
|
||||
|
||||
import com.earth2me.essentials.items.CustomItemResolver;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import net.ess3.provider.SpawnEggProvider;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -19,20 +17,6 @@ public interface IEssentials extends com.earth2me.essentials.IEssentials {
|
||||
*/
|
||||
Collection<String> getVanishedPlayersNew();
|
||||
|
||||
/**
|
||||
* Get the spawn egg provider for the current platform.
|
||||
*
|
||||
* @return The current active spawn egg provider
|
||||
*/
|
||||
SpawnEggProvider getSpawnEggProvider();
|
||||
|
||||
/**
|
||||
* Get the potion meta provider for the current platform.
|
||||
*
|
||||
* @return The current active potion meta provider
|
||||
*/
|
||||
PotionMetaProvider getPotionMetaProvider();
|
||||
|
||||
/**
|
||||
* Get the {@link CustomItemResolver} that is currently in use.
|
||||
*
|
||||
|
@ -1,16 +1,13 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@ProviderData(description = "Legacy Item Unbreakable Provider")
|
||||
public class LegacyItemUnbreakableProvider implements ItemUnbreakableProvider {
|
||||
@Override
|
||||
public void setUnbreakable(ItemMeta meta, boolean unbreakable) {
|
||||
meta.spigot().setUnbreakable(unbreakable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Legacy ItemMeta Unbreakable Provider";
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package net.ess3.provider;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public interface MaterialTagProvider {
|
||||
public interface MaterialTagProvider extends Provider {
|
||||
boolean tagExists(String tagName);
|
||||
|
||||
boolean isTagged(String tagName, Material material);
|
||||
|
@ -0,0 +1,5 @@
|
||||
package net.ess3.provider;
|
||||
|
||||
public interface OnlineModeProvider extends Provider {
|
||||
String getOnlineModeString();
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
package net.ess3.provider;
|
||||
|
||||
public interface Provider {
|
||||
String getDescription();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package net.ess3.provider.providers;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
@ -10,6 +12,7 @@ import org.bukkit.potion.PotionType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ProviderData(description = "1.9+ Potion Meta Provider", weight = 1)
|
||||
public class BasePotionDataProvider implements PotionMetaProvider {
|
||||
private static final Map<Integer, PotionType> damageValueToType = ImmutableMap.<Integer, PotionType>builder()
|
||||
.put(1, PotionType.REGEN)
|
||||
@ -64,8 +67,13 @@ public class BasePotionDataProvider implements PotionMetaProvider {
|
||||
return potion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.9+ Potion Meta Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
Class.forName("org.bukkit.potion.PotionData");
|
||||
return true;
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
|
||||
@ProviderData(description = "1.8.3+ Spawner Item Provider")
|
||||
public class BlockMetaSpawnerItemProvider implements SpawnerItemProvider {
|
||||
@Override
|
||||
public ItemStack setEntityType(final ItemStack is, final EntityType type) throws IllegalArgumentException {
|
||||
@ -24,9 +26,4 @@ public class BlockMetaSpawnerItemProvider implements SpawnerItemProvider {
|
||||
final CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
|
||||
return bs.getSpawnedType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.8.3+ Spawner Provider";
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,4 @@ public class BukkitCommandSendListenerProvider extends CommandSendListenerProvid
|
||||
final Predicate<String> filter = filter(event.getPlayer());
|
||||
event.getCommands().removeIf(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Bukkit synchronous command send listener";
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.MaterialTagProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
|
||||
@ -8,6 +10,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ProviderData(description = "Bukkit Material Tag Provider")
|
||||
public class BukkitMaterialTagProvider implements MaterialTagProvider {
|
||||
private final Map<String, Tag<Material>> stringToTagMap = new HashMap<>();
|
||||
|
||||
@ -46,4 +49,14 @@ public class BukkitMaterialTagProvider implements MaterialTagProvider {
|
||||
}
|
||||
return stringToTagMap.get(tagName);
|
||||
}
|
||||
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
Class.forName("org.bukkit.Tag");
|
||||
return true;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.SpawnerBlockProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
@ProviderData(description = "1.12+ Spawner Block Provider", weight = 1)
|
||||
public class BukkitSpawnerBlockProvider implements SpawnerBlockProvider {
|
||||
@Override
|
||||
public void setMaxSpawnDelay(final CreatureSpawner spawner, final int delay) {
|
||||
@ -14,8 +17,13 @@ public class BukkitSpawnerBlockProvider implements SpawnerBlockProvider {
|
||||
spawner.setMinSpawnDelay(delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Bukkit 1.12+ provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
CreatureSpawner.class.getDeclaredMethod("setMaxSpawnDelay", int.class);
|
||||
return true;
|
||||
} catch (final NoSuchMethodException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.World;
|
||||
|
||||
@ProviderData(description = "Fixed Height World Info Provider")
|
||||
public class FixedHeightWorldInfoProvider implements WorldInfoProvider {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Fixed world info provider for pre-1.16";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight(World world) {
|
||||
// Method has existed since Beta 1.7 (yes, *beta*)
|
||||
|
@ -1,10 +1,13 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.SpawnEggProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ProviderData(description = "1.13+ Spawn Egg Provider", weight = 2)
|
||||
public class FlatSpawnEggProvider implements SpawnEggProvider {
|
||||
@Override
|
||||
public ItemStack createEggItem(final EntityType type) throws IllegalArgumentException {
|
||||
@ -21,8 +24,14 @@ public class FlatSpawnEggProvider implements SpawnEggProvider {
|
||||
throw new IllegalArgumentException("Not a spawn egg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.13+ Flattening Spawn Egg Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
//noinspection unused
|
||||
final Material yourMother = Material.COW_SPAWN_EGG;
|
||||
return true;
|
||||
} catch (final Throwable ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ProviderData(description = "1.8 Potion Meta Provider")
|
||||
public class LegacyPotionMetaProvider implements PotionMetaProvider {
|
||||
@Override
|
||||
public ItemStack createPotionItem(final Material initial, final int effectId) {
|
||||
@ -12,9 +14,4 @@ public class LegacyPotionMetaProvider implements PotionMetaProvider {
|
||||
potion.setDurability((short) effectId);
|
||||
return potion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Legacy 1.8 Potion Meta Provider";
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.SpawnEggProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.SpawnEgg;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ProviderData(description = "1.8 Spawn Egg Provider")
|
||||
public class LegacySpawnEggProvider implements SpawnEggProvider {
|
||||
@Override
|
||||
public ItemStack createEggItem(final EntityType type) throws IllegalArgumentException {
|
||||
@ -21,9 +23,4 @@ public class LegacySpawnEggProvider implements SpawnEggProvider {
|
||||
}
|
||||
throw new IllegalArgumentException("Item is missing data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Legacy 1.8 Spawn Egg Provider";
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.World;
|
||||
|
||||
@ProviderData(description = "1.17.1+ World Info Provider", weight = 2)
|
||||
public class ModernDataWorldInfoProvider implements WorldInfoProvider {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "API world info provider for data-driven worldgen for 1.17.1+";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight(World world) {
|
||||
return world.getMaxHeight();
|
||||
@ -23,4 +21,14 @@ public class ModernDataWorldInfoProvider implements WorldInfoProvider {
|
||||
public int getMinHeight(World world) {
|
||||
return world.getMinHeight();
|
||||
}
|
||||
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
Class.forName("org.bukkit.generator.WorldInfo");
|
||||
return true;
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,24 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@ProviderData(description = "1.11+ Item Unbreakable Provider", weight = 1)
|
||||
public class ModernItemUnbreakableProvider implements ItemUnbreakableProvider {
|
||||
@Override
|
||||
public void setUnbreakable(ItemMeta meta, boolean unbreakable) {
|
||||
meta.setUnbreakable(unbreakable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.11+ ItemMeta Unbreakable Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
ItemMeta.class.getDeclaredMethod("setUnbreakable", boolean.class);
|
||||
return true;
|
||||
} catch (final NoSuchMethodException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -8,6 +10,7 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@ProviderData(description = "1.14.4+ Persistent Data Container Provider", weight = 1)
|
||||
public class ModernPersistentDataProvider implements PersistentDataProvider {
|
||||
private final Plugin plugin;
|
||||
|
||||
@ -44,8 +47,13 @@ public class ModernPersistentDataProvider implements PersistentDataProvider {
|
||||
itemStack.getItemMeta().getPersistentDataContainer().remove(new NamespacedKey(plugin, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.14+ Persistent Data Container Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
Class.forName("org.bukkit.persistence.PersistentDataHolder");
|
||||
return true;
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.SignDataProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@ProviderData(description = "1.14+ Sign Data Provider")
|
||||
public class ModernSignDataProvider implements SignDataProvider {
|
||||
private final Plugin plugin;
|
||||
|
||||
@ -36,8 +39,13 @@ public class ModernSignDataProvider implements SignDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.14+ Persistent Data Sign Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
Class.forName("org.bukkit.block.TileState");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package net.essentialsx.providers;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface ProviderData {
|
||||
String description();
|
||||
|
||||
int weight() default 0;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package net.essentialsx.providers;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface ProviderTest {
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.World;
|
||||
|
||||
@ProviderData(description = "Reflection World Info Provider", weight = 1)
|
||||
public class ReflDataWorldInfoProvider implements WorldInfoProvider {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NMS world info provider for data-driven worldgen for 1.16.x";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight(World world) {
|
||||
// Method has existed since Beta 1.7 (yes, *beta*)
|
||||
@ -28,4 +26,10 @@ public class ReflDataWorldInfoProvider implements WorldInfoProvider {
|
||||
// Worlds could not go below 0 until Minecraft 1.16
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
// troll face
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.FormattedCommandAlias;
|
||||
|
||||
@ -12,13 +13,14 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ProviderData(description = "Reflection Formatted Command Alias Provider")
|
||||
public class ReflFormattedCommandAliasProvider implements FormattedCommandAliasProvider {
|
||||
|
||||
private final boolean paper;
|
||||
private final Field formatStringsField;
|
||||
private final MethodHandle buildCommandMethodHandle;
|
||||
|
||||
public ReflFormattedCommandAliasProvider(boolean paper) {
|
||||
public ReflFormattedCommandAliasProvider(final boolean paper) {
|
||||
this.paper = paper;
|
||||
|
||||
final Class<? extends FormattedCommandAlias> formattedCommandAliasClass;
|
||||
@ -85,8 +87,4 @@ public class ReflFormattedCommandAliasProvider implements FormattedCommandAliasP
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NMS Reflection Provider for FormattedCommandAlias methods";
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
@ -11,6 +12,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ProviderData(description = "Reflection Known Commands Provider")
|
||||
public class ReflKnownCommandsProvider implements KnownCommandsProvider {
|
||||
private final Map<String, Command> knownCommands;
|
||||
|
||||
@ -25,6 +27,7 @@ public class ReflKnownCommandsProvider implements KnownCommandsProvider {
|
||||
final SimpleCommandMap simpleCommandMap = (SimpleCommandMap) commandMapField.get(Bukkit.getServer());
|
||||
final Field knownCommandsField = ReflUtil.getFieldCached(SimpleCommandMap.class, "knownCommands");
|
||||
if (knownCommandsField != null) {
|
||||
//noinspection unchecked
|
||||
knownCommands = (Map<String, Command>) knownCommandsField.get(simpleCommandMap);
|
||||
}
|
||||
}
|
||||
@ -40,9 +43,4 @@ public class ReflKnownCommandsProvider implements KnownCommandsProvider {
|
||||
public Map<String, Command> getKnownCommands() {
|
||||
return this.knownCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NMS Reflection Known Commands Provider";
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import net.ess3.provider.OnlineModeProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
||||
public class ReflOnlineModeProvider {
|
||||
@ProviderData(description = "Reflection Online Mode Provider")
|
||||
public class ReflOnlineModeProvider implements OnlineModeProvider {
|
||||
private final MethodHandle spigotBungeeGetter;
|
||||
private final MethodHandle paperBungeeGetter;
|
||||
private final Object paperProxiesInstance;
|
||||
@ -42,6 +45,7 @@ public class ReflOnlineModeProvider {
|
||||
this.fancyPaperCheck = fancyCheck;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOnlineModeString() {
|
||||
if (spigotBungeeGetter == null) {
|
||||
return Bukkit.getOnlineMode() ? "Online Mode" : "Offline Mode";
|
||||
@ -53,7 +57,7 @@ public class ReflOnlineModeProvider {
|
||||
}
|
||||
|
||||
if (fancyPaperCheck) {
|
||||
if ((boolean) paperBungeeGetter.invoke()) {
|
||||
if ((boolean) (paperProxiesInstance != null ? paperBungeeGetter.invoke(paperProxiesInstance) : paperBungeeGetter.invoke())) {
|
||||
// Could be Velocity or Bungee, so do not specify.
|
||||
return "Proxy Mode";
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@ -15,6 +16,7 @@ import java.util.Locale;
|
||||
* Stores persistent data on 1.8-1.13 in a manner that's consistent with PDC on 1.14+ to enable
|
||||
* seamless upgrades.
|
||||
*/
|
||||
@ProviderData(description = "Reflection Persistent Data Container Provider")
|
||||
public class ReflPersistentDataProvider implements PersistentDataProvider {
|
||||
private static final String PDC_ROOT_TAG = "PublicBukkitValues";
|
||||
private static final String ROOT_TAG = "tag";
|
||||
@ -123,9 +125,4 @@ public class ReflPersistentDataProvider implements PersistentDataProvider {
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.13 >= Persistent Data Container Provider";
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,13 @@ package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import net.ess3.provider.ServerStateProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
||||
@ProviderData(description = "Reflection Server State Provider")
|
||||
public class ReflServerStateProvider implements ServerStateProvider {
|
||||
private final Object nmsServer;
|
||||
private final MethodHandle nmsIsRunning;
|
||||
@ -48,9 +50,4 @@ public class ReflServerStateProvider implements ServerStateProvider {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NMS Reflection Server State Provider";
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,11 @@ package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.nms.refl.SpawnEggRefl;
|
||||
import net.ess3.provider.SpawnEggProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ProviderData(description = "1.9-1.12.2 Spawn Egg Provider", weight = 1)
|
||||
public class ReflSpawnEggProvider implements SpawnEggProvider {
|
||||
|
||||
@Override
|
||||
@ -24,9 +26,4 @@ public class ReflSpawnEggProvider implements SpawnEggProvider {
|
||||
throw new IllegalArgumentException(e.getMessage(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NMS Reflection Provider";
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,14 @@ package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import net.ess3.provider.SpawnerBlockProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@ProviderData(description = "Reflection Spawner Block Provider")
|
||||
public class ReflSpawnerBlockProvider implements SpawnerBlockProvider {
|
||||
@Override
|
||||
public void setMaxSpawnDelay(final CreatureSpawner spawner, final int delay) {
|
||||
@ -33,11 +35,6 @@ public class ReflSpawnerBlockProvider implements SpawnerBlockProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Reflection based provider";
|
||||
}
|
||||
|
||||
private Object getNMSSpawner(final CreatureSpawner spawner) {
|
||||
try {
|
||||
final Class<?> craftWorld = ReflUtil.getOBCClass("CraftWorld");
|
||||
|
@ -2,12 +2,14 @@ package net.ess3.nms.refl.providers;
|
||||
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import net.ess3.provider.SyncCommandsProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
||||
@ProviderData(description = "Reflection Sync Commands Provider")
|
||||
public class ReflSyncCommandsProvider implements SyncCommandsProvider {
|
||||
private final MethodHandle nmsSyncCommands;
|
||||
|
||||
@ -22,11 +24,6 @@ public class ReflSyncCommandsProvider implements SyncCommandsProvider {
|
||||
nmsSyncCommands = syncCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NMS Reflection Sync Commands Provider";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncCommands() {
|
||||
if (nmsSyncCommands != null) {
|
||||
|
@ -27,9 +27,4 @@ public class PaperCommandSendListenerProvider extends CommandSendListenerProvide
|
||||
|
||||
children.removeIf(node -> filter.test(node.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Paper async Brigadier command send listener";
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
|
||||
@ProviderData(description = "Paper Container Provider")
|
||||
public class PaperContainerProvider implements ContainerProvider {
|
||||
|
||||
@Override
|
||||
@ -36,9 +41,13 @@ public class PaperContainerProvider implements ContainerProvider {
|
||||
return player.openStonecutter(null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Paper Container Opening Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
HumanEntity.class.getDeclaredMethod("openCartographyTable", Location.class, boolean.class);
|
||||
return true;
|
||||
} catch (final NoSuchMethodException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,19 +1,29 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ProviderData(description = "Paper Known Commands Provider", weight = 1)
|
||||
public class PaperKnownCommandsProvider implements KnownCommandsProvider {
|
||||
@Override
|
||||
public Map<String, Command> getKnownCommands() {
|
||||
return Bukkit.getCommandMap().getKnownCommands();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Paper Known Commands Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
Bukkit.class.getDeclaredMethod("getCommandMap");
|
||||
CommandMap.class.getDeclaredMethod("getKnownCommands");
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package net.ess3.provider.providers;
|
||||
import com.destroystokyo.paper.MaterialSetTag;
|
||||
import com.destroystokyo.paper.MaterialTags;
|
||||
import net.ess3.provider.MaterialTagProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
|
||||
@ -10,6 +12,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ProviderData(description = "Paper Material Tag Provider", weight = 1)
|
||||
public class PaperMaterialTagProvider implements MaterialTagProvider {
|
||||
private final Map<String, Tag<Material>> bukkitTagMap = new HashMap<>();
|
||||
private final Map<String, MaterialSetTag> paperTagMap = new HashMap<>();
|
||||
@ -73,4 +76,15 @@ public class PaperMaterialTagProvider implements MaterialTagProvider {
|
||||
}
|
||||
return bukkitTagMap.get(tagName);
|
||||
}
|
||||
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
Class.forName("org.bukkit.Tag");
|
||||
Class.forName("com.destroystokyo.paper.MaterialTags");
|
||||
return true;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,4 @@ public class PaperRecipeBookListener extends ProviderListener {
|
||||
public void onPlayerRecipeBookClick(final PlayerRecipeBookClickEvent event) {
|
||||
function.accept(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Paper Player Recipe Book Click Event Provider";
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ProviderData(description = "Paper Serialization Provider")
|
||||
public class PaperSerializationProvider implements SerializationProvider {
|
||||
|
||||
@Override
|
||||
@ -15,8 +18,13 @@ public class PaperSerializationProvider implements SerializationProvider {
|
||||
return ItemStack.deserializeBytes(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Paper Serialization Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
ItemStack.class.getDeclaredMethod("serializeAsBytes");
|
||||
return true;
|
||||
} catch (final NoSuchMethodException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,24 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.ServerStateProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ProviderData(description = "Paper Server State Provider", weight = 1)
|
||||
public class PaperServerStateProvider implements ServerStateProvider {
|
||||
@Override
|
||||
public boolean isStopping() {
|
||||
return Bukkit.isStopping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Paper Server State Provider";
|
||||
@ProviderTest
|
||||
public static boolean test() {
|
||||
try {
|
||||
Bukkit.class.getDeclaredMethod("isStopping");
|
||||
return true;
|
||||
} catch (final NoSuchMethodException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user