7 Commits

Author SHA1 Message Date
81e65810e1 Bumps version for release
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
2024-08-07 14:09:42 +02:00
0dab832bfd Adds a note about sticks being an NPC selector
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
2024-08-07 13:24:06 +02:00
1510960089 Fixes missing cost message for extended salvage
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
2024-08-03 17:05:28 +02:00
cdb0f267a3 Renames an event method
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
2024-08-03 16:44:15 +02:00
81c15b6600 Adds information about the appropriate crafting station in ActionStartEvent
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
2024-08-03 16:32:44 +02:00
5efba6687c Adds a separate message for clicking an NPC with an empty hand
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
2024-08-03 13:09:09 +02:00
d0df4800f0 Changes back to SNAPSHOT
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
2024-07-29 19:35:10 +02:00
17 changed files with 135 additions and 17 deletions

View File

@ -83,6 +83,11 @@ example planks into wood, four wood will be taken.
When an item is salvaged, EXP will be returned based on enchantments on the item.
Note that sticks are valid items to be handled by Scrappers if extended salvage is enabled. The item is also the default
item for selecting NPCs in Citizens. If you find the NPC selection message annoying, and don't normally use sticks for
selection, you can change the item in Citizens' config and replace it with STRUCTURE_VOID or some other unobtainable
item.
## Commands
| Command | Arguments | Description |
@ -230,6 +235,7 @@ All currently supported presets, and available filters for each preset:
| startReforgeMessage | &eOk, let's see what I can do... | The message displayed when a blacksmith starts reforging an item. |
| successMessage | There you go! All better! | The message displayed when a blacksmith successfully repairs an item. |
| notDamagedMessage | &cThat item is not in need of repair | The message displayed if a player tries to reforge an item with full durability. |
| noItemMessage | Please present the item you want to reforge | The message displayed when a blacksmith is clicked with an empty hand |
### Scrapper global-only options
@ -284,6 +290,7 @@ All currently supported presets, and available filters for each preset:
| cannotSalvageArmorTrimMessage | &cI'm sorry, but I'm unable to salvage armor trims! | The message displayed when telling a player that the scrapper cannot salvage items with armor trim. |
| armorTrimSalvageNotFoundMessage | &cI'm sorry, but I don't know how to salvage that armor trim! | The message displayed when telling a player that the scrapper cannot find the correct items to return as armor trim salvage. This will happen if more armor trim materials are added, or the Spigot API is changed. |
| cannotSalvageNetheriteMessage | &cI'm sorry, but I'm unable to salvage netherite items! | The message displayed when telling a player that the scrapper cannot salvage netherite items. |
| noItemMessage | Please present the item you want to salvage | The message displayed when a scrapper is clicked with an empty hand |
## Language customization

View File

@ -6,7 +6,7 @@
<groupId>net.knarcraft</groupId>
<artifactId>blacksmith</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<name>Blacksmith</name>
<description>Blacksmith NPC for the Citizens API</description>

View File

@ -175,6 +175,16 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
return asString(BlacksmithSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
}
/**
* Gets the message displayed if a player presents the blacksmith with an empty hand
*
* @return <p>The no item message</p>
*/
@NotNull
public String getNoItemMessage() {
return asString(BlacksmithSetting.NO_ITEM_MESSAGE);
}
/**
* Gets all items reforge-able by this NPC
*

View File

@ -186,6 +186,12 @@ public enum BlacksmithSetting implements Setting {
"The message to display if a player is trying to reforge an item with full durability",
true, true),
/**
* The message displayed when clicking a blacksmith with an empty hand
*/
NO_ITEM_MESSAGE("noItemMessage", SettingValueType.STRING, "Please present the item you want to reforge",
"The message to display when a blacksmith is clicked with an empty hand", true, true),
/*------------------
| Global settings |
------------------*/

View File

@ -178,13 +178,25 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
}
/**
* The message displayed if a player presents a different item after seeing the price to salvage an item
* Gets the message displayed if a player presents a different item after seeing the price to salvage an item
*
* @return <p>The item changed message</p>
*/
@NotNull
public String getItemChangedMessage() {
return asString(ScrapperSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
}
/**
* Gets the message displayed if a player presents the scrapper with an empty hand
*
* @return <p>The no item message</p>
*/
@NotNull
public String getNoItemMessage() {
return asString(ScrapperSetting.NO_ITEM_MESSAGE);
}
/**
* Gets the minimum delay used to wait for a salvaging to finish.
*

View File

@ -236,6 +236,12 @@ public enum ScrapperSetting implements Setting {
"&cI'm sorry, but I'm unable to salvage netherite items!",
"The message to display when asked to salvage netherite items, and that option is disabled", true, true),
/**
* The message displayed when clicking a scrapper with an empty hand
*/
NO_ITEM_MESSAGE("noItemMessage", SettingValueType.STRING, "Please present the item you want to salvage",
"The message to display when a scrapper is clicked with an empty hand", true, true),
/*------------------
| Global settings |
------------------*/

View File

@ -1,5 +1,7 @@
package net.knarcraft.blacksmith.event;
import org.bukkit.Material;
/**
* An event triggered when a blacksmith or scrapper starts reforging or salvaging an item
*/
@ -13,4 +15,11 @@ public interface ActionStartEvent extends BlacksmithPluginEvent {
*/
long getActionDurationTicks();
/**
* Gets the appropriate crafting station for this action
*
* @return <p>The appropriate crafting station</p>
*/
Material getCraftingStation();
}

View File

@ -1,6 +1,7 @@
package net.knarcraft.blacksmith.event;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -12,17 +13,21 @@ public class BlacksmithReforgeStartEvent extends AbstractBlacksmithPluginEvent i
private static final HandlerList handlers = new HandlerList();
private final long durationTicks;
private final Material craftingStation;
/**
* Instantiates a new blacksmith reforge start event
*
* @param npc <p>The NPC involved in the event</p>
* @param player <p>The player involved in the event</p>
* @param durationTicks <p>The duration of the reforge</p>
* @param npc <p>The NPC involved in the event</p>
* @param player <p>The player involved in the event</p>
* @param durationTicks <p>The duration of the reforge</p>
* @param craftingStation <p>The appropriate crafting station for this reforging</p>
*/
public BlacksmithReforgeStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks) {
public BlacksmithReforgeStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks,
@NotNull Material craftingStation) {
super(npc, player);
this.durationTicks = durationTicks;
this.craftingStation = craftingStation;
}
@Override
@ -30,6 +35,11 @@ public class BlacksmithReforgeStartEvent extends AbstractBlacksmithPluginEvent i
return durationTicks;
}
@Override
public Material getCraftingStation() {
return craftingStation;
}
/**
* Gets a handler-list containing all event handlers
*

View File

@ -1,6 +1,7 @@
package net.knarcraft.blacksmith.event;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -13,17 +14,21 @@ public class ScrapperSalvageStartEvent extends AbstractBlacksmithPluginEvent imp
private static final HandlerList handlers = new HandlerList();
private final long durationTicks;
private final Material craftingStation;
/**
* Instantiates a new scrapper salvage start event
*
* @param npc <p>The NPC involved in the event</p>
* @param player <p>The player involved in the event</p>
* @param durationTicks <p>The duration of the salvage</p>
* @param npc <p>The NPC involved in the event</p>
* @param player <p>The player involved in the event</p>
* @param durationTicks <p>The duration of the salvage</p>
* @param craftingStation <p>The appropriate crafting station for this salvaging</p>
*/
public ScrapperSalvageStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks) {
public ScrapperSalvageStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks,
@NotNull Material craftingStation) {
super(npc, player);
this.durationTicks = durationTicks;
this.craftingStation = craftingStation;
}
@Override
@ -31,6 +36,11 @@ public class ScrapperSalvageStartEvent extends AbstractBlacksmithPluginEvent imp
return this.durationTicks;
}
@Override
public Material getCraftingStation() {
return this.craftingStation;
}
/**
* Gets a handler-list containing all event handlers
*

View File

@ -92,7 +92,7 @@ public class EconomyManager {
private static double getSalvageCost(@NotNull SalvageMethod salvageMethod) {
GlobalScrapperSettings settings = BlacksmithPlugin.getInstance().getGlobalScrapperSettings();
return switch (salvageMethod) {
case SALVAGE -> settings.getSalvageCost();
case SALVAGE, EXTENDED_SALVAGE -> settings.getSalvageCost();
case NETHERITE -> settings.getNetheriteSalvageCost();
case ARMOR_TRIM -> settings.getArmorTrimSalvageCost();
};

View File

@ -10,6 +10,11 @@ public enum SalvageMethod {
*/
SALVAGE,
/**
* Salvaging unrepairable items normally by returning the item's crafting recipe, but with unrestricted
*/
EXTENDED_SALVAGE,
/**
* Removing the armor trim from an item
*/

View File

@ -68,6 +68,11 @@ public class BlacksmithTrait extends CustomTrait<BlacksmithSetting> {
@Override
public void startSession(@NotNull Player player) {
ItemStack hand = player.getInventory().getItemInMainHand();
if (hand.getType().isAir()) {
sendNPCMessage(this.npc, player, config.getNoItemMessage());
return;
}
//Refuse if not repairable, or if reforge-able items is set, but doesn't include the held item
List<Material> reforgeAbleItems = config.getReforgeAbleItems();

View File

@ -92,6 +92,11 @@ public class ReforgeSession extends Session implements Runnable {
}
}
@Override
protected @NotNull Material getCraftingStation() {
return Material.ANVIL;
}
/**
* Runs the actual reforge which fixes the item and gives it back to the player
*/

View File

@ -9,6 +9,7 @@ import net.knarcraft.blacksmith.manager.EconomyManager;
import net.knarcraft.blacksmith.property.SalvageMethod;
import net.knarcraft.blacksmith.util.ItemHelper;
import net.knarcraft.blacksmith.util.SalvageHelper;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -87,6 +88,15 @@ public class SalvageSession extends Session implements Runnable {
}
}
@Override
protected @NotNull Material getCraftingStation() {
return switch (this.salvageMethod) {
case EXTENDED_SALVAGE -> Material.CRAFTING_TABLE;
case SALVAGE -> Material.ANVIL;
case NETHERITE, ARMOR_TRIM -> Material.SMITHING_TABLE;
};
}
/**
* Runs the actual salvage which fixes the item and gives it back to the player
*/

View File

@ -85,6 +85,11 @@ public class ScrapperTrait extends CustomTrait<ScrapperSetting> {
*/
public void startSession(@NotNull Player player) {
ItemStack itemInHand = player.getInventory().getItemInMainHand().clone();
if (itemInHand.getType().isAir()) {
sendNPCMessage(this.npc, player, config.getNoItemMessage());
return;
}
List<Material> salvageAbleItems = getSettings().getSalvageAbleItems();
boolean extended = getSettings().extendedSalvageEnabled();
@ -172,12 +177,13 @@ public class ScrapperTrait extends CustomTrait<ScrapperSetting> {
// Check if any salvage will be produced
RecipeResult recipeResult = getSalvage(itemInHand, extended);
SalvageMethod method = ItemHelper.isRepairable(itemInHand) ? SalvageMethod.SALVAGE : SalvageMethod.EXTENDED_SALVAGE;
boolean noUsefulSalvage = recipeResult == null || recipeResult.salvage().isEmpty();
if (noUsefulSalvage) {
sendNPCMessage(this.npc, player, getSettings().getTooDamagedMessage());
return new SalvageResult(SalvageMethod.SALVAGE, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
return new SalvageResult(method, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
} else {
return new SalvageResult(SalvageMethod.SALVAGE, recipeResult.salvage(), SalvageState.FOUND_SALVAGE,
return new SalvageResult(method, recipeResult.salvage(), SalvageState.FOUND_SALVAGE,
recipeResult.recipe().getResult().getAmount());
}
}
@ -250,7 +256,7 @@ public class ScrapperTrait extends CustomTrait<ScrapperSetting> {
replacer.add("{item}", itemInHand.getType().name().toLowerCase().replace('_', ' '));
if (salvageMethod == SalvageMethod.ARMOR_TRIM) {
sendNPCMessage(this.npc, player, replacer.replace(getSettings().getArmorTrimCostMessage()));
} else if (salvageMethod == SalvageMethod.SALVAGE) {
} else if (salvageMethod == SalvageMethod.SALVAGE || salvageMethod == SalvageMethod.EXTENDED_SALVAGE) {
String expectedYield;
if (ItemHelper.getDamage(itemInHand) <= 0) {
expectedYield = getSettings().getFullSalvageMessage();
@ -261,6 +267,8 @@ public class ScrapperTrait extends CustomTrait<ScrapperSetting> {
sendNPCMessage(this.npc, player, replacer.replace(getSettings().getCostMessage()));
} else if (salvageMethod == SalvageMethod.NETHERITE) {
sendNPCMessage(this.npc, player, replacer.replace(getSettings().getNetheriteCostMessage()));
} else {
BlacksmithPlugin.error("Unrecognized salvage method " + salvageMethod);
}
}

View File

@ -6,6 +6,7 @@ import net.knarcraft.blacksmith.event.BlacksmithReforgeStartEvent;
import net.knarcraft.blacksmith.event.NPCSoundEvent;
import net.knarcraft.blacksmith.event.ScrapperSalvageStartEvent;
import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.World;
@ -100,10 +101,11 @@ public abstract class Session implements Runnable {
this.finishTime = System.currentTimeMillis() + (actionDelay * 1000L);
long actionDelayTicks = actionDelay * 20L;
BlacksmithPlugin instance = BlacksmithPlugin.getInstance();
if (this instanceof ReforgeSession) {
BlacksmithPlugin.getInstance().callEvent(new BlacksmithReforgeStartEvent(npc, player, actionDelayTicks));
instance.callEvent(new BlacksmithReforgeStartEvent(npc, player, actionDelayTicks, getCraftingStation()));
} else if (this instanceof SalvageSession) {
BlacksmithPlugin.getInstance().callEvent(new ScrapperSalvageStartEvent(npc, player, actionDelayTicks));
instance.callEvent(new ScrapperSalvageStartEvent(npc, player, actionDelayTicks, getCraftingStation()));
}
taskId = scheduler.scheduleSyncDelayedTask(BlacksmithPlugin.getInstance(), this, actionDelayTicks);
@ -157,6 +159,13 @@ public abstract class Session implements Runnable {
*/
protected abstract int getActionDelay();
/**
* Gets the appropriate crafting station for this session
*
* @return <p>The appropriate crafting station</p>
*/
protected abstract @NotNull Material getCraftingStation();
/**
* Plays an NPC sound
*

View File

@ -111,6 +111,9 @@ blacksmith:
# The message to display if a player is trying to reforge an item with full durability
notDamagedMessage: "&cThat item is not in need of repair"
# The message to display when a blacksmith is clicked with an empty hand
noItemMessage: "Please present the item you want to reforge"
# Settings for the scrapper trait
scrapper:
@ -239,4 +242,7 @@ scrapper:
armorTrimSalvageNotFoundMessage: "&cI'm sorry, but I don't know how to salvage that armor trim!"
# The message to display when asked to salvage netherite items, and that option is disabled
cannotSalvageNetheriteMessage: "&cI'm sorry, but I'm unable to salvage netherite items!"
cannotSalvageNetheriteMessage: "&cI'm sorry, but I'm unable to salvage netherite items!"
# The message to display when a scrapper is clicked with an empty hand
noItemMessage: "Please present the item you want to salvage"