added and implemented taskchain

This commit is contained in:
2024-10-04 20:42:17 +02:00
parent 4f4a6aef10
commit ab71f09f8a
12 changed files with 130 additions and 102 deletions

View File

@@ -0,0 +1,96 @@
package eu.mhsl.minecraft.pixelblocks;
import co.aikar.taskchain.BukkitTaskChainFactory;
import co.aikar.taskchain.TaskChain;
import co.aikar.taskchain.TaskChainFactory;
import eu.mhsl.minecraft.pixelblocks.commands.CreatePixelBlockCommand;
import eu.mhsl.minecraft.pixelblocks.commands.ExitWorldCommand;
import eu.mhsl.minecraft.pixelblocks.listeners.*;
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public final class Main extends JavaPlugin {
public static Main plugin;
public static PixelBlockConfiguration configuration;
public static PixelBlockDatabase database;
public static TaskChainFactory taskFactory;
public static List<PixelBlock> pixelBlocks = new ArrayList<>();
public static <T> TaskChain<T> newChain() {
return taskFactory.newChain();
}
public static <T> TaskChain<T> newSharedChain(String name) {
return taskFactory.newSharedChain(name);
}
@Override
public void onLoad() {
Main.plugin = this;
FileConfiguration config = this.getConfig();
PixelBlockConfiguration.setDefaults(config);
this.saveConfig();
Main.configuration = new PixelBlockConfiguration(
config.getInt(PixelBlockConfiguration.Keys.PixelsPerBlock.getKey()),
config.getDouble(PixelBlockConfiguration.Keys.HitboxOffset.getKey()),
config.getBoolean(PixelBlockConfiguration.Keys.OnlyBreakableByOwners.getKey()),
config.getBoolean(PixelBlockConfiguration.Keys.OnlyEditableByOwners.getKey())
);
File databaseFile = new File(plugin.getDataFolder(), "blocks.db");
Main.database = new PixelBlockDatabase("jdbc:sqlite:" + databaseFile);
}
@Override
public void onEnable() {
Main.taskFactory = BukkitTaskChainFactory.create(this);
database.loadPixelBlocks();
Listener[] listeners = {
new EnterPixelBlockListener(),
new FallOutOfPixelBlockListener(),
new BreakPixelListener(),
new PlacePixelBlockListener(),
new PreventInventorysListener(),
new ExitPixelWorldListener(),
new PreventIllegalBlocksListener(),
new BreakPixelBlockListener(),
new PlacePixelListener(),
new PreventHopperActionsListener(),
new PreventLiquidsFlowListener(),
new PreventPistonsListener(),
new PreventEntityPlacementListener(),
new DiscoverRecipesListener()
};
for (Listener listener : listeners) {
getServer().getPluginManager().registerEvents(listener, plugin);
}
Objects.requireNonNull(getCommand("createpixelblock")).setExecutor(new CreatePixelBlockCommand());
Objects.requireNonNull(getCommand("exitworld")).setExecutor(new ExitWorldCommand());
Bukkit.addRecipe(PixelBlockItem.getRecipe());
}
@Override
public void onDisable() {
try {
database.close();
} catch (SQLException e) {
throw new RuntimeException("Failed disabling", e);
}
}
}