mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
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:
commit
bb9da8870e
@ -94,8 +94,10 @@ public class CraftingStatus {
|
||||
public void remove(CraftingInfo craft) {
|
||||
int index = crafts.indexOf(craft);
|
||||
if (index != -1)
|
||||
for (int j = index; j < crafts.size(); j++)
|
||||
crafts.get(j).removeDelay(Math.max(0, craft.getLeft() - craft.getElapsed()));
|
||||
for (int j = index + 1; j < crafts.size(); j++) {
|
||||
CraftingInfo nextCraft = crafts.get(j);
|
||||
nextCraft.delay = Math.max(0, nextCraft.delay - craft.getLeft());
|
||||
}
|
||||
crafts.remove(craft);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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 {
|
||||
super(config);
|
||||
@ -55,7 +56,12 @@ public class CraftingRecipe extends Recipe {
|
||||
if (sweetOutput == null) {
|
||||
|
||||
// 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
|
||||
@ -71,7 +77,12 @@ public class CraftingRecipe extends Recipe {
|
||||
if (sweetOutput == null) {
|
||||
|
||||
// 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
|
||||
@ -88,14 +99,24 @@ public class CraftingRecipe extends Recipe {
|
||||
if (!output.isValid(ffp)) {
|
||||
|
||||
// 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?
|
||||
if (output.getItemStack(ffp) == null) {
|
||||
|
||||
// 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?
|
||||
@ -121,21 +142,35 @@ public class CraftingRecipe extends Recipe {
|
||||
* way to save an MMOItem in the config file TODO save as ItemStack
|
||||
*/
|
||||
private final double craftingTime;
|
||||
public double getCraftingTime() { return craftingTime; }
|
||||
public boolean isInstant() { return craftingTime <= 0; }
|
||||
|
||||
public double getCraftingTime() {
|
||||
return craftingTime;
|
||||
}
|
||||
|
||||
public boolean isInstant() {
|
||||
return craftingTime <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The item specified by the player that will be produced by this recipe.
|
||||
*/
|
||||
@NotNull public ProvidedUIFilter getOutput() { return output; }
|
||||
@NotNull private final ProvidedUIFilter output;
|
||||
@NotNull
|
||||
public ProvidedUIFilter getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final ProvidedUIFilter output;
|
||||
|
||||
@Nullable
|
||||
ConfigMMOItem identifiedMMO;
|
||||
|
||||
@Nullable ConfigMMOItem identifiedMMO;
|
||||
/**
|
||||
* @return The output ItemStack from this
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@NotNull public ItemStack getOutputItemStack(@Nullable RPGPlayer rpg) {
|
||||
@NotNull
|
||||
public ItemStack getOutputItemStack(@Nullable RPGPlayer rpg) {
|
||||
|
||||
// Generate as MMOItem
|
||||
if (identifiedMMO != null && rpg != null) {
|
||||
@ -151,10 +186,12 @@ public class CraftingRecipe extends Recipe {
|
||||
// Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection.
|
||||
return output.getItemStack(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The preview ItemStack from this
|
||||
*/
|
||||
@NotNull public ItemStack getPreviewItemStack() {
|
||||
@NotNull
|
||||
public ItemStack getPreviewItemStack() {
|
||||
|
||||
// Generate as MMOItem
|
||||
if (identifiedMMO != null) {
|
||||
@ -175,10 +212,14 @@ public class CraftingRecipe extends Recipe {
|
||||
ItemMeta itemMeta = gen.getItemMeta();
|
||||
if (itemMeta != null) {
|
||||
itemMeta.setDisplayName(SilentNumbers.getItemName(gen, false) + "\u00a7\u02ab");
|
||||
gen.setItemMeta(itemMeta); }
|
||||
gen.setItemMeta(itemMeta);
|
||||
}
|
||||
return gen;
|
||||
}
|
||||
public int getOutputAmount() { return output.getAmount(1); }
|
||||
|
||||
public int getOutputAmount() {
|
||||
return output.getAmount(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean whenUsed(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
|
||||
@ -190,7 +231,6 @@ public class CraftingRecipe extends Recipe {
|
||||
* and directly add the output to the player's inventory
|
||||
*/
|
||||
if (isInstant()) {
|
||||
|
||||
ItemStack result = hasOption(RecipeOption.OUTPUT_ITEM) ? getOutputItemStack(data.getRPG()) : null;
|
||||
PlayerUseCraftingStationEvent event = new PlayerUseCraftingStationEvent(data, station, recipe, result);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
@ -216,7 +256,7 @@ public class CraftingRecipe extends Recipe {
|
||||
/*
|
||||
* If the recipe is not instant, add the item to the crafting queue
|
||||
*/
|
||||
} else {
|
||||
}
|
||||
|
||||
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(data, station, recipe);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
@ -232,7 +272,6 @@ public class CraftingRecipe extends Recipe {
|
||||
// Recipe was successfully used
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
|
||||
@ -252,7 +291,9 @@ public class CraftingRecipe extends Recipe {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack display(CheckedRecipe recipe) { return ConfigItems.CRAFTING_RECIPE_DISPLAY.newBuilder(recipe).build(); }
|
||||
public ItemStack display(CheckedRecipe recipe) {
|
||||
return ConfigItems.CRAFTING_RECIPE_DISPLAY.newBuilder(recipe).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckedRecipe evaluateRecipe(PlayerData data, IngredientInventory inv) {
|
||||
|
Loading…
Reference in New Issue
Block a user