136 lines
6.5 KiB
Java
Raw Normal View History

2020-07-10 22:12:37 +02:00
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2021 IntellectualSites
2020-07-10 22:12:37 +02:00
*
* 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
2020-08-15 14:59:29 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020-07-10 22:12:37 +02:00
*/
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-10 22:12:37 +02:00
import com.plotsquared.bukkit.BukkitPlatform;
2021-01-07 21:24:38 +00:00
import com.plotsquared.bukkit.listener.SingleWorldListener;
2020-07-10 22:12:37 +02:00
import com.plotsquared.bukkit.player.BukkitPlayerManager;
import com.plotsquared.bukkit.queue.BukkitChunkCoordinator;
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.BukkitRegionManager;
import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitUtil;
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;
import com.plotsquared.core.inject.factory.ChunkCoordinatorBuilderFactory;
import com.plotsquared.core.inject.factory.ChunkCoordinatorFactory;
2020-07-11 17:19:19 +02:00
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
2020-08-17 16:21:11 +01:00
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
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;
import com.plotsquared.core.queue.ChunkCoordinator;
2020-07-10 22:12:37 +02:00
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.QueueProvider;
2020-08-17 16:21:11 +01:00
import com.plotsquared.core.queue.subscriber.DefaultProgressSubscriber;
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
2020-07-10 22:12:37 +02:00
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.InventoryUtil;
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 org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
2020-07-10 22:12:37 +02:00
2020-07-17 17:24:45 +02:00
public class BukkitModule extends AbstractModule {
2020-07-10 22:12:37 +02:00
private final BukkitPlatform bukkitPlatform;
public BukkitModule(final @NonNull BukkitPlatform bukkitPlatform) {
2020-07-17 17:24:45 +02:00
this.bukkitPlatform = bukkitPlatform;
}
@Override
protected void configure() {
2020-07-10 22:12:37 +02:00
bind(PlayerManager.class).to(BukkitPlayerManager.class);
bind(JavaPlugin.class).toInstance(bukkitPlatform);
bind(PlotPlatform.class).toInstance(bukkitPlatform);
bind(BukkitPlatform.class).toInstance(bukkitPlatform);
2020-07-10 22:12:37 +02:00
bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class).to(HybridGen.class);
// Console actor
@NonNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
2020-07-10 22:12:37 +02:00
WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console));
bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
bind(SetupUtils.class).to(BukkitSetupUtils.class);
bind(WorldUtil.class).to(BukkitUtil.class);
install(new FactoryModuleBuilder()
.implement(ProgressSubscriber.class, DefaultProgressSubscriber.class)
.build(ProgressSubscriberFactory.class));
2020-07-24 16:24:53 +01:00
bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(QueueProvider.of(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-11 05:29:41 +02:00
if (Settings.Enabled_Components.WORLDS) {
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
2021-01-07 21:24:38 +00:00
try {
bind(SingleWorldListener.class).toInstance(new SingleWorldListener());
} catch (Exception e) {
e.printStackTrace();
}
2020-07-11 05:29:41 +02:00
} else {
bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
}
2020-07-11 17:19:19 +02:00
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
install(new FactoryModuleBuilder()
.implement(ChunkCoordinator.class, BukkitChunkCoordinator.class)
.build(ChunkCoordinatorFactory.class));
install(new FactoryModuleBuilder().build(ChunkCoordinatorBuilderFactory.class));
2020-07-10 22:12:37 +02:00
}
@Provides
@Singleton
@NonNull EconHandler provideEconHandler() {
2020-07-14 18:49:40 +02:00
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
try {
2020-07-22 12:35:48 +02:00
return new BukkitEconHandler();
2020-07-14 18:49:40 +02:00
} catch (final Exception ignored) {
}
}
return EconHandler.nullEconHandler();
2020-07-14 18:49:40 +02:00
}
2020-07-10 22:12:37 +02:00
}