mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
227723fe10 | ||
|
|
785333e8d1 | ||
|
|
bc784b8d46 | ||
|
|
f5ddada892 | ||
|
|
a43155b0c5 | ||
|
|
e327d132e2 | ||
|
|
f09f2d3703 |
2
pom.xml
2
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.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ToolStats</name>
|
<name>ToolStats</name>
|
||||||
|
|||||||
@@ -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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -123,13 +126,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 +148,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user