mirror of
https://github.com/songoda/EpicEnchants.git
synced 2024-09-28 23:57:33 +02:00
- Improved the info menus.
This commit is contained in:
parent
817aa2cb8d
commit
19caa00bc5
@ -31,8 +31,8 @@ public abstract class EffectExecutor {
|
|||||||
this.section = section;
|
this.section = section;
|
||||||
this.triggerTypes = GeneralUtils.parseTrigger(section.getString("trigger"));
|
this.triggerTypes = GeneralUtils.parseTrigger(section.getString("trigger"));
|
||||||
this.condition = Condition.of(section.getString("condition"));
|
this.condition = Condition.of(section.getString("condition"));
|
||||||
this.simultaneous = section.isConfigurationSection("effects") ? section.getConfigurationSection("effects").getKeys(false).stream()
|
this.simultaneous = section.isConfigurationSection("simultaneous") ? section.getConfigurationSection("simultaneous").getKeys(false).stream()
|
||||||
.map(s -> "effects." + s)
|
.map(s -> "simultaneous." + s)
|
||||||
.map(section::getConfigurationSection)
|
.map(section::getConfigurationSection)
|
||||||
.map(EffectManager::getEffect)
|
.map(EffectManager::getEffect)
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
@ -41,7 +41,11 @@ public abstract class EffectExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAndRun(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType) {
|
public void testAndRun(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType) {
|
||||||
if (!triggerTypes.contains(type)) {
|
testAndRun(user, opponent, level, type, event, eventType, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAndRun(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType, boolean simul) {
|
||||||
|
if (!simul && !triggerTypes.contains(type)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +63,7 @@ public abstract class EffectExecutor {
|
|||||||
execute(user, opponent, level, eventType);
|
execute(user, opponent, level, eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
simultaneous.forEach(e -> e.execute(user, opponent, level, eventType));
|
simultaneous.forEach(e -> e.testAndRun(user, opponent, level, type, event, eventType, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType);
|
public abstract void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType);
|
||||||
|
@ -41,8 +41,8 @@ public class Potion extends EffectExecutor {
|
|||||||
|
|
||||||
LeveledModifier duration = LeveledModifier.of(getSection().getString("duration"));
|
LeveledModifier duration = LeveledModifier.of(getSection().getString("duration"));
|
||||||
|
|
||||||
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, ((int) duration.get(level, 60, user, opponent)),
|
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, (int) duration.get(level, 60, user, opponent) * 20,
|
||||||
((int) amplifier.get(level - 1, 0, user, opponent)), false, false)), user, opponent);
|
(int) amplifier.get(level - 1, 0, user, opponent), false, false)), user, opponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.songoda.epicenchants.managers;
|
package com.songoda.epicenchants.managers;
|
||||||
|
|
||||||
import com.songoda.epicenchants.EpicEnchants;
|
import com.songoda.epicenchants.EpicEnchants;
|
||||||
import com.songoda.epicenchants.utils.objects.FileLocationObject;
|
import com.songoda.epicenchants.utils.objects.FileLocation;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
@ -12,14 +12,14 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static com.songoda.epicenchants.utils.objects.FileLocationObject.of;
|
import static com.songoda.epicenchants.utils.objects.FileLocation.of;
|
||||||
import static java.io.File.separator;
|
import static java.io.File.separator;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
public class FileManager extends Manager<String, FileConfiguration> {
|
public class FileManager extends Manager<String, FileConfiguration> {
|
||||||
|
|
||||||
private final String directory;
|
private final String directory;
|
||||||
private final LinkedHashSet<FileLocationObject> files = new LinkedHashSet<>(asList(
|
private final LinkedHashSet<FileLocation> files = new LinkedHashSet<>(asList(
|
||||||
of("config.yml", true),
|
of("config.yml", true),
|
||||||
of("menus/main-info-menu.yml", true),
|
of("menus/main-info-menu.yml", true),
|
||||||
of("menus/enchanter-menu.yml", true, true),
|
of("menus/enchanter-menu.yml", true, true),
|
||||||
|
@ -6,11 +6,13 @@ import com.songoda.epicenchants.objects.Group;
|
|||||||
import com.songoda.epicenchants.utils.objects.FastInv;
|
import com.songoda.epicenchants.utils.objects.FastInv;
|
||||||
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static com.songoda.epicenchants.objects.Placeholder.of;
|
import static com.songoda.epicenchants.objects.Placeholder.of;
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
||||||
@ -18,22 +20,33 @@ import static java.util.Arrays.stream;
|
|||||||
|
|
||||||
public class InfoMenu extends FastInv {
|
public class InfoMenu extends FastInv {
|
||||||
public InfoMenu(EpicEnchants instance, FileConfiguration config) {
|
public InfoMenu(EpicEnchants instance, FileConfiguration config) {
|
||||||
super(config.getInt("size"), color(config.getString("title")));
|
super(config.getInt("rows") * 9, color(config.getString("title")));
|
||||||
|
|
||||||
Group group = instance.getGroupManager().getValue(config.getString("group")).orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group")));
|
Group group = instance.getGroupManager().getValue(config.getString("group")).orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group")));
|
||||||
|
|
||||||
|
Set<Integer> slots;
|
||||||
|
|
||||||
|
if (config.getString("slots").equalsIgnoreCase("ALL_SLOTS")) {
|
||||||
|
slots = IntStream.range(0, config.getInt("rows") * 9).boxed().collect(Collectors.toSet());
|
||||||
|
} else {
|
||||||
String[] split = config.getString("slots").split(",");
|
String[] split = config.getString("slots").split(",");
|
||||||
Set<Integer> slots = stream(split, 0, split.length)
|
slots = stream(split, 0, split.length).filter(StringUtils::isNumeric).map(Integer::parseInt).collect(Collectors.toSet());
|
||||||
.filter(StringUtils::isNumeric)
|
}
|
||||||
.map(Integer::parseInt)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
Iterator<Enchant> enchantIterator = instance.getEnchantManager().getEnchants(group).iterator();
|
Iterator<Enchant> enchantIterator = instance.getEnchantManager().getEnchants(group).iterator();
|
||||||
slots.stream().filter(slot -> enchantIterator.hasNext()).forEach(slot -> {
|
slots.stream().filter(slot -> enchantIterator.hasNext()).forEach(slot -> {
|
||||||
Enchant enchant = enchantIterator.next();
|
Enchant enchant = enchantIterator.next();
|
||||||
|
|
||||||
|
String whitelist = instance.getItemGroup().getGroup(enchant.getItemWhitelist())
|
||||||
|
.map(s -> StringUtils.capitalize(s.getName().toLowerCase()))
|
||||||
|
.orElse(String.join(", ", enchant.getItemWhitelist().stream().map(Material::toString).collect(Collectors.toSet())));
|
||||||
|
|
||||||
addItem(slot, new ItemBuilder(config.getConfigurationSection("enchant-item"),
|
addItem(slot, new ItemBuilder(config.getConfigurationSection("enchant-item"),
|
||||||
of("group_color", enchant.getGroup().getColor()),
|
of("group_color", enchant.getGroup().getColor()),
|
||||||
of("enchant", enchant.getIdentifier()),
|
of("enchant", enchant.getIdentifier()),
|
||||||
|
of("max_level", enchant.getMaxLevel()),
|
||||||
|
of("applicable_to", whitelist),
|
||||||
|
of("enchant", enchant.getIdentifier()),
|
||||||
of("description", enchant.getDescription())).build());
|
of("description", enchant.getDescription())).build());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -17,13 +17,11 @@ public class MainInfoMenu extends FastInv implements Listener {
|
|||||||
.stream()
|
.stream()
|
||||||
.map(s -> "contents." + s)
|
.map(s -> "contents." + s)
|
||||||
.map(config::getConfigurationSection)
|
.map(config::getConfigurationSection)
|
||||||
.forEach(section -> {
|
.forEach(section -> addItem(section.getInt("slot"), new ItemBuilder(section).build(), event -> {
|
||||||
addItem(section.getInt("slot"), new ItemBuilder(section).build(), event -> {
|
|
||||||
Group group = instance.getGroupManager().getValue(section.getString("group"))
|
Group group = instance.getGroupManager().getValue(section.getString("group"))
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + section.getString("group")));
|
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + section.getString("group")));
|
||||||
instance.getInfoManager().getMenu(group).ifPresent(menu -> menu.open(event.getPlayer()));
|
instance.getInfoManager().getMenu(group).ifPresent(menu -> menu.open(event.getPlayer()));
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,6 @@ public class LeveledModifier {
|
|||||||
|
|
||||||
String toTest = Placeholders.setPlaceholders(string, user, opponent, level);
|
String toTest = Placeholders.setPlaceholders(string, user, opponent, level);
|
||||||
|
|
||||||
return (double) GeneralUtils.parseJS(toTest, "LeveledModifier", def);
|
return (double) (int) GeneralUtils.parseJS(toTest, "LeveledModifier", def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,22 +2,22 @@ package com.songoda.epicenchants.utils.objects;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
public class FileLocationObject {
|
public class FileLocation {
|
||||||
@Getter private final boolean required, versionDependent;
|
@Getter private final boolean required, versionDependent;
|
||||||
@Getter private final String path;
|
@Getter private final String path;
|
||||||
|
|
||||||
private FileLocationObject(String path, boolean required, boolean versionDependent) {
|
private FileLocation(String path, boolean required, boolean versionDependent) {
|
||||||
this.required = required;
|
this.required = required;
|
||||||
this.versionDependent = versionDependent;
|
this.versionDependent = versionDependent;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileLocationObject of(String path, boolean required) {
|
public static FileLocation of(String path, boolean required) {
|
||||||
return new FileLocationObject(path, required, false);
|
return new FileLocation(path, required, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileLocationObject of(String path, boolean required, boolean versionDependent) {
|
public static FileLocation of(String path, boolean required, boolean versionDependent) {
|
||||||
return new FileLocationObject(path, required, versionDependent);
|
return new FileLocation(path, required, versionDependent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResourcePath(String dir) {
|
public String getResourcePath(String dir) {
|
@ -72,15 +72,15 @@ public class ItemBuilder {
|
|||||||
|
|
||||||
if (section.contains("lore")) {
|
if (section.contains("lore")) {
|
||||||
List<String> lore = section.getStringList("lore");
|
List<String> lore = section.getStringList("lore");
|
||||||
|
outer:
|
||||||
for (int i = 0; i < lore.size(); i++) {
|
for (int i = 0; i < lore.size(); i++) {
|
||||||
String string = lore.get(i);
|
String string = lore.get(i);
|
||||||
|
|
||||||
for (Placeholder placeholder : placeholders) {
|
for (Placeholder placeholder : placeholders) {
|
||||||
if (placeholder.getToReplace() instanceof HashSet && string.contains(placeholder.getPlaceholder())) {
|
if (placeholder.getToReplace() instanceof ArrayList && string.contains(placeholder.getPlaceholder())) {
|
||||||
lore.remove(i);
|
lore.remove(i);
|
||||||
|
lore.addAll(i, (ArrayList<String>) placeholder.getToReplace());
|
||||||
Set<String> stringSet = (Set<String>) placeholder.getToReplace();
|
continue outer;
|
||||||
lore.addAll(i, stringSet);
|
|
||||||
} else {
|
} else {
|
||||||
string = string.replace(placeholder.getPlaceholder(), placeholder.getToReplace().toString());
|
string = string.replace(placeholder.getPlaceholder(), placeholder.getToReplace().toString());
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class GeneralUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Set<TriggerType> parseTrigger(String triggers) {
|
public static Set<TriggerType> parseTrigger(String triggers) {
|
||||||
return Arrays.stream(triggers.replaceAll("\\s+", "").split(",")).map(TriggerType::valueOf).collect(Collectors.toSet());
|
return triggers == null ? Collections.emptySet() : Arrays.stream(triggers.replaceAll("\\s+", "").split(",")).map(TriggerType::valueOf).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getHeldItem(Player player, Event event) {
|
public static ItemStack getHeldItem(Player player, Event event) {
|
||||||
@ -79,10 +79,9 @@ public class GeneralUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object parseJS(String toParse, String type, Object def) {
|
public static Object parseJS(String toParse, String type, Object def) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return SCRIPT_ENGINE.eval(toParse);
|
return SCRIPT_ENGINE.eval(toParse);
|
||||||
} catch (ScriptException | NumberFormatException e) {
|
} catch (ScriptException e) {
|
||||||
Bukkit.getLogger().warning("[EpicEnchants] One of your " + type + " expressions is not properly formatted.");
|
Bukkit.getLogger().warning("[EpicEnchants] One of your " + type + " expressions is not properly formatted.");
|
||||||
Bukkit.getLogger().warning(toParse);
|
Bukkit.getLogger().warning(toParse);
|
||||||
return def;
|
return def;
|
||||||
|
@ -76,6 +76,14 @@ public class ItemGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Group> getGroup(Set<Material> materials) {
|
public Optional<Group> getGroup(Set<Material> materials) {
|
||||||
|
Optional<Group> group = Arrays.stream(Group.values())
|
||||||
|
.filter(s -> !s.getChildren().isEmpty() && s.getChildren().stream().allMatch(child -> materials.containsAll(groupMap.get(child))))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
if (group.isPresent()) {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
return groupMap.asMap().entrySet().stream().filter(s -> s.getValue().equals(materials)).map(Map.Entry::getKey).findFirst();
|
return groupMap.asMap().entrySet().stream().filter(s -> s.getValue().equals(materials)).map(Map.Entry::getKey).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
title: "Elite enchants"
|
title: "Elite enchants"
|
||||||
size: 9
|
rows: 1
|
||||||
|
|
||||||
#Slots that you want enchants to be displayed on
|
#Slots that you want enchants to be displayed on
|
||||||
slots: "4,5,6"
|
slots: "ALL_SLOTS"
|
||||||
|
|
||||||
#The group of the enchants to be displayed
|
#The group of the enchants to be displayed
|
||||||
group: ELITE
|
group: ELITE
|
||||||
|
|
||||||
enchant-item:
|
enchant-item:
|
||||||
material: "PAPER"
|
material: "PAPER"
|
||||||
display-name: "{group_color} {enchant}"
|
display-name: "{group_color}{enchant}"
|
||||||
lore:
|
lore:
|
||||||
|
- "&7Max level: &f{max_level}"
|
||||||
|
- "&7Applicable to: &f{applicable_to}"
|
||||||
- "&7Description:"
|
- "&7Description:"
|
||||||
- "{description}"
|
- "{description}"
|
@ -1,15 +1,17 @@
|
|||||||
title: "Legendary enchants"
|
title: "Legendary enchants"
|
||||||
size: 9
|
rows: 1
|
||||||
|
|
||||||
#Slots that you want enchants to be displayed on
|
#Slots that you want enchants to be displayed on
|
||||||
slots: "4,5,6"
|
slots: "ALL_SLOTS"
|
||||||
|
|
||||||
#The group of the enchants to be displayed
|
#The group of the enchants to be displayed
|
||||||
group: LEGENDARY
|
group: LEGENDARY
|
||||||
|
|
||||||
enchant-item:
|
enchant-item:
|
||||||
material: "PAPER"
|
material: "PAPER"
|
||||||
display-name: "{group_color} {enchant}"
|
display-name: "{group_color}{enchant}"
|
||||||
lore:
|
lore:
|
||||||
|
- "&7Max level: &f{max_level}"
|
||||||
|
- "&7Applicable to: &f{applicable_to}"
|
||||||
- "&7Description:"
|
- "&7Description:"
|
||||||
- "{description}"
|
- "{description}"
|
@ -1,15 +1,17 @@
|
|||||||
title: "Simple enchants"
|
title: "Simple enchants"
|
||||||
size: 9
|
rows: 1
|
||||||
|
|
||||||
#Slots that you want enchants to be displayed on
|
#Slots that you want enchants to be displayed on
|
||||||
slots: "4,5,6"
|
slots: "ALL_SLOTS"
|
||||||
|
|
||||||
#The group of the enchants to be displayed
|
#The group of the enchants to be displayed
|
||||||
group: SIMPLE
|
group: SIMPLE
|
||||||
|
|
||||||
enchant-item:
|
enchant-item:
|
||||||
material: "PAPER"
|
material: "PAPER"
|
||||||
display-name: "{group_color} {enchant}"
|
display-name: "{group_color}{enchant}"
|
||||||
lore:
|
lore:
|
||||||
|
- "&7Max level: &f{max_level}"
|
||||||
|
- "&7Applicable to: &f{applicable_to}"
|
||||||
- "&7Description:"
|
- "&7Description:"
|
||||||
- "{description}"
|
- "{description}"
|
@ -1,15 +1,17 @@
|
|||||||
title: "Ultimate enchants"
|
title: "Ultimate enchants"
|
||||||
size: 9
|
rows: 1
|
||||||
|
|
||||||
#Slots that you want enchants to be displayed on
|
#Slots that you want enchants to be displayed on
|
||||||
slots: "4,5,6"
|
slots: "ALL_SLOTS"
|
||||||
|
|
||||||
#The group of the enchants to be displayed
|
#The group of the enchants to be displayed
|
||||||
group: ULTIMATE
|
group: ULTIMATE
|
||||||
|
|
||||||
enchant-item:
|
enchant-item:
|
||||||
material: "PAPER"
|
material: "PAPER"
|
||||||
display-name: "{group_color} {enchant}"
|
display-name: "{group_color}{enchant}"
|
||||||
lore:
|
lore:
|
||||||
|
- "&7Max level: &f{max_level}"
|
||||||
|
- "&7Applicable to: &f{applicable_to}"
|
||||||
- "&7Description:"
|
- "&7Description:"
|
||||||
- "{description}"
|
- "{description}"
|
@ -1,15 +1,17 @@
|
|||||||
title: "Unique enchants"
|
title: "Unique enchants"
|
||||||
size: 9
|
rows: 1
|
||||||
|
|
||||||
#Slots that you want enchants to be displayed on
|
#Slots that you want enchants to be displayed on
|
||||||
slots: "4,5,6"
|
slots: "ALL_SLOTS"
|
||||||
|
|
||||||
#The group of the enchants to be displayed
|
#The group of the enchants to be displayed
|
||||||
group: UNIQUE
|
group: UNIQUE
|
||||||
|
|
||||||
enchant-item:
|
enchant-item:
|
||||||
material: "PAPER"
|
material: "PAPER"
|
||||||
display-name: "{group_color} {enchant}"
|
display-name: "{group_color}{enchant}"
|
||||||
lore:
|
lore:
|
||||||
|
- "&7Max level: &f{max_level}"
|
||||||
|
- "&7Applicable to: &f{applicable_to}"
|
||||||
- "&7Description:"
|
- "&7Description:"
|
||||||
- "{description}"
|
- "{description}"
|
Loading…
Reference in New Issue
Block a user