1
mirror of https://github.com/CarmJos/EasyPlugin.git synced 2026-06-05 00:58:17 +08:00

Compare commits

..

3 Commits

14 changed files with 56 additions and 36 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -1,7 +1,6 @@
package cc.carm.lib.easyplugin.command;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permissible;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -16,7 +15,7 @@ public interface NamedExecutor {
List<String> getAliases();
default boolean hasPermission(Permissible permissible) {
default boolean hasPermission(CommandSender sender) {
return true;
}
@@ -13,16 +13,11 @@ public abstract class SubCommand implements NamedExecutor {
private final String name;
private final List<String> aliases;
public SubCommand(String name) {
this(name, new String[0]);
}
public SubCommand(String name, String... aliases) {
this.name = name;
this.aliases = Arrays.asList(aliases);
}
@Override
public String getName() {
return this.name;
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -6,19 +6,26 @@ import cc.carm.lib.easyplugin.utils.ColorParser;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
public class GUIConfiguration {
String title;
int lines;
protected String title;
protected int lines;
List<GUIItemConfiguration> guiItems;
protected Map<String, GUIItemConfiguration> guiItems;
public GUIConfiguration(String title, int lines, List<GUIItemConfiguration> guiItems) {
public GUIConfiguration(String title, int lines) {
this(title, lines, new LinkedHashMap<>(1));
}
public GUIConfiguration(String title, int lines, Map<String, GUIItemConfiguration> guiItems) {
this.title = title;
this.lines = lines;
this.guiItems = guiItems;
@@ -38,31 +45,50 @@ public class GUIConfiguration {
.get();
}
public List<GUIItemConfiguration> getGuiItems() {
public Map<String, GUIItemConfiguration> getGUIItems() {
return guiItems;
}
public void setupItems(Player player, GUI gui) {
getGuiItems().forEach(itemConfiguration -> itemConfiguration.setupItems(player, gui));
getGUIItems().values().forEach(itemConfiguration -> itemConfiguration.setupItems(player, gui));
}
public @NotNull Map<String, Object> serialize() {
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("title", this.title);
map.put("lines", this.lines);
if (!this.guiItems.isEmpty()) {
LinkedHashMap<String, Object> items = new LinkedHashMap<>();
this.guiItems.forEach((key, value) -> items.put(key, value.serialize()));
map.put("items", items);
}
return map;
}
public static GUIConfiguration readConfiguration(@Nullable ConfigurationSection section) {
if (section == null) return new GUIConfiguration("name", 6, new ArrayList<>());
String title = section.getString("title", "");
int lines = section.getInt("lines", 6);
ConfigurationSection itemsSection = section.getConfigurationSection("items");
if (itemsSection == null) return new GUIConfiguration(title, lines, new ArrayList<>());
if (section == null) return new GUIConfiguration("name", 6);
return new GUIConfiguration(
title, lines, itemsSection.getKeys(false).stream()
.map(key -> GUIItemConfiguration.readFrom(itemsSection.getConfigurationSection(key)))
.filter(Objects::nonNull)
.collect(Collectors.toList())
section.getString("title", ""),
section.getInt("lines", 6),
readItems(section.getConfigurationSection("items"))
);
}
public static Map<String, GUIItemConfiguration> readItems(ConfigurationSection itemsSection) {
Map<String, GUIItemConfiguration> items = new LinkedHashMap<>();
if (itemsSection == null) return items;
for (String key : itemsSection.getKeys(false)) {
GUIItemConfiguration item = GUIItemConfiguration.readFrom(itemsSection.getConfigurationSection(key));
if (item != null) items.put(key, item);
}
return items;
}
public static ClickType readClickType(String type) {
return Arrays.stream(ClickType.values())
.filter(click -> click.name().equalsIgnoreCase(type))
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.10</version>
<version>1.4.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -15,7 +15,7 @@
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-parent</artifactId>
<packaging>pom</packaging>
<version>1.4.10</version>
<version>1.4.12</version>
<modules>
<module>base/main</module>