This commit is contained in:
mfnalex 2023-03-30 15:22:04 +02:00
parent fc616c973d
commit 3e5dccc9bd
4 changed files with 45 additions and 4 deletions

16
pom.xml
View File

@ -9,7 +9,7 @@
<name>ChestSort</name>
<url>https://www.chestsort.de</url>
<description>Allows automatic chest sorting!</description>
<version>13.5.1</version>
<version>13.6.0</version>
<packaging>jar</packaging>
<properties>
@ -87,6 +87,11 @@
<shadedPattern>de.jeff_media.chestsort.paperlib</shadedPattern>
</relocation>
<relocation>
<pattern>com.jeff_media.morepersistentdatatypes</pattern>
<shadedPattern>com.jeff_media.chestsort.morepersistentdatatypes</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<excludes>
@ -204,10 +209,17 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jeff_media</groupId>
<artifactId>MorePersistentDataTypes</artifactId>
<version>2.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jeff_media</groupId>
<artifactId>JeffLib</artifactId>
<version>12.0.0</version>
<version>12.3.1</version>
<scope>compile</scope>
</dependency>

View File

@ -1,8 +1,11 @@
package de.jeff_media.chestsort.gui;
import com.jeff_media.morepersistentdatatypes.DataType;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.data.PlayerSetting;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -10,6 +13,10 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class GUIListener implements Listener {
private static final ChestSortPlugin main = ChestSortPlugin.getInstance();
@ -26,8 +33,12 @@ public class GUIListener implements Listener {
if(!(event.getWhoClicked() instanceof Player)) return;
Player player = (Player) event.getWhoClicked();
PlayerSetting setting = main.getPlayerSetting(player);
String function = clicked.getItemMeta().getPersistentDataContainer().getOrDefault(new NamespacedKey(main,"function"), PersistentDataType.STRING,"");
String function = Objects.requireNonNull(clicked.getItemMeta()).getPersistentDataContainer().getOrDefault(new NamespacedKey(main,"function"), PersistentDataType.STRING,"");
List<String> userCommands = clicked.getItemMeta().getPersistentDataContainer().getOrDefault(new NamespacedKey(main,"user-commands"), DataType.asList(DataType.STRING), new ArrayList<>());
List<String> adminCommands = clicked.getItemMeta().getPersistentDataContainer().getOrDefault(new NamespacedKey(main,"admin-commands"), DataType.asList(DataType.STRING), new ArrayList<>());
executeCommands(player, player, userCommands);
executeCommands(player, Bukkit.getConsoleSender(), adminCommands);
//System.out.println("Click in GUI: " + function);
switch (function) {
@ -44,6 +55,12 @@ public class GUIListener implements Listener {
}
new NewUI(player).showGUI();
}
private void executeCommands(Player player, CommandSender sender, List<String> commands) {
for(String command : commands) {
main.getServer().dispatchCommand(sender, command.replace("{player}", player.getName()));
}
}
}

View File

@ -1,5 +1,6 @@
package de.jeff_media.chestsort.gui;
import com.jeff_media.morepersistentdatatypes.DataType;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.enums.Hotkey;
import com.jeff_media.jefflib.ItemStackUtils;
@ -13,6 +14,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.List;
public class NewUI {
private static final ChestSortPlugin main = ChestSortPlugin.getInstance();
@ -44,6 +47,10 @@ public class NewUI {
ItemMeta meta = button.getItemMeta();
assert meta != null;
meta.getPersistentDataContainer().set(new NamespacedKey(main,"function"),PersistentDataType.STRING, buttonName.split("-")[0]);
List<String> userCommands = conf.getStringList("items." + buttonName + ".commands.player");
List<String> adminCommands = conf.getStringList("items." + buttonName + ".commands.console");
meta.getPersistentDataContainer().set(new NamespacedKey(main,"user-commands"), DataType.asList(DataType.STRING), userCommands);
meta.getPersistentDataContainer().set(new NamespacedKey(main,"admin-commands"), DataType.asList(DataType.STRING), adminCommands);
button.setItemMeta(meta);
}
return button;

View File

@ -21,6 +21,11 @@
# enchantments:
# unbreaking: 3
# efficiency: 5
# commands:
# player:
# - "say Hello" # command that will be run as the player
# console:
# - "tell {player} Hello" # command that will be run as the console
title: "<#000000>&l[<#007700>&lChest<#339933>&lSort<#000000>&l] &rSettings"
size: 45