inline some usages

This commit is contained in:
Josh Roy 2023-12-26 10:59:46 -05:00
parent 7f417ef09b
commit 0360db3a0f
No known key found for this signature in database
GPG Key ID: 86A69D08540BC29A
34 changed files with 109 additions and 78 deletions

View File

@ -67,7 +67,7 @@ public class AlternativeCommandsHandler {
private Map<String, Command> getPluginCommands(Plugin plugin) { private Map<String, Command> getPluginCommands(Plugin plugin) {
final Map<String, Command> commands = new HashMap<>(); final Map<String, Command> commands = new HashMap<>();
for (final Map.Entry<String, Command> entry : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().entrySet()) { for (final Map.Entry<String, Command> entry : ess.provider(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
if (entry.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) entry.getValue()).getPlugin().equals(plugin)) { if (entry.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) entry.getValue()).getPlugin().equals(plugin)) {
commands.put(entry.getKey(), entry.getValue()); commands.put(entry.getKey(), entry.getValue());
} }

View File

@ -506,7 +506,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
@Override @Override
public void onDisable() { public void onDisable() {
final boolean stopping = getProviders().get(ServerStateProvider.class).isStopping(); final boolean stopping = provider(ServerStateProvider.class).isStopping();
if (!stopping) { if (!stopping) {
LOGGER.log(Level.SEVERE, tl("serverReloading")); LOGGER.log(Level.SEVERE, tl("serverReloading"));
} }
@ -619,8 +619,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
// Check for disabled commands // Check for disabled commands
if (getSettings().isCommandDisabled(commandLabel)) { if (getSettings().isCommandDisabled(commandLabel)) {
if (getProviders().get(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) { if (provider(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) {
final Command newCmd = getProviders().get(KnownCommandsProvider.class).getKnownCommands().get(commandLabel); final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
if (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this) { if (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this) {
return newCmd.tabComplete(cSender, commandLabel, args); return newCmd.tabComplete(cSender, commandLabel, args);
} }
@ -725,8 +725,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
// Check for disabled commands // Check for disabled commands
if (getSettings().isCommandDisabled(commandLabel)) { if (getSettings().isCommandDisabled(commandLabel)) {
if (getProviders().get(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) { if (provider(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) {
final Command newCmd = getProviders().get(KnownCommandsProvider.class).getKnownCommands().get(commandLabel); final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
if (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin())) { if (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin())) {
return newCmd.execute(cSender, commandLabel, args); return newCmd.execute(cSender, commandLabel, args);
} }

View File

@ -28,11 +28,11 @@ public class EssentialsBlockListener implements Listener {
public void onBlockPlace(final BlockPlaceEvent event) { public void onBlockPlace(final BlockPlaceEvent event) {
final ItemStack is = event.getItemInHand(); final ItemStack is = event.getItemInHand();
if (is.getType() == MaterialUtil.SPAWNER && ess.getProviders().get(PersistentDataProvider.class).getString(is, "convert") != null) { if (is.getType() == MaterialUtil.SPAWNER && ess.provider(PersistentDataProvider.class).getString(is, "convert") != null) {
final BlockState blockState = event.getBlockPlaced().getState(); final BlockState blockState = event.getBlockPlaced().getState();
if (blockState instanceof CreatureSpawner) { if (blockState instanceof CreatureSpawner) {
final CreatureSpawner spawner = (CreatureSpawner) blockState; final CreatureSpawner spawner = (CreatureSpawner) blockState;
final EntityType type = ess.getProviders().get(SpawnerItemProvider.class).getEntityType(event.getItemInHand()); final EntityType type = ess.provider(SpawnerItemProvider.class).getEntityType(event.getItemInHand());
if (type != null && Mob.fromBukkitType(type) != null) { if (type != null && Mob.fromBukkitType(type) != null) {
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) { if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) {
spawner.setSpawnedType(type); spawner.setSpawnedType(type);

View File

@ -607,10 +607,10 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
// If the plugin command does not exist, check if it is an alias from commands.yml // If the plugin command does not exist, check if it is an alias from commands.yml
if (ess.getServer().getPluginCommand(cmd) == null) { if (ess.getServer().getPluginCommand(cmd) == null) {
final Command knownCommand = ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().get(cmd); final Command knownCommand = ess.provider(KnownCommandsProvider.class).getKnownCommands().get(cmd);
if (knownCommand instanceof FormattedCommandAlias) { if (knownCommand instanceof FormattedCommandAlias) {
final FormattedCommandAlias command = (FormattedCommandAlias) knownCommand; final FormattedCommandAlias command = (FormattedCommandAlias) knownCommand;
for (String fullCommand : ess.getProviders().get(FormattedCommandAliasProvider.class).createCommands(command, event.getPlayer(), args.split(" "))) { for (String fullCommand : ess.provider(FormattedCommandAliasProvider.class).createCommands(command, event.getPlayer(), args.split(" "))) {
handlePlayerCommandPreprocess(event, fullCommand); handlePlayerCommandPreprocess(event, fullCommand);
} }
return; return;

View File

@ -8,6 +8,7 @@ import com.earth2me.essentials.commands.PlayerNotFoundException;
import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.perm.PermissionsHandler;
import com.earth2me.essentials.updatecheck.UpdateChecker; import com.earth2me.essentials.updatecheck.UpdateChecker;
import com.earth2me.essentials.userstorage.IUserMap; import com.earth2me.essentials.userstorage.IUserMap;
import net.ess3.provider.Provider;
import net.essentialsx.api.v2.services.BalanceTop; import net.essentialsx.api.v2.services.BalanceTop;
import net.essentialsx.api.v2.services.mail.MailService; import net.essentialsx.api.v2.services.mail.MailService;
import org.bukkit.Server; import org.bukkit.Server;
@ -131,4 +132,8 @@ public interface IEssentials extends Plugin {
PluginCommand getPluginCommand(String cmd); PluginCommand getPluginCommand(String cmd);
ProviderFactory getProviders(); ProviderFactory getProviders();
default <P extends Provider> P provider(final Class<P> providerClass) {
return getProviders().get(providerClass);
}
} }

View File

@ -190,13 +190,14 @@ public class Kit {
} }
final ItemStack stack; final ItemStack stack;
final SerializationProvider serializationProvider = ess.provider(SerializationProvider.class);
if (kitItem.startsWith("@")) { if (kitItem.startsWith("@")) {
if (ess.getProviders().get(SerializationProvider.class) == null) { if (serializationProvider == null) {
ess.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName())); ess.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName()));
continue; continue;
} }
stack = ess.getProviders().get(SerializationProvider.class).deserializeItem(Base64Coder.decodeLines(kitItem.substring(1))); stack = serializationProvider.deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
} else { } else {
final String[] parts = kitItem.split(" +"); final String[] parts = kitItem.split(" +");
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1); final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);

View File

@ -702,7 +702,7 @@ public class MetaItemStack {
private void setUnbreakable(final IEssentials ess, final ItemStack is, final boolean unbreakable) { private void setUnbreakable(final IEssentials ess, final ItemStack is, final boolean unbreakable) {
final ItemMeta meta = is.getItemMeta(); final ItemMeta meta = is.getItemMeta();
ess.getProviders().get(ItemUnbreakableProvider.class).setUnbreakable(meta, unbreakable); ess.provider(ItemUnbreakableProvider.class).setUnbreakable(meta, unbreakable);
is.setItemMeta(meta); is.setItemMeta(meta);
} }
} }

View File

@ -26,16 +26,17 @@ public class RandomTeleport implements IConf {
private final IEssentials ess; private final IEssentials ess;
private final EssentialsConfiguration config; private final EssentialsConfiguration config;
private final ConcurrentLinkedQueue<Location> cachedLocations = new ConcurrentLinkedQueue<>(); private final ConcurrentLinkedQueue<Location> cachedLocations = new ConcurrentLinkedQueue<>();
private WorldInfoProvider worldInfoProvider;
public RandomTeleport(final IEssentials essentials) { public RandomTeleport(final IEssentials essentials) {
this.ess = essentials; this.ess = essentials;
config = new EssentialsConfiguration(new File(essentials.getDataFolder(), "tpr.yml"), "/tpr.yml", config = new EssentialsConfiguration(new File(essentials.getDataFolder(), "tpr.yml"), "/tpr.yml",
"Configuration for the random teleport command.\nSome settings may be defaulted, and can be changed via the /settpr command in-game."); "Configuration for the random teleport command.\nSome settings may be defaulted, and can be changed via the /settpr command in-game.");
reloadConfig();
} }
@Override @Override
public void reloadConfig() { public void reloadConfig() {
worldInfoProvider = ess.provider(WorldInfoProvider.class);
config.load(); config.load();
cachedLocations.clear(); cachedLocations.clear();
} }
@ -178,7 +179,7 @@ public class RandomTeleport implements IConf {
final Location location = new Location( final Location location = new Location(
center.getWorld(), center.getWorld(),
center.getX() + offsetX, center.getX() + offsetX,
ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(center.getWorld()), worldInfoProvider.getMaxHeight(center.getWorld()),
center.getZ() + offsetZ, center.getZ() + offsetZ,
360 * RANDOM.nextFloat() - 180, 360 * RANDOM.nextFloat() - 180,
0 0
@ -196,7 +197,7 @@ public class RandomTeleport implements IConf {
// Returns an appropriate elevation for a given location in the nether, or -1 if none is found // Returns an appropriate elevation for a given location in the nether, or -1 if none is found
private double getNetherYAt(final Location location) { private double getNetherYAt(final Location location) {
for (int y = 32; y < ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(location.getWorld()); ++y) { for (int y = 32; y < worldInfoProvider.getMaxHeight(location.getWorld()); ++y) {
if (!LocationUtil.isBlockUnsafe(ess, location.getWorld(), location.getBlockX(), y, location.getBlockZ())) { if (!LocationUtil.isBlockUnsafe(ess, location.getWorld(), location.getBlockX(), y, location.getBlockZ())) {
return y; return y;
} }
@ -205,7 +206,7 @@ public class RandomTeleport implements IConf {
} }
private boolean isValidRandomLocation(final Location location) { private boolean isValidRandomLocation(final Location location) {
return location.getBlockY() > ess.getProviders().get(WorldInfoProvider.class).getMinHeight(location.getWorld()) && !this.getExcludedBiomes().contains(location.getBlock().getBiome()); return location.getBlockY() > worldInfoProvider.getMinHeight(location.getWorld()) && !this.getExcludedBiomes().contains(location.getBlock().getBiome());
} }
public File getFile() { public File getFile() {

View File

@ -315,9 +315,11 @@ public class Settings implements net.ess3.api.ISettings {
} }
private void _addAlternativeCommand(final String label, final Command current) { private void _addAlternativeCommand(final String label, final Command current) {
final KnownCommandsProvider knownCommandsProvider = ess.provider(KnownCommandsProvider.class);
Command cmd = ess.getAlternativeCommandsHandler().getAlternative(label); Command cmd = ess.getAlternativeCommandsHandler().getAlternative(label);
if (cmd == null) { if (cmd == null) {
for (final Map.Entry<String, Command> entry : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().entrySet()) { for (final Map.Entry<String, Command> entry : knownCommandsProvider.getKnownCommands().entrySet()) {
final String[] split = entry.getKey().split(":"); final String[] split = entry.getKey().split(":");
if (entry.getValue() != current && split[split.length - 1].equals(label)) { if (entry.getValue() != current && split[split.length - 1].equals(label)) {
cmd = entry.getValue(); cmd = entry.getValue();
@ -327,7 +329,7 @@ public class Settings implements net.ess3.api.ISettings {
} }
if (cmd != null) { if (cmd != null) {
ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().put(label, cmd); knownCommandsProvider.getKnownCommands().put(label, cmd);
} }
} }
@ -681,14 +683,16 @@ public class Settings implements net.ess3.api.ISettings {
overriddenCommands = _getOverriddenCommands(); overriddenCommands = _getOverriddenCommands();
playerCommands = _getPlayerCommands(); playerCommands = _getPlayerCommands();
final KnownCommandsProvider knownCommandsProvider = ess.provider(KnownCommandsProvider.class);
// This will be late loaded // This will be late loaded
if (ess.getProviders().get(KnownCommandsProvider.class) != null) { if (knownCommandsProvider != null) {
boolean mapModified = false; boolean mapModified = false;
if (!disabledBukkitCommands.isEmpty()) { if (!disabledBukkitCommands.isEmpty()) {
if (isDebug()) { if (isDebug()) {
ess.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!"); ess.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!");
} }
ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().putAll(disabledBukkitCommands); knownCommandsProvider.getKnownCommands().putAll(disabledBukkitCommands);
disabledBukkitCommands.clear(); disabledBukkitCommands.clear();
mapModified = true; mapModified = true;
} }
@ -700,7 +704,7 @@ public class Settings implements net.ess3.api.ISettings {
if (isDebug()) { if (isDebug()) {
ess.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias); ess.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias);
} }
final Command removed = ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().remove(effectiveAlias); final Command removed = knownCommandsProvider.getKnownCommands().remove(effectiveAlias);
if (removed != null) { if (removed != null) {
if (isDebug()) { if (isDebug()) {
ess.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!"); ess.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!");
@ -718,14 +722,16 @@ public class Settings implements net.ess3.api.ISettings {
} }
} }
final SyncCommandsProvider syncCommandsProvider = ess.provider(SyncCommandsProvider.class);
if (mapModified) { if (mapModified) {
if (isDebug()) { if (isDebug()) {
ess.getLogger().log(Level.INFO, "Syncing commands"); ess.getLogger().log(Level.INFO, "Syncing commands");
} }
if (reloadCount.get() < 2) { if (reloadCount.get() < 2) {
ess.scheduleSyncDelayedTask(() -> ess.getProviders().get(SyncCommandsProvider.class).syncCommands()); ess.scheduleSyncDelayedTask(syncCommandsProvider::syncCommands);
} else { } else {
ess.getProviders().get(SyncCommandsProvider.class).syncCommands(); syncCommandsProvider.syncCommands();
} }
} }
} }

View File

@ -14,11 +14,13 @@ public class Commandanvil extends EssentialsCommand {
@Override @Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
if (ess.getProviders().get(ContainerProvider.class) == null) { final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
if (containerProvider == null) {
user.sendMessage(tl("unsupportedBrand")); user.sendMessage(tl("unsupportedBrand"));
return; return;
} }
ess.getProviders().get(ContainerProvider.class).openAnvil(user.getBase()); containerProvider.openAnvil(user.getBase());
} }
} }

View File

@ -24,7 +24,7 @@ public class Commandbottom extends EssentialsCommand {
final int bottomZ = user.getLocation().getBlockZ(); final int bottomZ = user.getLocation().getBlockZ();
final float pitch = user.getLocation().getPitch(); final float pitch = user.getLocation().getPitch();
final float yaw = user.getLocation().getYaw(); final float yaw = user.getLocation().getYaw();
final Location unsafe = new Location(user.getWorld(), bottomX, ess.getProviders().get(WorldInfoProvider.class).getMinHeight(user.getWorld()), bottomZ, yaw, pitch); final Location unsafe = new Location(user.getWorld(), bottomX, ess.provider(WorldInfoProvider.class).getMinHeight(user.getWorld()), bottomZ, yaw, pitch);
final Location safe = LocationUtil.getSafeDestination(ess, unsafe); final Location safe = LocationUtil.getSafeDestination(ess, unsafe);
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel); final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
future.thenAccept(success -> { future.thenAccept(success -> {

View File

@ -14,11 +14,13 @@ public class Commandcartographytable extends EssentialsCommand {
@Override @Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (ess.getProviders().get(ContainerProvider.class) == null) { final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
if (containerProvider == null) {
user.sendMessage(tl("unsupportedBrand")); user.sendMessage(tl("unsupportedBrand"));
return; return;
} }
ess.getProviders().get(ContainerProvider.class).openCartographyTable(user.getBase()); containerProvider.openCartographyTable(user.getBase());
} }
} }

View File

@ -42,9 +42,10 @@ public class Commandcreatekit extends EssentialsCommand {
final ItemStack[] items = Inventories.getInventory(user.getBase(), true); final ItemStack[] items = Inventories.getInventory(user.getBase(), true);
final List<String> list = new ArrayList<>(); final List<String> list = new ArrayList<>();
final SerializationProvider serializationProvider = ess.provider(SerializationProvider.class);
boolean useSerializationProvider = ess.getSettings().isUseBetterKits(); boolean useSerializationProvider = ess.getSettings().isUseBetterKits();
if (useSerializationProvider && ess.getProviders().get(SerializationProvider.class) == null) { if (useSerializationProvider && serializationProvider == null) {
ess.showError(user.getSource(), new Exception(tl("createKitUnsupported")), commandLabel); ess.showError(user.getSource(), new Exception(tl("createKitUnsupported")), commandLabel);
useSerializationProvider = false; useSerializationProvider = false;
} }
@ -53,7 +54,7 @@ public class Commandcreatekit extends EssentialsCommand {
if (is != null && is.getType() != null && is.getType() != Material.AIR) { if (is != null && is.getType() != null && is.getType() != Material.AIR) {
final String serialized; final String serialized;
if (useSerializationProvider) { if (useSerializationProvider) {
serialized = "@" + Base64Coder.encodeLines(ess.getProviders().get(SerializationProvider.class).serializeItem(is)); serialized = "@" + Base64Coder.encodeLines(serializationProvider.serializeItem(is));
} else { } else {
serialized = ess.getItemDb().serialize(is); serialized = ess.getItemDb().serialize(is);
} }

View File

@ -262,7 +262,7 @@ public class Commandessentials extends EssentialsCommand {
serverData.addProperty("bukkit-version", Bukkit.getBukkitVersion()); serverData.addProperty("bukkit-version", Bukkit.getBukkitVersion());
serverData.addProperty("server-version", Bukkit.getVersion()); serverData.addProperty("server-version", Bukkit.getVersion());
serverData.addProperty("server-brand", Bukkit.getName()); serverData.addProperty("server-brand", Bukkit.getName());
serverData.addProperty("online-mode", ess.getProviders().get(OnlineModeProvider.class).getOnlineModeString()); serverData.addProperty("online-mode", ess.provider(OnlineModeProvider.class).getOnlineModeString());
final JsonObject supportStatus = new JsonObject(); final JsonObject supportStatus = new JsonObject();
final VersionUtil.SupportStatus status = VersionUtil.getServerSupportStatus(); final VersionUtil.SupportStatus status = VersionUtil.getServerSupportStatus();
supportStatus.addProperty("status", status.name()); supportStatus.addProperty("status", status.name());
@ -333,7 +333,7 @@ public class Commandessentials extends EssentialsCommand {
final Plugin essDiscordLink = Bukkit.getPluginManager().getPlugin("EssentialsDiscordLink"); final Plugin essDiscordLink = Bukkit.getPluginManager().getPlugin("EssentialsDiscordLink");
final Plugin essSpawn = Bukkit.getPluginManager().getPlugin("EssentialsSpawn"); final Plugin essSpawn = Bukkit.getPluginManager().getPlugin("EssentialsSpawn");
final Map<String, Command> knownCommandsCopy = new HashMap<>(ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands()); final Map<String, Command> knownCommandsCopy = new HashMap<>(ess.provider(KnownCommandsProvider.class).getKnownCommands());
final Map<String, String> disabledCommandsCopy = new HashMap<>(ess.getAlternativeCommandsHandler().disabledCommands()); final Map<String, String> disabledCommandsCopy = new HashMap<>(ess.getAlternativeCommandsHandler().disabledCommands());
// Further operations will be heavy IO // Further operations will be heavy IO

View File

@ -14,11 +14,13 @@ public class Commandgrindstone extends EssentialsCommand {
@Override @Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (ess.getProviders().get(ContainerProvider.class) == null) { final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
if (containerProvider == null) {
user.sendMessage(tl("unsupportedBrand")); user.sendMessage(tl("unsupportedBrand"));
return; return;
} }
ess.getProviders().get(ContainerProvider.class).openGrindstone(user.getBase()); containerProvider.openGrindstone(user.getBase());
} }
} }

View File

@ -37,7 +37,7 @@ public class Commandhelp extends EssentialsCommand {
if (input.getLines().isEmpty()) { if (input.getLines().isEmpty()) {
if (pageStr != null && pageStr.startsWith("/")) { if (pageStr != null && pageStr.startsWith("/")) {
final String cmd = pageStr.substring(1); final String cmd = pageStr.substring(1);
for (final Map.Entry<String, Command> knownCmd : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().entrySet()) { for (final Map.Entry<String, Command> knownCmd : ess.provider(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
if (knownCmd.getKey().equalsIgnoreCase(cmd)) { if (knownCmd.getKey().equalsIgnoreCase(cmd)) {
user.sendMessage(tl("commandHelpLine1", cmd)); user.sendMessage(tl("commandHelpLine1", cmd));
user.sendMessage(tl("commandHelpLine2", knownCmd.getValue().getDescription())); user.sendMessage(tl("commandHelpLine2", knownCmd.getValue().getDescription()));

View File

@ -14,11 +14,13 @@ public class Commandloom extends EssentialsCommand {
@Override @Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (ess.getProviders().get(ContainerProvider.class) == null) { final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
if (containerProvider == null) {
user.sendMessage(tl("unsupportedBrand")); user.sendMessage(tl("unsupportedBrand"));
return; return;
} }
ess.getProviders().get(ContainerProvider.class).openLoom(user.getBase()); containerProvider.openLoom(user.getBase());
} }
} }

View File

@ -14,11 +14,13 @@ public class Commandsmithingtable extends EssentialsCommand {
@Override @Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
if (ess.getProviders().get(ContainerProvider.class) == null) { final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
if (containerProvider == null) {
user.sendMessage(tl("unsupportedBrand")); user.sendMessage(tl("unsupportedBrand"));
return; return;
} }
ess.getProviders().get(ContainerProvider.class).openSmithingTable(user.getBase()); containerProvider.openSmithingTable(user.getBase());
} }
} }

View File

@ -61,7 +61,7 @@ public class Commandspawner extends EssentialsCommand {
final CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState(); final CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
spawner.setSpawnedType(mob.getType()); spawner.setSpawnedType(mob.getType());
if (delay > 0) { if (delay > 0) {
final SpawnerBlockProvider spawnerBlockProvider = ess.getProviders().get(SpawnerBlockProvider.class); final SpawnerBlockProvider spawnerBlockProvider = ess.provider(SpawnerBlockProvider.class);
spawnerBlockProvider.setMinSpawnDelay(spawner, 1); spawnerBlockProvider.setMinSpawnDelay(spawner, 1);
spawnerBlockProvider.setMaxSpawnDelay(spawner, Integer.MAX_VALUE); spawnerBlockProvider.setMaxSpawnDelay(spawner, Integer.MAX_VALUE);
spawnerBlockProvider.setMinSpawnDelay(spawner, delay); spawnerBlockProvider.setMinSpawnDelay(spawner, delay);

View File

@ -14,11 +14,13 @@ public class Commandstonecutter extends EssentialsCommand {
@Override @Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (ess.getProviders().get(ContainerProvider.class) == null) { final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
if (containerProvider == null) {
user.sendMessage(tl("unsupportedBrand")); user.sendMessage(tl("unsupportedBrand"));
return; return;
} }
ess.getProviders().get(ContainerProvider.class).openStonecutter(user.getBase()); containerProvider.openStonecutter(user.getBase());
} }
} }

View File

@ -23,7 +23,7 @@ public class Commandtop extends EssentialsCommand {
final int topZ = user.getLocation().getBlockZ(); final int topZ = user.getLocation().getBlockZ();
final float pitch = user.getLocation().getPitch(); final float pitch = user.getLocation().getPitch();
final float yaw = user.getLocation().getYaw(); final float yaw = user.getLocation().getYaw();
final Location unsafe = new Location(user.getWorld(), topX, ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(user.getWorld()), topZ, yaw, pitch); final Location unsafe = new Location(user.getWorld(), topX, ess.provider(WorldInfoProvider.class).getMaxHeight(user.getWorld()), topZ, yaw, pitch);
final Location safe = LocationUtil.getSafeDestination(ess, unsafe); final Location safe = LocationUtil.getSafeDestination(ess, unsafe);
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel); final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
future.thenAccept(success -> { future.thenAccept(success -> {

View File

@ -278,7 +278,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand {
* Lists all commands. * Lists all commands.
*/ */
protected final List<String> getCommands(Server server) { protected final List<String> getCommands(Server server) {
final Map<String, Command> commandMap = Maps.newHashMap(this.ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands()); final Map<String, Command> commandMap = Maps.newHashMap(this.ess.provider(KnownCommandsProvider.class).getKnownCommands());
final List<String> commands = Lists.newArrayListWithCapacity(commandMap.size()); final List<String> commands = Lists.newArrayListWithCapacity(commandMap.size());
for (final Command command : commandMap.values()) { for (final Command command : commandMap.values()) {
if (!(command instanceof PluginIdentifiableCommand)) { if (!(command instanceof PluginIdentifiableCommand)) {

View File

@ -151,8 +151,8 @@ public class FlatItemDb extends AbstractItemDb {
// setItemMeta to prevent a race condition // setItemMeta to prevent a race condition
final EntityType entity = data.getEntity(); final EntityType entity = data.getEntity();
if (entity != null && material.toString().contains("SPAWNER")) { if (entity != null && material.toString().contains("SPAWNER")) {
ess.getProviders().get(SpawnerItemProvider.class).setEntityType(stack, entity); ess.provider(SpawnerItemProvider.class).setEntityType(stack, entity);
ess.getProviders().get(PersistentDataProvider.class).set(stack, "convert", "true"); ess.provider(PersistentDataProvider.class).set(stack, "convert", "true");
} }
return stack; return stack;
@ -210,7 +210,7 @@ public class FlatItemDb extends AbstractItemDb {
final PotionData potion = ((PotionMeta) item.getItemMeta()).getBasePotionData(); final PotionData potion = ((PotionMeta) item.getItemMeta()).getBasePotionData();
return new ItemData(type, potion); return new ItemData(type, potion);
} else if (type.toString().contains("SPAWNER")) { } else if (type.toString().contains("SPAWNER")) {
final EntityType entity = ess.getProviders().get(SpawnerItemProvider.class).getEntityType(item); final EntityType entity = ess.provider(SpawnerItemProvider.class).getEntityType(item);
return new ItemData(type, entity); return new ItemData(type, entity);
} else { } else {
return new ItemData(type); return new ItemData(type);

View File

@ -192,8 +192,8 @@ public class LegacyItemDb extends AbstractItemDb {
if (mat == MOB_SPAWNER) { if (mat == MOB_SPAWNER) {
if (metaData == 0) metaData = EntityType.PIG.getTypeId(); if (metaData == 0) metaData = EntityType.PIG.getTypeId();
try { try {
retval = ess.getProviders().get(SpawnerItemProvider.class).setEntityType(retval, EntityType.fromId(metaData)); retval = ess.provider(SpawnerItemProvider.class).setEntityType(retval, EntityType.fromId(metaData));
ess.getProviders().get(PersistentDataProvider.class).set(retval, "convert", "true"); ess.provider(PersistentDataProvider.class).set(retval, "convert", "true");
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners."); throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
} }
@ -204,10 +204,10 @@ public class LegacyItemDb extends AbstractItemDb {
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new Exception("Can't spawn entity ID " + metaData + " from spawn eggs."); throw new Exception("Can't spawn entity ID " + metaData + " from spawn eggs.");
} }
retval = ess.getProviders().get(SpawnEggProvider.class).createEggItem(type); retval = ess.provider(SpawnEggProvider.class).createEggItem(type);
} else if (mat.name().endsWith("POTION") } 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 && 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.getProviders().get(PotionMetaProvider.class).createPotionItem(mat, metaData); retval = ess.provider(PotionMetaProvider.class).createPotionItem(mat, metaData);
} else { } else {
retval.setDurability(metaData); retval.setDurability(metaData);
} }

View File

@ -166,24 +166,26 @@ public class EssentialsSign {
} }
public void setOwnerData(final IEssentials ess, final User user, final ISign signProvider) { public void setOwnerData(final IEssentials ess, final User user, final ISign signProvider) {
if (ess.getProviders().get(SignDataProvider.class) == null) { final SignDataProvider dataProvider = ess.provider(SignDataProvider.class);
if (dataProvider == null) {
return; return;
} }
final Sign sign = (Sign) signProvider.getBlock().getState(); final Sign sign = (Sign) signProvider.getBlock().getState();
ess.getProviders().get(SignDataProvider.class).setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString()); dataProvider.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) { public boolean isOwner(final IEssentials ess, final User user, final ISign signProvider, final int nameIndex, final String namePrefix) {
final SignDataProvider dataProvider = ess.provider(SignDataProvider.class);
final Sign sign = (Sign) signProvider.getBlock().getState(); final Sign sign = (Sign) signProvider.getBlock().getState();
if (ess.getProviders().get(SignDataProvider.class) == null || ess.getProviders().get(SignDataProvider.class).getSignData(sign, SIGN_OWNER_KEY) == null) { if (dataProvider == null || dataProvider.getSignData(sign, SIGN_OWNER_KEY) == null) {
final boolean isLegacyOwner = FormatUtil.stripFormat(signProvider.getLine(nameIndex)).equalsIgnoreCase(getUsername(user)); final boolean isLegacyOwner = FormatUtil.stripFormat(signProvider.getLine(nameIndex)).equalsIgnoreCase(getUsername(user));
if (ess.getProviders().get(SignDataProvider.class) != null && isLegacyOwner) { if (dataProvider != null && isLegacyOwner) {
ess.getProviders().get(SignDataProvider.class).setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString()); dataProvider.setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString());
} }
return isLegacyOwner; return isLegacyOwner;
} }
if (user.getUUID().toString().equals(ess.getProviders().get(SignDataProvider.class).getSignData(sign, SIGN_OWNER_KEY))) { if (user.getUUID().toString().equals(dataProvider.getSignData(sign, SIGN_OWNER_KEY))) {
signProvider.setLine(nameIndex, namePrefix + getUsername(user)); signProvider.setLine(nameIndex, namePrefix + getUsername(user));
return true; return true;
} }

View File

@ -13,7 +13,7 @@ public class SignAnvil extends EssentialsSign {
@Override @Override
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
if (ess.getProviders().get(ContainerProvider.class) == null) { if (ess.provider(ContainerProvider.class) == null) {
player.sendMessage(tl("unsupportedBrand")); player.sendMessage(tl("unsupportedBrand"));
return false; return false;
} }
@ -22,7 +22,7 @@ public class SignAnvil extends EssentialsSign {
@Override @Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
ess.getProviders().get(ContainerProvider.class).openAnvil(player.getBase()); ess.provider(ContainerProvider.class).openAnvil(player.getBase());
return true; return true;
} }
} }

View File

@ -13,7 +13,7 @@ public class SignCartography extends EssentialsSign {
@Override @Override
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
if (ess.getProviders().get(ContainerProvider.class) == null) { if (ess.provider(ContainerProvider.class) == null) {
player.sendMessage(tl("unsupportedBrand")); player.sendMessage(tl("unsupportedBrand"));
return false; return false;
} }
@ -22,7 +22,7 @@ public class SignCartography extends EssentialsSign {
@Override @Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
ess.getProviders().get(ContainerProvider.class).openCartographyTable(player.getBase()); ess.provider(ContainerProvider.class).openCartographyTable(player.getBase());
return true; return true;
} }
} }

View File

@ -23,7 +23,7 @@ public class SignEnchant extends EssentialsSign {
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
final ItemStack stack; final ItemStack stack;
final String itemName = sign.getLine(1); final String itemName = sign.getLine(1);
final MaterialTagProvider tagProvider = ess.getProviders().get(MaterialTagProvider.class); final MaterialTagProvider tagProvider = ess.provider(MaterialTagProvider.class);
try { try {
stack = itemName.equals("*") || itemName.equalsIgnoreCase("any") || (tagProvider != null && tagProvider.tagExists(itemName)) ? null : getItemStack(sign.getLine(1), 1, ess); stack = itemName.equals("*") || itemName.equalsIgnoreCase("any") || (tagProvider != null && tagProvider.tagExists(itemName)) ? null : getItemStack(sign.getLine(1), 1, ess);
} catch (final SignException e) { } catch (final SignException e) {
@ -68,7 +68,7 @@ public class SignEnchant extends EssentialsSign {
@Override @Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
final ItemStack playerHand = Inventories.getItemInHand(player.getBase()); final ItemStack playerHand = Inventories.getItemInHand(player.getBase());
final MaterialTagProvider tagProvider = ess.getProviders().get(MaterialTagProvider.class); final MaterialTagProvider tagProvider = ess.provider(MaterialTagProvider.class);
final String itemName = sign.getLine(1); 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 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); final Trade charge = getTrade(sign, 3, ess);

View File

@ -13,7 +13,7 @@ public class SignGrindstone extends EssentialsSign {
@Override @Override
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
if (ess.getProviders().get(ContainerProvider.class) == null) { if (ess.provider(ContainerProvider.class) == null) {
player.sendMessage(tl("unsupportedBrand")); player.sendMessage(tl("unsupportedBrand"));
return false; return false;
} }
@ -22,7 +22,7 @@ public class SignGrindstone extends EssentialsSign {
@Override @Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
ess.getProviders().get(ContainerProvider.class).openGrindstone(player.getBase()); ess.provider(ContainerProvider.class).openGrindstone(player.getBase());
return true; return true;
} }
} }

View File

@ -13,7 +13,7 @@ public class SignLoom extends EssentialsSign {
@Override @Override
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
if (ess.getProviders().get(ContainerProvider.class) == null) { if (ess.provider(ContainerProvider.class) == null) {
player.sendMessage(tl("unsupportedBrand")); player.sendMessage(tl("unsupportedBrand"));
return false; return false;
} }
@ -22,7 +22,7 @@ public class SignLoom extends EssentialsSign {
@Override @Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
ess.getProviders().get(ContainerProvider.class).openLoom(player.getBase()); ess.provider(ContainerProvider.class).openLoom(player.getBase());
return true; return true;
} }
} }

View File

@ -13,7 +13,7 @@ public class SignSmithing extends EssentialsSign {
@Override @Override
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) {
if (ess.getProviders().get(ContainerProvider.class) == null) { if (ess.provider(ContainerProvider.class) == null) {
player.sendMessage(tl("unsupportedBrand")); player.sendMessage(tl("unsupportedBrand"));
return false; return false;
} }
@ -22,7 +22,7 @@ public class SignSmithing extends EssentialsSign {
@Override @Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) {
ess.getProviders().get(ContainerProvider.class).openSmithingTable(player.getBase()); ess.provider(ContainerProvider.class).openSmithingTable(player.getBase());
return true; return true;
} }
} }

View File

@ -34,7 +34,7 @@ public class HelpInput implements IText {
} }
final Multimap<Plugin, Command> pluginCommands = HashMultimap.create(); final Multimap<Plugin, Command> pluginCommands = HashMultimap.create();
for (final Command command : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().values()) { for (final Command command : ess.provider(KnownCommandsProvider.class).getKnownCommands().values()) {
if (!(command instanceof PluginIdentifiableCommand)) { if (!(command instanceof PluginIdentifiableCommand)) {
continue; continue;
} }

View File

@ -61,7 +61,7 @@ public final class CommandMapUtil {
} else if (value instanceof FormattedCommandAlias) { } else if (value instanceof FormattedCommandAlias) {
json.addProperty("source", "commands.yml"); json.addProperty("source", "commands.yml");
final JsonArray formatStrings = new JsonArray(); final JsonArray formatStrings = new JsonArray();
for (final String entry : ess.getProviders().get(FormattedCommandAliasProvider.class).getFormatStrings((FormattedCommandAlias) value)) { for (final String entry : ess.provider(FormattedCommandAliasProvider.class).getFormatStrings((FormattedCommandAlias) value)) {
formatStrings.add(new JsonPrimitive(entry)); formatStrings.add(new JsonPrimitive(entry));
} }
json.add("bukkit_aliases", formatStrings); json.add("bukkit_aliases", formatStrings);

View File

@ -110,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) { public static boolean isBlockAboveAir(IEssentials ess, final World world, final int x, final int y, final int z) {
return y > ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(world) || HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType()); return y > ess.provider(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) { public static boolean isBlockOutsideWorldBorder(final World world, final int x, final int z) {
@ -215,10 +215,12 @@ public final class LocationUtil {
if (loc == null || loc.getWorld() == null) { if (loc == null || loc.getWorld() == null) {
throw new Exception(tl("destinationNotSet")); throw new Exception(tl("destinationNotSet"));
} }
final WorldInfoProvider worldInfoProvider = ess.provider(WorldInfoProvider.class);
final World world = loc.getWorld(); final World world = loc.getWorld();
final int worldMinY = ess.getProviders().get(WorldInfoProvider.class).getMinHeight(world); final int worldMinY = worldInfoProvider.getMinHeight(world);
final int worldLogicalY = ess.getProviders().get(WorldInfoProvider.class).getLogicalHeight(world); final int worldLogicalY = worldInfoProvider.getLogicalHeight(world);
final int worldMaxY = loc.getBlockY() < worldLogicalY ? worldLogicalY : ess.getProviders().get(WorldInfoProvider.class).getMaxHeight(world); final int worldMaxY = loc.getBlockY() < worldLogicalY ? worldLogicalY : worldInfoProvider.getMaxHeight(world);
int x = loc.getBlockX(); int x = loc.getBlockX();
int y = (int) Math.round(loc.getY()); int y = (int) Math.round(loc.getY());
int z = loc.getBlockZ(); int z = loc.getBlockZ();
@ -275,13 +277,14 @@ public final class LocationUtil {
} }
public static boolean shouldFly(IEssentials ess, final Location loc) { public static boolean shouldFly(IEssentials ess, final Location loc) {
final WorldInfoProvider worldInfoProvider = ess.provider(WorldInfoProvider.class);
final World world = loc.getWorld(); final World world = loc.getWorld();
final int x = loc.getBlockX(); final int x = loc.getBlockX();
int y = (int) Math.round(loc.getY()); int y = (int) Math.round(loc.getY());
final int z = loc.getBlockZ(); final int z = loc.getBlockZ();
int count = 0; int count = 0;
// Check whether more than 2 unsafe block are below player. // Check whether more than 2 unsafe block are below player.
while (LocationUtil.isBlockUnsafe(ess, world, x, y, z) && y >= ess.getProviders().get(WorldInfoProvider.class).getMinHeight(world)) { while (LocationUtil.isBlockUnsafe(ess, world, x, y, z) && y >= worldInfoProvider.getMinHeight(world)) {
y--; y--;
count++; count++;
if (count > 2) { if (count > 2) {
@ -290,7 +293,7 @@ public final class LocationUtil {
} }
// If not then check if player is in the void // If not then check if player is in the void
return y < ess.getProviders().get(WorldInfoProvider.class).getMinHeight(world); return y < worldInfoProvider.getMinHeight(world);
} }
public static class Vector3D { public static class Vector3D {