mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-04-23 03:21:22 +00:00
move keys to own class
this took forever
This commit is contained in:
@@ -143,12 +143,12 @@ public class ItemChecker {
|
||||
*/
|
||||
public boolean checkTokens(PersistentDataContainer container, String targetToken) {
|
||||
// make sure the item has tokens
|
||||
if (!container.has(toolStats.tokenApplied, PersistentDataType.STRING)) {
|
||||
if (!container.has(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the tokens for this item
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
String tokens = container.get(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -169,12 +169,12 @@ public class ItemChecker {
|
||||
return new String[0];
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (!container.has(toolStats.tokenApplied, PersistentDataType.STRING)) {
|
||||
if (!container.has(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING)) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
// get the tokens for this item
|
||||
String tokensRaw = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
String tokensRaw = container.get(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING);
|
||||
if (tokensRaw == null) {
|
||||
return new String[0];
|
||||
}
|
||||
@@ -198,12 +198,12 @@ public class ItemChecker {
|
||||
String[] tokens = getTokens(item);
|
||||
// there are no tokens
|
||||
if (tokens.length == 0) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, token);
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, token);
|
||||
} else {
|
||||
// other tokens exist, so add
|
||||
String[] newTokens = Arrays.copyOf(tokens, tokens.length + 1);
|
||||
newTokens[tokens.length] = token;
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
@@ -321,36 +321,48 @@ public class ItemChecker {
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
ArrayList<String> tokens = new ArrayList<>();
|
||||
if (container.has(toolStats.playerKills)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getPlayerKills())) {
|
||||
tokens.add("player-kills");
|
||||
}
|
||||
if (container.has(toolStats.mobKills)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getMobKills())) {
|
||||
tokens.add("mob-kills");
|
||||
}
|
||||
if (container.has(toolStats.blocksMined)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getBlocksMined())) {
|
||||
tokens.add("blocks-mined");
|
||||
}
|
||||
if (container.has(toolStats.cropsHarvested)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getCropsHarvested())) {
|
||||
tokens.add("crops-mined");
|
||||
}
|
||||
if (container.has(toolStats.fishCaught)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getFishCaught())) {
|
||||
tokens.add("fish-caught");
|
||||
}
|
||||
if (container.has(toolStats.sheepSheared)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getSheepSheared())) {
|
||||
tokens.add("sheep-sheared");
|
||||
}
|
||||
if (container.has(toolStats.armorDamage)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getArmorDamage())) {
|
||||
tokens.add("damage-taken");
|
||||
}
|
||||
if (container.has(toolStats.arrowsShot)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getArrowsShot())) {
|
||||
tokens.add("arrows-shot");
|
||||
}
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getFlightTime())) {
|
||||
tokens.add("flight-time");
|
||||
}
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getDamageDone())) {
|
||||
tokens.add("damage-done");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getWitherKills())) {
|
||||
tokens.add("wither-kills");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getEnderDragonKills())) {
|
||||
tokens.add("enderdragon-kills");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getCriticalStrikes())) {
|
||||
tokens.add("critical-strikes");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getTridentThrows())) {
|
||||
tokens.add("trident-throws");
|
||||
}
|
||||
if (tokens.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -387,6 +399,6 @@ public class ItemChecker {
|
||||
public boolean keyCheck(PersistentDataContainer container) {
|
||||
return container.getKeys().stream()
|
||||
.map(NamespacedKey::getKey)
|
||||
.anyMatch(key -> toolStats.tokenKeys.stream().anyMatch(tokenKey -> tokenKey.getKey().equalsIgnoreCase(key)));
|
||||
.anyMatch(key -> toolStats.toolStatsKeys.getTokenKeys().stream().anyMatch(tokenKey -> tokenKey.getKey().equalsIgnoreCase(key)));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -209,7 +209,7 @@ public class TokenData {
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, tokenType);
|
||||
tokenData.set(toolStats.toolStatsKeys.getTokenType(), PersistentDataType.STRING, tokenType);
|
||||
token.setItemMeta(tokenMeta);
|
||||
|
||||
// set the custom model data
|
||||
|
||||
182
src/main/java/lol/hyper/toolstats/tools/ToolStatsKeys.java
Normal file
182
src/main/java/lol/hyper/toolstats/tools/ToolStatsKeys.java
Normal file
@@ -0,0 +1,182 @@
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ToolStatsKeys {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final Set<NamespacedKey> tokenKeys = new HashSet<>();
|
||||
|
||||
public ToolStatsKeys(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
private NamespacedKey itemOwner;
|
||||
private NamespacedKey timeCreated;
|
||||
private NamespacedKey playerKills;
|
||||
private NamespacedKey mobKills;
|
||||
private NamespacedKey blocksMined;
|
||||
private NamespacedKey cropsHarvested;
|
||||
private NamespacedKey fishCaught;
|
||||
private NamespacedKey sheepSheared;
|
||||
private NamespacedKey armorDamage;
|
||||
private NamespacedKey damageDone;
|
||||
private NamespacedKey newElytra;
|
||||
private NamespacedKey hash;
|
||||
private NamespacedKey arrowsShot;
|
||||
private NamespacedKey droppedBy;
|
||||
private NamespacedKey flightTime;
|
||||
private NamespacedKey tokenType;
|
||||
private NamespacedKey tokenApplied;
|
||||
private NamespacedKey witherKills;
|
||||
private NamespacedKey enderDragonKills;
|
||||
private NamespacedKey criticalStrikes;
|
||||
private NamespacedKey tridentThrows;
|
||||
private NamespacedKey originType;
|
||||
|
||||
public void make() {
|
||||
itemOwner = new NamespacedKey(toolStats, "owner");
|
||||
timeCreated = new NamespacedKey(toolStats, "time-created");
|
||||
playerKills = new NamespacedKey(toolStats, "player-kills");
|
||||
mobKills = new NamespacedKey(toolStats, "mob-kills");
|
||||
blocksMined = new NamespacedKey(toolStats, "generic-mined");
|
||||
cropsHarvested = new NamespacedKey(toolStats, "crops-mined");
|
||||
fishCaught = new NamespacedKey(toolStats, "fish-caught");
|
||||
sheepSheared = new NamespacedKey(toolStats, "sheared");
|
||||
armorDamage = new NamespacedKey(toolStats, "damage-taken");
|
||||
damageDone = new NamespacedKey(toolStats, "damage-done");
|
||||
newElytra = new NamespacedKey(toolStats, "new");
|
||||
hash = new NamespacedKey(toolStats, "hash");
|
||||
arrowsShot = new NamespacedKey(toolStats, "arrows-shot");
|
||||
droppedBy = new NamespacedKey(toolStats, "dropped-by");
|
||||
flightTime = new NamespacedKey(toolStats, "flightTime");
|
||||
tokenType = new NamespacedKey(toolStats, "token-type");
|
||||
tokenApplied = new NamespacedKey(toolStats, "token-applied");
|
||||
witherKills = new NamespacedKey(toolStats, "wither-kills");
|
||||
enderDragonKills = new NamespacedKey(toolStats, "enderdragon-kills");
|
||||
criticalStrikes = new NamespacedKey(toolStats, "critical-strikes");
|
||||
tridentThrows = new NamespacedKey(toolStats, "trident-throws");
|
||||
originType = new NamespacedKey(toolStats, "origin");
|
||||
|
||||
// save which stat can be used by a reset token
|
||||
tokenKeys.add(blocksMined);
|
||||
tokenKeys.add(playerKills);
|
||||
tokenKeys.add(mobKills);
|
||||
tokenKeys.add(cropsHarvested);
|
||||
tokenKeys.add(sheepSheared);
|
||||
tokenKeys.add(fishCaught);
|
||||
tokenKeys.add(flightTime);
|
||||
tokenKeys.add(arrowsShot);
|
||||
tokenKeys.add(armorDamage);
|
||||
tokenKeys.add(witherKills);
|
||||
tokenKeys.add(enderDragonKills);
|
||||
tokenKeys.add(criticalStrikes);
|
||||
tokenKeys.add(tridentThrows);
|
||||
}
|
||||
|
||||
public NamespacedKey getItemOwner() {
|
||||
return itemOwner;
|
||||
}
|
||||
|
||||
public NamespacedKey getTimeCreated() {
|
||||
return timeCreated;
|
||||
}
|
||||
|
||||
public NamespacedKey getPlayerKills() {
|
||||
return playerKills;
|
||||
}
|
||||
|
||||
public NamespacedKey getMobKills() {
|
||||
return mobKills;
|
||||
}
|
||||
|
||||
public NamespacedKey getBlocksMined() {
|
||||
return blocksMined;
|
||||
}
|
||||
|
||||
public NamespacedKey getCropsHarvested() {
|
||||
return cropsHarvested;
|
||||
}
|
||||
|
||||
public NamespacedKey getFishCaught() {
|
||||
return fishCaught;
|
||||
}
|
||||
|
||||
public NamespacedKey getSheepSheared() {
|
||||
return sheepSheared;
|
||||
}
|
||||
|
||||
public NamespacedKey getArmorDamage() {
|
||||
return armorDamage;
|
||||
}
|
||||
|
||||
public NamespacedKey getDamageDone() {
|
||||
return damageDone;
|
||||
}
|
||||
|
||||
public NamespacedKey getElytraKey() {
|
||||
return newElytra;
|
||||
}
|
||||
|
||||
public NamespacedKey getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public NamespacedKey getArrowsShot() {
|
||||
return arrowsShot;
|
||||
}
|
||||
|
||||
public NamespacedKey getDroppedBy() {
|
||||
return droppedBy;
|
||||
}
|
||||
|
||||
public NamespacedKey getFlightTime() {
|
||||
return flightTime;
|
||||
}
|
||||
|
||||
public NamespacedKey getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
|
||||
public NamespacedKey getTokenApplied() {
|
||||
return tokenApplied;
|
||||
}
|
||||
|
||||
public NamespacedKey getWitherKills() {
|
||||
return witherKills;
|
||||
}
|
||||
|
||||
public NamespacedKey getEnderDragonKills() {
|
||||
return enderDragonKills;
|
||||
}
|
||||
|
||||
public NamespacedKey getCriticalStrikes() {
|
||||
return criticalStrikes;
|
||||
}
|
||||
|
||||
public NamespacedKey getTridentThrows() {
|
||||
return tridentThrows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores how an item was created.
|
||||
* 0 = crafted.
|
||||
* 1 = dropped.
|
||||
* 2 = looted.
|
||||
* 3 = traded.
|
||||
* 4 = founded (for elytras).
|
||||
* 5 = fished.
|
||||
* 6 = spawned in (creative).
|
||||
*/
|
||||
public NamespacedKey getOriginType() {
|
||||
return originType;
|
||||
}
|
||||
|
||||
public Set<NamespacedKey> getTokenKeys() {
|
||||
return tokenKeys;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user