@@ -90,7 +90,9 @@ public void onAnvilEvent(PrepareAnvilEvent event) {
9090 }
9191
9292 if (tokenType .equalsIgnoreCase ("remove" )) {
93- remove (event , clone );
93+ ItemStack removedStats = toolStats .itemLore .removeAll (clone , false );
94+ event .setResult (removedStats );
95+ event .getView ().setRepairCost (toolStats .itemChecker .getCost ("remove" ));
9496 return ;
9597 }
9698
@@ -394,155 +396,4 @@ private void reset(PrepareAnvilEvent event, ItemStack inputItem) {
394396 event .setResult (finalItem );
395397 event .getView ().setRepairCost (toolStats .itemChecker .getCost ("reset" ));
396398 }
397-
398- /**
399- * Remove all stats from an item.
400- *
401- * @param event The PrepareAnvilEvent event.
402- * @param inputItem The input item to remove stats from.
403- */
404- private void remove (PrepareAnvilEvent event , ItemStack inputItem ) {
405- ItemStack finalItem = inputItem .clone ();
406- ItemMeta meta = finalItem .getItemMeta ();
407- PersistentDataContainer container = meta .getPersistentDataContainer ();
408-
409- // remove the applied tokens
410- if (container .has (toolStats .tokenApplied )) {
411- container .remove (toolStats .tokenApplied );
412- }
413-
414- if (container .has (toolStats .playerKills )) {
415- Integer playerKills = container .get (toolStats .playerKills , PersistentDataType .INTEGER );
416- if (playerKills == null ) {
417- return ;
418- }
419-
420- container .remove (toolStats .playerKills );
421-
422- String playerKillsFormatted = toolStats .numberFormat .formatInt (playerKills );
423- Component lineToRemove = toolStats .configTools .formatLore ("kills.player" , "{kills}" , playerKillsFormatted );
424- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
425- finalItem .setItemMeta (meta );
426- }
427- if (container .has (toolStats .mobKills )) {
428- Integer mobKills = container .get (toolStats .mobKills , PersistentDataType .INTEGER );
429- if (mobKills == null ) {
430- return ;
431- }
432-
433- container .remove (toolStats .mobKills );
434-
435- String mobKillsFormatted = toolStats .numberFormat .formatInt (mobKills );
436- Component lineToRemove = toolStats .configTools .formatLore ("kills.mob" , "{kills}" , mobKillsFormatted );
437- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
438- finalItem .setItemMeta (meta );
439- }
440- if (container .has (toolStats .blocksMined )) {
441- Integer blocksMined = container .get (toolStats .blocksMined , PersistentDataType .INTEGER );
442- if (blocksMined == null ) {
443- return ;
444- }
445-
446- container .remove (toolStats .blocksMined );
447-
448- String blocksMinedFormatted = toolStats .numberFormat .formatInt (blocksMined );
449- Component lineToRemove = toolStats .configTools .formatLore ("blocks-mined" , "{blocks}" , blocksMinedFormatted );
450- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
451- finalItem .setItemMeta (meta );
452- }
453- if (container .has (toolStats .cropsHarvested )) {
454- Integer cropsHarvested = container .get (toolStats .playerKills , PersistentDataType .INTEGER );
455- if (cropsHarvested == null ) {
456- return ;
457- }
458-
459- container .remove (toolStats .cropsHarvested );
460-
461- String cropsHarvestedFormatted = toolStats .numberFormat .formatInt (cropsHarvested );
462- Component lineToRemove = toolStats .configTools .formatLore ("crops-harvested" , "{crops}" , cropsHarvestedFormatted );
463- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
464- finalItem .setItemMeta (meta );
465- }
466- if (container .has (toolStats .fishCaught )) {
467- Integer fishCaught = container .get (toolStats .fishCaught , PersistentDataType .INTEGER );
468- if (fishCaught == null ) {
469- return ;
470- }
471-
472- container .remove (toolStats .fishCaught );
473-
474- String fishCaughtFormatted = toolStats .numberFormat .formatInt (fishCaught );
475- Component lineToRemove = toolStats .configTools .formatLore ("fished.fish-caught" , "{fish}" , fishCaughtFormatted );
476- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
477- finalItem .setItemMeta (meta );
478- }
479- if (container .has (toolStats .sheepSheared )) {
480- Integer sheepSheared = container .get (toolStats .sheepSheared , PersistentDataType .INTEGER );
481- if (sheepSheared == null ) {
482- return ;
483- }
484-
485- container .remove (toolStats .sheepSheared );
486-
487- String sheepShearedFormatted = toolStats .numberFormat .formatInt (sheepSheared );
488- Component lineToRemove = toolStats .configTools .formatLore ("sheep.sheared" , "{sheep}" , sheepShearedFormatted );
489- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
490- finalItem .setItemMeta (meta );
491- }
492- if (container .has (toolStats .armorDamage )) {
493- Double armorDamage = container .get (toolStats .armorDamage , PersistentDataType .DOUBLE );
494- if (armorDamage == null ) {
495- return ;
496- }
497-
498- container .remove (toolStats .armorDamage );
499-
500- String armorDamageFormatted = toolStats .numberFormat .formatDouble (armorDamage );
501- Component lineToRemove = toolStats .configTools .formatLore ("damage-taken" , "{damage}" , armorDamageFormatted );
502- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
503- finalItem .setItemMeta (meta );
504- }
505- if (container .has (toolStats .damageDone )) {
506- Double damageDone = container .get (toolStats .damageDone , PersistentDataType .DOUBLE );
507- if (damageDone == null ) {
508- return ;
509- }
510-
511- container .remove (toolStats .damageDone );
512-
513- String damageDoneFormatted = toolStats .numberFormat .formatDouble (damageDone );
514- Component lineToRemove = toolStats .configTools .formatLore ("damage-done" , "{damage}" , damageDoneFormatted );
515- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
516- finalItem .setItemMeta (meta );
517- }
518- if (container .has (toolStats .arrowsShot )) {
519- Integer arrowsShot = container .get (toolStats .arrowsShot , PersistentDataType .INTEGER );
520- if (arrowsShot == null ) {
521- return ;
522- }
523-
524- container .remove (toolStats .arrowsShot );
525-
526- String arrowsShotFormatted = toolStats .numberFormat .formatInt (arrowsShot );
527- Component lineToRemove = toolStats .configTools .formatLore ("arrows-shot" , "{arrows}" , arrowsShotFormatted );
528- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
529- finalItem .setItemMeta (meta );
530- }
531- if (container .has (toolStats .flightTime )) {
532- Long flightTime = container .get (toolStats .flightTime , PersistentDataType .LONG );
533- if (flightTime == null ) {
534- return ;
535- }
536-
537- container .remove (toolStats .flightTime );
538-
539- String flightTimeFormatted = toolStats .numberFormat .formatDouble (flightTime );
540- Component lineToRemove = toolStats .configTools .formatLore ("flight-time" , "{time}" , flightTimeFormatted );
541- meta .lore (toolStats .itemLore .removeLore (meta .lore (), lineToRemove ));
542- finalItem .setItemMeta (meta );
543- }
544-
545- event .setResult (finalItem );
546- event .getView ().setRepairCost (toolStats .itemChecker .getCost ("remove" ));
547- }
548399}
0 commit comments