forked from Upstream/CommandPanels
3.20.1.0
This commit is contained in:
parent
53dafd8f69
commit
abafd085aa
@ -31,6 +31,11 @@
|
||||
<option name="name" value="codemc-repo" />
|
||||
<option name="url" value="https://repo.codemc.io/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="opencollab-snapshot" />
|
||||
<option name="name" value="opencollab-snapshot" />
|
||||
<option name="url" value="https://repo.opencollab.dev/main/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="placeholderapi" />
|
||||
<option name="name" value="placeholderapi" />
|
||||
|
16
pom.xml
16
pom.xml
@ -116,6 +116,10 @@
|
||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>opencollab-snapshot</id>
|
||||
<url>https://repo.opencollab.dev/main/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -225,5 +229,17 @@
|
||||
<version>2.20.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geysermc.geyser</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geysermc.floodgate</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -49,7 +49,6 @@ placeholders:
|
||||
end: '}'
|
||||
updater:
|
||||
auto-update: false
|
||||
minor-updates-only: true
|
||||
update-checks: true
|
||||
purchase:
|
||||
currency:
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 3.20.0.3
|
||||
version: 3.20.1.0
|
||||
main: me.rockyhawk.commandpanels.CommandPanels
|
||||
name: CommandPanels
|
||||
author: RockyHawk
|
||||
|
@ -23,6 +23,7 @@ import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom;
|
||||
import me.rockyhawk.commandpanels.datamanager.DebugManager;
|
||||
import me.rockyhawk.commandpanels.datamanager.PanelDataLoader;
|
||||
import me.rockyhawk.commandpanels.editor.*;
|
||||
import me.rockyhawk.commandpanels.floodgatecp.OpenFloodgateGUI;
|
||||
import me.rockyhawk.commandpanels.generatepanels.Commandpanelsgenerate;
|
||||
import me.rockyhawk.commandpanels.generatepanels.GenUtils;
|
||||
import me.rockyhawk.commandpanels.generatepanels.TabCompleteGenerate;
|
||||
@ -108,6 +109,7 @@ public class CommandPanels extends JavaPlugin{
|
||||
public InventorySaver inventorySaver = new InventorySaver(this);
|
||||
public ItemStackSerializer itemSerializer = new ItemStackSerializer(this);
|
||||
public UserInputUtils inputUtils = new UserInputUtils(this);
|
||||
public OpenFloodgateGUI floodgateOpenGUI = new OpenFloodgateGUI(this);
|
||||
|
||||
public File panelsf = new File(this.getDataFolder() + File.separator + "panels");
|
||||
public YamlConfiguration blockConfig; //where panel block locations are stored
|
||||
@ -182,6 +184,7 @@ public class CommandPanels extends JavaPlugin{
|
||||
this.getServer().getPluginManager().registerEvents(new ItemFallManager(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new OpenOnJoin(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new OutsideClickEvent(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new OpenFloodgateGUI(this), this);
|
||||
|
||||
//load in the updater if requested
|
||||
if (Objects.requireNonNull(config.getString("updater.update-checks")).equalsIgnoreCase("true")) {
|
||||
|
@ -36,6 +36,7 @@ public class CommandPanelImport implements CommandExecutor {
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpi <file name> <url>"));
|
||||
return true;
|
||||
|
@ -85,6 +85,7 @@ public class CommandPanelsEditor implements CommandExecutor {
|
||||
}
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpe <parameters>"));
|
||||
return true;
|
||||
|
160
src/me/rockyhawk/commandpanels/floodgatecp/OpenFloodgateGUI.java
Normal file
160
src/me/rockyhawk/commandpanels/floodgatecp/OpenFloodgateGUI.java
Normal file
@ -0,0 +1,160 @@
|
||||
package me.rockyhawk.commandpanels.floodgatecp;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.geysermc.cumulus.form.CustomForm;
|
||||
import org.geysermc.cumulus.form.SimpleForm;
|
||||
import org.geysermc.cumulus.response.CustomFormResponse;
|
||||
import org.geysermc.cumulus.response.SimpleFormResponse;
|
||||
import org.geysermc.cumulus.util.FormImage;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OpenFloodgateGUI implements Listener {
|
||||
private CommandPanels plugin;
|
||||
|
||||
public OpenFloodgateGUI(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPanelOpen(PanelOpenedEvent e) {
|
||||
if (!FloodgateApi.getInstance().isFloodgatePlayer(e.getPlayer().getUniqueId()) ||
|
||||
!e.getPanel().getConfig().contains("floodgate")) return;
|
||||
|
||||
FloodgatePlayer fgPlayer = FloodgateApi.getInstance().getPlayer(e.getPlayer().getUniqueId());
|
||||
ConfigurationSection fgPanel = e.getPanel().getConfig().getConfigurationSection("floodgate");
|
||||
|
||||
if (fgPanel.contains("simple")) {
|
||||
createAndSendSimpleForm(e, fgPlayer, fgPanel);
|
||||
} else {
|
||||
createAndSendCustomForm(e, fgPlayer, fgPanel);
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
private void createAndSendSimpleForm(PanelOpenedEvent e, FloodgatePlayer fgPlayer, ConfigurationSection fgPanel) {
|
||||
SimpleForm.Builder form = SimpleForm.builder()
|
||||
.title(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), e.getPanel().getConfig().getString("title"))))
|
||||
.content(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fgPanel.getString("simple"))));
|
||||
|
||||
List<String> buttonCommands;
|
||||
try {
|
||||
buttonCommands = processButtons(fgPanel, form, e.getPanel(), e.getPlayer());
|
||||
}catch (Exception err){
|
||||
e.getPlayer().sendMessage(plugin.tag + ChatColor.RED + "FloodGate panel button config error");
|
||||
plugin.debug(err, e.getPlayer());
|
||||
return;
|
||||
}
|
||||
|
||||
form.validResultHandler((SimpleFormResponse response) -> {
|
||||
int clickedButtonId = response.clickedButtonId();
|
||||
String configKey = buttonCommands.get(clickedButtonId);
|
||||
if(fgPanel.contains(configKey + ".commands")) {
|
||||
plugin.commandTags.runCommands(e.getPanel(), PanelPosition.Top, e.getPlayer(), fgPanel.getStringList(configKey + ".commands"));
|
||||
}
|
||||
});
|
||||
|
||||
fgPlayer.sendForm(form.build());
|
||||
}
|
||||
|
||||
private List<String> processButtons(ConfigurationSection fgPanel, SimpleForm.Builder form, Panel panel, Player p) {
|
||||
List<String> commandsOrder = new ArrayList<>();
|
||||
fgPanel.getKeys(false).stream()
|
||||
.filter(key -> key.matches("\\d+"))
|
||||
.sorted()
|
||||
.forEach(key -> {
|
||||
ConfigurationSection buttonConfig = fgPanel.getConfigurationSection(key);
|
||||
if (buttonConfig == null) return;
|
||||
|
||||
String buttonContent = plugin.tex.placeholders(panel, null, p, buttonConfig.getString("text"));
|
||||
if (!buttonConfig.contains("icon")) {
|
||||
form.button(buttonContent);
|
||||
} else {
|
||||
FormImage.Type type = FormImage.Type.valueOf(plugin.tex.placeholders(panel, null, p, buttonConfig.getString("icon.type")).toUpperCase());
|
||||
String texture = plugin.tex.placeholders(panel, null, p, buttonConfig.getString("icon.texture"));
|
||||
form.button(buttonContent, type, texture);
|
||||
}
|
||||
commandsOrder.add(key);
|
||||
});
|
||||
return commandsOrder;
|
||||
}
|
||||
|
||||
private void createAndSendCustomForm(PanelOpenedEvent e, FloodgatePlayer fgPlayer, ConfigurationSection fgPanel) {
|
||||
CustomForm.Builder form = CustomForm.builder()
|
||||
.title(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), e.getPanel().getConfig().getString("title")));
|
||||
|
||||
List<String> commandsOrder = new ArrayList<>();
|
||||
fgPanel.getKeys(false).forEach(key -> {
|
||||
if (key.matches("\\d+")) {
|
||||
ConfigurationSection fieldConfig = fgPanel.getConfigurationSection(key);
|
||||
try {
|
||||
String type = "toggle";
|
||||
if(fieldConfig.contains("type")) {
|
||||
type = fieldConfig.getString("type").toLowerCase();
|
||||
}
|
||||
switch (type) {
|
||||
case "toggle":
|
||||
form.toggle(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("text")),
|
||||
Boolean.parseBoolean(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("default"))));
|
||||
commandsOrder.add(key);
|
||||
break;
|
||||
case "slider":
|
||||
form.slider(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("text")),
|
||||
Long.parseLong(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("min"))),
|
||||
Long.parseLong(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("max"))),
|
||||
Long.parseLong(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("step"))),
|
||||
Long.parseLong(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("default"))));
|
||||
commandsOrder.add(key);
|
||||
break;
|
||||
case "input":
|
||||
form.input(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("text")),
|
||||
plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("placeholder")),
|
||||
plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("default")));
|
||||
commandsOrder.add(key);
|
||||
break;
|
||||
case "dropdown":
|
||||
form.dropdown(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("text")),
|
||||
plugin.tex.placeholdersList(e.getPanel(), null, e.getPlayer(), fieldConfig.getStringList("options"), true));
|
||||
commandsOrder.add(key);
|
||||
break;
|
||||
}
|
||||
}catch (Exception err){
|
||||
e.getPlayer().sendMessage(plugin.tag + ChatColor.RED + "FloodGate panel button config error");
|
||||
plugin.debug(err, e.getPlayer());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
form.validResultHandler((CustomFormResponse response) -> {
|
||||
for (String configKey : commandsOrder) { // Iterate over each command configuration key
|
||||
if (!response.hasNext()) {
|
||||
break; // Safety check to prevent NoSuchElementException
|
||||
}
|
||||
if(fgPanel.contains(configKey + ".commands")) {
|
||||
Object fieldValue = response.next(); // Retrieve the next response value
|
||||
String value = String.valueOf(fieldValue); // Convert the field value to String
|
||||
List<String> commands = fgPanel.getStringList(configKey + ".commands"); // Retrieve commands for this field
|
||||
List<String> processedCommands = new ArrayList<>();
|
||||
for (String command : commands) {
|
||||
processedCommands.add(command.replaceAll("%cp-input%", value)); // Replace the placeholder in each command
|
||||
}
|
||||
plugin.commandTags.runCommands(e.getPanel(), PanelPosition.Top, e.getPlayer(), processedCommands); // Execute the processed commands
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fgPlayer.sendForm(form.build());
|
||||
}
|
||||
}
|
@ -98,22 +98,28 @@ public class UtilsOpenWithItem implements Listener {
|
||||
public void onPlayerRespawn(PlayerRespawnEvent e){
|
||||
plugin.hotbar.updateHotbarItems(e.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e){
|
||||
if(!plugin.openWithItem){
|
||||
//if none of the panels have open-with-item
|
||||
return;
|
||||
}
|
||||
|
||||
//a new list instance has to be created with the dropped items to avoid ConcurrentModificationException
|
||||
for(ItemStack s : new ArrayList<>(e.getDrops())){
|
||||
try {
|
||||
if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").isEmpty()) {
|
||||
//do not remove items that are not stationary
|
||||
if(!plugin.nbt.getNBT(s, "CommandPanelsHotbar").endsWith("-1")) {
|
||||
e.getDrops().remove(s);
|
||||
try {
|
||||
for (ItemStack s : new ArrayList<>(e.getDrops())) {
|
||||
try {
|
||||
if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").isEmpty()) {
|
||||
//do not remove items that are not stationary
|
||||
if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").endsWith("-1")) {
|
||||
e.getDrops().remove(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(NullPointerException | IllegalArgumentException ignore){}
|
||||
} catch (NullPointerException | IllegalArgumentException ignore) {}
|
||||
}
|
||||
}catch (NullPointerException ignore){
|
||||
System.out.println("crapped out");
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
@ -17,6 +18,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class InventorySaver implements Listener {
|
||||
public YamlConfiguration inventoryConfig;
|
||||
@ -50,13 +52,26 @@ public class InventorySaver implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
/*
|
||||
Run LOW event priority to run first ensuring other plugins and event handlers do not
|
||||
use the CommandPanels panel instead of the players inventory when making decisions
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onDeath(PlayerDeathEvent e){
|
||||
//drop the players inventory if a panel is open in the inventory
|
||||
//drop the players inventory if a mutli panel is open in the inventory
|
||||
if (plugin.openPanels.hasPanelOpen(e.getEntity().getName(), PanelPosition.Middle) || plugin.openPanels.hasPanelOpen(e.getEntity().getName(), PanelPosition.Bottom)) {
|
||||
if(e.getKeepInventory()) return;
|
||||
|
||||
e.getDrops().clear();
|
||||
e.getDrops().addAll(Arrays.asList(plugin.inventorySaver.getNormalInventory(e.getEntity())));
|
||||
|
||||
// Retrieve the inventory, filter out null items, and then add them to e.getDrops()
|
||||
// e.getDrops() will just return Null in general, just by containing null items in it
|
||||
ItemStack[] inventoryItems = plugin.inventorySaver.getNormalInventory(e.getEntity());
|
||||
List<ItemStack> nonNullItems = Arrays.stream(inventoryItems)
|
||||
.filter(Objects::nonNull) // Filter out null items
|
||||
.collect(Collectors.toList()); // Collect the remaining items into a list
|
||||
|
||||
e.getDrops().addAll(nonNullItems);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,13 +130,9 @@ public class Updater implements Listener {
|
||||
//return if auto-update is false
|
||||
return;
|
||||
}
|
||||
if(Objects.equals(plugin.config.getString("updater.minor-updates-only"), "true")){
|
||||
//only update versions that will not break
|
||||
if(thisVersion.split("\\.")[1].equals(latestVersion.split("\\.")[1]) && thisVersion.split("\\.")[0].equals(latestVersion.split("\\.")[0])){
|
||||
//the first and second number of the version is the same, updates: [major.major.minor.minor]
|
||||
downloadFile(latestVersion,pluginFileName);
|
||||
}
|
||||
}else{
|
||||
if(thisVersion.split("\\.")[1].equals(latestVersion.split("\\.")[1]) && thisVersion.split("\\.")[0].equals(latestVersion.split("\\.")[0])){
|
||||
//only update if the latest version is a minor update
|
||||
//the first and second number of the version is the same, updates: [major.major.minor.minor]
|
||||
downloadFile(latestVersion,pluginFileName);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user