6.2.4 - Item Generation Bug Fixes

Fixed '/mi generate' not randomizing items
Fixed '/mi generate' not respecting '-id:'
Item Builder no longer throwing errors if tier doesn't have gen options
This commit is contained in:
ASangarin 2020-10-15 03:09:19 +02:00
parent 066b6d5269
commit e25ffdf366
6 changed files with 68 additions and 13 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOItems</artifactId>
<version>6.2.3</version>
<version>6.2.4</version>
<name>MMOItems</name>
<description>A great item solution for your RPG server.</description>

View File

@ -54,7 +54,7 @@ public class MMOItemBuilder {
public MMOItemBuilder(MMOItemTemplate template, int level, ItemTier tier) {
this.level = level;
this.tier = tier;
this.capacity = (tier != null ? tier.getCapacity() : MMOItems.plugin.getLanguage().defaultItemCapacity).calculate(level);
this.capacity = (tier != null && tier.hasCapacity() ? tier.getCapacity() : MMOItems.plugin.getLanguage().defaultItemCapacity).calculate(level);
this.mmoitem = new MMOItem(template.getType(), template.getId());
// apply base item data

View File

@ -0,0 +1,18 @@
package net.Indyuce.mmoitems.api.item.template.explorer;
import java.util.function.Predicate;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
public class IDFilter implements Predicate<MMOItemTemplate> {
private final String id;
public IDFilter(String id) {
this.id = id;
}
@Override
public boolean test(MMOItemTemplate template) {
return template.getId().equalsIgnoreCase(id);
}
}

View File

@ -2,6 +2,7 @@ package net.Indyuce.mmoitems.api.item.template.explorer;
import java.util.Collection;
import java.util.Optional;
import java.util.Random;
import java.util.function.Predicate;
import net.Indyuce.mmoitems.MMOItems;
@ -19,6 +20,7 @@ import net.Indyuce.mmoitems.api.player.RPGPlayer;
*
*/
public class TemplateExplorer {
private final Random random = new Random();
/*
* Not defined at the beginning to save extra performance, if there are 100+
@ -36,14 +38,20 @@ public class TemplateExplorer {
}
public Optional<MMOItemTemplate> rollLoot() {
return all.stream().findAny();
switch (count()) {
case 0:
return Optional.empty();
case 1:
return all.stream().findFirst();
default:
return all.stream().skip(random.nextInt(count() - 1)).findFirst();
}
}
/**
* Util method to easily generate random MI loot
*
* @param player
* The player
* @param player The player
* @return Random item with random tier and item level which matches the
* player's level
*/

View File

@ -17,6 +17,7 @@ import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.item.template.explorer.ClassFilter;
import net.Indyuce.mmoitems.api.item.template.explorer.IDFilter;
import net.Indyuce.mmoitems.api.item.template.explorer.TemplateExplorer;
import net.Indyuce.mmoitems.api.item.template.explorer.TypeFilter;
import net.Indyuce.mmoitems.api.player.PlayerData;
@ -39,6 +40,7 @@ public class GenerateCommandTreeNode extends CommandTreeNode {
@Override
public CommandResult execute(CommandSender sender, String[] args) {
try {
if(args.length < 2) return CommandResult.THROW_USAGE;
final Player target = Bukkit.getPlayer(args[1]);
Validate.notNull(target, "Could not find player called " + args[1] + ".");
@ -60,10 +62,15 @@ public class GenerateCommandTreeNode extends CommandTreeNode {
builder.applyFilter(new ClassFilter(rpgPlayer));
if (handler.hasArgument("class"))
builder.applyFilter(new ClassFilter(handler.getValue("class").replace("-", " ").replace("_", " ")));
String type = null;
if (handler.hasArgument("type")) {
String format = handler.getValue("type");
Validate.isTrue(Type.isValid(format), "Could not find type with ID '" + format + "'");
builder.applyFilter(new TypeFilter(Type.get(format)));
type = handler.getValue("type");
Validate.isTrue(Type.isValid(type), "Could not find type with ID '" + type + "'");
builder.applyFilter(new TypeFilter(Type.get(type)));
}
if (handler.hasArgument("id")) {
Validate.isTrue(type != null, "You have to specify a type if using the id option!");
builder.applyFilter(new IDFilter(handler.getValue("id")));
}
Optional<MMOItemTemplate> optional = builder.rollLoot();

View File

@ -11,7 +11,8 @@ TRASH:
range: 6
name: 'Trash'
prefix: '&8'
# This tier has no generation options specified.
# In that case, it'll use the default values set in config.yml
COMMON:
name: '&7&lCOMMON'
parent: TRASH
@ -19,6 +20,8 @@ COMMON:
range: 6
name: 'Common'
prefix: '&7'
# This tier has no generation options specified.
# In that case, it'll use the default values set in config.yml
UNCOMMON:
# Tier name displayed in the item lore.
@ -77,10 +80,10 @@ RARE:
range: 6
prefix: '&6'
generation:
chance: 0.01
chance: 0.06
capacity:
base: 12
scale: .2
base: 9
scale: .15
spread: .1
max-spread: .3
deconstruct-item:
@ -111,6 +114,13 @@ VERY_RARE:
items:
MATERIAL:
WEAPON_POWDER: 100,1-1,0
generation:
chance: 0.03
capacity:
base: 10
scale: .17
spread: .1
max-spread: .3
LEGENDARY:
name: '&b&lLEGENDARY'
unidentification:
@ -128,6 +138,13 @@ LEGENDARY:
items:
MATERIAL:
WEAPON_POWDER: 100,1-1,0
generation:
chance: 0.01
capacity:
base: 12
scale: .2
spread: .1
max-spread: .3
MYTHICAL:
name: '&5&lMYTHICAL'
unidentification:
@ -169,7 +186,8 @@ EPIC:
items:
MATERIAL:
WEAPON_POWDER: 100,1-1,0
# This tier has no generation options specified.
# In that case, it'll use the default values set in config.yml
MAGICAL:
name: '&2&lMAGICAL'
unidentification:
@ -187,6 +205,8 @@ MAGICAL:
items:
MATERIAL:
WEAPON_POWDER: 100,1-1,0
# This tier has no generation options specified.
# In that case, it'll use the default values set in config.yml
UNIQUE:
name: '&c&lUNIQUE'
unidentification:
@ -204,3 +224,5 @@ UNIQUE:
items:
MATERIAL:
WEAPON_POWDER: 100,1-1,0
# This tier has no generation options specified.
# In that case, it'll use the default values set in config.yml