diff --git a/src/main/java/lol/hyper/toolstats/ToolStats.java b/src/main/java/lol/hyper/toolstats/ToolStats.java index 80dc721..5dced8f 100644 --- a/src/main/java/lol/hyper/toolstats/ToolStats.java +++ b/src/main/java/lol/hyper/toolstats/ToolStats.java @@ -113,7 +113,7 @@ public final class ToolStats extends JavaPlugin { */ public final NamespacedKey originType = new NamespacedKey(this, "origin"); - public final int CONFIG_VERSION = 7; + public final int CONFIG_VERSION = 8; public final Logger logger = this.getLogger(); public final File configFile = new File(this.getDataFolder(), "config.yml"); diff --git a/src/main/java/lol/hyper/toolstats/events/EntityDeath.java b/src/main/java/lol/hyper/toolstats/events/EntityDeath.java index 7e266d8..b6bfaef 100644 --- a/src/main/java/lol/hyper/toolstats/events/EntityDeath.java +++ b/src/main/java/lol/hyper/toolstats/events/EntityDeath.java @@ -29,7 +29,8 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import java.util.*; +import java.util.List; +import java.util.UUID; public class EntityDeath implements Listener { @@ -59,7 +60,7 @@ public class EntityDeath implements Listener { } if (toolStats.itemChecker.isValidItem(droppedItem.getType())) { - ItemStack newItem = addLore(droppedItem, livingEntity.getName()); + ItemStack newItem = addLore(droppedItem, livingEntity); if (newItem != null) { event.getDrops().set(i, newItem); } @@ -73,9 +74,9 @@ public class EntityDeath implements Listener { * Adds "drop by" tag to item. * * @param oldItem The item to add lore to. - * @param mob The mob or player name. + * @param entity The mob dying. */ - private ItemStack addLore(ItemStack oldItem, String mob) { + private ItemStack addLore(ItemStack oldItem, LivingEntity entity) { ItemStack newItem = oldItem.clone(); ItemMeta meta = newItem.getItemMeta(); if (meta == null) { @@ -86,7 +87,13 @@ public class EntityDeath implements Listener { container.set(toolStats.originType, PersistentDataType.INTEGER, 1); if (toolStats.config.getBoolean("enabled.dropped-by")) { - String newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mob); + String mobName = toolStats.config.getString("messages.mob." + entity.getType()); + toolStats.logger.info("messages.mob." + entity.getType()); + toolStats.logger.info(mobName); + if (mobName == null) { + mobName = entity.getName(); + } + String newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName); List newLore = toolStats.itemLore.addItemLore(meta, newLine); meta.setLore(newLore); } diff --git a/src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java b/src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java index afc4d2b..0bd15c4 100644 --- a/src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java +++ b/src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java @@ -37,6 +37,7 @@ package lol.hyper.toolstats.tools.config; import lol.hyper.toolstats.ToolStats; import lol.hyper.toolstats.tools.config.versions.Version6; import lol.hyper.toolstats.tools.config.versions.Version7; +import lol.hyper.toolstats.tools.config.versions.Version8; public class ConfigUpdater { @@ -49,17 +50,22 @@ public class ConfigUpdater { public void updateConfig() { int version = toolStats.config.getInt("config-version"); - // this will be a switch in the future - // Upgrade 5 to 6 - if (version == 5) { - Version6 version6 = new Version6(toolStats); - version6.update(); - } - - // Upgrade 6 to 7 - if (version == 6) { - Version7 version7 = new Version7(toolStats); - version7.update(); + switch(version) { + case 5: { + // Version 5 to 6 + Version6 version6 = new Version6(toolStats); + version6.update(); + } + case 6: { + // Version 6 to 7 + Version7 version7 = new Version7(toolStats); + version7.update(); + } + case 7: { + // Version 7 to 8 + Version8 version8 = new Version8(toolStats); + version8.update(); + } } } } diff --git a/src/main/java/lol/hyper/toolstats/tools/config/versions/Version7.java b/src/main/java/lol/hyper/toolstats/tools/config/versions/Version7.java index 3d8c2ae..dd638c3 100644 --- a/src/main/java/lol/hyper/toolstats/tools/config/versions/Version7.java +++ b/src/main/java/lol/hyper/toolstats/tools/config/versions/Version7.java @@ -43,7 +43,7 @@ public class Version7 { try { toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml"); } catch (IOException exception) { - toolStats.logger.severe("Unable to save config-5.yml!"); + toolStats.logger.severe("Unable to save config-6.yml!"); throw new RuntimeException(exception); } @@ -65,6 +65,6 @@ public class Version7 { throw new RuntimeException(exception); } toolStats.loadConfig(); - toolStats.logger.info("Config has been updated to version 7. A copy of version 5 has been saved as config-6.yml"); + toolStats.logger.info("Config has been updated to version 7. A copy of version 6 has been saved as config-6.yml"); } } diff --git a/src/main/java/lol/hyper/toolstats/tools/config/versions/Version8.java b/src/main/java/lol/hyper/toolstats/tools/config/versions/Version8.java new file mode 100644 index 0000000..ebc10b7 --- /dev/null +++ b/src/main/java/lol/hyper/toolstats/tools/config/versions/Version8.java @@ -0,0 +1,75 @@ +/* + * This file is part of ToolStats. + * + * ToolStats 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. + * + * ToolStats 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 + * along with ToolStats. If not, see . + */ + +package lol.hyper.toolstats.tools.config.versions; + +import lol.hyper.toolstats.ToolStats; +import org.bukkit.configuration.ConfigurationSection; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Version8 { + + private final ToolStats toolStats; + + /** + * Used for updating from version 7 to 8. + * + * @param toolStats ToolStats instance. + */ + public Version8(ToolStats toolStats) { + this.toolStats = toolStats; + } + + /** + * Perform the config update. + */ + public void update() { + // save the old config first + try { + toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-7.yml"); + } catch (IOException exception) { + toolStats.logger.severe("Unable to save config-7.yml!"); + throw new RuntimeException(exception); + } + + // we make this super verbose so that admins can see what's being added + toolStats.logger.info("Updating config.yml to version 8."); + toolStats.config.set("config-version", 8); + + // Add example to setting mob names + toolStats.logger.info("Adding example for messages.mob.ZOMBIE"); + toolStats.config.set("messages.mob.ZOMBIE", "Zombie"); + + List mobComments = new ArrayList<>(); + mobComments.add("Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html"); + toolStats.config.setComments("messages.mob", mobComments); + + // save the config and reload it + try { + toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml"); + } catch (IOException exception) { + toolStats.logger.severe("Unable to save config.yml!"); + throw new RuntimeException(exception); + } + toolStats.loadConfig(); + toolStats.logger.info("Config has been updated to version 8. A copy of version 7 has been saved as config-7.yml"); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 45df9e4..10c3f5f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -117,6 +117,9 @@ messages: shift-click-warning: crafting: "&cCrafting items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API." trading: "&cTrading items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API." + # Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html + mobs: + ZOMBIE: "Zombie" # Change the default formatting for dates. # See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format