Files
src
build.gradle
settings.gradle
Code
52 1,901
src/main/java/dev/chaosgg/chaositems/ChaosItemsPlugin.java
package dev.chaosgg.chaositems;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public final class ChaosItemsPlugin extends JavaPlugin {
private ChaosItemFactory itemFactory;
private CostumeManager costumeManager;
private ChaosItemsListener listener;
@Override
public void onEnable() {
saveDefaultConfig();
exportResourcePack();
itemFactory = new ChaosItemFactory(this);
costumeManager = new CostumeManager(this);
listener = new ChaosItemsListener(this, itemFactory, costumeManager);
Bukkit.getPluginManager().registerEvents(listener, this);
Bukkit.getPluginManager().registerEvents(costumeManager, this);
ChaosItemsCommand commandHandler = new ChaosItemsCommand(this, itemFactory, costumeManager);
PluginCommand chaosItemsCommand = getCommand("chaositems");
if (chaosItemsCommand != null) {
chaosItemsCommand.setExecutor(commandHandler);
chaosItemsCommand.setTabCompleter(commandHandler);
}
PluginCommand costumesCommand = getCommand("kostiumy");
if (costumesCommand != null) {
costumesCommand.setExecutor(commandHandler);
}
}
@Override
public void onDisable() {
if (listener != null) {
listener.shutdown();
}
if (costumeManager != null) {
costumeManager.shutdown();
}
}
public String message(String path) {
return getConfig().getString("messages." + path, "<red>Missing message: " + path);
}
private void exportResourcePack() {
Path output = getDataFolder().toPath().resolve("ChaosItems-resourcepack.zip");
try {
Files.createDirectories(getDataFolder().toPath());
InputStream fileList = getResource("resourcepack/pack-files.txt");
if (fileList == null) {
throw new IOException("Missing resourcepack/pack-files.txt");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(fileList, StandardCharsets.UTF_8));
ZipOutputStream zip = new ZipOutputStream(Files.newOutputStream(output))) {
String path;
while ((path = reader.readLine()) != null) {
if (path.isBlank()) {
continue;
}
InputStream resource = getResource("resourcepack/" + path);
if (resource == null) {
throw new IOException("Missing resourcepack file: " + path);
}
try (resource) {
zip.putNextEntry(new ZipEntry(path));
resource.transferTo(zip);
zip.closeEntry();
}
}
}
getLogger().info("Created resource pack: " + output);
} catch (IOException exception) {
getLogger().severe("Could not create resource pack: " + exception.getMessage());
}
}
}