This commit is contained in:
rockyhawk64 2021-07-18 11:29:37 +10:00
parent 6aa3593a3f
commit 9dc1f1bacb
9 changed files with 90 additions and 56 deletions

View File

@ -48,6 +48,7 @@ placeholders:
updater:
auto-update: true
minor-updates-only: true
update-checks: true
purchase:
currency:
success: '&aSuccessfully Bought For $%cp-args%'

View File

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

View File

@ -35,7 +35,6 @@ public class Utils implements Listener {
//when clicked on a panel
Player p = (Player)e.getWhoClicked();
int clickedSlot = e.getSlot();
ItemStack clicked = e.getCurrentItem();
if(!plugin.openPanels.hasPanelOpen(p.getName(),PanelPosition.Top) || e.getClick() == ClickType.DOUBLE_CLICK){
return;
@ -52,7 +51,7 @@ public class Utils implements Listener {
//if the panel is clicked on the outside area of the GUI
if (panel.getConfig().contains("outside-commands")) {
try {
plugin.commandTags.runCommands(panel,PanelPosition.Top,p, panel.getConfig().getStringList("outside-commands"));
plugin.commandTags.runCommands(panel,PanelPosition.Top,p, panel.getConfig().getStringList("outside-commands"),e.getClick());
}catch(Exception s){
plugin.debug(s,p);
}
@ -133,52 +132,13 @@ public class Utils implements Listener {
}
}
commands = commandsAfterSequence;
for (int i = 0; commands.size() - 1 >= i; i++) {
try {
switch(commands.get(i).split("\\s")[0]){
case "right=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("right=", "").trim());
if (e.getClick() != ClickType.RIGHT) {
plugin.commandTags.runCommands(panel,position,p,commands,e.getClick());
/*for (int i = 0; commands.size() - 1 >= i; i++) {
commands.set(i,plugin.commandTags.hasCorrectClick(commands.get(i),e.getClick()));
if(commands.get(i).equals("")){
//click type is wrong
continue;
}
break;
}
case "rightshift=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("rightshift=", "").trim());
if (e.getClick() != ClickType.SHIFT_RIGHT) {
continue;
}
break;
}
case "left=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("left=", "").trim());
if (e.getClick() != ClickType.LEFT) {
continue;
}
break;
}
case "leftshift=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("leftshift=", "").trim());
if (e.getClick() != ClickType.SHIFT_LEFT) {
continue;
}
break;
}
case "middle=":{
commands.set(i, commands.get(i).replace("middle=", "").trim());
if (e.getClick() != ClickType.MIDDLE) {
continue;
}
break;
}
}
} catch (Exception click) {
//skip if you can't do this
}
//start custom command placeholders
try {
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", clicked.getType().toString()));
@ -198,7 +158,7 @@ public class Utils implements Listener {
if(val == PaywallOutput.NotApplicable){
plugin.commandTags.runCommand(panel,position, p, commands.get(i));
}
}
}*/
}
}
}

View File

@ -17,6 +17,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
@ -30,6 +31,25 @@ public class CommandTags {
this.plugin = pl;
}
//with the click type included
public void runCommands(Panel panel, PanelPosition position,Player p, List<String> commands, ClickType click){
for (String command : commands) {
command = plugin.commandTags.hasCorrectClick(command,click);
if(command.equals("")){
//click type is wrong
continue;
}
PaywallOutput val = plugin.commandTags.commandPayWall(panel,p,command);
if(val == PaywallOutput.Blocked){
break;
}
if(val == PaywallOutput.NotApplicable){
plugin.commandTags.runCommand(panel,position,p, command);
}
}
}
public void runCommands(Panel panel, PanelPosition position,Player p, List<String> commands){
for (String command : commands) {
PaywallOutput val = plugin.commandTags.commandPayWall(panel,p,command);
@ -65,6 +85,56 @@ public class CommandTags {
plugin.getServer().getPluginManager().registerEvents(new ItemTags(plugin), plugin);
}
public String hasCorrectClick(String command, ClickType click){
try {
switch(command.split("\\s")[0]){
case "right=":{
//if commands is for right clicking, remove the 'right=' and continue
command = command.replace("right= ", "");
if (click != ClickType.RIGHT) {
return "";
}
break;
}
case "rightshift=":{
//if commands is for right clicking, remove the 'right=' and continue
command = command.replace("rightshift= ", "");
if (click != ClickType.SHIFT_RIGHT) {
return "";
}
break;
}
case "left=":{
//if commands is for right clicking, remove the 'right=' and continue
command = command.replace("left= ", "");
if (click != ClickType.LEFT) {
return "";
}
break;
}
case "leftshift=":{
//if commands is for right clicking, remove the 'right=' and continue
command = command.replace("leftshift= ", "");
if (click != ClickType.SHIFT_LEFT) {
return "";
}
break;
}
case "middle=":{
command = command.replace("middle= ", "");
if (click != ClickType.MIDDLE) {
return "";
}
break;
}
}
return command;
} catch (Exception ex) {
return "";
//skip if you can't do this
}
}
@SuppressWarnings("deprecation")
public PaywallOutput commandPayWall(Panel panel, Player p, String command) { //return 0 means no funds, 1 is they passed and 2 means paywall is not this command
String tag = plugin.config.getString("config.format.tag") + " ";

View File

@ -24,7 +24,7 @@ public class SpecialTags implements Listener {
e.commandTagUsed();
//if player uses open= it will open the panel, with the option to add custom placeholders
String panelName = e.args[0];
String cmd = String.join(" ",e.args).replace(e.args[0],"").trim();
String cmd = String.join(" ",e.args).replace(e.args[0] + " ","").trim();
Panel openPanel = null;
PanelPosition openPosition = e.pos;

View File

@ -6,6 +6,7 @@ import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
@ -30,7 +31,7 @@ public class HotbarItemLoader {
}
//return true if found
public boolean stationaryExecute(int slot, Player p, boolean openPanel){
public boolean stationaryExecute(int slot, Player p, ClickType click, boolean openPanel){
if(stationaryItems.get(p.getUniqueId()).list.containsKey(slot)){
if(openPanel) {
try {
@ -49,9 +50,7 @@ public class HotbarItemLoader {
return false;
}
if(panel.getHotbarSection(p).contains("commands")){
for(String command : panel.getHotbarSection(p).getStringList("commands")){
plugin.commandTags.runCommand(panel,PanelPosition.Top,p, command);
}
plugin.commandTags.runCommands(panel,PanelPosition.Top,p,panel.getHotbarSection(p).getStringList("commands"),click);
return true;
}
panel.open(p, PanelPosition.Top);

View File

@ -14,6 +14,10 @@ public class UtilsChestSortEvent implements Listener {
}
@EventHandler
public void onChestSortEvent(ChestSortEvent e){
//if player is null it is not necessary
if(e.getPlayer() == null){
return;
}
//cancel if a panel is opened at all
if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName(), PanelPosition.Top)){
e.setCancelled(true);

View File

@ -40,7 +40,7 @@ public class UtilsOpenWithItem implements Listener {
return;
}
if(e.getClickedInventory().getType() == InventoryType.PLAYER && !e.isCancelled()) {
if (plugin.hotbar.stationaryExecute(e.getSlot(), p, true)) {
if (plugin.hotbar.stationaryExecute(e.getSlot(), p,e.getClick(), true)) {
e.setCancelled(true);
p.updateInventory();
}

View File

@ -28,7 +28,7 @@ public class Updater implements Listener {
//send update message when the player joins the game with the permission
@EventHandler
public void joinGame(PlayerJoinEvent e){
if(e.getPlayer().hasPermission("commandpanel.update")){
if(e.getPlayer().hasPermission("commandpanel.update") && plugin.config.getBoolean("updater.update-checks")){
if(githubNewUpdate(false)){
new BukkitRunnable() {
@Override