Slight player attribute API change

This commit is contained in:
Indyuce 2020-07-04 13:59:39 +02:00
parent fa0d13efa8
commit 0bc2cf6d44
4 changed files with 15 additions and 19 deletions

View File

@ -2,8 +2,6 @@ package net.Indyuce.mmocore.api.player.attribute;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
@ -18,8 +16,8 @@ public class PlayerAttribute {
private final int max;
/*
* used to store stats using StatType, but attributes also need to access non
* basic MMOCore stats hence the string maps keys
* used to store stats using StatType, but attributes also need to access
* non basic MMOCore stats hence the string maps keys
*/
private final Map<String, StatModifier> buffs = new HashMap<>();
@ -38,8 +36,7 @@ public class PlayerAttribute {
String stat = key.toUpperCase().replace("-", "_").replace(" ", "_");
buffs.put(stat, new StatModifier(config.getString("buff." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING,
"Could not load buff '" + key + "' from attribute '" + id + "': " + exception.getMessage());
MMOCore.log(Level.WARNING, "Could not load buff '" + key + "' from attribute '" + id + "': " + exception.getMessage());
}
}
@ -59,7 +56,7 @@ public class PlayerAttribute {
return max;
}
public Set<Entry<String, StatModifier>> getBuffs() {
return buffs.entrySet();
public Map<String, StatModifier> getBuffs() {
return buffs;
}
}

View File

@ -193,8 +193,8 @@ public class PlayerAttributes {
public void update() {
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(id);
int total = getTotal();
attribute.getBuffs().forEach(buff -> data.getStats().getInstance(buff.getKey()).addModifier("attribute." + attribute.getId(),
buff.getValue().multiply(total)));
attribute.getBuffs()
.forEach((key, buff) -> data.getStats().getInstance(key).addModifier("attribute." + attribute.getId(), buff.multiply(total)));
}
public String getId() {

View File

@ -54,6 +54,7 @@ public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabC
CommandParser reader = readCommand(args);
List<String> list = reader.readTabCompletion();
return args[args.length - 1].isEmpty() ? list : list.stream().filter(string -> string.toLowerCase().startsWith(args[args.length - 1].toLowerCase())).collect(Collectors.toList());
return args[args.length - 1].isEmpty() ? list
: list.stream().filter(string -> string.toLowerCase().startsWith(args[args.length - 1].toLowerCase())).collect(Collectors.toList());
}
}

View File

@ -1,7 +1,5 @@
package net.Indyuce.mmocore.gui;
import java.util.Map.Entry;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryClickEvent;
@ -17,7 +15,6 @@ import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.InventoryPlaceholderItem;
import net.Indyuce.mmocore.gui.api.item.NoPlaceholderItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.mmogroup.mmolib.api.stat.modifier.StatModifier;
public class AttributeView extends EditableInventory {
public AttributeView() {
@ -52,7 +49,8 @@ public class AttributeView extends EditableInventory {
public AttributeItem(String function, ConfigurationSection config) {
super(config);
attribute = MMOCore.plugin.attributeManager.get(function.substring("attribute_".length()).toLowerCase().replace(" ", "-").replace("_", "-"));
attribute = MMOCore.plugin.attributeManager
.get(function.substring("attribute_".length()).toLowerCase().replace(" ", "-").replace("_", "-"));
}
@Override
@ -66,10 +64,10 @@ public class AttributeView extends EditableInventory {
holders.register("max", attribute.getMax());
holders.register("current", total);
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
for (Entry<String, StatModifier> entry : attribute.getBuffs()) {
holders.register("buff_" + entry.getKey().toLowerCase(), entry.getValue());
holders.register("total_" + entry.getKey().toLowerCase(), entry.getValue().multiply(total));
}
attribute.getBuffs().forEach((key, buff) -> {
holders.register("buff_" + key.toLowerCase(), buff);
holders.register("total_" + key.toLowerCase(), buff.multiply(total));
});
return holders;
}
}