mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
remove all "config" things into it's own thing
This commit is contained in:
@@ -22,6 +22,7 @@ import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
|
|||||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||||
import lol.hyper.toolstats.events.*;
|
import lol.hyper.toolstats.events.*;
|
||||||
import lol.hyper.toolstats.tools.*;
|
import lol.hyper.toolstats.tools.*;
|
||||||
|
import lol.hyper.toolstats.tools.config.ConfigTools;
|
||||||
import lol.hyper.toolstats.tools.config.ConfigUpdater;
|
import lol.hyper.toolstats.tools.config.ConfigUpdater;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
@@ -106,7 +107,6 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
public final int CONFIG_VERSION = 6;
|
public final int CONFIG_VERSION = 6;
|
||||||
public final Logger logger = this.getLogger();
|
public final Logger logger = this.getLogger();
|
||||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||||
private final Pattern COLOR_CODES = Pattern.compile("(?i)&[0-9A-FK-ORX]");
|
|
||||||
|
|
||||||
public BlocksMined blocksMined;
|
public BlocksMined blocksMined;
|
||||||
public ChunkPopulate chunkPopulate;
|
public ChunkPopulate chunkPopulate;
|
||||||
@@ -131,6 +131,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
public CreativeEvent creativeEvent;
|
public CreativeEvent creativeEvent;
|
||||||
public ItemChecker itemChecker;
|
public ItemChecker itemChecker;
|
||||||
public ShootBow shootBow;
|
public ShootBow shootBow;
|
||||||
|
public ConfigTools configTools;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -160,6 +161,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
creativeEvent = new CreativeEvent(this);
|
creativeEvent = new CreativeEvent(this);
|
||||||
itemChecker = new ItemChecker();
|
itemChecker = new ItemChecker();
|
||||||
shootBow = new ShootBow(this);
|
shootBow = new ShootBow(this);
|
||||||
|
configTools = new ConfigTools(this);
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(blocksMined, this);
|
Bukkit.getServer().getPluginManager().registerEvents(blocksMined, this);
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
|
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
|
||||||
@@ -218,124 +220,6 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks the config to see if we want to show lore on certain items.
|
|
||||||
*
|
|
||||||
* @param material The item type to check.
|
|
||||||
* @param configName The config we are checking under.
|
|
||||||
* @return If we want to allow lore or not.
|
|
||||||
*/
|
|
||||||
public boolean checkConfig(Material material, String configName) {
|
|
||||||
String itemName = material.toString().toLowerCase();
|
|
||||||
String itemType = null;
|
|
||||||
// hardcode these
|
|
||||||
if (material == Material.BOW || material == Material.CROSSBOW || material == Material.SHEARS || material == Material.TRIDENT) {
|
|
||||||
if (material == Material.BOW) {
|
|
||||||
itemType = "bow";
|
|
||||||
}
|
|
||||||
if (material == Material.SHEARS) {
|
|
||||||
itemType = "shears";
|
|
||||||
}
|
|
||||||
if (material == Material.TRIDENT) {
|
|
||||||
itemType = "trident";
|
|
||||||
}
|
|
||||||
if (material == Material.CROSSBOW) {
|
|
||||||
itemType = "crossbow";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
itemType = itemName.substring(itemName.indexOf('_') + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (itemType) {
|
|
||||||
case "pickaxe": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".pickaxe");
|
|
||||||
}
|
|
||||||
case "sword": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".sword");
|
|
||||||
}
|
|
||||||
case "shovel": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".shovel");
|
|
||||||
}
|
|
||||||
case "axe": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".axe");
|
|
||||||
}
|
|
||||||
case "hoe": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".hoe");
|
|
||||||
}
|
|
||||||
case "shears": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".shears");
|
|
||||||
}
|
|
||||||
case "crossbow":
|
|
||||||
case "bow": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".bow");
|
|
||||||
}
|
|
||||||
case "trident": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".trident");
|
|
||||||
}
|
|
||||||
case "helmet":
|
|
||||||
case "chestplate":
|
|
||||||
case "leggings":
|
|
||||||
case "boots": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".armor");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the lore message from the config.
|
|
||||||
*
|
|
||||||
* @param configName The config name, "messages." is already in front.
|
|
||||||
* @param raw If you want the raw message with the formatting codes and placeholders.
|
|
||||||
* @return The lore message.
|
|
||||||
*/
|
|
||||||
public String getLoreFromConfig(String configName, boolean raw) {
|
|
||||||
String lore = config.getString("messages." + configName);
|
|
||||||
if (lore == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (raw) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', lore);
|
|
||||||
} else {
|
|
||||||
// remove all color codes
|
|
||||||
// this is used to compare the current lore on the item
|
|
||||||
// Example: [§7Arrows shot: §8] is on the lore
|
|
||||||
// this will return [Arrows shot: ] so we can match it
|
|
||||||
lore = COLOR_CODES.matcher(lore).replaceAll("");
|
|
||||||
if (lore.contains("{player}")) {
|
|
||||||
lore = lore.replace("{player}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{date}")) {
|
|
||||||
lore = lore.replace("{date}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{name}")) {
|
|
||||||
lore = lore.replace("{name}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{kills}")) {
|
|
||||||
lore = lore.replace("{kills}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{blocks}")) {
|
|
||||||
lore = lore.replace("{blocks}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{sheep}")) {
|
|
||||||
lore = lore.replace("{sheep}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{damage}")) {
|
|
||||||
lore = lore.replace("{damage}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{fish}")) {
|
|
||||||
lore = lore.replace("{fish}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{crops}")) {
|
|
||||||
lore = lore.replace("{crops}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{arrows}")) {
|
|
||||||
lore = lore.replace("{arrows}", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BukkitAudiences getAdventure() {
|
public BukkitAudiences getAdventure() {
|
||||||
if (this.adventure == null) {
|
if (this.adventure == null) {
|
||||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
PersistentDataContainer container = finalMeta.getPersistentDataContainer();
|
PersistentDataContainer container = finalMeta.getPersistentDataContainer();
|
||||||
List<String> lore = new ArrayList<>();
|
List<String> lore = new ArrayList<>();
|
||||||
|
|
||||||
String caughtByLore = toolStats.getLoreFromConfig("fished.caught-by", false);
|
String caughtByLore = toolStats.configTools.getLoreFromConfig("fished.caught-by", false);
|
||||||
String lootedByLore = toolStats.getLoreFromConfig("looted.found-by", false);
|
String lootedByLore = toolStats.configTools.getLoreFromConfig("looted.found-by", false);
|
||||||
String tradedByLore = toolStats.getLoreFromConfig("traded.traded-by", false);
|
String tradedByLore = toolStats.configTools.getLoreFromConfig("traded.traded-by", false);
|
||||||
String spawnedByLore = toolStats.getLoreFromConfig("spawned-in.spawned-by", false);
|
String spawnedByLore = toolStats.configTools.getLoreFromConfig("spawned-in.spawned-by", false);
|
||||||
|
|
||||||
// make sure the config messages are not null
|
// make sure the config messages are not null
|
||||||
if (caughtByLore == null || lootedByLore == null || tradedByLore == null || spawnedByLore == null) {
|
if (caughtByLore == null || lootedByLore == null || tradedByLore == null || spawnedByLore == null) {
|
||||||
@@ -145,11 +145,11 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
// hard code elytras
|
// hard code elytras
|
||||||
if (finalItem.getType() == Material.ELYTRA) {
|
if (finalItem.getType() == Material.ELYTRA) {
|
||||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||||
lore.add(toolStats.getLoreFromConfig("looted.found-by", true).replace("{player}", player.getName()));
|
lore.add(toolStats.configTools.getLoreFromConfig("looted.found-by", true).replace("{player}", player.getName()));
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||||
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||||
if (time != null) {
|
if (time != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("looted.found-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
lore.add(toolStats.configTools.getLoreFromConfig("looted.found-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finalMeta.setLore(lore);
|
finalMeta.setLore(lore);
|
||||||
@@ -160,7 +160,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolStats.checkConfig(original.getType(), "created-by")) {
|
if (toolStats.configTools.checkConfig(original.getType(), "created-by")) {
|
||||||
if (container.has(toolStats.genericOwner, new UUIDDataType())) {
|
if (container.has(toolStats.genericOwner, new UUIDDataType())) {
|
||||||
UUID owner = container.get(toolStats.genericOwner, new UUIDDataType());
|
UUID owner = container.get(toolStats.genericOwner, new UUIDDataType());
|
||||||
String ownerName = null;
|
String ownerName = null;
|
||||||
@@ -181,95 +181,95 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
// show how the item was created based on the previous lore
|
// show how the item was created based on the previous lore
|
||||||
switch (origin) {
|
switch (origin) {
|
||||||
case 0: {
|
case 0: {
|
||||||
lore.add(toolStats.getLoreFromConfig("created.created-by", true).replace("{player}", ownerName));
|
lore.add(toolStats.configTools.getLoreFromConfig("created.created-by", true).replace("{player}", ownerName));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
lore.add(toolStats.getLoreFromConfig("looted.looted-by", true).replace("{player}", ownerName));
|
lore.add(toolStats.configTools.getLoreFromConfig("looted.looted-by", true).replace("{player}", ownerName));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: {
|
case 3: {
|
||||||
lore.add(toolStats.getLoreFromConfig("traded.traded-by", true).replace("{player}", ownerName));
|
lore.add(toolStats.configTools.getLoreFromConfig("traded.traded-by", true).replace("{player}", ownerName));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 4: {
|
case 4: {
|
||||||
lore.add(toolStats.getLoreFromConfig("looted.found-by", true).replace("{player}", ownerName));
|
lore.add(toolStats.configTools.getLoreFromConfig("looted.found-by", true).replace("{player}", ownerName));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: {
|
case 5: {
|
||||||
lore.add(toolStats.getLoreFromConfig("fished.caught-by", true).replace("{player}", ownerName));
|
lore.add(toolStats.configTools.getLoreFromConfig("fished.caught-by", true).replace("{player}", ownerName));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 6: {
|
case 6: {
|
||||||
lore.add(toolStats.getLoreFromConfig("spawned-in.spawned-by", true).replace("{player}", ownerName));
|
lore.add(toolStats.configTools.getLoreFromConfig("spawned-in.spawned-by", true).replace("{player}", ownerName));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toolStats.checkConfig(original.getType(), "created-date")) {
|
if (toolStats.configTools.checkConfig(original.getType(), "created-date")) {
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||||
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||||
if (time != null) {
|
if (time != null) {
|
||||||
// show how when the item was created based on the previous lore
|
// show how when the item was created based on the previous lore
|
||||||
switch (origin) {
|
switch (origin) {
|
||||||
case 0: {
|
case 0: {
|
||||||
lore.add(toolStats.getLoreFromConfig("created.created-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
lore.add(toolStats.configTools.getLoreFromConfig("created.created-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
lore.add(toolStats.getLoreFromConfig("looted.looted-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
lore.add(toolStats.configTools.getLoreFromConfig("looted.looted-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: {
|
case 3: {
|
||||||
lore.add(toolStats.getLoreFromConfig("traded.traded-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
lore.add(toolStats.configTools.getLoreFromConfig("traded.traded-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 4: {
|
case 4: {
|
||||||
lore.add(toolStats.getLoreFromConfig("looted.found-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
lore.add(toolStats.configTools.getLoreFromConfig("looted.found-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: {
|
case 5: {
|
||||||
lore.add(toolStats.getLoreFromConfig("fished.caught-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
lore.add(toolStats.configTools.getLoreFromConfig("fished.caught-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 6: {
|
case 6: {
|
||||||
lore.add(toolStats.getLoreFromConfig("spawned-in.spawned-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
lore.add(toolStats.configTools.getLoreFromConfig("spawned-in.spawned-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toolStats.checkConfig(original.getType(), "player-kills")) {
|
if (toolStats.configTools.checkConfig(original.getType(), "player-kills")) {
|
||||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
||||||
Integer kills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
Integer kills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
||||||
if (kills != null) {
|
if (kills != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("kills.player", true).replace("{kills}", toolStats.numberFormat.formatInt(kills)));
|
lore.add(toolStats.configTools.getLoreFromConfig("kills.player", true).replace("{kills}", toolStats.numberFormat.formatInt(kills)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toolStats.checkConfig(original.getType(), "mob-kills")) {
|
if (toolStats.configTools.checkConfig(original.getType(), "mob-kills")) {
|
||||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
||||||
Integer kills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
Integer kills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
||||||
if (kills != null) {
|
if (kills != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("kills.mob", true).replace("{kills}", toolStats.numberFormat.formatInt(kills)));
|
lore.add(toolStats.configTools.getLoreFromConfig("kills.mob", true).replace("{kills}", toolStats.numberFormat.formatInt(kills)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toolStats.checkConfig(original.getType(), "blocks-mined")) {
|
if (toolStats.configTools.checkConfig(original.getType(), "blocks-mined")) {
|
||||||
if (original.getType().toString().toLowerCase(Locale.ROOT).contains("hoe")) {
|
if (original.getType().toString().toLowerCase(Locale.ROOT).contains("hoe")) {
|
||||||
if (container.has(toolStats.cropsHarvested, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.cropsHarvested, PersistentDataType.INTEGER)) {
|
||||||
Integer crops = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
|
Integer crops = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
|
||||||
if (crops != null) {
|
if (crops != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("crops-harvested", true).replace("{crops}", toolStats.numberFormat.formatInt(crops)));
|
lore.add(toolStats.configTools.getLoreFromConfig("crops-harvested", true).replace("{crops}", toolStats.numberFormat.formatInt(crops)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
||||||
Integer blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
Integer blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
||||||
if (blocksMined != null) {
|
if (blocksMined != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("blocks-mined", true).replace("{blocks}", toolStats.numberFormat.formatInt(blocksMined)));
|
lore.add(toolStats.configTools.getLoreFromConfig("blocks-mined", true).replace("{blocks}", toolStats.numberFormat.formatInt(blocksMined)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,7 +277,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
|
||||||
Integer fish = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
|
Integer fish = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
|
||||||
if (fish != null) {
|
if (fish != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("fished.fish-caught", true).replace("{fish}", toolStats.numberFormat.formatInt(fish)));
|
lore.add(toolStats.configTools.getLoreFromConfig("fished.fish-caught", true).replace("{fish}", toolStats.numberFormat.formatInt(fish)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,7 +285,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
|
||||||
Integer sheep = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
|
Integer sheep = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
|
||||||
if (sheep != null) {
|
if (sheep != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("sheep-sheared", true).replace("{sheep}", toolStats.numberFormat.formatInt(sheep)));
|
lore.add(toolStats.configTools.getLoreFromConfig("sheep-sheared", true).replace("{sheep}", toolStats.numberFormat.formatInt(sheep)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,7 +293,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.armorDamage, PersistentDataType.DOUBLE)) {
|
if (container.has(toolStats.armorDamage, PersistentDataType.DOUBLE)) {
|
||||||
Double damage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
Double damage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||||
if (damage != null) {
|
if (damage != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("damage-taken", true).replace("{damage}", toolStats.numberFormat.formatDouble(damage)));
|
lore.add(toolStats.configTools.getLoreFromConfig("damage-taken", true).replace("{damage}", toolStats.numberFormat.formatDouble(damage)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.arrowsShot, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.arrowsShot, PersistentDataType.INTEGER)) {
|
||||||
Integer arrows = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
Integer arrows = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||||
if (arrows != null) {
|
if (arrows != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("arrows-shot", true).replace("{arrows}", toolStats.numberFormat.formatInt(arrows)));
|
lore.add(toolStats.configTools.getLoreFromConfig("arrows-shot", true).replace("{arrows}", toolStats.numberFormat.formatInt(arrows)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public class BlocksMined implements Listener {
|
|||||||
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined);
|
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(playerTool.getType(), "blocks-mined")) {
|
if (toolStats.configTools.checkConfig(playerTool.getType(), "blocks-mined")) {
|
||||||
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{blocks}", blocksMinedFormatted, "blocks-mined");
|
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{blocks}", blocksMinedFormatted, "blocks-mined");
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
@@ -144,7 +144,7 @@ public class BlocksMined implements Listener {
|
|||||||
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined);
|
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(playerTool.getType(), "blocks-mined")) {
|
if (toolStats.configTools.checkConfig(playerTool.getType(), "blocks-mined")) {
|
||||||
String cropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
String cropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{crops}", cropsMinedFormatted, "crops-harvested");
|
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{crops}", cropsMinedFormatted, "crops-harvested");
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ public class CraftItem implements Listener {
|
|||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
}
|
}
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(itemStack.getType(), "created-date")) {
|
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-date")) {
|
||||||
String createdOnRaw = toolStats.getLoreFromConfig("created.created-on", true);
|
String createdOnRaw = toolStats.configTools.getLoreFromConfig("created.created-on", true);
|
||||||
if (createdOnRaw == null) {
|
if (createdOnRaw == null) {
|
||||||
toolStats.logger.warning("There is no lore message for messages.created.created-on!");
|
toolStats.logger.warning("There is no lore message for messages.created.created-on!");
|
||||||
return null;
|
return null;
|
||||||
@@ -130,8 +130,8 @@ public class CraftItem implements Listener {
|
|||||||
lore.add(createdOnRaw.replace("{date}", toolStats.numberFormat.formatDate(finalDate)));
|
lore.add(createdOnRaw.replace("{date}", toolStats.numberFormat.formatDate(finalDate)));
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
}
|
}
|
||||||
if (toolStats.checkConfig(itemStack.getType(), "created-by")) {
|
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-by")) {
|
||||||
String createdByRaw = toolStats.getLoreFromConfig("created.created-by", true);
|
String createdByRaw = toolStats.configTools.getLoreFromConfig("created.created-by", true);
|
||||||
if (createdByRaw == null) {
|
if (createdByRaw == null) {
|
||||||
toolStats.logger.warning("There is no lore message for messages.created.created-by!");
|
toolStats.logger.warning("There is no lore message for messages.created.created-by!");
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public class CreativeEvent implements Listener {
|
|||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||||
|
|
||||||
if (toolStats.checkConfig(newSpawnedItem.getType(), "spawned-in")) {
|
if (toolStats.configTools.checkConfig(newSpawnedItem.getType(), "spawned-in")) {
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ public class EntityDamage implements Listener {
|
|||||||
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
|
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(itemStack.getType(), "player-kills")) {
|
if (toolStats.configTools.checkConfig(itemStack.getType(), "player-kills")) {
|
||||||
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
|
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
@@ -279,7 +279,7 @@ public class EntityDamage implements Listener {
|
|||||||
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
|
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(itemStack.getType(), "mob-kills")) {
|
if (toolStats.configTools.checkConfig(itemStack.getType(), "mob-kills")) {
|
||||||
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
|
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
@@ -349,7 +349,7 @@ public class EntityDamage implements Listener {
|
|||||||
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
|
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(newTrident.getType(), "mob-kills")) {
|
if (toolStats.configTools.checkConfig(newTrident.getType(), "mob-kills")) {
|
||||||
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
|
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
@@ -385,7 +385,7 @@ public class EntityDamage implements Listener {
|
|||||||
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
|
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(newTrident.getType(), "player-kills")) {
|
if (toolStats.configTools.checkConfig(newTrident.getType(), "player-kills")) {
|
||||||
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
|
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class GenerateLoot implements Listener {
|
|||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||||
|
|
||||||
if (toolStats.checkConfig(newItem.getType(), "looted-tag")) {
|
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-tag")) {
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ public class PlayerFish implements Listener {
|
|||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||||
|
|
||||||
if (toolStats.checkConfig(newItem.getType(), "fished-tag")) {
|
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-tag")) {
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class VillagerTrade implements Listener {
|
|||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||||
|
|
||||||
if (toolStats.checkConfig(newItem.getType(), "traded-tag")) {
|
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-tag")) {
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ public class ItemLore {
|
|||||||
* @return The item's new lore.
|
* @return The item's new lore.
|
||||||
*/
|
*/
|
||||||
public List<String> addItemLore(ItemMeta itemMeta, String placeholder, String placeholderValue, String configLorePath) {
|
public List<String> addItemLore(ItemMeta itemMeta, String placeholder, String placeholderValue, String configLorePath) {
|
||||||
String configLore = toolStats.getLoreFromConfig(configLorePath, false);
|
String configLore = toolStats.configTools.getLoreFromConfig(configLorePath, false);
|
||||||
String configLoreRaw = toolStats.getLoreFromConfig(configLorePath, true);
|
String configLoreRaw = toolStats.configTools.getLoreFromConfig(configLorePath, true);
|
||||||
|
|
||||||
if (configLore == null || configLoreRaw == null) {
|
if (configLore == null || configLoreRaw == null) {
|
||||||
toolStats.logger.warning("There is no lore message for messages." + configLorePath + "!");
|
toolStats.logger.warning("There is no lore message for messages." + configLorePath + "!");
|
||||||
@@ -106,8 +106,8 @@ public class ItemLore {
|
|||||||
// set the lore based on the origin
|
// set the lore based on the origin
|
||||||
switch (origin) {
|
switch (origin) {
|
||||||
case 2: {
|
case 2: {
|
||||||
dateCreatedLore = toolStats.getLoreFromConfig("looted.looted-on", true);
|
dateCreatedLore = toolStats.configTools.getLoreFromConfig("looted.looted-on", true);
|
||||||
itemOwnerLore = toolStats.getLoreFromConfig("looted.looted-by", true);
|
itemOwnerLore = toolStats.configTools.getLoreFromConfig("looted.looted-by", true);
|
||||||
|
|
||||||
if (dateCreatedLore == null) {
|
if (dateCreatedLore == null) {
|
||||||
toolStats.logger.warning("messages.looted.looted-on is not set in your config!");
|
toolStats.logger.warning("messages.looted.looted-on is not set in your config!");
|
||||||
@@ -122,8 +122,8 @@ public class ItemLore {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: {
|
case 3: {
|
||||||
dateCreatedLore = toolStats.getLoreFromConfig("traded.traded-on", true);
|
dateCreatedLore = toolStats.configTools.getLoreFromConfig("traded.traded-on", true);
|
||||||
itemOwnerLore = toolStats.getLoreFromConfig("traded.traded-by", true);
|
itemOwnerLore = toolStats.configTools.getLoreFromConfig("traded.traded-by", true);
|
||||||
|
|
||||||
if (dateCreatedLore == null) {
|
if (dateCreatedLore == null) {
|
||||||
toolStats.logger.warning("messages.traded.traded-on is not set in your config!");
|
toolStats.logger.warning("messages.traded.traded-on is not set in your config!");
|
||||||
@@ -138,8 +138,8 @@ public class ItemLore {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 4: {
|
case 4: {
|
||||||
dateCreatedLore = toolStats.getLoreFromConfig("looted.found-on", true);
|
dateCreatedLore = toolStats.configTools.getLoreFromConfig("looted.found-on", true);
|
||||||
itemOwnerLore = toolStats.getLoreFromConfig("looted.found-by", true);
|
itemOwnerLore = toolStats.configTools.getLoreFromConfig("looted.found-by", true);
|
||||||
|
|
||||||
if (dateCreatedLore == null) {
|
if (dateCreatedLore == null) {
|
||||||
toolStats.logger.warning("messages.looted.found-on is not set in your config!");
|
toolStats.logger.warning("messages.looted.found-on is not set in your config!");
|
||||||
@@ -154,8 +154,8 @@ public class ItemLore {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: {
|
case 5: {
|
||||||
dateCreatedLore = toolStats.getLoreFromConfig("fished.caught-on", true);
|
dateCreatedLore = toolStats.configTools.getLoreFromConfig("fished.caught-on", true);
|
||||||
itemOwnerLore = toolStats.getLoreFromConfig("fished.caught-by", true);
|
itemOwnerLore = toolStats.configTools.getLoreFromConfig("fished.caught-by", true);
|
||||||
|
|
||||||
if (dateCreatedLore == null) {
|
if (dateCreatedLore == null) {
|
||||||
toolStats.logger.warning("messages.fished.caught-on is not set in your config!");
|
toolStats.logger.warning("messages.fished.caught-on is not set in your config!");
|
||||||
@@ -170,8 +170,8 @@ public class ItemLore {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 6: {
|
case 6: {
|
||||||
dateCreatedLore = toolStats.getLoreFromConfig("spawned-in.spawned-on", true);
|
dateCreatedLore = toolStats.configTools.getLoreFromConfig("spawned-in.spawned-on", true);
|
||||||
itemOwnerLore = toolStats.getLoreFromConfig("spawned-in.spawned-by", true);
|
itemOwnerLore = toolStats.configTools.getLoreFromConfig("spawned-in.spawned-by", true);
|
||||||
|
|
||||||
if (dateCreatedLore == null) {
|
if (dateCreatedLore == null) {
|
||||||
toolStats.logger.warning("messages.spawned-in.spawned-on is not set in your config!");
|
toolStats.logger.warning("messages.spawned-in.spawned-on is not set in your config!");
|
||||||
@@ -219,12 +219,12 @@ public class ItemLore {
|
|||||||
lore = itemMeta.getLore();
|
lore = itemMeta.getLore();
|
||||||
Integer origin = null;
|
Integer origin = null;
|
||||||
|
|
||||||
String createdBy = toolStats.getLoreFromConfig("created.created-by", false);
|
String createdBy = toolStats.configTools.getLoreFromConfig("created.created-by", false);
|
||||||
String createdOn = toolStats.getLoreFromConfig("created.created-on", false);
|
String createdOn = toolStats.configTools.getLoreFromConfig("created.created-on", false);
|
||||||
String caughtBy = toolStats.getLoreFromConfig("fished.caught-by", false);
|
String caughtBy = toolStats.configTools.getLoreFromConfig("fished.caught-by", false);
|
||||||
String lootedBy = toolStats.getLoreFromConfig("looted.looted-by", false);
|
String lootedBy = toolStats.configTools.getLoreFromConfig("looted.looted-by", false);
|
||||||
String foundBy = toolStats.getLoreFromConfig("looted.found-by", false);
|
String foundBy = toolStats.configTools.getLoreFromConfig("looted.found-by", false);
|
||||||
String tradedBy = toolStats.getLoreFromConfig("traded.traded-by", false);
|
String tradedBy = toolStats.configTools.getLoreFromConfig("traded.traded-by", false);
|
||||||
|
|
||||||
for (String line : lore) {
|
for (String line : lore) {
|
||||||
// this is the worst code I have ever written
|
// this is the worst code I have ever written
|
||||||
|
|||||||
162
src/main/java/lol/hyper/toolstats/tools/config/ConfigTools.java
Normal file
162
src/main/java/lol/hyper/toolstats/tools/config/ConfigTools.java
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class ConfigTools {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
private final Pattern COLOR_CODES = Pattern.compile("(?i)&[0-9A-FK-ORX]");
|
||||||
|
|
||||||
|
public ConfigTools(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the config to see if we want to show lore on certain items.
|
||||||
|
*
|
||||||
|
* @param material The item type to check.
|
||||||
|
* @param configName The config we are checking under.
|
||||||
|
* @return If we want to allow lore or not.
|
||||||
|
*/
|
||||||
|
public boolean checkConfig(Material material, String configName) {
|
||||||
|
String itemName = material.toString().toLowerCase();
|
||||||
|
String itemType = null;
|
||||||
|
// hardcode these
|
||||||
|
if (material == Material.BOW || material == Material.CROSSBOW || material == Material.SHEARS || material == Material.TRIDENT || material == Material.FISHING_ROD) {
|
||||||
|
switch (material) {
|
||||||
|
case CROSSBOW:
|
||||||
|
case BOW: {
|
||||||
|
itemType = "bow";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SHEARS: {
|
||||||
|
itemType = "shears";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TRIDENT: {
|
||||||
|
itemType = "trident";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FISHING_ROD: {
|
||||||
|
itemType = "fishing-rod";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
itemType = itemName.substring(itemName.indexOf('_') + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (itemType) {
|
||||||
|
case "pickaxe": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".pickaxe");
|
||||||
|
}
|
||||||
|
case "sword": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".sword");
|
||||||
|
}
|
||||||
|
case "shovel": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".shovel");
|
||||||
|
}
|
||||||
|
case "axe": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".axe");
|
||||||
|
}
|
||||||
|
case "hoe": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".hoe");
|
||||||
|
}
|
||||||
|
case "shears": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".shears");
|
||||||
|
}
|
||||||
|
case "crossbow":
|
||||||
|
case "bow": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".bow");
|
||||||
|
}
|
||||||
|
case "trident": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".trident");
|
||||||
|
}
|
||||||
|
case "fishing-rod": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||||
|
}
|
||||||
|
case "helmet":
|
||||||
|
case "chestplate":
|
||||||
|
case "leggings":
|
||||||
|
case "boots": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".armor");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the lore message from the config.
|
||||||
|
*
|
||||||
|
* @param configName The config name, "messages." is already in front.
|
||||||
|
* @param raw If you want the raw message with the formatting codes and placeholders.
|
||||||
|
* @return The lore message.
|
||||||
|
*/
|
||||||
|
public String getLoreFromConfig(String configName, boolean raw) {
|
||||||
|
String lore = toolStats.config.getString("messages." + configName);
|
||||||
|
if (lore == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (raw) {
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', lore);
|
||||||
|
} else {
|
||||||
|
// remove all color codes
|
||||||
|
// this is used to compare the current lore on the item
|
||||||
|
// Example: [§7Arrows shot: §8] is on the lore
|
||||||
|
// this will return [Arrows shot: ] so we can match it
|
||||||
|
lore = COLOR_CODES.matcher(lore).replaceAll("");
|
||||||
|
if (lore.contains("{player}")) {
|
||||||
|
lore = lore.replace("{player}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{date}")) {
|
||||||
|
lore = lore.replace("{date}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{name}")) {
|
||||||
|
lore = lore.replace("{name}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{kills}")) {
|
||||||
|
lore = lore.replace("{kills}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{blocks}")) {
|
||||||
|
lore = lore.replace("{blocks}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{sheep}")) {
|
||||||
|
lore = lore.replace("{sheep}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{damage}")) {
|
||||||
|
lore = lore.replace("{damage}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{fish}")) {
|
||||||
|
lore = lore.replace("{fish}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{crops}")) {
|
||||||
|
lore = lore.replace("{crops}", "");
|
||||||
|
}
|
||||||
|
if (lore.contains("{arrows}")) {
|
||||||
|
lore = lore.replace("{arrows}", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user