From 0bc2cf6d44e2e78eb7b9cc4cf469e5d644a3fe62 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 4 Jul 2020 13:59:39 +0200 Subject: [PATCH] Slight player attribute API change --- .../api/player/attribute/PlayerAttribute.java | 13 +++++-------- .../api/player/attribute/PlayerAttributes.java | 4 ++-- .../Indyuce/mmocore/command/MMOCoreCommand.java | 3 ++- .../net/Indyuce/mmocore/gui/AttributeView.java | 14 ++++++-------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttribute.java b/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttribute.java index 920c3e0a..76da07ad 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttribute.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttribute.java @@ -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 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> getBuffs() { - return buffs.entrySet(); + public Map getBuffs() { + return buffs; } } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttributes.java b/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttributes.java index 2eabaca2..bb2fc929 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttributes.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/attribute/PlayerAttributes.java @@ -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() { diff --git a/src/main/java/net/Indyuce/mmocore/command/MMOCoreCommand.java b/src/main/java/net/Indyuce/mmocore/command/MMOCoreCommand.java index 955b85b1..2c870325 100644 --- a/src/main/java/net/Indyuce/mmocore/command/MMOCoreCommand.java +++ b/src/main/java/net/Indyuce/mmocore/command/MMOCoreCommand.java @@ -54,6 +54,7 @@ public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabC CommandParser reader = readCommand(args); List 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()); } } diff --git a/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java b/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java index 57fb2705..bdb82aca 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java @@ -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 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; } }