mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50b5823daf | ||
|
|
c87d0ca3bf | ||
|
|
d1a16ff2e6 | ||
|
|
9134da31f4 | ||
|
|
0cf85edda6 | ||
|
|
7fe0234785 | ||
|
|
6385814b52 | ||
|
|
603e1ac1fd | ||
|
|
86dc5f421a | ||
|
|
7d9be0cfd1 | ||
|
|
f7bacec617 | ||
|
|
227723fe10 | ||
|
|
785333e8d1 | ||
|
|
bc784b8d46 | ||
|
|
f5ddada892 | ||
|
|
a43155b0c5 | ||
|
|
e327d132e2 | ||
|
|
f09f2d3703 |
@@ -6,6 +6,7 @@
|
|||||||
<a href="https://github.com/hyperdefined/ToolStats/releases"><img src="https://img.shields.io/github/downloads/hyperdefined/ToolStats/total?logo=github" alt="Downloads"></a>
|
<a href="https://github.com/hyperdefined/ToolStats/releases"><img src="https://img.shields.io/github/downloads/hyperdefined/ToolStats/total?logo=github" alt="Downloads"></a>
|
||||||
<img src="https://img.shields.io/badge/made%20with-love%20&%20fluff-red" alt="Made with love & fluff">
|
<img src="https://img.shields.io/badge/made%20with-love%20&%20fluff-red" alt="Made with love & fluff">
|
||||||
<a href="https://ko-fi.com/hyperdefined"><img src="https://img.shields.io/badge/Donate-Ko--fi-red" alt="Donate via Ko-fi"></a>
|
<a href="https://ko-fi.com/hyperdefined"><img src="https://img.shields.io/badge/Donate-Ko--fi-red" alt="Donate via Ko-fi"></a>
|
||||||
|
<img alt="Discord" src="https://img.shields.io/discord/1267600843356639413?style=flat&logo=discord&label=Discord">
|
||||||
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
|
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
|
||||||
<a href="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4"><img src="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4.svg" alt="wakatime"></a>
|
<a href="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4"><img src="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4.svg" alt="wakatime"></a>
|
||||||
</p>
|
</p>
|
||||||
@@ -42,5 +43,8 @@ If item lore is ever incorrect/missing, you can run `/toolstats reset`. This com
|
|||||||
## Documentation
|
## Documentation
|
||||||
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
|
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
You can join the [Discord](https://discord.gg/rJuQXVcJz8) for support.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).
|
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<groupId>lol.hyper</groupId>
|
<groupId>lol.hyper</groupId>
|
||||||
<artifactId>toolstats</artifactId>
|
<artifactId>toolstats</artifactId>
|
||||||
<version>1.8</version>
|
<version>1.8.3</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ToolStats</name>
|
<name>ToolStats</name>
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>3.0.3</version>
|
<version>3.1.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
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 Logger logger = this.getLogger();
|
||||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,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) {
|
||||||
toolStats.configTools.formatLore("damage-taken", "{damage}", toolStats.numberFormat.formatDouble(damage));
|
lore.add(toolStats.configTools.formatLore("damage-taken", "{damage}", toolStats.numberFormat.formatDouble(damage)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,7 +305,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) {
|
||||||
toolStats.configTools.formatLore("arrows-shot", "{arrows}", toolStats.numberFormat.formatInt(arrows));
|
lore.add(toolStats.configTools.formatLore("arrows-shot", "{arrows}", toolStats.numberFormat.formatInt(arrows)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class EntityDamage implements Listener {
|
|||||||
|
|
||||||
private final ToolStats toolStats;
|
private final ToolStats toolStats;
|
||||||
public final Set<UUID> trackedMobs = new HashSet<>();
|
public final Set<UUID> trackedMobs = new HashSet<>();
|
||||||
private final List<EntityDamageEvent.DamageCause> ignoredCauses = Arrays.asList(EntityDamageEvent.DamageCause.SUICIDE, EntityDamageEvent.DamageCause.VOID, EntityDamageEvent.DamageCause.CUSTOM, EntityDamageEvent.DamageCause.KILL);
|
private final List<String> ignoredDamageCauses = Arrays.asList("SUICIDE", "VOID", "CUSTOM", "KILL");
|
||||||
|
|
||||||
public EntityDamage(ToolStats toolStats) {
|
public EntityDamage(ToolStats toolStats) {
|
||||||
this.toolStats = toolStats;
|
this.toolStats = toolStats;
|
||||||
@@ -57,8 +57,8 @@ public class EntityDamage implements Listener {
|
|||||||
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
||||||
|
|
||||||
// ignore void and /kill damage
|
// ignore void and /kill damage
|
||||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
String cause = event.getCause().toString().toUpperCase();
|
||||||
if (ignoredCauses.contains(cause)) {
|
if (ignoredDamageCauses.contains(cause)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,8 +166,8 @@ public class EntityDamage implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ignore void and /kill damage
|
// ignore void and /kill damage
|
||||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
String cause = event.getCause().toString().toUpperCase();
|
||||||
if (ignoredCauses.contains(cause)) {
|
if (ignoredDamageCauses.contains(cause)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,8 +196,8 @@ public class EntityDamage implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ignore void and /kill damage
|
// ignore void and /kill damage
|
||||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
String cause = event.getCause().toString().toUpperCase();
|
||||||
if (ignoredCauses.contains(cause)) {
|
if (ignoredDamageCauses.contains(cause)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +324,6 @@ public class EntityDamage implements Listener {
|
|||||||
toolStats.logger.warning(itemStack + " does not have valid damage-taken set! Resting to zero. This should NEVER happen.");
|
toolStats.logger.warning(itemStack + " does not have valid damage-taken set! Resting to zero. This should NEVER happen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
damageTaken = damageTaken + damage;
|
|
||||||
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
|
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||||
@@ -368,8 +367,8 @@ public class EntityDamage implements Listener {
|
|||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.configTools.checkConfig(newTrident.getType(), "mob-kills")) {
|
if (toolStats.configTools.checkConfig(newTrident.getType(), "mob-kills")) {
|
||||||
String oldMobKillsFormatted = toolStats.numberFormat.formatDouble(mobKills);
|
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||||
String newMobKillsFormatted = toolStats.numberFormat.formatDouble(mobKills + 1);
|
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + 1);
|
||||||
String oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
String oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||||
String newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
|
String newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
|
||||||
if (oldLine == null || newLine == null) {
|
if (oldLine == null || newLine == null) {
|
||||||
@@ -409,8 +408,8 @@ public class EntityDamage implements Listener {
|
|||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.configTools.checkConfig(newTrident.getType(), "player-kills")) {
|
if (toolStats.configTools.checkConfig(newTrident.getType(), "player-kills")) {
|
||||||
String oldPlayerKillsFormatted = toolStats.numberFormat.formatDouble(playerKills);
|
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||||
String newPlayerKillsFormatted = toolStats.numberFormat.formatDouble(playerKills + 1);
|
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + 1);
|
||||||
String oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
String oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||||
String newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
|
String newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
|
||||||
if (oldLine == null || newLine == null) {
|
if (oldLine == null || newLine == null) {
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class EntityDeath implements Listener {
|
public class EntityDeath implements Listener {
|
||||||
|
|
||||||
@@ -53,13 +54,13 @@ public class EntityDeath implements Listener {
|
|||||||
ItemMeta droppedItemMeta = droppedItem.getItemMeta();
|
ItemMeta droppedItemMeta = droppedItem.getItemMeta();
|
||||||
if (droppedItemMeta != null) {
|
if (droppedItemMeta != null) {
|
||||||
PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer();
|
PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer();
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||||
continue; // ignore any items that have our tags
|
continue; // ignore any items that have our tags
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (toolStats.itemChecker.isValidItem(droppedItem.getType())) {
|
if (toolStats.itemChecker.isValidItem(droppedItem.getType())) {
|
||||||
ItemStack newItem = addLore(droppedItem, livingEntity.getName());
|
ItemStack newItem = addLore(droppedItem, livingEntity);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
event.getDrops().set(i, newItem);
|
event.getDrops().set(i, newItem);
|
||||||
}
|
}
|
||||||
@@ -73,9 +74,9 @@ public class EntityDeath implements Listener {
|
|||||||
* Adds "drop by" tag to item.
|
* Adds "drop by" tag to item.
|
||||||
*
|
*
|
||||||
* @param oldItem The item to add lore to.
|
* @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();
|
ItemStack newItem = oldItem.clone();
|
||||||
ItemMeta meta = newItem.getItemMeta();
|
ItemMeta meta = newItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
@@ -86,7 +87,11 @@ public class EntityDeath implements Listener {
|
|||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
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());
|
||||||
|
if (mobName == null) {
|
||||||
|
mobName = entity.getName();
|
||||||
|
}
|
||||||
|
String newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
List<String> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,13 +86,14 @@ public class PlayerMove implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the duration of the flight
|
// get the duration of the flight
|
||||||
long duration = (System.currentTimeMillis() - startTime) + flightTime;
|
long duration = (System.currentTimeMillis() - startTime);
|
||||||
|
double newDuration = flightTime + duration;
|
||||||
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
|
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||||
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
||||||
String newFlightFormatted = toolStats.numberFormat.formatDouble((double) (flightTime + duration) / 1000);
|
String newFlightFormatted = toolStats.numberFormat.formatDouble(newDuration / 1000);
|
||||||
String oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
String oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
||||||
String newLine = toolStats.configTools.formatLore("flight-time", "{time}", newFlightFormatted);
|
String newLine = toolStats.configTools.formatLore("flight-time", "{time}", newFlightFormatted);
|
||||||
if (oldLine == null || newLine == null) {
|
if (oldLine == null || newLine == null) {
|
||||||
|
|||||||
@@ -64,15 +64,14 @@ public class SheepShear implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sheep sheep = (Sheep) entity;
|
|
||||||
// make sure the sheep is not sheared
|
// make sure the sheep is not sheared
|
||||||
|
Sheep sheep = (Sheep) entity;
|
||||||
if (sheep.isSheared()) {
|
if (sheep.isSheared()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the stats
|
// update the stats
|
||||||
ItemStack finalShears = shears;
|
addLore(shears);
|
||||||
addLore(finalShears);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable ItemStack getShears(Player player) {
|
private static @Nullable ItemStack getShears(Player player) {
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ public class ItemChecker {
|
|||||||
if (lowerCase.contains("_helmet") || lowerCase.contains("_chestplate") || lowerCase.contains("_leggings") || lowerCase.contains("_boots")) {
|
if (lowerCase.contains("_helmet") || lowerCase.contains("_chestplate") || lowerCase.contains("_leggings") || lowerCase.contains("_boots")) {
|
||||||
armorItems.add(material);
|
armorItems.add(material);
|
||||||
}
|
}
|
||||||
|
if (lowerCase.equalsIgnoreCase("mace")) {
|
||||||
|
meleeItems.add(material);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hardcode these
|
// hardcode these
|
||||||
|
|||||||
@@ -24,13 +24,10 @@ import org.bukkit.persistence.PersistentDataType;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class ItemLore {
|
public class ItemLore {
|
||||||
|
|
||||||
private final ToolStats toolStats;
|
private final ToolStats toolStats;
|
||||||
public static final Pattern COLOR_CODES = Pattern.compile("[&§]([0-9a-fk-or])");
|
|
||||||
public static final Pattern HEX_PATTERN = Pattern.compile("[&§]#([A-Fa-f0-9]{6})");
|
|
||||||
|
|
||||||
public ItemLore(ToolStats toolStats) {
|
public ItemLore(ToolStats toolStats) {
|
||||||
this.toolStats = toolStats;
|
this.toolStats = toolStats;
|
||||||
|
|||||||
@@ -18,15 +18,18 @@
|
|||||||
package lol.hyper.toolstats.tools.config;
|
package lol.hyper.toolstats.tools.config;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.ItemLore;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class ConfigTools {
|
public class ConfigTools {
|
||||||
|
|
||||||
private final ToolStats toolStats;
|
private final ToolStats toolStats;
|
||||||
|
public static final Pattern COLOR_CODES = Pattern.compile("[&§]([0-9a-fk-or])");
|
||||||
|
public static final Pattern CONFIG_HEX_PATTERN = Pattern.compile("[&§]#([A-Fa-f0-9]{6})");
|
||||||
|
public static final Pattern MINECRAFT_HEX_PATTERN = Pattern.compile("§x(?:§[a-fA-F0-9]){6}|§[a-fA-F0-9]");
|
||||||
|
|
||||||
public ConfigTools(ToolStats toolStats) {
|
public ConfigTools(ToolStats toolStats) {
|
||||||
this.toolStats = toolStats;
|
this.toolStats = toolStats;
|
||||||
@@ -96,6 +99,9 @@ public class ConfigTools {
|
|||||||
case "fishing-rod": {
|
case "fishing-rod": {
|
||||||
return toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
return toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||||
}
|
}
|
||||||
|
case "mace": {
|
||||||
|
return toolStats.config.getBoolean("enabled." + configName + ".mace");
|
||||||
|
}
|
||||||
case "helmet":
|
case "helmet":
|
||||||
case "chestplate":
|
case "chestplate":
|
||||||
case "leggings":
|
case "leggings":
|
||||||
@@ -123,13 +129,13 @@ public class ConfigTools {
|
|||||||
// set the placeholder to the value
|
// set the placeholder to the value
|
||||||
lore = lore.replace(placeHolder, String.valueOf(value));
|
lore = lore.replace(placeHolder, String.valueOf(value));
|
||||||
|
|
||||||
Matcher hexMatcher = ItemLore.HEX_PATTERN.matcher(lore);
|
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(lore);
|
||||||
while (hexMatcher.find()) {
|
while (hexMatcher.find()) {
|
||||||
String hexCode = hexMatcher.group(1);
|
String hexCode = hexMatcher.group(1);
|
||||||
lore = lore.replaceAll(hexMatcher.group(), net.md_5.bungee.api.ChatColor.of("#" + hexCode).toString());
|
lore = lore.replaceAll(hexMatcher.group(), net.md_5.bungee.api.ChatColor.of("#" + hexCode).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher colorMatcher = ItemLore.COLOR_CODES.matcher(lore);
|
Matcher colorMatcher = COLOR_CODES.matcher(lore);
|
||||||
while (colorMatcher.find()) {
|
while (colorMatcher.find()) {
|
||||||
String colorCode = colorMatcher.group(1);
|
String colorCode = colorMatcher.group(1);
|
||||||
lore = lore.replaceAll("&" + colorCode, ChatColor.getByChar(colorCode).toString());
|
lore = lore.replaceAll("&" + colorCode, ChatColor.getByChar(colorCode).toString());
|
||||||
@@ -145,8 +151,9 @@ public class ConfigTools {
|
|||||||
* @return The message without color codes.
|
* @return The message without color codes.
|
||||||
*/
|
*/
|
||||||
public String removeColor(String message) {
|
public String removeColor(String message) {
|
||||||
message = ItemLore.COLOR_CODES.matcher(message).replaceAll("");
|
message = MINECRAFT_HEX_PATTERN.matcher(message).replaceAll("");
|
||||||
message = ItemLore.HEX_PATTERN.matcher(message).replaceAll("");
|
message = COLOR_CODES.matcher(message).replaceAll("");
|
||||||
|
message = CONFIG_HEX_PATTERN.matcher(message).replaceAll("");
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ package lol.hyper.toolstats.tools.config;
|
|||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version6;
|
import lol.hyper.toolstats.tools.config.versions.Version6;
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version7;
|
import lol.hyper.toolstats.tools.config.versions.Version7;
|
||||||
|
import lol.hyper.toolstats.tools.config.versions.Version8;
|
||||||
|
|
||||||
public class ConfigUpdater {
|
public class ConfigUpdater {
|
||||||
|
|
||||||
@@ -49,17 +50,25 @@ public class ConfigUpdater {
|
|||||||
public void updateConfig() {
|
public void updateConfig() {
|
||||||
int version = toolStats.config.getInt("config-version");
|
int version = toolStats.config.getInt("config-version");
|
||||||
|
|
||||||
// this will be a switch in the future
|
switch(version) {
|
||||||
// Upgrade 5 to 6
|
case 5: {
|
||||||
if (version == 5) {
|
// Version 5 to 6
|
||||||
Version6 version6 = new Version6(toolStats);
|
Version6 version6 = new Version6(toolStats);
|
||||||
version6.update();
|
version6.update();
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
// Upgrade 6 to 7
|
case 6: {
|
||||||
if (version == 6) {
|
// Version 6 to 7
|
||||||
Version7 version7 = new Version7(toolStats);
|
Version7 version7 = new Version7(toolStats);
|
||||||
version7.update();
|
version7.update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 7: {
|
||||||
|
// Version 7 to 8
|
||||||
|
Version8 version8 = new Version8(toolStats);
|
||||||
|
version8.update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class Version7 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
|
||||||
} catch (IOException exception) {
|
} 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);
|
throw new RuntimeException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +65,6 @@ public class Version7 {
|
|||||||
throw new RuntimeException(exception);
|
throw new RuntimeException(exception);
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* 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.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");
|
||||||
|
|
||||||
|
// Add mace to enabled sections
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-by.mace");
|
||||||
|
toolStats.config.set("enabled.created-by.mace", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-date.mace");
|
||||||
|
toolStats.config.set("enabled.created-date.mace", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.player-kills.mace");
|
||||||
|
toolStats.config.set("enabled.player-kills.mace", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.mob-kills.mace");
|
||||||
|
toolStats.config.set("enabled.mob-kills.mace", true);
|
||||||
|
|
||||||
|
List<String> 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
mace: true
|
||||||
# Will show time the item is created
|
# Will show time the item is created
|
||||||
created-date:
|
created-date:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
@@ -19,6 +20,7 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
mace: true
|
||||||
# Will show "Fished by <player>"
|
# Will show "Fished by <player>"
|
||||||
fished-tag:
|
fished-tag:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
@@ -54,11 +56,13 @@ enabled:
|
|||||||
axe: true
|
axe: true
|
||||||
trident: true
|
trident: true
|
||||||
bow: true
|
bow: true
|
||||||
|
mace: true
|
||||||
mob-kills:
|
mob-kills:
|
||||||
sword: true
|
sword: true
|
||||||
axe: true
|
axe: true
|
||||||
trident: true
|
trident: true
|
||||||
bow: true
|
bow: true
|
||||||
|
mace: true
|
||||||
blocks-mined:
|
blocks-mined:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
shovel: true
|
shovel: true
|
||||||
@@ -75,6 +79,7 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
mace: true
|
||||||
fish-caught: true
|
fish-caught: true
|
||||||
sheep-sheared: true
|
sheep-sheared: true
|
||||||
armor-damage: true
|
armor-damage: true
|
||||||
@@ -117,6 +122,9 @@ messages:
|
|||||||
shift-click-warning:
|
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."
|
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."
|
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.
|
# Change the default formatting for dates.
|
||||||
# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format
|
# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format
|
||||||
|
|||||||
Reference in New Issue
Block a user