forked from Upstream/mmocore
Slight player attribute API change
This commit is contained in:
parent
fa0d13efa8
commit
0bc2cf6d44
@ -2,8 +2,6 @@ package net.Indyuce.mmocore.api.player.attribute;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
@ -18,8 +16,8 @@ public class PlayerAttribute {
|
|||||||
private final int max;
|
private final int max;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* used to store stats using StatType, but attributes also need to access non
|
* used to store stats using StatType, but attributes also need to access
|
||||||
* basic MMOCore stats hence the string maps keys
|
* non basic MMOCore stats hence the string maps keys
|
||||||
*/
|
*/
|
||||||
private final Map<String, StatModifier> buffs = new HashMap<>();
|
private final Map<String, StatModifier> buffs = new HashMap<>();
|
||||||
|
|
||||||
@ -38,8 +36,7 @@ public class PlayerAttribute {
|
|||||||
String stat = key.toUpperCase().replace("-", "_").replace(" ", "_");
|
String stat = key.toUpperCase().replace("-", "_").replace(" ", "_");
|
||||||
buffs.put(stat, new StatModifier(config.getString("buff." + key)));
|
buffs.put(stat, new StatModifier(config.getString("buff." + key)));
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOCore.log(Level.WARNING,
|
MMOCore.log(Level.WARNING, "Could not load buff '" + key + "' from attribute '" + id + "': " + exception.getMessage());
|
||||||
"Could not load buff '" + key + "' from attribute '" + id + "': " + exception.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +56,7 @@ public class PlayerAttribute {
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Entry<String, StatModifier>> getBuffs() {
|
public Map<String, StatModifier> getBuffs() {
|
||||||
return buffs.entrySet();
|
return buffs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,8 +193,8 @@ public class PlayerAttributes {
|
|||||||
public void update() {
|
public void update() {
|
||||||
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(id);
|
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(id);
|
||||||
int total = getTotal();
|
int total = getTotal();
|
||||||
attribute.getBuffs().forEach(buff -> data.getStats().getInstance(buff.getKey()).addModifier("attribute." + attribute.getId(),
|
attribute.getBuffs()
|
||||||
buff.getValue().multiply(total)));
|
.forEach((key, buff) -> data.getStats().getInstance(key).addModifier("attribute." + attribute.getId(), buff.multiply(total)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -54,6 +54,7 @@ public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabC
|
|||||||
|
|
||||||
CommandParser reader = readCommand(args);
|
CommandParser reader = readCommand(args);
|
||||||
List<String> list = reader.readTabCompletion();
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.Indyuce.mmocore.gui;
|
package net.Indyuce.mmocore.gui;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
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.InventoryPlaceholderItem;
|
||||||
import net.Indyuce.mmocore.gui.api.item.NoPlaceholderItem;
|
import net.Indyuce.mmocore.gui.api.item.NoPlaceholderItem;
|
||||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||||
import net.mmogroup.mmolib.api.stat.modifier.StatModifier;
|
|
||||||
|
|
||||||
public class AttributeView extends EditableInventory {
|
public class AttributeView extends EditableInventory {
|
||||||
public AttributeView() {
|
public AttributeView() {
|
||||||
@ -52,7 +49,8 @@ public class AttributeView extends EditableInventory {
|
|||||||
public AttributeItem(String function, ConfigurationSection config) {
|
public AttributeItem(String function, ConfigurationSection config) {
|
||||||
super(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
|
@Override
|
||||||
@ -66,10 +64,10 @@ public class AttributeView extends EditableInventory {
|
|||||||
holders.register("max", attribute.getMax());
|
holders.register("max", attribute.getMax());
|
||||||
holders.register("current", total);
|
holders.register("current", total);
|
||||||
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
|
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
|
||||||
for (Entry<String, StatModifier> entry : attribute.getBuffs()) {
|
attribute.getBuffs().forEach((key, buff) -> {
|
||||||
holders.register("buff_" + entry.getKey().toLowerCase(), entry.getValue());
|
holders.register("buff_" + key.toLowerCase(), buff);
|
||||||
holders.register("total_" + entry.getKey().toLowerCase(), entry.getValue().multiply(total));
|
holders.register("total_" + key.toLowerCase(), buff.multiply(total));
|
||||||
}
|
});
|
||||||
return holders;
|
return holders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user