Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void onEnable() {

saveDefaultConfig();

// Auto-add missing config keys from new plugin versions
ConfigValidator.migrateConfig(this);

// Check for config mismatches
ConfigValidator.checkConfigMismatches(this);

Expand All @@ -46,6 +49,9 @@ public void onEnable() {
BlockConfigManager.initialize(this);
BlockConfigManager.getInstance().loadConfig();

// Load help book content from bundled YAML
HelpBookContent.load(this);

// Check for ProtocolLib for WASD input detection
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
getLogger().warning("==================================================");
Expand Down Expand Up @@ -219,6 +225,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
// Reload block configuration
BlockConfigManager.getInstance().reloadConfig();
// Reload help book content
HelpBookContent.load(this);
// Reload special drowned config
if (specialDrownedListener != null) {
specialDrownedListener.reloadConfig();
Expand All @@ -240,48 +248,47 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

if (args.length < 2) {
sender.sendMessage("Usage: /blockships give <item>");
sender.sendMessage("Available items:");
sender.sendMessage(" - ship_wheel");
var shipsSection = getConfig().getConfigurationSection("ships");
if (shipsSection != null) {
for (String shipType : shipsSection.getKeys(false)) {
sender.sendMessage(" - " + shipType);
}
}
sendGiveableItems(sender);
return true;
}

String itemType = args[1].toLowerCase();

// Handle ship_wheel specially
// Ship wheel
if (itemType.equals("ship_wheel")) {
ItemStack wheel = displayShip.createShipWheelItem();
player.getInventory().addItem(wheel);
sender.sendMessage("Gave you a ship wheel!");
return true;
}

// Verify ship type exists in config
if (!getConfig().contains("ships." + itemType)) {
sender.sendMessage("Unknown item: " + itemType);
sender.sendMessage("Available items:");
sender.sendMessage(" - ship_wheel");
var shipsSection = getConfig().getConfigurationSection("ships");
if (shipsSection != null) {
for (String type : shipsSection.getKeys(false)) {
sender.sendMessage(" - " + type);
}
}
// Captain's Manual (written book)
if (itemType.equals("captains_manual")) {
ItemStack manual = HelpBookContent.createWrittenBook();
player.getInventory().addItem(manual);
sender.sendMessage("Gave you a Captain's Manual!");
return true;
}

// Create ship kit with default wood (SPRUCE) and banner (WHITE)
ItemStack defaultBanner = new ItemStack(Material.WHITE_BANNER);
ItemStack shipKit = DisplayShip.createShipKit(itemType, defaultBanner, "SPRUCE", this);
// Custom items (ship_engine, balloon, etc.)
if (getConfig().contains("custom-items." + itemType)) {
ItemStack item = displayShip.getItemFactory().createItem(itemType, "_DEFAULT", null);
player.getInventory().addItem(item);
sender.sendMessage("Gave you a " + itemType + "!");
return true;
}

// Ship kits
if (getConfig().contains("ships." + itemType)) {
ItemStack defaultBanner = new ItemStack(Material.WHITE_BANNER);
ItemStack shipKit = DisplayShip.createShipKit(itemType, defaultBanner, "SPRUCE", this);
player.getInventory().addItem(shipKit);
sender.sendMessage("Gave you a " + itemType + " ship kit!");
return true;
}

// Give to player
player.getInventory().addItem(shipKit);
sender.sendMessage("Gave you a " + itemType + " ship kit!");
sender.sendMessage("Unknown item: " + itemType);
sendGiveableItems(sender);
return true;
}

Expand Down Expand Up @@ -486,6 +493,39 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return false;
}

private void sendGiveableItems(CommandSender sender) {
sender.sendMessage("Available items:");
sender.sendMessage(" - ship_wheel");
sender.sendMessage(" - captains_manual");
var customItemsSection = getConfig().getConfigurationSection("custom-items");
if (customItemsSection != null) {
for (String key : customItemsSection.getKeys(false)) {
sender.sendMessage(" - " + key);
}
}
var shipsSection = getConfig().getConfigurationSection("ships");
if (shipsSection != null) {
for (String key : shipsSection.getKeys(false)) {
sender.sendMessage(" - " + key);
}
}
}

private List<String> getGiveableItemNames() {
List<String> items = new ArrayList<>();
items.add("ship_wheel");
items.add("captains_manual");
var customItemsSection = getConfig().getConfigurationSection("custom-items");
if (customItemsSection != null) {
items.addAll(customItemsSection.getKeys(false));
}
var shipsSection = getConfig().getConfigurationSection("ships");
if (shipsSection != null) {
items.addAll(shipsSection.getKeys(false));
}
return items;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (!command.getName().equalsIgnoreCase("blockships")) {
Expand Down Expand Up @@ -522,15 +562,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
String subcommand = args[0].toLowerCase();

if (subcommand.equals("give") && sender.hasPermission("blockships.give")) {
// Complete with ship_wheel and ship types from config
List<String> types = new ArrayList<>();
types.add("ship_wheel");
var shipsSection = getConfig().getConfigurationSection("ships");
if (shipsSection != null) {
types.addAll(shipsSection.getKeys(false));
}

for (String type : types) {
for (String type : getGiveableItemNames()) {
if (type.toLowerCase().startsWith(args[1].toLowerCase())) {
completions.add(type);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package anon.def9a2a4.blockships;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.*;
Expand Down Expand Up @@ -74,4 +76,40 @@ private static String readFile(File file) throws IOException {
}
return result.toString(StandardCharsets.UTF_8);
}

/**
* Adds missing config keys from the bundled JAR config into the user's config.
* Only adds keys that don't exist — never overwrites existing values.
* Controlled by the "auto-migrate-config" setting (default: true).
*/
public static void migrateConfig(JavaPlugin plugin) {
if (!plugin.getConfig().getBoolean("auto-migrate-config", true)) {
return;
}

try (InputStream jarStream = plugin.getResource("config.yml")) {
if (jarStream == null) return;

YamlConfiguration jarConfig = YamlConfiguration.loadConfiguration(
new InputStreamReader(jarStream, StandardCharsets.UTF_8));

var diskConfig = plugin.getConfig();
int added = 0;

for (String key : jarConfig.getKeys(true)) {
if (!jarConfig.isConfigurationSection(key) && !diskConfig.contains(key)) {
diskConfig.set(key, jarConfig.get(key));
added++;
}
}

if (added > 0) {
plugin.saveConfig();
plugin.reloadConfig();
plugin.getLogger().info("Config migration: added " + added + " new config key(s)");
}
} catch (IOException e) {
plugin.getLogger().warning("Config migration failed: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ public class CustomItem {
private final Material baseMaterial;
private final String textureSet;
private final String variantSource;
private final boolean enchantGlint;
private final Plugin plugin;
private final ItemTextureManager textureManager;
private final NamespacedKey itemIdKey;
private final NamespacedKey variantKey;

public CustomItem(String id, String displayNameTemplate, Material baseMaterial,
String textureSet, String variantSource,
String textureSet, String variantSource, boolean enchantGlint,
Plugin plugin, ItemTextureManager textureManager) {
this.id = id;
this.displayNameTemplate = displayNameTemplate;
this.baseMaterial = baseMaterial;
this.textureSet = textureSet;
this.variantSource = variantSource;
this.enchantGlint = enchantGlint;
this.plugin = plugin;
this.textureManager = textureManager;
this.itemIdKey = new NamespacedKey(plugin, "custom_item_id");
Expand Down Expand Up @@ -89,6 +91,11 @@ public ItemStack create(String variant) {
}
}

// Apply enchantment glint
if (enchantGlint) {
meta.setEnchantmentGlintOverride(true);
}

item.setItemMeta(meta);
return item;
}
Expand Down
Loading
Loading