mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-10 22:55:04 +00:00
remove all "config" things into it's own thing
This commit is contained in:
@@ -42,8 +42,8 @@ public class ItemLore {
|
||||
* @return The item's new lore.
|
||||
*/
|
||||
public List<String> addItemLore(ItemMeta itemMeta, String placeholder, String placeholderValue, String configLorePath) {
|
||||
String configLore = toolStats.getLoreFromConfig(configLorePath, false);
|
||||
String configLoreRaw = toolStats.getLoreFromConfig(configLorePath, true);
|
||||
String configLore = toolStats.configTools.getLoreFromConfig(configLorePath, false);
|
||||
String configLoreRaw = toolStats.configTools.getLoreFromConfig(configLorePath, true);
|
||||
|
||||
if (configLore == null || configLoreRaw == null) {
|
||||
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
|
||||
switch (origin) {
|
||||
case 2: {
|
||||
dateCreatedLore = toolStats.getLoreFromConfig("looted.looted-on", true);
|
||||
itemOwnerLore = toolStats.getLoreFromConfig("looted.looted-by", true);
|
||||
dateCreatedLore = toolStats.configTools.getLoreFromConfig("looted.looted-on", true);
|
||||
itemOwnerLore = toolStats.configTools.getLoreFromConfig("looted.looted-by", true);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.looted.looted-on is not set in your config!");
|
||||
@@ -122,8 +122,8 @@ public class ItemLore {
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
dateCreatedLore = toolStats.getLoreFromConfig("traded.traded-on", true);
|
||||
itemOwnerLore = toolStats.getLoreFromConfig("traded.traded-by", true);
|
||||
dateCreatedLore = toolStats.configTools.getLoreFromConfig("traded.traded-on", true);
|
||||
itemOwnerLore = toolStats.configTools.getLoreFromConfig("traded.traded-by", true);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.traded.traded-on is not set in your config!");
|
||||
@@ -138,8 +138,8 @@ public class ItemLore {
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
dateCreatedLore = toolStats.getLoreFromConfig("looted.found-on", true);
|
||||
itemOwnerLore = toolStats.getLoreFromConfig("looted.found-by", true);
|
||||
dateCreatedLore = toolStats.configTools.getLoreFromConfig("looted.found-on", true);
|
||||
itemOwnerLore = toolStats.configTools.getLoreFromConfig("looted.found-by", true);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.looted.found-on is not set in your config!");
|
||||
@@ -154,8 +154,8 @@ public class ItemLore {
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
dateCreatedLore = toolStats.getLoreFromConfig("fished.caught-on", true);
|
||||
itemOwnerLore = toolStats.getLoreFromConfig("fished.caught-by", true);
|
||||
dateCreatedLore = toolStats.configTools.getLoreFromConfig("fished.caught-on", true);
|
||||
itemOwnerLore = toolStats.configTools.getLoreFromConfig("fished.caught-by", true);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.fished.caught-on is not set in your config!");
|
||||
@@ -170,8 +170,8 @@ public class ItemLore {
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
dateCreatedLore = toolStats.getLoreFromConfig("spawned-in.spawned-on", true);
|
||||
itemOwnerLore = toolStats.getLoreFromConfig("spawned-in.spawned-by", true);
|
||||
dateCreatedLore = toolStats.configTools.getLoreFromConfig("spawned-in.spawned-on", true);
|
||||
itemOwnerLore = toolStats.configTools.getLoreFromConfig("spawned-in.spawned-by", true);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.spawned-in.spawned-on is not set in your config!");
|
||||
@@ -219,12 +219,12 @@ public class ItemLore {
|
||||
lore = itemMeta.getLore();
|
||||
Integer origin = null;
|
||||
|
||||
String createdBy = toolStats.getLoreFromConfig("created.created-by", false);
|
||||
String createdOn = toolStats.getLoreFromConfig("created.created-on", false);
|
||||
String caughtBy = toolStats.getLoreFromConfig("fished.caught-by", false);
|
||||
String lootedBy = toolStats.getLoreFromConfig("looted.looted-by", false);
|
||||
String foundBy = toolStats.getLoreFromConfig("looted.found-by", false);
|
||||
String tradedBy = toolStats.getLoreFromConfig("traded.traded-by", false);
|
||||
String createdBy = toolStats.configTools.getLoreFromConfig("created.created-by", false);
|
||||
String createdOn = toolStats.configTools.getLoreFromConfig("created.created-on", false);
|
||||
String caughtBy = toolStats.configTools.getLoreFromConfig("fished.caught-by", false);
|
||||
String lootedBy = toolStats.configTools.getLoreFromConfig("looted.looted-by", false);
|
||||
String foundBy = toolStats.configTools.getLoreFromConfig("looted.found-by", false);
|
||||
String tradedBy = toolStats.configTools.getLoreFromConfig("traded.traded-by", false);
|
||||
|
||||
for (String line : lore) {
|
||||
// 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