71 lines
2.5 KiB
Java

package eu.mhsl.minecraft.pixelblocks;
import eu.mhsl.minecraft.pixelblocks.commands.CreatePixelBlockCommand;
import eu.mhsl.minecraft.pixelblocks.commands.ExitWorldCommand;
import eu.mhsl.minecraft.pixelblocks.listeners.*;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.Objects;
public final class PixelBlocks extends JavaPlugin {
public static PixelBlocks plugin;
public static DataBase dataBase;
public static String pathSeparator = File.separator;
@Override
public void onEnable() {
PixelBlocks.plugin = this;
this.getLogger().info("PixelBlocks Plugin was enabled.");
dataBase = new DataBase("jdbc:sqlite:pixelblocks.db");
dataBase.loadPixelBlocks();
Listener[] listeners = {
new PlayerInteractListener(),
new PlayerMoveListener(),
new EntityDamageListener(),
new BlockBreakListener(),
new BlockPlaceListener(),
new CreatureSpawnListener(),
new EntityExplodeListener(),
new BlockExplodeListener(),
new PlayerPortalListener(),
new InventoryListener(),
new PlayerChangeWorldListener(),
new CraftItemListener()
};
for (Listener listener : listeners) {
getServer().getPluginManager().registerEvents(listener, plugin);
}
Objects.requireNonNull(getCommand("createpixelblock")).setExecutor(new CreatePixelBlockCommand());
Objects.requireNonNull(getCommand("exitworld")).setExecutor(new ExitWorldCommand());
ItemStack item = ItemStack.of(Material.GRAY_STAINED_GLASS);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("Pixelblock");
meta.setEnchantmentGlintOverride(true);
meta.setItemName("Pixelblock");
item.setItemMeta(meta);
NamespacedKey key = new NamespacedKey(this, "pixelblock");
ShapedRecipe recipe = new ShapedRecipe(key, item);
recipe.shape("ABA", "BCB", "ABA");
recipe.setIngredient('A', Material.DIAMOND_BLOCK);
recipe.setIngredient('B', Material.EMERALD_BLOCK);
recipe.setIngredient('C', Material.GRAY_STAINED_GLASS);
Bukkit.addRecipe(recipe);
}
}