Merge branch '1200-not-properly-calculating-time-from-crafting-stations-when-cancelling-an-item-crafting' into 'master'

Craft delay calculation patch

See merge request phoenix-dvpmt/mmoitems!65
This commit is contained in:
Jules 2023-04-23 10:27:38 +00:00
commit bb9da8870e
2 changed files with 353 additions and 310 deletions

View File

@ -12,163 +12,165 @@ import java.util.logging.Level;
public class CraftingStatus { public class CraftingStatus {
/* /*
* saves data about items being constructed in specific stations. players * saves data about items being constructed in specific stations. players
* must go back to the station GUI and claim their item once it's ready * must go back to the station GUI and claim their item once it's ready
*/ */
private final Map<String, CraftingQueue> queues = new HashMap<>(); private final Map<String, CraftingQueue> queues = new HashMap<>();
public void load(PlayerData data, ConfigurationSection config) { public void load(PlayerData data, ConfigurationSection config) {
String name = data.isOnline() ? data.getPlayer().getName() : "Unknown Player"; String name = data.isOnline() ? data.getPlayer().getName() : "Unknown Player";
for (String stationId : config.getKeys(false)) { for (String stationId : config.getKeys(false)) {
if (!MMOItems.plugin.getCrafting().hasStation(stationId)) { if (!MMOItems.plugin.getCrafting().hasStation(stationId)) {
MMOItems.plugin.getLogger().log(Level.WARNING, MMOItems.plugin.getLogger().log(Level.WARNING,
"An error occurred while trying to load crafting station recipe data of '" + name + "': " "An error occurred while trying to load crafting station recipe data of '" + name + "': "
+ "could not find crafting station with ID '" + stationId + "could not find crafting station with ID '" + stationId
+ "', make sure you backup that player data file before the user logs off."); + "', make sure you backup that player data file before the user logs off.");
continue; continue;
} }
CraftingStation station = MMOItems.plugin.getCrafting().getStation(stationId); CraftingStation station = MMOItems.plugin.getCrafting().getStation(stationId);
CraftingQueue queue = new CraftingQueue(station); CraftingQueue queue = new CraftingQueue(station);
queues.put(stationId, queue); queues.put(stationId, queue);
for (String recipeConfigId : config.getConfigurationSection(stationId).getKeys(false)) { for (String recipeConfigId : config.getConfigurationSection(stationId).getKeys(false)) {
String recipeId = config.getString(stationId + "." + recipeConfigId + ".recipe"); String recipeId = config.getString(stationId + "." + recipeConfigId + ".recipe");
if (recipeId == null || !station.hasRecipe(recipeId)) { if (recipeId == null || !station.hasRecipe(recipeId)) {
MMOItems.plugin.getLogger().log(Level.WARNING, MMOItems.plugin.getLogger().log(Level.WARNING,
"An error occurred while trying to load crafting station recipe data of '" + name + "': " "An error occurred while trying to load crafting station recipe data of '" + name + "': "
+ "could not find recipe with ID '" + recipeId + "could not find recipe with ID '" + recipeId
+ "', make sure you backup that player data file before the user logs off."); + "', make sure you backup that player data file before the user logs off.");
continue; continue;
} }
Recipe recipe = station.getRecipe(recipeId); Recipe recipe = station.getRecipe(recipeId);
if (!(recipe instanceof CraftingRecipe)) { if (!(recipe instanceof CraftingRecipe)) {
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occurred while trying to load crafting station recipe data of '" MMOItems.plugin.getLogger().log(Level.WARNING, "An error occurred while trying to load crafting station recipe data of '"
+ name + "': " + "recipe '" + recipe.getId() + "' is not a CRAFTING recipe."); + name + "': " + "recipe '" + recipe.getId() + "' is not a CRAFTING recipe.");
continue; continue;
} }
queue.add((CraftingRecipe) recipe, config.getLong(stationId + "." + recipeConfigId + ".started"), queue.add((CraftingRecipe) recipe, config.getLong(stationId + "." + recipeConfigId + ".started"),
config.getLong(stationId + "." + recipeConfigId + ".delay")); config.getLong(stationId + "." + recipeConfigId + ".delay"));
} }
} }
} }
public void save(ConfigurationSection config) { public void save(ConfigurationSection config) {
for (String station : queues.keySet()) { for (String station : queues.keySet()) {
CraftingQueue queue = queues.get(station); CraftingQueue queue = queues.get(station);
for (CraftingInfo craft : queue.getCrafts()) { for (CraftingInfo craft : queue.getCrafts()) {
config.set(station + ".recipe-" + craft.getUniqueId().toString() + ".recipe", craft.getRecipe().getId()); config.set(station + ".recipe-" + craft.getUniqueId().toString() + ".recipe", craft.getRecipe().getId());
config.set(station + ".recipe-" + craft.getUniqueId().toString() + ".started", craft.started); config.set(station + ".recipe-" + craft.getUniqueId().toString() + ".started", craft.started);
config.set(station + ".recipe-" + craft.getUniqueId().toString() + ".delay", craft.delay); config.set(station + ".recipe-" + craft.getUniqueId().toString() + ".delay", craft.delay);
} }
} }
} }
public CraftingQueue getQueue(CraftingStation station) { public CraftingQueue getQueue(CraftingStation station) {
if (!queues.containsKey(station.getId())) if (!queues.containsKey(station.getId()))
queues.put(station.getId(), new CraftingQueue(station)); queues.put(station.getId(), new CraftingQueue(station));
return queues.get(station.getId()); return queues.get(station.getId());
} }
public static class CraftingQueue { public static class CraftingQueue {
private final String station; private final String station;
private final List<CraftingInfo> crafts = new ArrayList<>(); private final List<CraftingInfo> crafts = new ArrayList<>();
public CraftingQueue(CraftingStation station) { public CraftingQueue(CraftingStation station) {
this.station = station.getId(); this.station = station.getId();
} }
public List<CraftingInfo> getCrafts() { public List<CraftingInfo> getCrafts() {
return crafts; return crafts;
} }
public boolean isFull(CraftingStation station) { public boolean isFull(CraftingStation station) {
return crafts.size() >= station.getMaxQueueSize(); return crafts.size() >= station.getMaxQueueSize();
} }
public void remove(CraftingInfo craft) { public void remove(CraftingInfo craft) {
int index = crafts.indexOf(craft); int index = crafts.indexOf(craft);
if (index != -1) if (index != -1)
for (int j = index; j < crafts.size(); j++) for (int j = index + 1; j < crafts.size(); j++) {
crafts.get(j).removeDelay(Math.max(0, craft.getLeft() - craft.getElapsed())); CraftingInfo nextCraft = crafts.get(j);
crafts.remove(craft); nextCraft.delay = Math.max(0, nextCraft.delay - craft.getLeft());
} }
crafts.remove(craft);
}
public CraftingInfo getCraft(UUID uuid) { public CraftingInfo getCraft(UUID uuid) {
for (CraftingInfo craft : crafts) for (CraftingInfo craft : crafts)
if (craft.getUniqueId().equals(uuid)) if (craft.getUniqueId().equals(uuid))
return craft; return craft;
return null; return null;
} }
/* /*
* when adding a crafting recipe, the delay is the actual crafting time * when adding a crafting recipe, the delay is the actual crafting time
* PLUS the delay left for the previous item since it's a queue. * PLUS the delay left for the previous item since it's a queue.
*/ */
public void add(CraftingRecipe recipe) { public void add(CraftingRecipe recipe) {
add(recipe, System.currentTimeMillis(), add(recipe, System.currentTimeMillis(),
(crafts.size() == 0 ? 0 : crafts.get(crafts.size() - 1).getLeft()) + (long) recipe.getCraftingTime() * 1000); (crafts.size() == 0 ? 0 : crafts.get(crafts.size() - 1).getLeft()) + (long) recipe.getCraftingTime() * 1000);
} }
private void add(CraftingRecipe recipe, long started, long delay) { private void add(CraftingRecipe recipe, long started, long delay) {
crafts.add(new CraftingInfo(recipe, started, delay)); crafts.add(new CraftingInfo(recipe, started, delay));
} }
@Deprecated @Deprecated
public CraftingStation getStation() { public CraftingStation getStation() {
return MMOItems.plugin.getCrafting().getStation(station); return MMOItems.plugin.getCrafting().getStation(station);
} }
public class CraftingInfo { public class CraftingInfo {
private final String recipe; private final String recipe;
private final UUID uuid = UUID.randomUUID(); private final UUID uuid = UUID.randomUUID();
private final long started; private final long started;
private long delay; private long delay;
private CraftingInfo(CraftingRecipe recipe, long started, long delay) { private CraftingInfo(CraftingRecipe recipe, long started, long delay) {
this.recipe = recipe.getId(); this.recipe = recipe.getId();
this.started = started; this.started = started;
this.delay = delay; this.delay = delay;
} }
public UUID getUniqueId() { public UUID getUniqueId() {
return uuid; return uuid;
} }
/** /**
* @deprecated /mi reload stations force MI to save the recipe * @deprecated /mi reload stations force MI to save the recipe
* IDs instead of a direct reference to the crafting recipe * IDs instead of a direct reference to the crafting recipe
*/ */
@Deprecated @Deprecated
public CraftingRecipe getRecipe() { public CraftingRecipe getRecipe() {
return (CraftingRecipe) getStation().getRecipe(recipe); return (CraftingRecipe) getStation().getRecipe(recipe);
} }
public boolean isReady() { public boolean isReady() {
return getLeft() == 0; return getLeft() == 0;
} }
public void removeDelay(long amount) { public void removeDelay(long amount) {
this.delay -= amount; this.delay -= amount;
} }
public long getElapsed() { public long getElapsed() {
return Math.max((long) getRecipe().getCraftingTime() * 1000, System.currentTimeMillis() - started); return Math.max((long) getRecipe().getCraftingTime() * 1000, System.currentTimeMillis() - started);
} }
public long getLeft() { public long getLeft() {
return Math.max(0, started + delay - System.currentTimeMillis()); return Math.max(0, started + delay - System.currentTimeMillis());
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof CraftingInfo && ((CraftingInfo) obj).uuid.equals(uuid); return obj instanceof CraftingInfo && ((CraftingInfo) obj).uuid.equals(uuid);
} }
} }
} }
} }

View File

@ -30,232 +30,273 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class CraftingRecipe extends Recipe { public class CraftingRecipe extends Recipe {
@NotNull public static final String UNSPECIFIED = "N/A"; @NotNull
public static final String UNSPECIFIED = "N/A";
public CraftingRecipe(@NotNull ConfigurationSection config) throws IllegalArgumentException { public CraftingRecipe(@NotNull ConfigurationSection config) throws IllegalArgumentException {
super(config); super(config);
craftingTime = config.getDouble("crafting-time"); craftingTime = config.getDouble("crafting-time");
// Legacy loading // Legacy loading
String uiFilter = config.getString("output.item", UNSPECIFIED); String uiFilter = config.getString("output.item", UNSPECIFIED);
String miType = config.getString("output.type", UNSPECIFIED).toUpperCase().replace("-", "_").replace(" ", "_"); String miType = config.getString("output.type", UNSPECIFIED).toUpperCase().replace("-", "_").replace(" ", "_");
String miID = config.getString("output.id", UNSPECIFIED).toUpperCase().replace("-", "_").replace(" ", "_"); String miID = config.getString("output.id", UNSPECIFIED).toUpperCase().replace("-", "_").replace(" ", "_");
// Yes // Yes
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get()); FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
// Both legacy specified? // Both legacy specified?
if (!UNSPECIFIED.equals(miType) && !UNSPECIFIED.equals(miID)) { if (!UNSPECIFIED.equals(miType) && !UNSPECIFIED.equals(miID)) {
// Generate filter // Generate filter
ProvidedUIFilter sweetOutput = UIFilterManager.getUIFilter("m", miType, miID, config.getString("output.amount", "1"), ffp); ProvidedUIFilter sweetOutput = UIFilterManager.getUIFilter("m", miType, miID, config.getString("output.amount", "1"), ffp);
// Is it null? // Is it null?
if (sweetOutput == null) { if (sweetOutput == null) {
// Throw message // Throw message
throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> { if (message instanceof FriendlyFeedbackMessage) { return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get()); } return ""; }), "")); throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> {
} if (message instanceof FriendlyFeedbackMessage) {
return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get());
}
return "";
}), ""));
}
// Accept // Accept
output = sweetOutput; output = sweetOutput;
// New method specified? // New method specified?
} else if (!UNSPECIFIED.equals(uiFilter)) { } else if (!UNSPECIFIED.equals(uiFilter)) {
// Generate filter // Generate filter
ProvidedUIFilter sweetOutput = UIFilterManager.getUIFilter(uiFilter, ffp); ProvidedUIFilter sweetOutput = UIFilterManager.getUIFilter(uiFilter, ffp);
// Is it null? // Is it null?
if (sweetOutput == null) { if (sweetOutput == null) {
// Throw message // Throw message
throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> { if (message instanceof FriendlyFeedbackMessage) { return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get()); } return ""; }), "")); throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> {
} if (message instanceof FriendlyFeedbackMessage) {
return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get());
}
return "";
}), ""));
}
// Accept // Accept
output = sweetOutput; output = sweetOutput;
// Invalid filter // Invalid filter
} else { } else {
// Throw message // Throw message
throw new IllegalArgumentException(FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Config must contain a valid Type and ID, or a valid UIFilter. ")); throw new IllegalArgumentException(FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Config must contain a valid Type and ID, or a valid UIFilter. "));
} }
// Valid UIFilter? // Valid UIFilter?
if (!output.isValid(ffp)) { if (!output.isValid(ffp)) {
// Throw message // Throw message
throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> { if (message instanceof FriendlyFeedbackMessage) { return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get()); } return ""; }), "")); throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> {
} if (message instanceof FriendlyFeedbackMessage) {
return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get());
}
return "";
}), ""));
}
// Valid UIFilter? // Valid UIFilter?
if (output.getItemStack(ffp) == null) { if (output.getItemStack(ffp) == null) {
// Throw message // Throw message
throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> { if (message instanceof FriendlyFeedbackMessage) { return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get()); } return ""; }), "")); throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> {
} if (message instanceof FriendlyFeedbackMessage) {
return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get());
}
return "";
}), ""));
}
// Its a MMOItem UIFilter, then? // Its a MMOItem UIFilter, then?
if (output.getParent() instanceof MMOItemUIFilter) { if (output.getParent() instanceof MMOItemUIFilter) {
// Find template // Find template
MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplate(MMOItems.plugin.getTypes().get(output.getArgument()), output.getData()); MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplate(MMOItems.plugin.getTypes().get(output.getArgument()), output.getData());
// Not possible tho // Not possible tho
if (template == null) { if (template == null) {
// Throw message // Throw message
throw new IllegalArgumentException(FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "This should be impossible, please contact $egunging$b: $fThe ProvidedUIFilter was flagged as 'valid' but clearly is not. $enet.Indyuce.mmoitems.api.crafting.recipe$b. ")); throw new IllegalArgumentException(FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "This should be impossible, please contact $egunging$b: $fThe ProvidedUIFilter was flagged as 'valid' but clearly is not. $enet.Indyuce.mmoitems.api.crafting.recipe$b. "));
} }
// Identify MMOItems operation // Identify MMOItems operation
identifiedMMO = new ConfigMMOItem(template, output.getAmount(1)); identifiedMMO = new ConfigMMOItem(template, output.getAmount(1));
} }
} }
/* /*
* There can't be any crafting time for upgrading recipes since there is no * There can't be any crafting time for upgrading recipes since there is no
* way to save an MMOItem in the config file TODO save as ItemStack * way to save an MMOItem in the config file TODO save as ItemStack
*/ */
private final double craftingTime; private final double craftingTime;
public double getCraftingTime() { return craftingTime; }
public boolean isInstant() { return craftingTime <= 0; }
/** public double getCraftingTime() {
* @return The item specified by the player that will be produced by this recipe. return craftingTime;
*/ }
@NotNull public ProvidedUIFilter getOutput() { return output; }
@NotNull private final ProvidedUIFilter output;
@Nullable ConfigMMOItem identifiedMMO; public boolean isInstant() {
/** return craftingTime <= 0;
* @return The output ItemStack from this }
*/
@SuppressWarnings("ConstantConditions")
@NotNull public ItemStack getOutputItemStack(@Nullable RPGPlayer rpg) {
// Generate as MMOItem /**
if (identifiedMMO != null && rpg != null) { * @return The item specified by the player that will be produced by this recipe.
*/
@NotNull
public ProvidedUIFilter getOutput() {
return output;
}
/* @NotNull
* Generate in the legacy way. I do this way to preserve private final ProvidedUIFilter output;
* backwards compatibility, since this is how it used to
* be done. Don't want to break that without good reason.
*/
return identifiedMMO.generate(rpg);
}
// Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection. @Nullable
return output.getItemStack(null); ConfigMMOItem identifiedMMO;
}
/**
* @return The preview ItemStack from this
*/
@NotNull public ItemStack getPreviewItemStack() {
// Generate as MMOItem /**
if (identifiedMMO != null) { * @return The output ItemStack from this
*/
@SuppressWarnings("ConstantConditions")
@NotNull
public ItemStack getOutputItemStack(@Nullable RPGPlayer rpg) {
/* // Generate as MMOItem
* Generate in the legacy way. I do this way to preserve if (identifiedMMO != null && rpg != null) {
* backwards compatibility, since this is how it used to
* be done. Don't want to break that without good reason.
*/
return identifiedMMO.getPreview();
}
// Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection. /*
//return output.getParent().getDisplayStack(output.getArgument(), output.getData(), null); * Generate in the legacy way. I do this way to preserve
//return output.getDisplayStack(null); * backwards compatibility, since this is how it used to
ItemStack gen = output.getParent().getDisplayStack(output.getArgument(), output.getData(), null); * be done. Don't want to break that without good reason.
gen.setAmount(output.getAmount(1)); */
ItemMeta itemMeta = gen.getItemMeta(); return identifiedMMO.generate(rpg);
if (itemMeta != null) { }
itemMeta.setDisplayName(SilentNumbers.getItemName(gen, false) + "\u00a7\u02ab");
gen.setItemMeta(itemMeta); }
return gen;
}
public int getOutputAmount() { return output.getAmount(1); }
@Override // Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection.
public boolean whenUsed(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) { return output.getItemStack(null);
if (!data.isOnline()) }
return false;
/* /**
* If the recipe is instant, take the ingredients off * @return The preview ItemStack from this
* and directly add the output to the player's inventory */
*/ @NotNull
if (isInstant()) { public ItemStack getPreviewItemStack() {
ItemStack result = hasOption(RecipeOption.OUTPUT_ITEM) ? getOutputItemStack(data.getRPG()) : null; // Generate as MMOItem
PlayerUseCraftingStationEvent event = new PlayerUseCraftingStationEvent(data, station, recipe, result); if (identifiedMMO != null) {
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return false;
/* /*
* Since instant recipes bypass the crafting queue MI still needs * Generate in the legacy way. I do this way to preserve
* to apply the trigger list when using an instant recipe * backwards compatibility, since this is how it used to
*/ * be done. Don't want to break that without good reason.
recipe.getRecipe().whenClaimed().forEach(trigger -> trigger.whenCrafting(data)); */
return identifiedMMO.getPreview();
}
if (result != null) // Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection.
new SmartGive(data.getPlayer()).give(result); //return output.getParent().getDisplayStack(output.getArgument(), output.getData(), null);
//return output.getDisplayStack(null);
ItemStack gen = output.getParent().getDisplayStack(output.getArgument(), output.getData(), null);
gen.setAmount(output.getAmount(1));
ItemMeta itemMeta = gen.getItemMeta();
if (itemMeta != null) {
itemMeta.setDisplayName(SilentNumbers.getItemName(gen, false) + "\u00a7\u02ab");
gen.setItemMeta(itemMeta);
}
return gen;
}
// Play sound public int getOutputAmount() {
if (!hasOption(RecipeOption.SILENT_CRAFT)) return output.getAmount(1);
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1); }
// Recipe was successfully used @Override
return true; public boolean whenUsed(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
if (!data.isOnline())
return false;
/* /*
* If the recipe is not instant, add the item to the crafting queue * If the recipe is instant, take the ingredients off
*/ * and directly add the output to the player's inventory
} else { */
if (isInstant()) {
ItemStack result = hasOption(RecipeOption.OUTPUT_ITEM) ? getOutputItemStack(data.getRPG()) : null;
PlayerUseCraftingStationEvent event = new PlayerUseCraftingStationEvent(data, station, recipe, result);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return false;
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(data, station, recipe); /*
Bukkit.getPluginManager().callEvent(called); * Since instant recipes bypass the crafting queue MI still needs
if (called.isCancelled()) * to apply the trigger list when using an instant recipe
return false; */
recipe.getRecipe().whenClaimed().forEach(trigger -> trigger.whenCrafting(data));
// Play sound if (result != null)
if (!hasOption(RecipeOption.SILENT_CRAFT)) new SmartGive(data.getPlayer()).give(result);
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
data.getCrafting().getQueue(station).add(this); // Play sound
if (!hasOption(RecipeOption.SILENT_CRAFT))
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
// Recipe was successfully used // Recipe was successfully used
return true; return true;
}
}
@Override /*
public boolean canUse(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) { * If the recipe is not instant, add the item to the crafting queue
if (isInstant()) */
return true; }
CraftingQueue queue = data.getCrafting().getQueue(station); PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(data, station, recipe);
if (queue.isFull(station)) { Bukkit.getPluginManager().callEvent(called);
if (!data.isOnline()) if (called.isCancelled())
return false; return false;
Message.CRAFTING_QUEUE_FULL.format(ChatColor.RED).send(data.getPlayer()); // Play sound
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); if (!hasOption(RecipeOption.SILENT_CRAFT))
return false; data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
}
return true;
}
@Override data.getCrafting().getQueue(station).add(this);
public ItemStack display(CheckedRecipe recipe) { return ConfigItems.CRAFTING_RECIPE_DISPLAY.newBuilder(recipe).build(); }
@Override // Recipe was successfully used
public CheckedRecipe evaluateRecipe(PlayerData data, IngredientInventory inv) { return true;
return new CheckedRecipe(this, data, inv); }
}
@Override
public boolean canUse(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
if (isInstant())
return true;
CraftingQueue queue = data.getCrafting().getQueue(station);
if (queue.isFull(station)) {
if (!data.isOnline())
return false;
Message.CRAFTING_QUEUE_FULL.format(ChatColor.RED).send(data.getPlayer());
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
return false;
}
return true;
}
@Override
public ItemStack display(CheckedRecipe recipe) {
return ConfigItems.CRAFTING_RECIPE_DISPLAY.newBuilder(recipe).build();
}
@Override
public CheckedRecipe evaluateRecipe(PlayerData data, IngredientInventory inv) {
return new CheckedRecipe(this, data, inv);
}
} }