mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Bug patched
This commit is contained in:
parent
9508df111b
commit
9db368628f
@ -12,163 +12,165 @@ import java.util.logging.Level;
|
||||
|
||||
public class CraftingStatus {
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
private final Map<String, CraftingQueue> queues = new HashMap<>();
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
private final Map<String, CraftingQueue> queues = new HashMap<>();
|
||||
|
||||
public void load(PlayerData data, ConfigurationSection config) {
|
||||
String name = data.isOnline() ? data.getPlayer().getName() : "Unknown Player";
|
||||
|
||||
for (String stationId : config.getKeys(false)) {
|
||||
if (!MMOItems.plugin.getCrafting().hasStation(stationId)) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING,
|
||||
"An error occurred while trying to load crafting station recipe data of '" + name + "': "
|
||||
+ "could not find crafting station with ID '" + stationId
|
||||
+ "', make sure you backup that player data file before the user logs off.");
|
||||
continue;
|
||||
}
|
||||
public void load(PlayerData data, ConfigurationSection config) {
|
||||
String name = data.isOnline() ? data.getPlayer().getName() : "Unknown Player";
|
||||
|
||||
CraftingStation station = MMOItems.plugin.getCrafting().getStation(stationId);
|
||||
CraftingQueue queue = new CraftingQueue(station);
|
||||
queues.put(stationId, queue);
|
||||
for (String stationId : config.getKeys(false)) {
|
||||
if (!MMOItems.plugin.getCrafting().hasStation(stationId)) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING,
|
||||
"An error occurred while trying to load crafting station recipe data of '" + name + "': "
|
||||
+ "could not find crafting station with ID '" + stationId
|
||||
+ "', make sure you backup that player data file before the user logs off.");
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String recipeConfigId : config.getConfigurationSection(stationId).getKeys(false)) {
|
||||
String recipeId = config.getString(stationId + "." + recipeConfigId + ".recipe");
|
||||
if (recipeId == null || !station.hasRecipe(recipeId)) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING,
|
||||
"An error occurred while trying to load crafting station recipe data of '" + name + "': "
|
||||
+ "could not find recipe with ID '" + recipeId
|
||||
+ "', make sure you backup that player data file before the user logs off.");
|
||||
continue;
|
||||
}
|
||||
CraftingStation station = MMOItems.plugin.getCrafting().getStation(stationId);
|
||||
CraftingQueue queue = new CraftingQueue(station);
|
||||
queues.put(stationId, queue);
|
||||
|
||||
Recipe recipe = station.getRecipe(recipeId);
|
||||
if (!(recipe instanceof CraftingRecipe)) {
|
||||
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.");
|
||||
continue;
|
||||
}
|
||||
for (String recipeConfigId : config.getConfigurationSection(stationId).getKeys(false)) {
|
||||
String recipeId = config.getString(stationId + "." + recipeConfigId + ".recipe");
|
||||
if (recipeId == null || !station.hasRecipe(recipeId)) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING,
|
||||
"An error occurred while trying to load crafting station recipe data of '" + name + "': "
|
||||
+ "could not find recipe with ID '" + recipeId
|
||||
+ "', make sure you backup that player data file before the user logs off.");
|
||||
continue;
|
||||
}
|
||||
|
||||
queue.add((CraftingRecipe) recipe, config.getLong(stationId + "." + recipeConfigId + ".started"),
|
||||
config.getLong(stationId + "." + recipeConfigId + ".delay"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Recipe recipe = station.getRecipe(recipeId);
|
||||
if (!(recipe instanceof CraftingRecipe)) {
|
||||
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.");
|
||||
continue;
|
||||
}
|
||||
|
||||
public void save(ConfigurationSection config) {
|
||||
for (String station : queues.keySet()) {
|
||||
CraftingQueue queue = queues.get(station);
|
||||
queue.add((CraftingRecipe) recipe, config.getLong(stationId + "." + recipeConfigId + ".started"),
|
||||
config.getLong(stationId + "." + recipeConfigId + ".delay"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (CraftingInfo craft : queue.getCrafts()) {
|
||||
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() + ".delay", craft.delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void save(ConfigurationSection config) {
|
||||
for (String station : queues.keySet()) {
|
||||
CraftingQueue queue = queues.get(station);
|
||||
|
||||
public CraftingQueue getQueue(CraftingStation station) {
|
||||
if (!queues.containsKey(station.getId()))
|
||||
queues.put(station.getId(), new CraftingQueue(station));
|
||||
return queues.get(station.getId());
|
||||
}
|
||||
for (CraftingInfo craft : queue.getCrafts()) {
|
||||
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() + ".delay", craft.delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class CraftingQueue {
|
||||
private final String station;
|
||||
private final List<CraftingInfo> crafts = new ArrayList<>();
|
||||
public CraftingQueue getQueue(CraftingStation station) {
|
||||
if (!queues.containsKey(station.getId()))
|
||||
queues.put(station.getId(), new CraftingQueue(station));
|
||||
return queues.get(station.getId());
|
||||
}
|
||||
|
||||
public CraftingQueue(CraftingStation station) {
|
||||
this.station = station.getId();
|
||||
}
|
||||
public static class CraftingQueue {
|
||||
private final String station;
|
||||
private final List<CraftingInfo> crafts = new ArrayList<>();
|
||||
|
||||
public List<CraftingInfo> getCrafts() {
|
||||
return crafts;
|
||||
}
|
||||
public CraftingQueue(CraftingStation station) {
|
||||
this.station = station.getId();
|
||||
}
|
||||
|
||||
public boolean isFull(CraftingStation station) {
|
||||
return crafts.size() >= station.getMaxQueueSize();
|
||||
}
|
||||
public List<CraftingInfo> getCrafts() {
|
||||
return crafts;
|
||||
}
|
||||
|
||||
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()));
|
||||
crafts.remove(craft);
|
||||
}
|
||||
public boolean isFull(CraftingStation station) {
|
||||
return crafts.size() >= station.getMaxQueueSize();
|
||||
}
|
||||
|
||||
public CraftingInfo getCraft(UUID uuid) {
|
||||
for (CraftingInfo craft : crafts)
|
||||
if (craft.getUniqueId().equals(uuid))
|
||||
return craft;
|
||||
return null;
|
||||
}
|
||||
public void remove(CraftingInfo craft) {
|
||||
int index = crafts.indexOf(craft);
|
||||
if (index != -1)
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
public void add(CraftingRecipe recipe) {
|
||||
add(recipe, System.currentTimeMillis(),
|
||||
(crafts.size() == 0 ? 0 : crafts.get(crafts.size() - 1).getLeft()) + (long) recipe.getCraftingTime() * 1000);
|
||||
}
|
||||
public CraftingInfo getCraft(UUID uuid) {
|
||||
for (CraftingInfo craft : crafts)
|
||||
if (craft.getUniqueId().equals(uuid))
|
||||
return craft;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void add(CraftingRecipe recipe, long started, long delay) {
|
||||
crafts.add(new CraftingInfo(recipe, started, delay));
|
||||
}
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
public void add(CraftingRecipe recipe) {
|
||||
add(recipe, System.currentTimeMillis(),
|
||||
(crafts.size() == 0 ? 0 : crafts.get(crafts.size() - 1).getLeft()) + (long) recipe.getCraftingTime() * 1000);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CraftingStation getStation() {
|
||||
return MMOItems.plugin.getCrafting().getStation(station);
|
||||
}
|
||||
private void add(CraftingRecipe recipe, long started, long delay) {
|
||||
crafts.add(new CraftingInfo(recipe, started, delay));
|
||||
}
|
||||
|
||||
public class CraftingInfo {
|
||||
private final String recipe;
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
private final long started;
|
||||
private long delay;
|
||||
@Deprecated
|
||||
public CraftingStation getStation() {
|
||||
return MMOItems.plugin.getCrafting().getStation(station);
|
||||
}
|
||||
|
||||
private CraftingInfo(CraftingRecipe recipe, long started, long delay) {
|
||||
this.recipe = recipe.getId();
|
||||
this.started = started;
|
||||
this.delay = delay;
|
||||
}
|
||||
public class CraftingInfo {
|
||||
private final String recipe;
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
private final long started;
|
||||
private long delay;
|
||||
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
private CraftingInfo(CraftingRecipe recipe, long started, long delay) {
|
||||
this.recipe = recipe.getId();
|
||||
this.started = started;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated /mi reload stations force MI to save the recipe
|
||||
* IDs instead of a direct reference to the crafting recipe
|
||||
*/
|
||||
@Deprecated
|
||||
public CraftingRecipe getRecipe() {
|
||||
return (CraftingRecipe) getStation().getRecipe(recipe);
|
||||
}
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return getLeft() == 0;
|
||||
}
|
||||
/**
|
||||
* @deprecated /mi reload stations force MI to save the recipe
|
||||
* IDs instead of a direct reference to the crafting recipe
|
||||
*/
|
||||
@Deprecated
|
||||
public CraftingRecipe getRecipe() {
|
||||
return (CraftingRecipe) getStation().getRecipe(recipe);
|
||||
}
|
||||
|
||||
public void removeDelay(long amount) {
|
||||
this.delay -= amount;
|
||||
}
|
||||
public boolean isReady() {
|
||||
return getLeft() == 0;
|
||||
}
|
||||
|
||||
public long getElapsed() {
|
||||
return Math.max((long) getRecipe().getCraftingTime() * 1000, System.currentTimeMillis() - started);
|
||||
}
|
||||
public void removeDelay(long amount) {
|
||||
this.delay -= amount;
|
||||
}
|
||||
|
||||
public long getLeft() {
|
||||
return Math.max(0, started + delay - System.currentTimeMillis());
|
||||
}
|
||||
public long getElapsed() {
|
||||
return Math.max((long) getRecipe().getCraftingTime() * 1000, System.currentTimeMillis() - started);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof CraftingInfo && ((CraftingInfo) obj).uuid.equals(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
public long getLeft() {
|
||||
return Math.max(0, started + delay - System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof CraftingInfo && ((CraftingInfo) obj).uuid.equals(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,232 +30,273 @@ 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);
|
||||
public CraftingRecipe(@NotNull ConfigurationSection config) throws IllegalArgumentException {
|
||||
super(config);
|
||||
|
||||
craftingTime = config.getDouble("crafting-time");
|
||||
craftingTime = config.getDouble("crafting-time");
|
||||
|
||||
// Legacy loading
|
||||
String uiFilter = config.getString("output.item", UNSPECIFIED);
|
||||
String miType = config.getString("output.type", UNSPECIFIED).toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
String miID = config.getString("output.id", UNSPECIFIED).toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
// Legacy loading
|
||||
String uiFilter = config.getString("output.item", UNSPECIFIED);
|
||||
String miType = config.getString("output.type", UNSPECIFIED).toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
String miID = config.getString("output.id", UNSPECIFIED).toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
|
||||
// Yes
|
||||
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
|
||||
// Yes
|
||||
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
|
||||
|
||||
// Both legacy specified?
|
||||
if (!UNSPECIFIED.equals(miType) && !UNSPECIFIED.equals(miID)) {
|
||||
// Both legacy specified?
|
||||
if (!UNSPECIFIED.equals(miType) && !UNSPECIFIED.equals(miID)) {
|
||||
|
||||
// Generate filter
|
||||
ProvidedUIFilter sweetOutput = UIFilterManager.getUIFilter("m", miType, miID, config.getString("output.amount", "1"), ffp);
|
||||
// Generate filter
|
||||
ProvidedUIFilter sweetOutput = UIFilterManager.getUIFilter("m", miType, miID, config.getString("output.amount", "1"), ffp);
|
||||
|
||||
// Is it null?
|
||||
if (sweetOutput == null) {
|
||||
// Is it null?
|
||||
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 message
|
||||
throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> {
|
||||
if (message instanceof FriendlyFeedbackMessage) {
|
||||
return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get());
|
||||
}
|
||||
return "";
|
||||
}), ""));
|
||||
}
|
||||
|
||||
// Accept
|
||||
output = sweetOutput;
|
||||
// Accept
|
||||
output = sweetOutput;
|
||||
|
||||
// New method specified?
|
||||
} else if (!UNSPECIFIED.equals(uiFilter)) {
|
||||
// New method specified?
|
||||
} else if (!UNSPECIFIED.equals(uiFilter)) {
|
||||
|
||||
// Generate filter
|
||||
ProvidedUIFilter sweetOutput = UIFilterManager.getUIFilter(uiFilter, ffp);
|
||||
// Generate filter
|
||||
ProvidedUIFilter sweetOutput = UIFilterManager.getUIFilter(uiFilter, ffp);
|
||||
|
||||
// Is it null?
|
||||
if (sweetOutput == null) {
|
||||
// Is it null?
|
||||
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 message
|
||||
throw new IllegalArgumentException(SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> {
|
||||
if (message instanceof FriendlyFeedbackMessage) {
|
||||
return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get());
|
||||
}
|
||||
return "";
|
||||
}), ""));
|
||||
}
|
||||
|
||||
// Accept
|
||||
output = sweetOutput;
|
||||
// Accept
|
||||
output = sweetOutput;
|
||||
|
||||
// Invalid filter
|
||||
} else {
|
||||
// Invalid filter
|
||||
} else {
|
||||
|
||||
// Throw message
|
||||
throw new IllegalArgumentException(FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Config must contain a valid Type and ID, or a valid UIFilter. "));
|
||||
}
|
||||
// Throw message
|
||||
throw new IllegalArgumentException(FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Config must contain a valid Type and ID, or a valid UIFilter. "));
|
||||
}
|
||||
|
||||
// Valid UIFilter?
|
||||
if (!output.isValid(ffp)) {
|
||||
// Valid UIFilter?
|
||||
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 message
|
||||
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) {
|
||||
// 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 message
|
||||
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?
|
||||
if (output.getParent() instanceof MMOItemUIFilter) {
|
||||
// Its a MMOItem UIFilter, then?
|
||||
if (output.getParent() instanceof MMOItemUIFilter) {
|
||||
|
||||
// Find template
|
||||
MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplate(MMOItems.plugin.getTypes().get(output.getArgument()), output.getData());
|
||||
// Find template
|
||||
MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplate(MMOItems.plugin.getTypes().get(output.getArgument()), output.getData());
|
||||
|
||||
// Not possible tho
|
||||
if (template == null) {
|
||||
// Not possible tho
|
||||
if (template == null) {
|
||||
|
||||
// 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 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. "));
|
||||
}
|
||||
|
||||
// Identify MMOItems operation
|
||||
identifiedMMO = new ConfigMMOItem(template, output.getAmount(1));
|
||||
}
|
||||
}
|
||||
// Identify MMOItems operation
|
||||
identifiedMMO = new ConfigMMOItem(template, output.getAmount(1));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
private final double craftingTime;
|
||||
public double getCraftingTime() { return craftingTime; }
|
||||
public boolean isInstant() { return craftingTime <= 0; }
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
private final double craftingTime;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
public double getCraftingTime() {
|
||||
return craftingTime;
|
||||
}
|
||||
|
||||
@Nullable ConfigMMOItem identifiedMMO;
|
||||
/**
|
||||
* @return The output ItemStack from this
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@NotNull public ItemStack getOutputItemStack(@Nullable RPGPlayer rpg) {
|
||||
public boolean isInstant() {
|
||||
return craftingTime <= 0;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate in the legacy way. I do this way to preserve
|
||||
* backwards compatibility, since this is how it used to
|
||||
* be done. Don't want to break that without good reason.
|
||||
*/
|
||||
return identifiedMMO.generate(rpg);
|
||||
}
|
||||
@NotNull
|
||||
private final ProvidedUIFilter output;
|
||||
|
||||
// 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() {
|
||||
@Nullable
|
||||
ConfigMMOItem identifiedMMO;
|
||||
|
||||
// Generate as MMOItem
|
||||
if (identifiedMMO != null) {
|
||||
/**
|
||||
* @return The output ItemStack from this
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@NotNull
|
||||
public ItemStack getOutputItemStack(@Nullable RPGPlayer rpg) {
|
||||
|
||||
/*
|
||||
* Generate in the legacy way. I do this way to preserve
|
||||
* backwards compatibility, since this is how it used to
|
||||
* be done. Don't want to break that without good reason.
|
||||
*/
|
||||
return identifiedMMO.getPreview();
|
||||
}
|
||||
// Generate as MMOItem
|
||||
if (identifiedMMO != null && rpg != null) {
|
||||
|
||||
// Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection.
|
||||
//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;
|
||||
}
|
||||
public int getOutputAmount() { return output.getAmount(1); }
|
||||
/*
|
||||
* Generate in the legacy way. I do this way to preserve
|
||||
* backwards compatibility, since this is how it used to
|
||||
* be done. Don't want to break that without good reason.
|
||||
*/
|
||||
return identifiedMMO.generate(rpg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean whenUsed(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
|
||||
if (!data.isOnline())
|
||||
return false;
|
||||
// Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection.
|
||||
return output.getItemStack(null);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the recipe is instant, take the ingredients off
|
||||
* and directly add the output to the player's inventory
|
||||
*/
|
||||
if (isInstant()) {
|
||||
/**
|
||||
* @return The preview ItemStack from this
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getPreviewItemStack() {
|
||||
|
||||
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;
|
||||
// Generate as MMOItem
|
||||
if (identifiedMMO != null) {
|
||||
|
||||
/*
|
||||
* Since instant recipes bypass the crafting queue MI still needs
|
||||
* to apply the trigger list when using an instant recipe
|
||||
*/
|
||||
recipe.getRecipe().whenClaimed().forEach(trigger -> trigger.whenCrafting(data));
|
||||
/*
|
||||
* Generate in the legacy way. I do this way to preserve
|
||||
* backwards compatibility, since this is how it used to
|
||||
* be done. Don't want to break that without good reason.
|
||||
*/
|
||||
return identifiedMMO.getPreview();
|
||||
}
|
||||
|
||||
if (result != null)
|
||||
new SmartGive(data.getPlayer()).give(result);
|
||||
// Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection.
|
||||
//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
|
||||
if (!hasOption(RecipeOption.SILENT_CRAFT))
|
||||
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
|
||||
public int getOutputAmount() {
|
||||
return output.getAmount(1);
|
||||
}
|
||||
|
||||
// Recipe was successfully used
|
||||
return true;
|
||||
@Override
|
||||
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
|
||||
*/
|
||||
} else {
|
||||
/*
|
||||
* If the recipe is instant, take the ingredients off
|
||||
* 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);
|
||||
if (event.isCancelled())
|
||||
return false;
|
||||
|
||||
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(data, station, recipe);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return false;
|
||||
/*
|
||||
* Since instant recipes bypass the crafting queue MI still needs
|
||||
* to apply the trigger list when using an instant recipe
|
||||
*/
|
||||
recipe.getRecipe().whenClaimed().forEach(trigger -> trigger.whenCrafting(data));
|
||||
|
||||
// Play sound
|
||||
if (!hasOption(RecipeOption.SILENT_CRAFT))
|
||||
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
|
||||
if (result != null)
|
||||
new SmartGive(data.getPlayer()).give(result);
|
||||
|
||||
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
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Recipe was successfully used
|
||||
return true;
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerData data, IngredientInventory inv, CheckedRecipe recipe, CraftingStation station) {
|
||||
if (isInstant())
|
||||
return true;
|
||||
/*
|
||||
* If the recipe is not instant, add the item to the crafting queue
|
||||
*/
|
||||
}
|
||||
|
||||
CraftingQueue queue = data.getCrafting().getQueue(station);
|
||||
if (queue.isFull(station)) {
|
||||
if (!data.isOnline())
|
||||
return false;
|
||||
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(data, station, recipe);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
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;
|
||||
}
|
||||
// Play sound
|
||||
if (!hasOption(RecipeOption.SILENT_CRAFT))
|
||||
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
|
||||
|
||||
@Override
|
||||
public ItemStack display(CheckedRecipe recipe) { return ConfigItems.CRAFTING_RECIPE_DISPLAY.newBuilder(recipe).build(); }
|
||||
data.getCrafting().getQueue(station).add(this);
|
||||
|
||||
@Override
|
||||
public CheckedRecipe evaluateRecipe(PlayerData data, IngredientInventory inv) {
|
||||
return new CheckedRecipe(this, data, inv);
|
||||
}
|
||||
// Recipe was successfully used
|
||||
return true;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user