mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-05 06:57:35 +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) {
|
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);
|
||||||
|
nextCraft.delay = Math.max(0, nextCraft.delay - craft.getLeft());
|
||||||
|
}
|
||||||
crafts.remove(craft);
|
crafts.remove(craft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ 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);
|
||||||
@ -55,7 +56,12 @@ public class CraftingRecipe extends Recipe {
|
|||||||
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
|
||||||
@ -71,7 +77,12 @@ public class CraftingRecipe extends Recipe {
|
|||||||
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
|
||||||
@ -88,14 +99,24 @@ public class CraftingRecipe extends Recipe {
|
|||||||
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?
|
||||||
@ -121,21 +142,35 @@ public class CraftingRecipe extends Recipe {
|
|||||||
* 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 craftingTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInstant() {
|
||||||
|
return craftingTime <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The item specified by the player that will be produced by this recipe.
|
* @return The item specified by the player that will be produced by this recipe.
|
||||||
*/
|
*/
|
||||||
@NotNull public ProvidedUIFilter getOutput() { return output; }
|
@NotNull
|
||||||
@NotNull private final ProvidedUIFilter output;
|
public ProvidedUIFilter getOutput() {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final ProvidedUIFilter output;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
ConfigMMOItem identifiedMMO;
|
||||||
|
|
||||||
@Nullable ConfigMMOItem identifiedMMO;
|
|
||||||
/**
|
/**
|
||||||
* @return The output ItemStack from this
|
* @return The output ItemStack from this
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
@NotNull public ItemStack getOutputItemStack(@Nullable RPGPlayer rpg) {
|
@NotNull
|
||||||
|
public ItemStack getOutputItemStack(@Nullable RPGPlayer rpg) {
|
||||||
|
|
||||||
// Generate as MMOItem
|
// Generate as MMOItem
|
||||||
if (identifiedMMO != null && rpg != null) {
|
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.
|
// Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection.
|
||||||
return output.getItemStack(null);
|
return output.getItemStack(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The preview ItemStack from this
|
* @return The preview ItemStack from this
|
||||||
*/
|
*/
|
||||||
@NotNull public ItemStack getPreviewItemStack() {
|
@NotNull
|
||||||
|
public ItemStack getPreviewItemStack() {
|
||||||
|
|
||||||
// Generate as MMOItem
|
// Generate as MMOItem
|
||||||
if (identifiedMMO != null) {
|
if (identifiedMMO != null) {
|
||||||
@ -175,10 +212,14 @@ public class CraftingRecipe extends Recipe {
|
|||||||
ItemMeta itemMeta = gen.getItemMeta();
|
ItemMeta itemMeta = gen.getItemMeta();
|
||||||
if (itemMeta != null) {
|
if (itemMeta != null) {
|
||||||
itemMeta.setDisplayName(SilentNumbers.getItemName(gen, false) + "\u00a7\u02ab");
|
itemMeta.setDisplayName(SilentNumbers.getItemName(gen, false) + "\u00a7\u02ab");
|
||||||
gen.setItemMeta(itemMeta); }
|
gen.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
return gen;
|
return gen;
|
||||||
}
|
}
|
||||||
public int getOutputAmount() { return output.getAmount(1); }
|
|
||||||
|
public int getOutputAmount() {
|
||||||
|
return output.getAmount(1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean whenUsed(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
|
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
|
* and directly add the output to the player's inventory
|
||||||
*/
|
*/
|
||||||
if (isInstant()) {
|
if (isInstant()) {
|
||||||
|
|
||||||
ItemStack result = hasOption(RecipeOption.OUTPUT_ITEM) ? getOutputItemStack(data.getRPG()) : null;
|
ItemStack result = hasOption(RecipeOption.OUTPUT_ITEM) ? getOutputItemStack(data.getRPG()) : null;
|
||||||
PlayerUseCraftingStationEvent event = new PlayerUseCraftingStationEvent(data, station, recipe, result);
|
PlayerUseCraftingStationEvent event = new PlayerUseCraftingStationEvent(data, station, recipe, result);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
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
|
* If the recipe is not instant, add the item to the crafting queue
|
||||||
*/
|
*/
|
||||||
} else {
|
}
|
||||||
|
|
||||||
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(data, station, recipe);
|
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(data, station, recipe);
|
||||||
Bukkit.getPluginManager().callEvent(called);
|
Bukkit.getPluginManager().callEvent(called);
|
||||||
@ -232,7 +272,6 @@ public class CraftingRecipe extends Recipe {
|
|||||||
// Recipe was successfully used
|
// Recipe was successfully used
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUse(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
|
public boolean canUse(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
|
||||||
@ -252,7 +291,9 @@ public class CraftingRecipe extends Recipe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public CheckedRecipe evaluateRecipe(PlayerData data, IngredientInventory inv) {
|
public CheckedRecipe evaluateRecipe(PlayerData data, IngredientInventory inv) {
|
||||||
|
Loading…
Reference in New Issue
Block a user