9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-06 15:51:52 +00:00

Added GUI

This commit is contained in:
Auxilor
2021-08-20 17:30:21 +01:00
parent dfc0779ba5
commit e437a1f1ca
9 changed files with 259 additions and 31 deletions

View File

@@ -3,6 +3,7 @@ package com.willfp.ecoskills;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.ecoskills.commands.CommandEcoskills;
import com.willfp.ecoskills.commands.CommandSkills;
import com.willfp.ecoskills.effects.Effect;
import com.willfp.ecoskills.effects.Effects;
import com.willfp.ecoskills.skills.SkillDisplayListener;
@@ -66,7 +67,8 @@ public class EcoSkillsPlugin extends EcoPlugin {
@Override
protected List<PluginCommand> loadPluginCommands() {
return Arrays.asList(
new CommandEcoskills(this)
new CommandEcoskills(this),
new CommandSkills(this)
);
}
}

View File

@@ -0,0 +1,111 @@
package com.willfp.ecoskills.gui;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.FillerMask;
import com.willfp.eco.core.gui.slot.MaskMaterials;
import com.willfp.eco.core.gui.slot.Slot;
import com.willfp.eco.core.items.builder.SkullBuilder;
import com.willfp.eco.util.StringUtils;
import com.willfp.ecoskills.skills.Skill;
import com.willfp.ecoskills.skills.Skills;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
public class SkillGUI {
/**
* The home menu.
*/
private static Menu homeMenu;
/**
* Get the home menu.
*
* @return The home menu.
*/
public static Menu getHomeMenu() {
return homeMenu;
}
/**
* Update the menus.
*
* @param plugin The plugin.
*/
@ConfigUpdater
public static void update(@NotNull final EcoPlugin plugin) {
homeMenu = buildHomeMenu(plugin);
}
private static Menu buildHomeMenu(@NotNull final EcoPlugin plugin) {
String[] maskPattern = plugin.getConfigYml().getStrings("gui.mask.pattern", false).toArray(new String[0]);
Material[] maskMaterials = plugin.getConfigYml()
.getStrings("gui.mask.materials", false)
.stream()
.map(string -> Material.getMaterial(string.toUpperCase()))
.filter(Objects::nonNull)
.toArray(Material[]::new);
Function<Player, ItemStack> playerHeadItemBuilder = player -> {
ItemStack itemStack = new SkullBuilder()
.setDisplayName(plugin.getConfigYml().getString("gui.player-info.name"))
.addLoreLines(() -> {
List<String> lore = new ArrayList<>();
for (String string : plugin.getConfigYml().getStrings("gui.player-info.lore", false)) {
lore.add(StringUtils.format(string, player));
}
return lore;
})
.build();
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
assert meta != null;
meta.setOwningPlayer(player);
itemStack.setItemMeta(meta);
return itemStack;
};
return Menu.builder(plugin.getConfigYml().getInt("gui.rows"))
.setTitle(plugin.getLangYml().getString("menu.title"))
.setMask(
new FillerMask(
new MaskMaterials(
maskMaterials
),
maskPattern
)
)
.setSlot(
plugin.getConfigYml().getInt("gui.player-info.row"),
plugin.getConfigYml().getInt("gui.player-info.column"),
Slot.builder(playerHeadItemBuilder).build()
)
.modfiy(menuBuilder -> {
for (Skill skill : Skills.values()) {
menuBuilder.setSlot(
skill.getConfig().getInt("gui-position.row"),
skill.getConfig().getInt("gui-position.column"),
Slot.builder(
new ItemStack(
Objects.requireNonNull(Material.getMaterial(
skill.getConfig().getString("gui-item").toUpperCase()
))
)
).build()
);
}
})
.build();
}
}

View File

@@ -0,0 +1,23 @@
package com.willfp.ecoskills.commands
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.CommandHandler
import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.ecoskills.gui.SkillGUI
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
class CommandSkills(plugin: EcoPlugin) :
PluginCommand(
plugin,
"skills",
"ecoskills.command.skills",
true
) {
override fun getHandler(): CommandHandler {
return CommandHandler { sender: CommandSender, _: List<String> ->
val player = sender as Player
SkillGUI.getHomeMenu().open(player)
}
}
}

View File

@@ -3,6 +3,7 @@ package com.willfp.ecoskills.effects
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.integrations.placeholder.PlaceholderEntry
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoskills.EcoSkillsPlugin
import com.willfp.ecoskills.SkillObject
import com.willfp.ecoskills.getEffectLevel
@@ -40,5 +41,11 @@ abstract class Effect(
{ player -> player.getEffectLevel(this).toString() },
true
).register()
PlaceholderEntry(
"${id}_numeral",
{ player -> NumberUtils.toNumeral(player.getEffectLevel(this)) },
true
).register()
}
}

View File

@@ -4,12 +4,10 @@ import com.google.gson.annotations.Since
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.integrations.placeholder.PlaceholderEntry
import com.willfp.eco.util.NumberUtils
import com.willfp.eco.util.StringUtils
import com.willfp.ecoskills.EcoSkillsPlugin
import com.willfp.ecoskills.SkillObject
import com.willfp.ecoskills.*
import com.willfp.ecoskills.effects.Effects
import com.willfp.ecoskills.getSkillLevel
import com.willfp.ecoskills.getStatLevel
import com.willfp.ecoskills.stats.Stats
import org.bukkit.NamespacedKey
import org.bukkit.OfflinePlayer
@@ -67,6 +65,12 @@ abstract class Skill(
true
).register()
PlaceholderEntry(
"${id}_numeral",
{ player -> NumberUtils.toNumeral(player.getSkillLevel(this)) },
true
).register()
postUpdate()
}

View File

@@ -3,8 +3,10 @@ package com.willfp.ecoskills.stats
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.integrations.placeholder.PlaceholderEntry
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoskills.EcoSkillsPlugin
import com.willfp.ecoskills.SkillObject
import com.willfp.ecoskills.getEffectLevel
import com.willfp.ecoskills.getStatLevel
import com.willfp.ecoskills.skills.Skills
import org.bukkit.NamespacedKey
@@ -21,8 +23,6 @@ abstract class Stat(
val key: NamespacedKey
val uuid: UUID
val config: Config
lateinit var icon: String
lateinit var color: String
lateinit var name: String
init {
@@ -35,15 +35,25 @@ abstract class Stat(
}
fun update() {
icon = plugin.langYml.getString("stats.$id.icon")
name = plugin.langYml.getString("stats.$id.name")
color = plugin.langYml.getString("stats.$id.color")
PlaceholderEntry(
id,
{ player -> player.getStatLevel(this).toString() },
true
).register()
PlaceholderEntry(
"${id}_numeral",
{ player -> NumberUtils.toNumeral(player.getStatLevel(this)) },
true
).register()
PlaceholderEntry(
"${id}_name",
{ this.name },
false
).register()
}
open fun updateStatLevel(player: Player) {

View File

@@ -3,6 +3,43 @@
# by Auxilor
#
gui:
rows: 5
mask:
# The way the mask works is by having a list of materials
# And then a pattern to use those materials.
# The pattern is the rows in the GUI
# Each line must be 9 long, and the amount of rows should be the amount of rows in the GUI
# A zero represents nothing
# A 1 represents the first material
# A 2 represents the second material
# And so on, you can add up to 9.
materials:
- black_stained_glass_pane
pattern:
- "111101111"
- "111111111"
- "110000011"
- "110010011"
- "111101111"
player-info:
row: 1
column: 5
name: "&f%player%'s Stats:"
lore:
- "&f"
- " %ecoskills_defense_name%&f %ecoskills_defense%"
- " %ecoskills_strength_name%&f %ecoskills_strength%"
- " %ecoskills_crit_chance_name%&f %ecoskills_crit_chance%"
- " %ecoskills_crit_damage_name%&f %ecoskills_crit_damage%"
- " %ecoskills_speed_name%&f %ecoskills_speed%"
- " %ecoskills_wisdom_name%&f %ecoskills_wisdom%"
skills:
# Add more levels depending on the highest max level for all skills
level-xp-requirements:
@@ -72,9 +109,9 @@ skills:
enabled: true
message:
- "&f"
- " &3You levelled up &9%skill%&3 to level &e%level%&3!"
- " &#ff00aeYou levelled up &9%skill%&#ff00ae to &eLevel %level%&#ff00ae!"
- "&f"
- " &3&lREWARDS:"
- " &#ff00ae&lREWARDS:"
- "%rewards%"
- "&f"
sound:
@@ -88,6 +125,10 @@ skills:
mining:
gui-item: stone_pickaxe
gui-position:
row: 3
column: 3
# The maximum obtainable level
max-level: 50
@@ -97,8 +138,8 @@ skills:
- "versatile_tools:1"
rewards-messages:
- " &f+2 &#e884b0❤ Defense"
- " &6Versatile Tools %ecoskills_versatile_tools%"
- " &f+1 %ecoskills_defense_name%"
- " &6Versatile Tools %ecoskills_versatile_tools_numeral%"
# The xp rewards for each block type
# Specify with type:xp
@@ -132,33 +173,65 @@ skills:
- "ancient_debris:20"
combat:
gui-item: stone_sword
gui-position:
row: 3
column: 4
# The maximum obtainable level
max-level: 50
enchanting:
gui-item: enchanting_table
gui-position:
row: 3
column: 5
# The maximum obtainable level
max-level: 50
farming:
gui-position:
row: 3
column: 6
gui-item: golden_hoe
# The maximum obtainable level
max-level: 50
woodcutting:
gui-position:
row: 3
column: 7
gui-item: jungle_sapling
# The maximum obtainable level
max-level: 50
fishing:
gui-position:
row: 4
column: 3
gui-item: fishing_rod
# The maximum obtainable level
max-level: 50
alchemy:
gui-position:
row: 4
column: 4
gui-item: brewing_stand
# The maximum obtainable level
max-level: 50
armory:
gui-position:
row: 4
column: 6
gui-item: iron_chestplate
# The maximum obtainable level
max-level: 50
exploration:
gui-position:
row: 4
column: 7
gui-item: leather_boots
# The maximum obtainable level
max-level: 50

View File

@@ -8,6 +8,9 @@ messages:
invalid-player: "&cInvalid player!"
reset-player: "&fReset player!"
menu:
title: "Your Skills"
skills:
color: "&9"
mining:
@@ -31,29 +34,17 @@ skills:
stats:
defense:
name: "Defense"
color: '&#e884b0'
icon: '&#e884b0❤'
name: "&#e884b0🛡 Defense"
strength:
name: "Strength"
color: '&#db0000'
icon: '&#db0000❁'
name: "&#db0000🗡 Strength"
crit_chance:
name: "Crit Chance"
color: '&#f7ff85'
icon: '&#f7ff85☣'
name: "&#f7ff85☣ Crit Chance"
crit_damage:
name: "Crit Damage"
color: '&#000d9e'
icon: '&#000d9e☠'
name: "&#000d9e☠ Crit Damage"
speed:
name: "Speed"
color: '&#40ffe6'
icon: '&#40ffe6✦'
name: "&#40ffe6✦ Speed"
wisdom:
name: "Wisdom"
color: '&#c8ffa6'
icon: '&#c8ffa6✎'
name: "&#c8ffa6✎ Wisdom"
effects:
bountiful_harvest:

View File

@@ -14,6 +14,9 @@ commands:
ecoskills:
description: Base Command
permission: ecoskills.command.ecoskills
skills:
description: Open the skills menu
permission: ecoskills.command.skills
permissions:
ecoskills.*:
@@ -28,6 +31,7 @@ permissions:
ecoskills.command.reload: true
ecoskills.command.ecoskills: true
ecoskills.command.reset: true
ecoskills.command.skills: true
ecoskills.command.reload:
description: Allows reloading the config
@@ -35,6 +39,9 @@ permissions:
ecoskills.command.ecoskills:
description: Allows the use of /ecoskills.
default: true
ecoskills.command.skills:
description: Allows the use of /skills.
default: true
ecoskills.command.reset:
description: Allows the use of /ecoskills reset.
default: op