1919
2020import lol .hyper .toolstats .ToolStats ;
2121import lol .hyper .toolstats .tools .ItemChecker ;
22- import org .bukkit .Bukkit ;
2322import org .bukkit .GameMode ;
24- import org .bukkit .Material ;
2523import org .bukkit .entity .Player ;
2624import org .bukkit .event .EventHandler ;
2725import org .bukkit .event .EventPriority ;
3331import org .bukkit .persistence .PersistentDataContainer ;
3432import org .bukkit .persistence .PersistentDataType ;
3533
36- import java .util .ArrayList ;
3734import java .util .List ;
3835
3936public class BlocksMined implements Listener {
@@ -60,8 +57,8 @@ public void onBreak(BlockBreakEvent event) {
6057 if (!ItemChecker .isMineTool (heldItem .getType ())) {
6158 return ;
6259 }
63- // if it's an item we want, update the stats
64- Bukkit . getScheduler (). runTaskLater ( toolStats , () -> updateBlocksMined (heldItem ), 1 );
60+ // update the blocks mined
61+ updateBlocksMined (heldItem );
6562 }
6663
6764 private void updateBlocksMined (ItemStack playerTool ) {
@@ -86,40 +83,17 @@ private void updateBlocksMined(ItemStack playerTool) {
8683 blocksMined ++;
8784 container .set (toolStats .genericMined , PersistentDataType .INTEGER , blocksMined );
8885
89- String configLore = toolStats .getLoreFromConfig ( "blocks-mined" , false );
90- String configLoreRaw = toolStats .getLoreFromConfig ( " blocks-mined " , true );
86+ String blocksMinedFormatted = toolStats .numberFormat . formatInt ( blocksMined );
87+ List < String > newLore = toolStats .itemLore . addItemLore ( meta , "{ blocks} " , blocksMinedFormatted , "blocks-mined" );
9188
92- if ( configLore == null || configLoreRaw == null ) {
93- toolStats . logger . warning ( "There is no lore message for messages.blocks-mined!" );
89+ // if the list returned null, don't add it
90+ if ( newLore == null ) {
9491 return ;
9592 }
9693
97- List <String > lore ;
98- String newLine = configLoreRaw .replace ("{blocks}" , toolStats .numberFormat .formatInt (blocksMined ));
99- if (meta .hasLore ()) {
100- lore = meta .getLore ();
101- boolean hasLore = false ;
102- // we do a for loop like this, we can keep track of index
103- // this doesn't mess the lore up of existing items
104- for (int x = 0 ; x < lore .size (); x ++) {
105- if (lore .get (x ).contains (configLore )) {
106- hasLore = true ;
107- lore .set (x , newLine );
108- break ;
109- }
110- }
111- // if the item has lore but doesn't have the tag, add it
112- if (!hasLore ) {
113- lore .add (newLine );
114- }
115- } else {
116- // if the item has no lore, create a new list and add the string
117- lore = new ArrayList <>();
118- lore .add (newLine );
119- }
12094 // do we add the lore based on the config?
12195 if (toolStats .checkConfig (playerTool , "blocks-mined" )) {
122- meta .setLore (lore );
96+ meta .setLore (newLore );
12397 }
12498 playerTool .setItemMeta (meta );
12599 }
0 commit comments