mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-10 22:55:04 +00:00
lots of updates
- add hash to items when created - added "crops harvested" for hoes
This commit is contained in:
60
src/main/java/lol/hyper/toolstats/tools/HashMaker.java
Normal file
60
src/main/java/lol/hyper/toolstats/tools/HashMaker.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HashMaker {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public HashMaker(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
public String makeHash(Material itemType, UUID player, long timestamp) {
|
||||
String input = itemType.toString() + player.toString() + timestamp;
|
||||
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hashBytes = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : hashBytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException exception) {
|
||||
toolStats.logger.warning("Unable to generate hash for " + player.toString() + "!");
|
||||
toolStats.logger.warning("Generating a random UUID instead.");
|
||||
exception.printStackTrace();
|
||||
return java.util.UUID.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,10 @@ import java.util.Locale;
|
||||
|
||||
public class ItemChecker {
|
||||
|
||||
private static final String[] validItems = { "pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing", "elytra" };
|
||||
private static final String[] validArmor = { "helmet", "chestplate", "leggings", "boots" };
|
||||
private static final String[] validItems = {"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing", "elytra"};
|
||||
private static final String[] validArmor = {"helmet", "chestplate", "leggings", "boots"};
|
||||
private static final String[] validMelee = {"sword", "trident", "axe"};
|
||||
private static final String[] validMine = { "pickaxe", "axe", "hoe", "shovel", "shear" };
|
||||
private static final String[] validMine = {"pickaxe", "axe", "hoe", "shovel", "shear", "hoe"};
|
||||
|
||||
/**
|
||||
* Check if item is an armor piece.
|
||||
|
||||
@@ -63,7 +63,8 @@ public class ItemLore {
|
||||
for (int x = 0; x < newLore.size(); x++) {
|
||||
// check to see if the line matches the config value
|
||||
// this means we update this line only!
|
||||
if (newLore.get(x).contains(configLore)) {
|
||||
String line = newLore.get(x);
|
||||
if (line.contains(configLore)) {
|
||||
newLore.set(x, newLine);
|
||||
return newLore;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user