2020-07-10 22:12:37 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
|
|
|
* Copyright (C) 2020 IntellectualSites
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package com.plotsquared.bukkit.inject;
|
|
|
|
|
|
|
|
import com.google.inject.AbstractModule;
|
2020-07-15 13:18:09 +02:00
|
|
|
import com.google.inject.Provides;
|
|
|
|
import com.google.inject.Singleton;
|
2020-07-11 17:19:19 +02:00
|
|
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
2020-07-14 18:49:40 +02:00
|
|
|
import com.google.inject.util.Providers;
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.plotsquared.bukkit.BukkitPlatform;
|
|
|
|
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
2020-07-17 15:41:06 +01:00
|
|
|
import com.plotsquared.bukkit.queue.BukkitQueueCoordinator;
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitPermHandler;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitRegionManager;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitSetupUtils;
|
|
|
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
2020-07-15 13:18:09 +02:00
|
|
|
import com.plotsquared.bukkit.util.task.PaperTimeConverter;
|
|
|
|
import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.plotsquared.core.PlotPlatform;
|
|
|
|
import com.plotsquared.core.configuration.Settings;
|
|
|
|
import com.plotsquared.core.generator.HybridGen;
|
|
|
|
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
|
|
|
import com.plotsquared.core.inject.annotations.ConsoleActor;
|
|
|
|
import com.plotsquared.core.inject.annotations.DefaultGenerator;
|
2020-07-11 17:19:19 +02:00
|
|
|
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
|
2020-07-11 05:29:41 +02:00
|
|
|
import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
|
|
|
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
|
|
|
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.plotsquared.core.queue.GlobalBlockQueue;
|
|
|
|
import com.plotsquared.core.queue.QueueProvider;
|
|
|
|
import com.plotsquared.core.util.ChunkManager;
|
|
|
|
import com.plotsquared.core.util.EconHandler;
|
|
|
|
import com.plotsquared.core.util.InventoryUtil;
|
|
|
|
import com.plotsquared.core.util.PermHandler;
|
|
|
|
import com.plotsquared.core.util.PlayerManager;
|
|
|
|
import com.plotsquared.core.util.RegionManager;
|
|
|
|
import com.plotsquared.core.util.SchematicHandler;
|
|
|
|
import com.plotsquared.core.util.SetupUtils;
|
|
|
|
import com.plotsquared.core.util.WorldUtil;
|
|
|
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2020-07-17 15:41:06 +01:00
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2020-07-10 22:12:37 +02:00
|
|
|
|
2020-07-17 15:41:06 +01:00
|
|
|
@RequiredArgsConstructor
|
|
|
|
public class BukkitModule extends AbstractModule {
|
2020-07-10 22:12:37 +02:00
|
|
|
|
|
|
|
private final BukkitPlatform bukkitPlatform;
|
|
|
|
|
|
|
|
@Override protected void configure() {
|
|
|
|
bind(PlayerManager.class).to(BukkitPlayerManager.class);
|
|
|
|
bind(JavaPlugin.class).toInstance(bukkitPlatform);
|
|
|
|
bind(PlotPlatform.class).toInstance(bukkitPlatform);
|
2020-07-17 15:41:06 +01:00
|
|
|
bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class)
|
|
|
|
.to(HybridGen.class);
|
2020-07-10 22:12:37 +02:00
|
|
|
// Console actor
|
2020-07-14 18:49:40 +02:00
|
|
|
@Nonnull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
2020-07-17 15:41:06 +01:00
|
|
|
WorldEditPlugin wePlugin =
|
|
|
|
((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
|
|
|
bind(Actor.class).annotatedWith(ConsoleActor.class)
|
|
|
|
.toInstance(wePlugin.wrapCommandSender(console));
|
2020-07-10 22:12:37 +02:00
|
|
|
bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
|
|
|
|
bind(SetupUtils.class).to(BukkitSetupUtils.class);
|
|
|
|
bind(WorldUtil.class).to(BukkitUtil.class);
|
|
|
|
bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(
|
2020-07-17 15:41:06 +01:00
|
|
|
QueueProvider.of(BukkitQueueCoordinator.class, BukkitQueueCoordinator.class)));
|
2020-07-10 22:12:37 +02:00
|
|
|
bind(ChunkManager.class).to(BukkitChunkManager.class);
|
|
|
|
bind(RegionManager.class).to(BukkitRegionManager.class);
|
|
|
|
bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
|
2020-07-14 18:49:40 +02:00
|
|
|
this.setupVault();
|
2020-07-11 05:29:41 +02:00
|
|
|
if (Settings.Enabled_Components.WORLDS) {
|
|
|
|
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
|
|
|
|
} else {
|
|
|
|
bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
|
|
|
|
}
|
2020-07-11 17:19:19 +02:00
|
|
|
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
2020-07-10 22:12:37 +02:00
|
|
|
}
|
|
|
|
|
2020-07-14 18:49:40 +02:00
|
|
|
private void setupVault() {
|
|
|
|
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
|
|
|
BukkitPermHandler bukkitPermHandler = null;
|
|
|
|
try {
|
|
|
|
bukkitPermHandler = new BukkitPermHandler();
|
|
|
|
bind(PermHandler.class).toInstance(bukkitPermHandler);
|
|
|
|
} catch (final Exception ignored) {
|
|
|
|
bind(PermHandler.class).toProvider(Providers.of(null));
|
|
|
|
}
|
|
|
|
try {
|
2020-07-17 15:41:06 +01:00
|
|
|
final BukkitEconHandler bukkitEconHandler =
|
|
|
|
new BukkitEconHandler(bukkitPermHandler);
|
2020-07-14 18:49:40 +02:00
|
|
|
bind(EconHandler.class).toInstance(bukkitEconHandler);
|
|
|
|
} catch (final Exception ignored) {
|
|
|
|
bind(EconHandler.class).toProvider(Providers.of(null));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bind(PermHandler.class).toProvider(Providers.of(null));
|
|
|
|
bind(EconHandler.class).toProvider(Providers.of(null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 22:12:37 +02:00
|
|
|
}
|