This commit is contained in:
rockyhawk64 2022-06-30 13:09:19 +10:00
parent a429a38e4a
commit 5032e5f218
25 changed files with 115 additions and 122 deletions

View File

@ -10,7 +10,7 @@
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>
<module name="CommandPanels" target="8" /> <module name="CommandPanels" target="1.8" />
</bytecodeTargetLevel> </bytecodeTargetLevel>
</component> </component>
</project> </project>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: net.kyori:adventure-api:4.11.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-api/4.11.0/adventure-api-4.11.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-api/4.11.0/adventure-api-4.11.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-api/4.11.0/adventure-api-4.11.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: net.kyori:adventure-key:4.11.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-key/4.11.0/adventure-key-4.11.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-key/4.11.0/adventure-key-4.11.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-key/4.11.0/adventure-key-4.11.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: net.kyori:adventure-text-minimessage:4.11.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-text-minimessage/4.11.0/adventure-text-minimessage-4.11.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-text-minimessage/4.11.0/adventure-text-minimessage-4.11.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/adventure-text-minimessage/4.11.0/adventure-text-minimessage-4.11.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: net.kyori:examination-api:1.3.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/examination-api/1.3.0/examination-api-1.3.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/examination-api/1.3.0/examination-api-1.3.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/examination-api/1.3.0/examination-api-1.3.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: net.kyori:examination-string:1.3.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/examination-string/1.3.0/examination-string-1.3.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/examination-string/1.3.0/examination-string-1.3.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/kyori/examination-string/1.3.0/examination-string-1.3.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.jetbrains:annotations:23.0.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/23.0.0/annotations-23.0.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/23.0.0/annotations-23.0.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/23.0.0/annotations-23.0.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,7 +1,7 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="spigot-api-1.19-R0.1-SNAPSHOT"> <library name="spigot-api-1.19-R0.1-SNAPSHOT1">
<CLASSES> <CLASSES>
<root url="jar://$PROJECT_DIR$/../../../Intellij Plugin Testers/Plugin Tester 1.18.1/bundler/libraries/spigot-api-1.19-R0.1-SNAPSHOT.jar!/" /> <root url="jar://$PROJECT_DIR$/../../../Intellij Plugin Testers/Plugin Tester 1.19/bundler/libraries/spigot-api-1.19-R0.1-SNAPSHOT.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES /> <SOURCES />

View File

@ -7,7 +7,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="temurin-1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -10,7 +10,7 @@
<sourceFolder url="file://$MODULE_DIR$/resource_example" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/resource_example" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" /> <orderEntry type="jdk" jdkName="temurin-1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="HeadDatabaseAPI" level="project" /> <orderEntry type="library" name="HeadDatabaseAPI" level="project" />
<orderEntry type="library" name="TokenManager-3.2.4" level="project" /> <orderEntry type="library" name="TokenManager-3.2.4" level="project" />
@ -25,12 +25,12 @@
<orderEntry type="library" name="spigot-1.13.2" level="project" /> <orderEntry type="library" name="spigot-1.13.2" level="project" />
<orderEntry type="library" name="spigot" level="project" /> <orderEntry type="library" name="spigot" level="project" />
<orderEntry type="library" name="CoinsAPI 1.8.9" level="project" /> <orderEntry type="library" name="CoinsAPI 1.8.9" level="project" />
<orderEntry type="library" name="spigot-api-1.19-R0.1-SNAPSHOT1" level="project" />
<orderEntry type="library" name="Maven: net.kyori:adventure-text-minimessage:4.11.0" level="project" /> <orderEntry type="library" name="Maven: net.kyori:adventure-text-minimessage:4.11.0" level="project" />
<orderEntry type="library" name="Maven: net.kyori:adventure-api:4.11.0" level="project" /> <orderEntry type="library" name="Maven: net.kyori:adventure-api:4.11.0" level="project" />
<orderEntry type="library" name="Maven: net.kyori:adventure-key:4.11.0" level="project" /> <orderEntry type="library" name="Maven: net.kyori:adventure-key:4.11.0" level="project" />
<orderEntry type="library" name="Maven: net.kyori:examination-api:1.3.0" level="project" /> <orderEntry type="library" name="Maven: net.kyori:examination-api:1.3.0" level="project" />
<orderEntry type="library" name="Maven: net.kyori:examination-string:1.3.0" level="project" /> <orderEntry type="library" name="Maven: net.kyori:examination-string:1.3.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:23.0.0" level="project" /> <orderEntry type="library" name="Maven: org.jetbrains:annotations:23.0.0" level="project" />
<orderEntry type="library" name="spigot-api-1.19-R0.1-SNAPSHOT" level="project" />
</component> </component>
</module> </module>

View File

@ -20,7 +20,7 @@ config:
update-notifications: true update-notifications: true
panel-snooper: false panel-snooper: false
format: format:
tag: '&6[&bCommandPanels&6]' tag: '&6[&bCommandPanels&6] '
perms: '&cNo permission.' perms: '&cNo permission.'
reload: '&aReloaded.' reload: '&aReloaded.'
nopanel: '&cPanel not found.' nopanel: '&cPanel not found.'
@ -48,7 +48,7 @@ placeholders:
start: '{' start: '{'
end: '}' end: '}'
updater: updater:
auto-update: true auto-update: false
minor-updates-only: true minor-updates-only: true
update-checks: true update-checks: true
purchase: purchase:

View File

@ -1,4 +1,4 @@
version: 3.18.0.0 version: 3.18.1.0
main: me.rockyhawk.commandpanels.CommandPanels main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels name: CommandPanels
author: RockyHawk author: RockyHawk

View File

@ -15,6 +15,7 @@ panels:
stack: 1 stack: 1
name: '&cExit' name: '&cExit'
commands: commands:
- event= CommandPanels_EditorClosed
- cpc - cpc
'4': '4':
material: CHEST material: CHEST
@ -28,11 +29,11 @@ panels:
name: '&fItem Settings' name: '&fItem Settings'
commands: commands:
- "event= CommandPanels_OpenItemSettings" - "event= CommandPanels_OpenItemSettings"
'8': #'8':
material: COMPASS # material: COMPASS
stack: 1 # stack: 1
name: '&fItem Sections' # name: '&fItem Sections'
lore: # lore:
- "&cIN PROGRESS" # - "&cIN PROGRESS"
commands: # commands:
- "event= CommandPanels_OpenItemSections" # - "event= CommandPanels_OpenItemSections"

View File

@ -79,7 +79,7 @@ panels:
- cpc - cpc
player-input: player-input:
- "event= CPEditor_itemnbt %cp-player-input%" - "event= CPEditor_itemnbt %cp-player-input%"
'0': '18':
material: LAVA_BUCKET material: LAVA_BUCKET
name: '&cDelete Item' name: '&cDelete Item'
lore: lore:
@ -98,7 +98,7 @@ panels:
- cpc - cpc
player-input: player-input:
- "event= CPEditor_itemslot %cp-player-input%" - "event= CPEditor_itemslot %cp-player-input%"
'18': '0':
material: ENDER_CHEST material: ENDER_CHEST
name: '&fMove Item' name: '&fMove Item'
lore: lore:

View File

@ -86,6 +86,16 @@ public class Utils implements Listener {
//the panels proper position //the panels proper position
panel = plugin.openPanels.getOpenPanel(p.getName(),position); panel = plugin.openPanels.getOpenPanel(p.getName(),position);
//this will cancel click on editor open and then change the slot clicked
if(plugin.editorMain.settings.containsKey(p.getUniqueId())) {
if (plugin.editorMain.settings.get(p.getUniqueId()).hasEditorOpen && position == PanelPosition.Top) {
plugin.editorMain.settings.get(p.getUniqueId()).slotSelected = String.valueOf(e.getSlot());
plugin.editorMain.openGuiPage(plugin.editorMain.settings.get(p.getUniqueId()).menuOpen, p, PanelPosition.Middle);
e.setCancelled(true);
return;
}
}
//this loops through all the items in the panel //this loops through all the items in the panel
boolean foundSlot = false; boolean foundSlot = false;
for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){ for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){

View File

@ -6,7 +6,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
public class SerializerUtils { public class SerializerUtils {
public static Component serializeText(String msg){ public static Component serializeText(String msg){
Component parsedText = MiniMessage.miniMessage().deserialize(msg); return MiniMessage.miniMessage().deserialize(msg);
return parsedText;
} }
} }

View File

@ -45,6 +45,9 @@ public class Commandpanelsreload implements CommandExecutor {
//reloadHotbarSlots //reloadHotbarSlots
plugin.hotbar.reloadHotbarSlots(); plugin.hotbar.reloadHotbarSlots();
//reload tag
plugin.tag = plugin.tex.colour(plugin.config.getString("config.format.tag"));
//add custom commands to commands.yml //add custom commands to commands.yml
if(plugin.config.getString("config.auto-register-commands").equalsIgnoreCase("true")) { if(plugin.config.getString("config.auto-register-commands").equalsIgnoreCase("true")) {
registerCommands(); registerCommands();

View File

@ -66,7 +66,7 @@ public class SpecialTags implements Listener {
plugin.openPanels.closePanelForLoader(e.p.getName(),PanelPosition.Bottom); plugin.openPanels.closePanelForLoader(e.p.getName(),PanelPosition.Bottom);
}else if(position == PanelPosition.Top && plugin.openPanels.hasPanelOpen(e.p.getName(),position)){ }else if(position == PanelPosition.Top && plugin.openPanels.hasPanelOpen(e.p.getName(),position)){
//closing top closes all //closing top closes all
e.p.closeInventory(); plugin.commandTags.runCommand(e.panel,e.pos,e.p,"cpc");
} }
return; return;
} }

View File

@ -6,6 +6,7 @@ import me.rockyhawk.commandpanels.classresources.SerializerUtils;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent; import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions; import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType; import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -24,8 +25,18 @@ public class BasicTags implements Listener {
public void commandTag(CommandTagEvent e){ public void commandTag(CommandTagEvent e){
if(e.name.equalsIgnoreCase("cpc")){ if(e.name.equalsIgnoreCase("cpc")){
e.commandTagUsed(); e.commandTagUsed();
//unclosable panels are at the Top only
if(plugin.openPanels.getOpenPanel(e.p.getName(),PanelPosition.Top).getConfig().contains("panelType")){
if(plugin.openPanels.getOpenPanel(e.p.getName(),PanelPosition.Top).getConfig().getStringList("panelType").contains("unclosable")){
plugin.openPanels.closePanelForLoader(e.p.getName(),PanelPosition.Top);
plugin.openPanels.skipPanelClose.add(e.p.getName());
}
}
//this will close the current inventory //this will close the current inventory
e.p.closeInventory(); e.p.closeInventory();
plugin.openPanels.skipPanelClose.remove(e.p.getName());
return; return;
} }
if(e.name.equalsIgnoreCase("refresh")) { if(e.name.equalsIgnoreCase("refresh")) {

View File

@ -195,7 +195,11 @@ public class CPEventHandler implements Listener {
panel.getConfig().set("title", playerInput); panel.getConfig().set("title", playerInput);
break; break;
case "panelrows": case "panelrows":
panel.getConfig().set("rows", playerInput); if(isNumeric(playerInput)){
panel.getConfig().set("rows", Integer.parseInt(playerInput));
}else {
panel.getConfig().set("rows", playerInput);
}
break; break;
case "panelrefreshdelay": case "panelrefreshdelay":
panel.getConfig().set("refresh-delay", playerInput); panel.getConfig().set("refresh-delay", playerInput);

View File

@ -56,7 +56,6 @@ public class GenUtils implements Listener {
} }
} }
@SuppressWarnings("deprecation")
void generatePanel(Player p, Inventory inv){ void generatePanel(Player p, Inventory inv){
ArrayList<String> apanels = new ArrayList(); ArrayList<String> apanels = new ArrayList();
for(Panel panel : plugin.panelList){ for(Panel panel : plugin.panelList){

View File

@ -77,18 +77,26 @@ public class OpenPanelsLoader {
//close all of the panels for a player currently open //close all of the panels for a player currently open
public void closePanelForLoader(String playerName, PanelPosition position){ public void closePanelForLoader(String playerName, PanelPosition position){
if(!openPanels.containsKey(playerName) || skipPanelClose.contains(playerName)){ //close if not panel
if(!plugin.openPanels.openPanels.containsKey(playerName) || plugin.openPanels.skipPanelClose.contains(playerName)){
return; return;
} }
panelCloseCommands(playerName,position,openPanels.get(playerName).getPanel(position));
//snooper
if (plugin.config.contains("config.panel-snooper")) { if (plugin.config.contains("config.panel-snooper")) {
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).equalsIgnoreCase("true")) { if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).equalsIgnoreCase("true")) {
Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + playerName + " Closed " + openPanels.get(playerName).getPanel(position).getName() + " at " + position); Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + playerName + " Closed " + openPanels.get(playerName).getPanel(position).getName() + " at " + position);
} }
} }
//panel instance
Panel panel = openPanels.get(playerName).getPanel(position);
//run close commands once panel is closed
panelCloseCommands(playerName,position,panel);
//fire PanelClosedEvent //fire PanelClosedEvent
PanelClosedEvent closedEvent = new PanelClosedEvent(Bukkit.getPlayer(playerName),openPanels.get(playerName).getPanel(position),position); PanelClosedEvent closedEvent = new PanelClosedEvent(Bukkit.getPlayer(playerName),panel,position);
Bukkit.getPluginManager().callEvent(closedEvent); Bukkit.getPluginManager().callEvent(closedEvent);
openPanels.get(playerName).setPanel(null,position); openPanels.get(playerName).setPanel(null,position);

View File

@ -1,5 +1,6 @@
package me.rockyhawk.commandpanels.openpanelsmanager; package me.rockyhawk.commandpanels.openpanelsmanager;
import me.realized.tokenmanager.command.commands.subcommands.TopCommand;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel; import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelClosedEvent; import me.rockyhawk.commandpanels.api.PanelClosedEvent;
@ -40,7 +41,34 @@ public class UtilsPanelsLoader implements Listener {
//tell panel loader that player has closed the panel (there is also one of these in EditorUtils) //tell panel loader that player has closed the panel (there is also one of these in EditorUtils)
@EventHandler @EventHandler
public void onPlayerClosePanel(InventoryCloseEvent e){ public void onPlayerClosePanel(InventoryCloseEvent e){
//only do this if editor is disabled as it will disabled this code String playerName = e.getPlayer().getName();
//close if not panel
if(!plugin.openPanels.openPanels.containsKey(playerName) || plugin.openPanels.skipPanelClose.contains(playerName)){
return;
}
//check for panelType unclosable (unclosable is Top only)
if(plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).getConfig().contains("panelType")){
if(plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).getConfig().getStringList("panelType").contains("unclosable")){
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).open(Bukkit.getPlayer(playerName), PanelPosition.Top);
}
});
return;
}
}
//run commands-on-close for panels
if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName(),PanelPosition.Bottom)){
plugin.openPanels.panelCloseCommands(playerName,PanelPosition.Bottom,plugin.openPanels.getOpenPanel(playerName,PanelPosition.Bottom));
}
if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName(),PanelPosition.Middle)){
plugin.openPanels.panelCloseCommands(playerName,PanelPosition.Middle,plugin.openPanels.getOpenPanel(playerName,PanelPosition.Middle));
}
//close panels and run commands for Top panel
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top); plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top);
} }

View File

@ -64,9 +64,8 @@ public class Commandpanelblocks implements CommandExecutor {
return true; return true;
} }
//make the material name look okay //make the material name look okay
String materialNameFormatted = blockType.getType().toString().substring(0, 1).toUpperCase() + blockType.getType().toString().substring(1).toLowerCase(); String coordinates = blockLocation.getBlockX() + ", " + blockLocation.getBlockY() + ", " + blockLocation.getBlockZ();
materialNameFormatted = materialNameFormatted.replaceAll("_"," "); sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.WHITE + args[1] + ChatColor.GREEN + "will now open when right clicking a block in the coordinates " + ChatColor.WHITE + coordinates));
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.WHITE + args[1] + ChatColor.GREEN + " will now open when right clicking " + ChatColor.WHITE + materialNameFormatted));
}else{ }else{
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms"))); sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
} }

View File

@ -3,11 +3,11 @@ package me.rockyhawk.commandpanels.panelblocks;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import java.util.Objects; import java.util.Objects;
@ -17,41 +17,50 @@ public class PanelBlockOnClick implements Listener {
public PanelBlockOnClick(CommandPanels pl) { public PanelBlockOnClick(CommandPanels pl) {
this.plugin = pl; this.plugin = pl;
} }
@EventHandler @EventHandler
public void onInteract(PlayerInteractEvent e){ public void onInteract(PlayerInteractEvent e){
if(e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock() != null) {
e.setCancelled(blockClickEventTrigger(e.getClickedBlock().getLocation(), e.getPlayer()));
}
}
@EventHandler
public void onInteractEntity(PlayerInteractEntityEvent e){
if(!e.getPlayer().isSneaking()) {
e.setCancelled(blockClickEventTrigger(e.getRightClicked().getLocation().getBlock().getLocation(), e.getPlayer()));
}
}
public boolean blockClickEventTrigger(Location location, Player p){
//if panel blocks are disabled return //if panel blocks are disabled return
if(Objects.requireNonNull(plugin.config.getString("config.panel-blocks")).equalsIgnoreCase("false")){ if(Objects.requireNonNull(plugin.config.getString("config.panel-blocks")).equalsIgnoreCase("false")){
return; return false;
} }
if(e.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = e.getClickedBlock();
Player p = e.getPlayer();
assert block != null;
if(!plugin.blockConfig.contains("blocks")){ if(!plugin.blockConfig.contains("blocks")){
return; return false;
} }
if(plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Top)) { if(plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Top)) {
//some blocks run this event twice, skip if panel already open //some blocks run this event twice, skip if panel already open
//as blocks cannot be clicked obviously if a panel is open //as blocks cannot be clicked obviously if a panel is open
return; return false;
} }
for (String configLocation : Objects.requireNonNull(plugin.blockConfig.getConfigurationSection("blocks")).getKeys(false)) { for (String configLocation : Objects.requireNonNull(plugin.blockConfig.getConfigurationSection("blocks")).getKeys(false)) {
String[] loc = configLocation.split("_"); String[] loc = configLocation.split("_");
Location tempLocation = new Location(plugin.getServer().getWorld(loc[0].replaceAll("%dash%","_")),Double.parseDouble(loc[1]),Double.parseDouble(loc[2]),Double.parseDouble(loc[3])); Location tempLocation = new Location(plugin.getServer().getWorld(loc[0].replaceAll("%dash%","_")),Double.parseDouble(loc[1]),Double.parseDouble(loc[2]),Double.parseDouble(loc[3]));
if(tempLocation.equals(block.getLocation())){ if(tempLocation.equals(location)){
e.setCancelled(true);
if(plugin.blockConfig.contains("blocks." + configLocation + ".commands")){ if(plugin.blockConfig.contains("blocks." + configLocation + ".commands")){
for(String command : plugin.blockConfig.getStringList("blocks." + configLocation + ".commands")){ for(String command : plugin.blockConfig.getStringList("blocks." + configLocation + ".commands")){
plugin.commandTags.runCommand(null,PanelPosition.Top,p, command); plugin.commandTags.runCommand(null,PanelPosition.Top,p, command);
} }
return; return true;
} }
//uses the open= tag because it will open a panel with panel names, but also works with open= features like placeholders //uses the open= tag because it will open a panel with panel names, but also works with open= features like placeholders
String command = "open= " + plugin.blockConfig.getString("blocks." + configLocation + ".panel"); String command = "open= " + plugin.blockConfig.getString("blocks." + configLocation + ".panel");
plugin.commandTags.runCommand(null,PanelPosition.Top,p, command); plugin.commandTags.runCommand(null,PanelPosition.Top,p, command);
return true;
} }
} }
return false;
} }
} }