mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 09:01:47 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 376cde3529 | |||
| 6e555a700f | |||
| b7e9295685 | |||
| b5382a1cb3 |
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cc.carm.lib.easyplugin.command;
|
package cc.carm.lib.easyplugin.command;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.permissions.Permissible;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ public interface NamedExecutor {
|
|||||||
|
|
||||||
List<String> getAliases();
|
List<String> getAliases();
|
||||||
|
|
||||||
default boolean hasPermission(Permissible permissible) {
|
default boolean hasPermission(CommandSender sender) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,16 +13,11 @@ public abstract class SubCommand implements NamedExecutor {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final List<String> aliases;
|
private final List<String> aliases;
|
||||||
|
|
||||||
public SubCommand(String name) {
|
|
||||||
this(name, new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SubCommand(String name, String... aliases) {
|
public SubCommand(String name, String... aliases) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.aliases = Arrays.asList(aliases);
|
this.aliases = Arrays.asList(aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
+44
-18
@@ -6,19 +6,26 @@ import cc.carm.lib.easyplugin.utils.ColorParser;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class GUIConfiguration {
|
public class GUIConfiguration {
|
||||||
|
|
||||||
String title;
|
protected String title;
|
||||||
int lines;
|
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.title = title;
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
this.guiItems = guiItems;
|
this.guiItems = guiItems;
|
||||||
@@ -38,31 +45,50 @@ public class GUIConfiguration {
|
|||||||
.get();
|
.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GUIItemConfiguration> getGuiItems() {
|
public Map<String, GUIItemConfiguration> getGUIItems() {
|
||||||
return guiItems;
|
return guiItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setupItems(Player player, GUI gui) {
|
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) {
|
public static GUIConfiguration readConfiguration(@Nullable ConfigurationSection section) {
|
||||||
if (section == null) return new GUIConfiguration("name", 6, new ArrayList<>());
|
if (section == null) return new GUIConfiguration("name", 6);
|
||||||
|
|
||||||
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<>());
|
|
||||||
|
|
||||||
return new GUIConfiguration(
|
return new GUIConfiguration(
|
||||||
title, lines, itemsSection.getKeys(false).stream()
|
section.getString("title", ""),
|
||||||
.map(key -> GUIItemConfiguration.readFrom(itemsSection.getConfigurationSection(key)))
|
section.getInt("lines", 6),
|
||||||
.filter(Objects::nonNull)
|
readItems(section.getConfigurationSection("items"))
|
||||||
.collect(Collectors.toList())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
public static ClickType readClickType(String type) {
|
||||||
return Arrays.stream(ClickType.values())
|
return Arrays.stream(ClickType.values())
|
||||||
.filter(click -> click.name().equalsIgnoreCase(type))
|
.filter(click -> click.name().equalsIgnoreCase(type))
|
||||||
|
|||||||
+7
-5
@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
|
|||||||
public class GUIItemConfiguration {
|
public class GUIItemConfiguration {
|
||||||
|
|
||||||
@NotNull Material type;
|
@NotNull Material type;
|
||||||
|
int amount;
|
||||||
int data;
|
int data;
|
||||||
@Nullable String name;
|
@Nullable String name;
|
||||||
@NotNull List<String> lore;
|
@NotNull List<String> lore;
|
||||||
@@ -23,11 +24,12 @@ public class GUIItemConfiguration {
|
|||||||
@NotNull List<Integer> slots;
|
@NotNull List<Integer> slots;
|
||||||
@NotNull List<GUIActionConfiguration> actions;
|
@NotNull List<GUIActionConfiguration> actions;
|
||||||
|
|
||||||
public GUIItemConfiguration(@NotNull Material type, int data,
|
public GUIItemConfiguration(@NotNull Material type, int amount, int data,
|
||||||
@Nullable String name, @NotNull List<String> lore,
|
@Nullable String name, @NotNull List<String> lore,
|
||||||
@NotNull List<GUIActionConfiguration> actions,
|
@NotNull List<GUIActionConfiguration> actions,
|
||||||
@NotNull List<Integer> slots) {
|
@NotNull List<Integer> slots) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.amount = amount;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.lore = lore;
|
this.lore = lore;
|
||||||
@@ -36,8 +38,7 @@ public class GUIItemConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setupItems(Player player, GUI gui) {
|
public void setupItems(Player player, GUI gui) {
|
||||||
ItemStackFactory icon = new ItemStackFactory(this.type);
|
ItemStackFactory icon = new ItemStackFactory(this.type, this.amount, this.data);
|
||||||
icon.setDurability(this.data);
|
|
||||||
if (this.name != null) icon.setDisplayName(this.name);
|
if (this.name != null) icon.setDisplayName(this.name);
|
||||||
icon.setLore(MessageUtils.setPlaceholders(player, this.lore));
|
icon.setLore(MessageUtils.setPlaceholders(player, this.lore));
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ public class GUIItemConfiguration {
|
|||||||
|
|
||||||
map.put("type", this.type.name());
|
map.put("type", this.type.name());
|
||||||
if (this.name != null) map.put("name", this.name);
|
if (this.name != null) map.put("name", this.name);
|
||||||
|
if (this.amount != 1) map.put("amount", this.amount);
|
||||||
if (this.data != 0) map.put("data", this.data);
|
if (this.data != 0) map.put("data", this.data);
|
||||||
if (!this.lore.isEmpty()) map.put("lore", this.lore);
|
if (!this.lore.isEmpty()) map.put("lore", this.lore);
|
||||||
if (this.slots.size() > 1) {
|
if (this.slots.size() > 1) {
|
||||||
@@ -70,6 +72,7 @@ public class GUIItemConfiguration {
|
|||||||
String material = Optional.ofNullable(itemSection.getString("type")).orElse("STONE");
|
String material = Optional.ofNullable(itemSection.getString("type")).orElse("STONE");
|
||||||
Material type = Optional.ofNullable(Material.matchMaterial(material)).orElse(Material.STONE);
|
Material type = Optional.ofNullable(Material.matchMaterial(material)).orElse(Material.STONE);
|
||||||
int data = itemSection.getInt("data", 0);
|
int data = itemSection.getInt("data", 0);
|
||||||
|
int amount = itemSection.getInt("amount", 1);
|
||||||
String name = itemSection.getString("name");
|
String name = itemSection.getString("name");
|
||||||
List<String> lore = itemSection.getStringList("lore");
|
List<String> lore = itemSection.getStringList("lore");
|
||||||
|
|
||||||
@@ -85,10 +88,9 @@ public class GUIItemConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new GUIItemConfiguration(
|
return new GUIItemConfiguration(
|
||||||
type, data, name, lore, actions,
|
type, amount, data, name, lore, actions,
|
||||||
slots.size() > 0 ? slots : Collections.singletonList(slot)
|
slots.size() > 0 ? slots : Collections.singletonList(slot)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.MilkBowl</groupId>
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
<artifactId>VaultAPI</artifactId>
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.4.9</version>
|
<version>1.4.12</version>
|
||||||
<modules>
|
<modules>
|
||||||
|
|
||||||
<module>base/main</module>
|
<module>base/main</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user