forked from Upstream/CommandPanels
v3.15.5.0
This commit is contained in:
parent
46a7dd13b4
commit
c01133ac81
@ -1,4 +1,4 @@
|
||||
version: 3.15.4.0
|
||||
version: 3.15.5.0
|
||||
main: me.rockyhawk.commandpanels.CommandPanels
|
||||
name: CommandPanels
|
||||
author: RockyHawk
|
||||
|
@ -1,19 +1,17 @@
|
||||
package me.rockyhawk.commandpanels;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import me.rockyhawk.commandpanels.api.CommandPanelsAPI;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.classresources.*;
|
||||
import me.rockyhawk.commandpanels.classresources.ExecuteOpenVoids;
|
||||
import me.rockyhawk.commandpanels.classresources.GetCustomHeads;
|
||||
import me.rockyhawk.commandpanels.classresources.ItemCreation;
|
||||
import me.rockyhawk.commandpanels.classresources.OpenEditorGuis;
|
||||
import me.rockyhawk.commandpanels.classresources.item_fall.ItemFallManager;
|
||||
import me.rockyhawk.commandpanels.classresources.placeholders.CreateText;
|
||||
import me.rockyhawk.commandpanels.classresources.placeholders.Placeholders;
|
||||
import me.rockyhawk.commandpanels.commands.*;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTags;
|
||||
import me.rockyhawk.commandpanels.completetabs.CpTabComplete;
|
||||
import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom;
|
||||
import me.rockyhawk.commandpanels.datamanager.DebugManager;
|
||||
@ -25,10 +23,11 @@ import me.rockyhawk.commandpanels.ingameeditor.CpIngameEditCommand;
|
||||
import me.rockyhawk.commandpanels.ingameeditor.CpTabCompleteIngame;
|
||||
import me.rockyhawk.commandpanels.ingameeditor.EditorUserInput;
|
||||
import me.rockyhawk.commandpanels.ingameeditor.EditorUtils;
|
||||
|
||||
import me.rockyhawk.commandpanels.interactives.CommandpanelUserInput;
|
||||
import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher;
|
||||
import me.rockyhawk.commandpanels.interactives.OpenOnJoin;
|
||||
import me.rockyhawk.commandpanels.ioclasses.Sequence_1_13;
|
||||
import me.rockyhawk.commandpanels.ioclasses.Sequence_1_14;
|
||||
|
||||
import me.rockyhawk.commandpanels.legacy.LegacyVersion;
|
||||
import me.rockyhawk.commandpanels.legacy.PlayerHeads;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.OpenGUI;
|
||||
@ -42,21 +41,30 @@ import me.rockyhawk.commandpanels.openwithitem.UtilsOpenWithItem;
|
||||
import me.rockyhawk.commandpanels.panelblocks.BlocksTabComplete;
|
||||
import me.rockyhawk.commandpanels.panelblocks.Commandpanelblocks;
|
||||
import me.rockyhawk.commandpanels.panelblocks.PanelBlockOnClick;
|
||||
import me.rockyhawk.commandpanels.interactives.CommandpanelUserInput;
|
||||
import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher;
|
||||
import me.rockyhawk.commandpanels.updater.Updater;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CommandPanels extends JavaPlugin{
|
||||
public YamlConfiguration config;
|
||||
public Economy econ = null;
|
||||
@ -145,6 +153,10 @@ public class CommandPanels extends JavaPlugin{
|
||||
this.getServer().getPluginManager().registerEvents(new GenUtils(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new CommandpanelUserInput(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new ItemFallManager(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new OpenOnJoin(this), this);
|
||||
|
||||
//load in all built in command tags
|
||||
commandTags.registerBuiltInTags();
|
||||
|
||||
//if refresh-panels set to false, don't load this
|
||||
if(Objects.requireNonNull(config.getString("config.refresh-panels")).equalsIgnoreCase("true")){
|
||||
|
@ -7,7 +7,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Utils implements Listener {
|
||||
CommandPanels plugin;
|
||||
@ -149,22 +150,15 @@ public class Utils implements Listener {
|
||||
|
||||
//end custom command PlaceHolders
|
||||
|
||||
//do placeholders
|
||||
String command;
|
||||
if(commands.get(i).split("\\s")[0].equalsIgnoreCase("nopapi=")){
|
||||
//won't parse PAPI placeholders
|
||||
command = plugin.tex.papi(plugin.placeholders.setCpPlaceholders(panel,p,commands.get(i))).replace("nopapi=","").trim();
|
||||
}else{
|
||||
//will parse every placeholder
|
||||
command = plugin.tex.papi(panel,p,commands.get(i));
|
||||
}
|
||||
//do commands
|
||||
String command = plugin.tex.papi(panel,p,commands.get(i));
|
||||
|
||||
int val = plugin.commandTags.commandPayWall(p,command);
|
||||
if(val == 0){
|
||||
return;
|
||||
}
|
||||
if(val == 2){
|
||||
plugin.commandTags.commandTags(panel, p, command, commands.get(i));
|
||||
plugin.commandTags.runCommand(panel, p, commands.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package me.rockyhawk.commandpanels.api;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.customcommands.PanelPlaceholders;
|
||||
import me.rockyhawk.commandpanels.classresources.placeholders.PanelPlaceholders;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -8,16 +8,22 @@ public class PanelCommandEvent extends Event {
|
||||
|
||||
private final Player p;
|
||||
private final String args;
|
||||
private final Panel panel;
|
||||
|
||||
public PanelCommandEvent(Player player, String message) {
|
||||
public PanelCommandEvent(Player player, String message, Panel panel1) {
|
||||
this.p = player;
|
||||
this.args = message;
|
||||
this.panel = panel1;
|
||||
}
|
||||
|
||||
public Player getPlayer(){
|
||||
return this.p;
|
||||
}
|
||||
|
||||
public Panel getPanel(){
|
||||
return this.panel;
|
||||
}
|
||||
|
||||
public String getMessage(){
|
||||
return this.args;
|
||||
}
|
||||
|
@ -1,699 +0,0 @@
|
||||
package me.rockyhawk.commandpanels.classresources;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import me.realized.tokenmanager.api.TokenManager;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.api.PanelCommandEvent;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandTags {
|
||||
CommandPanels plugin;
|
||||
public CommandTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void commandTags(Panel panel, Player p, String command, String commandRAW) {
|
||||
//commandRAW is without placeholders
|
||||
switch(command.split("\\s")[0]){
|
||||
case "server=":{
|
||||
//this contacts bungee and tells it to send the server change command
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(command.split("\\s")[1]);
|
||||
Player player = Bukkit.getPlayerExact(p.getName());
|
||||
assert player != null;
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
break;
|
||||
}
|
||||
case "cpc":{
|
||||
//this will close the current inventory
|
||||
p.closeInventory();
|
||||
break;
|
||||
}
|
||||
case "event=":{
|
||||
//this will broadcast an event, with args event= [args no space]
|
||||
PanelCommandEvent commandEvent = new PanelCommandEvent(p,command.split("\\s")[1]);
|
||||
Bukkit.getPluginManager().callEvent(commandEvent);
|
||||
break;
|
||||
}
|
||||
case "set-data=":{
|
||||
if(command.split("\\s").length == 4){
|
||||
plugin.panelData.setUserData(getOffline(command.split("\\s")[3]),command.split("\\s")[1],plugin.tex.papiNoColour(panel,p,command.split("\\s")[2]),true);
|
||||
break;
|
||||
}
|
||||
//this will overwrite data. set-data= [data point] [data value] [optional player]
|
||||
plugin.panelData.setUserData(p.getUniqueId(),command.split("\\s")[1],plugin.tex.papiNoColour(panel,p,command.split("\\s")[2]),true);
|
||||
break;
|
||||
}
|
||||
case "add-data=":{
|
||||
if(command.split("\\s").length == 4){
|
||||
plugin.panelData.setUserData(getOffline(command.split("\\s")[3]),command.split("\\s")[1],plugin.tex.papiNoColour(panel,p,command.split("\\s")[2]),false);
|
||||
break;
|
||||
}
|
||||
//this will not overwrite existing data. add-data= [data point] [data value] [optional player]
|
||||
plugin.panelData.setUserData(p.getUniqueId(),command.split("\\s")[1],plugin.tex.papiNoColour(panel,p,command.split("\\s")[2]),false);
|
||||
break;
|
||||
}
|
||||
case "math-data=":{
|
||||
if(command.split("\\s").length == 4){
|
||||
plugin.panelData.doDataMath(getOffline(command.split("\\s")[3]),command.split("\\s")[1],plugin.tex.papiNoColour(panel,p,command.split("\\s")[2]));
|
||||
break;
|
||||
}
|
||||
//only works if data is number, goes math-data= [data point] [operator:number] [optional player] eg, math-data= -1 OR /3
|
||||
plugin.panelData.doDataMath(p.getUniqueId(),command.split("\\s")[1],plugin.tex.papiNoColour(panel,p,command.split("\\s")[2]));
|
||||
break;
|
||||
}
|
||||
case "clear-data=":{
|
||||
//will clear all data for player clear-data= [playerName]
|
||||
plugin.panelData.clearData(p.getUniqueId());
|
||||
break;
|
||||
}
|
||||
case "del-data=":{
|
||||
if(command.split("\\s").length == 3){
|
||||
plugin.panelData.delUserData(getOffline(command.split("\\s")[2]),command.split("\\s")[1]);
|
||||
break;
|
||||
}
|
||||
//this will remove data. del-data= [data point] [optional player]
|
||||
plugin.panelData.delUserData(p.getUniqueId(),command.split("\\s")[1]);
|
||||
break;
|
||||
}
|
||||
case "give-item=":{
|
||||
//this will remove data. give-item= [custom item].
|
||||
ItemStack itm = plugin.itemCreate.makeCustomItemFromConfig(null,plugin.openPanels.getOpenPanel(p.getName()).getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false);
|
||||
p.getInventory().addItem(itm);
|
||||
break;
|
||||
}
|
||||
case "open=":{
|
||||
//if player uses open= it will open the panel, with the option to add custom placeholders
|
||||
String panelName = commandRAW.split("\\s")[1];
|
||||
String cmd = commandRAW.replace("open= " + panelName,"");
|
||||
panelName = plugin.tex.papi(panel,p,panelName);
|
||||
|
||||
Panel openPanel = null;
|
||||
for(Panel pane : plugin.panelList){
|
||||
if(pane.getName().equals(panelName)){
|
||||
openPanel = pane.copy();
|
||||
}
|
||||
}
|
||||
if(openPanel == null){
|
||||
break;
|
||||
}
|
||||
|
||||
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
|
||||
for(int i = 0; i < cm.length; i++){
|
||||
if(cm[i].equals('[')){
|
||||
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
|
||||
//do not change the placeholder
|
||||
String placeholder = contents.substring(0,contents.indexOf(':'));
|
||||
//only convert placeholders for the value
|
||||
String value = plugin.tex.papi(openPanel,p,contents.substring(contents.indexOf(':')+1));
|
||||
openPanel.placeholders.addPlaceholder(placeholder,value);
|
||||
i = i+contents.length()-1;
|
||||
}
|
||||
}
|
||||
openPanel.open(p);
|
||||
break;
|
||||
}
|
||||
case "console=":{
|
||||
//if player uses console= it will perform command in the console
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("console=", "").trim());
|
||||
break;
|
||||
}
|
||||
case "placeholder=":{
|
||||
//placeholder is now placeholder= [place] [value]
|
||||
String cmd;
|
||||
cmd = commandRAW.replace("placeholder= ","");
|
||||
|
||||
if(panel == null){
|
||||
break;
|
||||
}
|
||||
|
||||
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
|
||||
for(int i = 0; i < cm.length; i++){
|
||||
if(cm[i].equals('[')){
|
||||
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
|
||||
//do not change the placeholder
|
||||
String placeholder = contents.substring(0,contents.indexOf(':'));
|
||||
//only convert placeholders for the value
|
||||
String value = plugin.tex.papi(panel,p,contents.substring(contents.indexOf(':')+1));
|
||||
panel.placeholders.addPlaceholder(placeholder,value);
|
||||
i = i+contents.length()-1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "setitem=":{
|
||||
//if player uses setitem= [custom item] [slot] it will change the item slot to something, used for placeable items
|
||||
//make a section in the panel called "custom-item" then whatever the title of the item is, put that here
|
||||
ConfigurationSection panelCF = plugin.openPanels.getOpenPanel(p.getName()).getConfig();
|
||||
ItemStack s = plugin.itemCreate.makeItemFromConfig(null,panelCF.getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, true);
|
||||
p.getOpenInventory().getTopInventory().setItem(Integer.parseInt(command.split("\\s")[2]), s);
|
||||
break;
|
||||
}
|
||||
case "refresh":{
|
||||
//this will just do a standard panel refresh, animate is set to 0
|
||||
plugin.createGUI.openGui(plugin.openPanels.getOpenPanel(p.getName()), p, 0,0);
|
||||
break;
|
||||
}
|
||||
case "op=":{
|
||||
//if player uses op= it will perform command as op
|
||||
boolean isop = p.isOp();
|
||||
try {
|
||||
p.setOp(true);
|
||||
Bukkit.dispatchCommand(p,command.replace("op=", "").trim());
|
||||
p.setOp(isop);
|
||||
} catch (Exception exc) {
|
||||
p.setOp(isop);
|
||||
plugin.debug(exc,p);
|
||||
p.sendMessage(plugin.tag + plugin.tex.papi( plugin.config.getString("config.format.error") + " op=: Error in op command!"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "delay=":{
|
||||
//if player uses op= it will perform command as op
|
||||
final int delaySeconds = Integer.parseInt(command.split("\\s")[1]);
|
||||
String finalCommand = command.split("\\s",3)[2];
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
commandTags(panel, p, finalCommand, commandRAW);
|
||||
}catch (Exception ex){
|
||||
//if there are any errors, cancel so that it doesn't loop errors
|
||||
plugin.debug(ex,p);
|
||||
this.cancel();
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskTimer(plugin, 20*delaySeconds, 20); //20 ticks == 1 second
|
||||
break;
|
||||
}
|
||||
case "buy=":{
|
||||
//if player uses buy= it will be eg. buy= <price> <item> <amount of item> <ID>
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1]));
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
//legacy ID
|
||||
byte id = 0;
|
||||
if(plugin.legacy.isLegacy()) {
|
||||
for (String argsTemp : command.split("\\s")) {
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p.getInventory().firstEmpty() >= 0) {
|
||||
p.getInventory().addItem(new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id));
|
||||
} else {
|
||||
Objects.requireNonNull(p.getLocation().getWorld()).dropItemNaturally(p.getLocation(), new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + plugin.config.getString("purchase.currency.failure")));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!"));
|
||||
}
|
||||
} catch (Exception buy) {
|
||||
plugin.debug(buy,p);
|
||||
p.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "tokenbuy=":{
|
||||
//if player uses tokenbuy= it will be eg. tokenbuy= <price> <item> <amount of item> <ID>
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
assert api != null;
|
||||
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
|
||||
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
//legacy ID
|
||||
byte id = 0;
|
||||
if(plugin.legacy.isLegacy()) {
|
||||
for (String argsTemp : command.split("\\s")) {
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p.getInventory().firstEmpty() >= 0) {
|
||||
p.getInventory().addItem(new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id));
|
||||
} else {
|
||||
Objects.requireNonNull(p.getLocation().getWorld()).dropItemNaturally(p.getLocation(), new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3]),id));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + plugin.config.getString("purchase.tokens.failure")));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + ChatColor.RED + "Buying Requires TokenManager to work!"));
|
||||
}
|
||||
} catch (Exception buy) {
|
||||
plugin.debug(buy,p);
|
||||
p.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "sell=":{
|
||||
//if player uses sell= it will be eg. sell= <cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
boolean sold = false;
|
||||
for (int f = 0; f < p.getInventory().getSize(); f++) {
|
||||
ItemStack itm = p.getInventory().getItem(f);
|
||||
if (itm != null && itm.getType().equals(Material.matchMaterial(command.split("\\s")[2]))) {
|
||||
//determine if the command contains parameters for extensions
|
||||
String potion = "false";
|
||||
for(String argsTemp : command.split("\\s")){
|
||||
if(argsTemp.startsWith("potion:")){
|
||||
potion = argsTemp.replace("potion:","");
|
||||
break;
|
||||
}
|
||||
}
|
||||
//legacy ID
|
||||
byte id = -1;
|
||||
if(plugin.legacy.isLegacy()) {
|
||||
for (String argsTemp : command.split("\\s")) {
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//check to ensure any extensions are checked
|
||||
try {
|
||||
if (!potion.equals("false")) {
|
||||
PotionMeta potionMeta = (PotionMeta) itm.getItemMeta();
|
||||
assert potionMeta != null;
|
||||
if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (id != -1) {
|
||||
if (itm.getDurability() != id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}catch(Exception exc){
|
||||
//skip unless plugin.debug enabled
|
||||
plugin.debug(exc,p);
|
||||
}
|
||||
if (itm.getAmount() >= new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount()) {
|
||||
int amt = itm.getAmount() - new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount();
|
||||
itm.setAmount(amt);
|
||||
p.getInventory().setItem(f, amt > 0 ? itm : null);
|
||||
plugin.econ.depositPlayer(p, Double.parseDouble(command.split("\\s")[1]));
|
||||
sold = true;
|
||||
p.updateInventory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!sold) {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + plugin.config.getString("purchase.item.failure")));
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", command.split("\\s")[2])));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + ChatColor.RED + "Selling Requires Vault and an Economy to work!"));
|
||||
}
|
||||
} catch (Exception sell) {
|
||||
plugin.debug(sell,p);
|
||||
p.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "tokensell=":{
|
||||
//if player uses tokensell= it will be eg. tokensell= <cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
boolean sold = false;
|
||||
for (int f = 0; f < p.getInventory().getSize(); f++) {
|
||||
ItemStack itm = p.getInventory().getItem(f);
|
||||
if (itm != null && itm.getType().equals(Material.matchMaterial(command.split("\\s")[2]))) {
|
||||
//determine if the command contains parameters for extensions
|
||||
String potion = "false";
|
||||
for(String argsTemp : command.split("\\s")){
|
||||
if(argsTemp.startsWith("potion:")){
|
||||
potion = argsTemp.replace("potion:","");
|
||||
}
|
||||
}
|
||||
//legacy ID
|
||||
byte id = -1;
|
||||
if(plugin.legacy.isLegacy()) {
|
||||
for (String argsTemp : command.split("\\s")) {
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//check to ensure any extensions are checked
|
||||
try {
|
||||
if (!potion.equals("false")) {
|
||||
PotionMeta potionMeta = (PotionMeta) itm.getItemMeta();
|
||||
assert potionMeta != null;
|
||||
if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (id != -1) {
|
||||
if (itm.getDurability() != id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}catch(Exception exc){
|
||||
//skip if it cannot do unless plugin.debug is enabled
|
||||
plugin.debug(exc,p);
|
||||
}
|
||||
if (itm.getAmount() >= new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount()) {
|
||||
int amt = itm.getAmount() - new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[2])), Integer.parseInt(command.split("\\s")[3])).getAmount();
|
||||
itm.setAmount(amt);
|
||||
p.getInventory().setItem(f, amt > 0 ? itm : null);
|
||||
plugin.econ.depositPlayer(p, Double.parseDouble(command.split("\\s")[1]));
|
||||
assert api != null;
|
||||
api.addTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||
sold = true;
|
||||
p.updateInventory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!sold) {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + plugin.config.getString("purchase.item.failure")));
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", command.split("\\s")[2])));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + ChatColor.RED + "Selling Requires TokenManager to work!"));
|
||||
}
|
||||
} catch (Exception sell) {
|
||||
plugin.debug(sell,p);
|
||||
p.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "msg=":{
|
||||
//if player uses msg= it will send the player a message
|
||||
p.sendMessage(command.replace("msg=", "").trim());
|
||||
break;
|
||||
}
|
||||
case "sound=":{
|
||||
//if player uses sound= it will play a sound (sound= [sound])
|
||||
try {
|
||||
p.playSound(p.getLocation(), Sound.valueOf(command.split("\\s")[1]), 1F, 1F);
|
||||
} catch (Exception s) {
|
||||
plugin.debug(s,p);
|
||||
p.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "buycommand=":{
|
||||
//if player uses buycommand [price] [command]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1]));
|
||||
//execute command under here
|
||||
String commandp = command;
|
||||
commandp = commandp.replace("buycommand=", "").trim();
|
||||
String price = commandp.split(" ", 2)[0];
|
||||
commandp = commandp.split(" ", 2)[1];
|
||||
commandTags(panel,p,commandp,commandRAW);
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", price)));
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + plugin.config.getString("purchase.currency.failure")));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!"));
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
p.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "tokenbuycommand=":{
|
||||
//if player uses tokenbuycommand [price] [command]
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
assert api != null;
|
||||
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
|
||||
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||
//execute command under here
|
||||
String commandp = command;
|
||||
commandp = commandp.replace("tokenbuycommand=", "").trim();
|
||||
String price = commandp.split(" ", 2)[0];
|
||||
commandp = commandp.split(" ", 2)[1];
|
||||
commandTags(panel,p,commandp,commandRAW);
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + Objects.requireNonNull(plugin.config.getString("purchase.token.success")).replaceAll("%cp-args%", price)));
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + plugin.config.getString("purchase.token.failure")));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + ChatColor.RED + "Buying Requires Vault and an Economy to work!"));
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
p.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "teleport=":{
|
||||
//if player uses teleport= x y z (optional other player)
|
||||
if (command.split("\\s").length == 6) {
|
||||
float x, y, z, yaw, pitch; //pitch is the heads Y axis and yaw is the X axis
|
||||
x = Float.parseFloat(command.split("\\s")[1]);
|
||||
y = Float.parseFloat(command.split("\\s")[2]);
|
||||
z = Float.parseFloat(command.split("\\s")[3]);
|
||||
yaw = Float.parseFloat(command.split("\\s")[4]);
|
||||
pitch = Float.parseFloat(command.split("\\s")[5]);
|
||||
p.teleport(new Location(p.getWorld(), x, y, z, yaw, pitch));
|
||||
} else if (command.split("\\s").length <= 4) {
|
||||
float x, y, z;
|
||||
x = Float.parseFloat(command.split("\\s")[1]);
|
||||
y = Float.parseFloat(command.split("\\s")[2]);
|
||||
z = Float.parseFloat(command.split("\\s")[3]);
|
||||
p.teleport(new Location(p.getWorld(), x, y, z));
|
||||
} else {
|
||||
try {
|
||||
Player otherplayer = Bukkit.getPlayer(command.split("\\s")[4]);
|
||||
float x, y, z;
|
||||
x = Float.parseFloat(command.split("\\s")[1]);
|
||||
y = Float.parseFloat(command.split("\\s")[2]);
|
||||
z = Float.parseFloat(command.split("\\s")[3]);
|
||||
assert otherplayer != null;
|
||||
otherplayer.teleport(new Location(otherplayer.getWorld(), x, y, z));
|
||||
} catch (Exception tpe) {
|
||||
p.sendMessage(plugin.tag + plugin.config.getString("config.format.notitem"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "sudo=":{
|
||||
//if player uses sudo= [command] to send a command as them
|
||||
p.chat( "/" + command.replaceAll("sudo=", "").trim());
|
||||
break;
|
||||
}
|
||||
case "send=":{
|
||||
//if player uses send= [message] to send a message as them
|
||||
p.chat( command.replaceAll("send=", "").trim());
|
||||
break;
|
||||
}
|
||||
case "stopsound=":{
|
||||
//if player uses stopsound= [sound]
|
||||
try {
|
||||
p.stopSound(Sound.valueOf(command.split("\\s")[1]));
|
||||
} catch (Exception ss) {
|
||||
plugin.debug(ss,p);
|
||||
p.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Bukkit.dispatchCommand(p, command);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private UUID getOffline(String playerName){
|
||||
//making this a separate function as it is long and deprecated
|
||||
return Bukkit.getOfflinePlayer(playerName).getUniqueId();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int commandPayWall(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") + " ";
|
||||
switch(command.split("\\s")[0]){
|
||||
case "paywall=": {
|
||||
//if player uses paywall= [price]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1]));
|
||||
p.sendMessage(plugin.tex.papi(Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
return 1;
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi(plugin.config.getString("purchase.currency.failure")));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( tag + ChatColor.RED + "Paying Requires Vault and an Economy to work!"));
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
p.sendMessage(plugin.tex.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
case "tokenpaywall=": {
|
||||
//if player uses tokenpaywall= [price]
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
assert api != null;
|
||||
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
|
||||
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||
//if the message is empty don't send
|
||||
p.sendMessage(plugin.tex.papi(Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
return 1;
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi(plugin.config.getString("purchase.tokens.failure")));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( tag + ChatColor.RED + "Needs TokenManager to work!"));
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
p.sendMessage(plugin.tex.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
case "item-paywall=": {
|
||||
//if player uses item-paywall= [Material] [Amount] [Id]
|
||||
//or player can use item-paywall= [custom-item]
|
||||
try {
|
||||
short id = 0;
|
||||
if(command.split("\\s").length == 4){
|
||||
id = Short.parseShort(command.split("\\s")[3]);
|
||||
}
|
||||
|
||||
//create the item to be removed
|
||||
ItemStack sellItem;
|
||||
if(command.split("\\s").length == 2) {
|
||||
sellItem = plugin.itemCreate.makeCustomItemFromConfig(null,plugin.openPanels.getOpenPanel(p.getName()).getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false);
|
||||
}else{
|
||||
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])), Integer.parseInt(command.split("\\s")[2]), id);
|
||||
}
|
||||
//this is not a boolean because it needs to return an int
|
||||
int removedItem = 0;
|
||||
|
||||
//loop through items in the inventory
|
||||
for(ItemStack content : p.getInventory().getContents()){
|
||||
|
||||
if(content == null){
|
||||
//skip slot if empty
|
||||
continue;
|
||||
}
|
||||
|
||||
if(command.split("\\s").length == 2){
|
||||
//if item paywall is custom item
|
||||
if(plugin.itemCreate.isIdentical(sellItem,content)){
|
||||
content.setAmount(content.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
removedItem = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
//if custom item is an mmo item (1.14+ for the API)
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && plugin.openPanels.getOpenPanel(p.getName()).getConfig().getString("custom-item." + command.split("\\s")[1] + ".material").startsWith("mmo=")) {
|
||||
String customItemMaterial = plugin.openPanels.getOpenPanel(p.getName()).getConfig().getString("custom-item." + command.split("\\s")[1] + ".material");
|
||||
String mmoType = customItemMaterial.split("\\s")[1];
|
||||
String mmoID = customItemMaterial.split("\\s")[2];
|
||||
|
||||
if (plugin.isMMOItem(content,mmoType,mmoID) && sellItem.getAmount() <= content.getAmount()) {
|
||||
content.setAmount(content.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
removedItem = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}catch (Exception ex){
|
||||
plugin.debug(ex,p);
|
||||
}
|
||||
|
||||
}else {
|
||||
//if the item is a standard material
|
||||
if (content.getType() == sellItem.getType()) {
|
||||
if (sellItem.getAmount() <= content.getAmount()) {
|
||||
content.setAmount(content.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
removedItem = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//send message and return
|
||||
if(removedItem == 0){
|
||||
p.sendMessage(plugin.tex.papi( tag + plugin.config.getString("purchase.item.failure")));
|
||||
}else{
|
||||
p.sendMessage(plugin.tex.papi(Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%",sellItem.getType().toString())));
|
||||
}
|
||||
return removedItem;
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
p.sendMessage(plugin.tex.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
case "xp-paywall=": {
|
||||
//if player uses xp-paywall= [price]
|
||||
try {
|
||||
int balance = p.getLevel();
|
||||
if (balance >= Integer.parseInt(command.split("\\s")[1])) {
|
||||
p.setLevel(p.getLevel() - Integer.parseInt(command.split("\\s")[1]));
|
||||
//if the message is empty don't send
|
||||
p.sendMessage(plugin.tex.papi(Objects.requireNonNull(plugin.config.getString("purchase.xp.success")).replaceAll("%cp-args%", command.split("\\s")[1])));
|
||||
return 1;
|
||||
} else {
|
||||
p.sendMessage(plugin.tex.papi( plugin.config.getString("purchase.xp.failure")));
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
p.sendMessage(plugin.tex.papi( tag + plugin.config.getString("config.format.error") + " " + "commands: " + command));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
}
|
@ -75,7 +75,7 @@ public class ExecuteOpenVoids {
|
||||
break;
|
||||
}
|
||||
if (val == 2) {
|
||||
plugin.commandTags.commandTags(panel,p, plugin.tex.papi(panel,p, command), command);
|
||||
plugin.commandTags.runCommand(panel,p, command);
|
||||
}
|
||||
}
|
||||
}catch(Exception s){
|
||||
@ -161,7 +161,7 @@ public class ExecuteOpenVoids {
|
||||
break;
|
||||
}
|
||||
if (val == 2) {
|
||||
plugin.commandTags.commandTags(panel,p, plugin.tex.papi(panel,p, command), command);
|
||||
plugin.commandTags.runCommand(panel,p, command);
|
||||
}
|
||||
}
|
||||
}catch(Exception s){
|
||||
|
@ -27,7 +27,10 @@ import org.bukkit.potion.PotionType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemCreation {
|
||||
|
@ -15,6 +15,19 @@ public class CreateText {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
//CommandPanels send message function
|
||||
public void sendMessage(Player p, String message){
|
||||
if(!message.equals("")) {
|
||||
p.sendMessage(papi(plugin.tag + message));
|
||||
}
|
||||
}
|
||||
|
||||
//CommandPanels send message function without the tag
|
||||
public void sendString(Player p, String message){
|
||||
if(!message.equals("")) {
|
||||
p.sendMessage(papi(message));
|
||||
}
|
||||
}
|
||||
|
||||
//papi except if it is a String List
|
||||
public List<String> papiNoColour(Panel panel, Player p, List<String> setpapi) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package me.rockyhawk.commandpanels.customcommands;
|
||||
package me.rockyhawk.commandpanels.classresources.placeholders;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -24,6 +24,23 @@ public class Placeholders {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public String setCpPlaceholders(Panel panel, Player p, String str){
|
||||
//do player input placeholder first
|
||||
if (str.contains("%cp-player-input%")) {
|
||||
for (String[] key : plugin.userInputStrings) {
|
||||
if (key[0].equals(p.getName())) {
|
||||
plugin.userInputStrings.add(new String[]{p.getName(), str});
|
||||
return "cpc";
|
||||
}
|
||||
}
|
||||
plugin.userInputStrings.add(new String[]{p.getName(), str});
|
||||
List<String> inputMessages = new ArrayList<String>(plugin.config.getStringList("config.input-message"));
|
||||
for (String temp : inputMessages) {
|
||||
temp = temp.replaceAll("%cp-args%", Objects.requireNonNull(plugin.config.getString("config.input-cancel")));
|
||||
p.sendMessage(plugin.tex.papi(panel,p, temp));
|
||||
}
|
||||
return "cpc";
|
||||
}
|
||||
|
||||
//replace nodes with PlaceHolders
|
||||
str = str.replaceAll("%cp-player-displayname%", p.getDisplayName());
|
||||
str = str.replaceAll("%cp-player-name%", p.getName());
|
||||
@ -235,7 +252,7 @@ public class Placeholders {
|
||||
int end = str.indexOf("%", str.indexOf("%cp-setdata-") + 1);
|
||||
String point_value = str.substring(start, end).replace("%cp-setdata-", "").replace("%", "");
|
||||
String command = "set-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
|
||||
plugin.commandTags.commandTags(panel,p, plugin.tex.papi(panel,p,command),command);
|
||||
plugin.commandTags.runCommand(panel,p, command);
|
||||
str = str.replace(str.substring(start, end) + "%", "");
|
||||
}catch (Exception ex){
|
||||
plugin.debug(ex,p);
|
||||
@ -249,7 +266,7 @@ public class Placeholders {
|
||||
int end = str.indexOf("%", str.indexOf("%cp-mathdata-") + 1);
|
||||
String point_value = str.substring(start, end).replace("%cp-mathdata-", "").replace("%", "");
|
||||
String command = "math-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
|
||||
plugin.commandTags.commandTags(panel,p, plugin.tex.papi(panel,p,command),command);
|
||||
plugin.commandTags.runCommand(panel,p,command);
|
||||
str = str.replace(str.substring(start, end) + "%", "");
|
||||
}catch (Exception ex){
|
||||
plugin.debug(ex,p);
|
||||
@ -290,21 +307,6 @@ public class Placeholders {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("VotingPlugin")) {
|
||||
str = str.replaceAll("%cp-votingplugin-points%", String.valueOf(UserManager.getInstance().getVotingPluginUser(p).getPoints()));
|
||||
}
|
||||
if (str.contains("%cp-player-input%")) {
|
||||
for (String[] key : plugin.userInputStrings) {
|
||||
if (key[0].equals(p.getName())) {
|
||||
plugin.userInputStrings.add(new String[]{p.getName(), str});
|
||||
return "cpc";
|
||||
}
|
||||
}
|
||||
plugin.userInputStrings.add(new String[]{p.getName(), str});
|
||||
List<String> inputMessages = new ArrayList<String>(plugin.config.getStringList("config.input-message"));
|
||||
for (String temp : inputMessages) {
|
||||
temp = temp.replaceAll("%cp-args%", Objects.requireNonNull(plugin.config.getString("config.input-cancel")));
|
||||
p.sendMessage(plugin.tex.papi(panel,p, temp));
|
||||
}
|
||||
str = "cpc";
|
||||
}
|
||||
//end nodes with PlaceHolders
|
||||
return str;
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package me.rockyhawk.commandpanels.commandtags;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class CommandTagEvent extends Event {
|
||||
|
||||
public final Player p;
|
||||
public final Panel panel;
|
||||
public String[] raw;
|
||||
public String[] args;
|
||||
public String name;
|
||||
public boolean commandTagUsed = false;
|
||||
|
||||
public CommandTagEvent(CommandPanels plugin, Panel panel1, Player player, String rawCommand1) {
|
||||
this.p = player;
|
||||
this.panel = panel1;
|
||||
|
||||
String[] split = rawCommand1.split(" ", 2);
|
||||
if(split.length == 1){
|
||||
split = new String[]{split[0],""};
|
||||
}
|
||||
if(split[1].contains("%cp-player-input%")){
|
||||
//set command to cpc and then use full command for input
|
||||
this.name = "cpc";
|
||||
return;
|
||||
}
|
||||
|
||||
this.name = split[0].trim();
|
||||
this.raw = split[1].trim().split("\\s");
|
||||
this.args = plugin.tex.papi(panel1,player,split[1].trim()).split("\\s");
|
||||
}
|
||||
|
||||
public void commandTagUsed(){
|
||||
commandTagUsed = true;
|
||||
}
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
206
src/me/rockyhawk/commandpanels/commandtags/CommandTags.java
Normal file
206
src/me/rockyhawk/commandpanels/commandtags/CommandTags.java
Normal file
@ -0,0 +1,206 @@
|
||||
package me.rockyhawk.commandpanels.commandtags;
|
||||
|
||||
import me.realized.tokenmanager.api.TokenManager;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.economy.BuyCommandTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.economy.BuyItemTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.economy.SellItemTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.other.DataTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.other.PlaceholderTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.other.SpecialTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.standard.BasicTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.standard.BungeeTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.standard.ItemTags;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CommandTags {
|
||||
CommandPanels plugin;
|
||||
public CommandTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
public void runCommand(Panel panel,Player p,String commandRAW){
|
||||
CommandTagEvent tags = new CommandTagEvent(plugin,panel,p,commandRAW);
|
||||
Bukkit.getPluginManager().callEvent(tags);
|
||||
if(!tags.commandTagUsed){
|
||||
Bukkit.dispatchCommand(p, plugin.tex.papi(panel,p,commandRAW.trim()));
|
||||
}
|
||||
}
|
||||
|
||||
//do this on startup to load listeners
|
||||
public void registerBuiltInTags(){
|
||||
plugin.getServer().getPluginManager().registerEvents(new BuyCommandTags(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new BuyItemTags(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new SellItemTags(plugin), plugin);
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new DataTags(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new PlaceholderTags(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new SpecialTags(plugin), plugin);
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new BasicTags(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new BungeeTags(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new ItemTags(plugin), plugin);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int commandPayWall(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") + " ";
|
||||
switch(command.split("\\s")[0]){
|
||||
case "paywall=": {
|
||||
//if player uses paywall= [price]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1]));
|
||||
plugin.tex.sendString(p,Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
return 1;
|
||||
} else {
|
||||
plugin.tex.sendString(p,plugin.config.getString("purchase.currency.failure"));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendString(p, tag + ChatColor.RED + "Paying Requires Vault and an Economy to work!");
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
plugin.tex.sendString(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
case "tokenpaywall=": {
|
||||
//if player uses tokenpaywall= [price]
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
assert api != null;
|
||||
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
|
||||
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||
//if the message is empty don't send
|
||||
plugin.tex.sendString(p,Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
return 1;
|
||||
} else {
|
||||
plugin.tex.sendString(p,plugin.config.getString("purchase.tokens.failure"));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendString(p, tag + ChatColor.RED + "Needs TokenManager to work!");
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
plugin.tex.sendString(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
case "item-paywall=": {
|
||||
//if player uses item-paywall= [Material] [Amount] [Id]
|
||||
//or player can use item-paywall= [custom-item]
|
||||
try {
|
||||
short id = 0;
|
||||
if(command.split("\\s").length == 4){
|
||||
id = Short.parseShort(command.split("\\s")[3]);
|
||||
}
|
||||
|
||||
//create the item to be removed
|
||||
ItemStack sellItem;
|
||||
if(command.split("\\s").length == 2) {
|
||||
sellItem = plugin.itemCreate.makeCustomItemFromConfig(null,plugin.openPanels.getOpenPanel(p.getName()).getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false);
|
||||
}else{
|
||||
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])), Integer.parseInt(command.split("\\s")[2]), id);
|
||||
}
|
||||
//this is not a boolean because it needs to return an int
|
||||
int removedItem = 0;
|
||||
|
||||
//loop through items in the inventory
|
||||
for(ItemStack content : p.getInventory().getContents()){
|
||||
|
||||
if(content == null){
|
||||
//skip slot if empty
|
||||
continue;
|
||||
}
|
||||
|
||||
if(command.split("\\s").length == 2){
|
||||
//if item paywall is custom item
|
||||
if(plugin.itemCreate.isIdentical(sellItem,content)){
|
||||
content.setAmount(content.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
removedItem = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
//if custom item is an mmo item (1.14+ for the API)
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && plugin.openPanels.getOpenPanel(p.getName()).getConfig().getString("custom-item." + command.split("\\s")[1] + ".material").startsWith("mmo=")) {
|
||||
String customItemMaterial = plugin.openPanels.getOpenPanel(p.getName()).getConfig().getString("custom-item." + command.split("\\s")[1] + ".material");
|
||||
String mmoType = customItemMaterial.split("\\s")[1];
|
||||
String mmoID = customItemMaterial.split("\\s")[2];
|
||||
|
||||
if (plugin.isMMOItem(content,mmoType,mmoID) && sellItem.getAmount() <= content.getAmount()) {
|
||||
content.setAmount(content.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
removedItem = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}catch (Exception ex){
|
||||
plugin.debug(ex,p);
|
||||
}
|
||||
|
||||
}else {
|
||||
//if the item is a standard material
|
||||
if (content.getType() == sellItem.getType()) {
|
||||
if (sellItem.getAmount() <= content.getAmount()) {
|
||||
content.setAmount(content.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
removedItem = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//send message and return
|
||||
if(removedItem == 0){
|
||||
plugin.tex.sendString(p, tag + plugin.config.getString("purchase.item.failure"));
|
||||
}else{
|
||||
plugin.tex.sendString(p,Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%",sellItem.getType().toString()));
|
||||
}
|
||||
return removedItem;
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
plugin.tex.sendString(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
case "xp-paywall=": {
|
||||
//if player uses xp-paywall= [price]
|
||||
try {
|
||||
int balance = p.getLevel();
|
||||
if (balance >= Integer.parseInt(command.split("\\s")[1])) {
|
||||
p.setLevel(p.getLevel() - Integer.parseInt(command.split("\\s")[1]));
|
||||
//if the message is empty don't send
|
||||
plugin.tex.sendString(p,Objects.requireNonNull(plugin.config.getString("purchase.xp.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
return 1;
|
||||
} else {
|
||||
plugin.tex.sendString(p, plugin.config.getString("purchase.xp.failure"));
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,p);
|
||||
plugin.tex.sendString(p, tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.economy;
|
||||
|
||||
import me.realized.tokenmanager.api.TokenManager;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BuyCommandTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public BuyCommandTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("buycommand=")){
|
||||
e.commandTagUsed();
|
||||
//if player uses buycommand [price] [command]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
if (plugin.econ.getBalance(e.p) >= Double.parseDouble(e.args[0])) {
|
||||
plugin.econ.withdrawPlayer(e.p, Double.parseDouble(e.args[0]));
|
||||
//execute command under here
|
||||
String price = e.args[0];
|
||||
plugin.commandTags.runCommand(e.panel,e.p,String.join(" ",e.raw));
|
||||
plugin.tex.sendMessage(e.p,plugin.config.getString("purchase.currency.success").replaceAll("%cp-args%", price));
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("purchase.currency.failure"));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires Vault and an Economy to work!");
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,e.p);
|
||||
plugin.tex.sendMessage(e.p,plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("tokenbuycommand=")){
|
||||
e.commandTagUsed();
|
||||
//if player uses tokenbuycommand [price] [command]
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
assert api != null;
|
||||
int balance = Integer.parseInt(Long.toString(api.getTokens(e.p).orElse(0)));
|
||||
if (balance >= Double.parseDouble(e.args[0])) {
|
||||
api.removeTokens(e.p, Long.parseLong(e.args[0]));
|
||||
//execute command under here
|
||||
String price = e.args[0];
|
||||
plugin.commandTags.runCommand(e.panel,e.p,String.join(" ",e.raw));
|
||||
plugin.tex.sendMessage(e.p, Objects.requireNonNull(plugin.config.getString("purchase.token.success")).replaceAll("%cp-args%", price));
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("purchase.token.failure"));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires Vault and an Economy to work!");
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc,e.p);
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.economy;
|
||||
|
||||
import me.realized.tokenmanager.api.TokenManager;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BuyItemTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public BuyItemTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("buy=")){
|
||||
e.commandTagUsed();
|
||||
//if player uses buy= it will be eg. buy= <price> <item> <amount of item> <ID>
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
if (plugin.econ.getBalance(e.p) >= Double.parseDouble(e.args[0])) {
|
||||
plugin.econ.withdrawPlayer(e.p, Double.parseDouble(e.args[0]));
|
||||
plugin.tex.sendMessage(e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", e.args[0]));
|
||||
giveItem(e.p, e.args);
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("purchase.currency.failure"));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires Vault and an Economy to work!");
|
||||
}
|
||||
} catch (Exception buy) {
|
||||
plugin.debug(buy,e.p);
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("tokenbuy=")) {
|
||||
e.commandTagUsed();
|
||||
//if player uses tokenbuy= it will be eg. tokenbuy= <price> <item> <amount of item> <ID>
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
assert api != null;
|
||||
int balance = Integer.parseInt(Long.toString(api.getTokens(e.p).orElse(0)));
|
||||
if (balance >= Double.parseDouble(e.args[0])) {
|
||||
api.removeTokens(e.p, Long.parseLong(e.args[0]));
|
||||
plugin.tex.sendMessage(e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", e.args[0]));
|
||||
giveItem(e.p,e.args);
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("purchase.tokens.failure"));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires TokenManager to work!");
|
||||
}
|
||||
} catch (Exception buy) {
|
||||
plugin.debug(buy, e.p);
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void giveItem(Player p, String[] args){
|
||||
//legacy ID
|
||||
byte id = 0;
|
||||
if(plugin.legacy.isLegacy()) {
|
||||
for (String argsTemp : args) {
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p.getInventory().firstEmpty() >= 0) {
|
||||
p.getInventory().addItem(new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]),id));
|
||||
} else {
|
||||
Objects.requireNonNull(p.getLocation().getWorld()).dropItemNaturally(p.getLocation(), new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]),id));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.economy;
|
||||
|
||||
import me.realized.tokenmanager.api.TokenManager;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SellItemTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public SellItemTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("sell=")){
|
||||
e.commandTagUsed();
|
||||
//if player uses sell= it will be eg. sell= <cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
boolean sold = checkItem(e.p, e.args);
|
||||
if (!sold) {
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("purchase.item.failure"));
|
||||
} else {
|
||||
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]));
|
||||
plugin.tex.sendMessage(e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
|
||||
}
|
||||
} catch (Exception sell) {
|
||||
plugin.debug(sell,e.p);
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("tokensell=")) {
|
||||
e.commandTagUsed();
|
||||
//if player uses tokensell= it will be eg. tokensell= <cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
boolean sold = checkItem(e.p, e.args);
|
||||
if (!sold) {
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("purchase.item.failure"));
|
||||
} else {
|
||||
assert api != null;
|
||||
api.addTokens(e.p, Long.parseLong(e.args[0]));
|
||||
plugin.tex.sendMessage(e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires TokenManager to work!");
|
||||
}
|
||||
} catch (Exception sell) {
|
||||
plugin.debug(sell,e.p);
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private boolean checkItem(Player p, String[] args){
|
||||
for (int f = 0; f < p.getInventory().getSize(); f++) {
|
||||
ItemStack itm = p.getInventory().getItem(f);
|
||||
if (itm != null && itm.getType().equals(Material.matchMaterial(args[1]))) {
|
||||
//determine if the command contains parameters for extensions
|
||||
String potion = "false";
|
||||
for(String argsTemp : args){
|
||||
if(argsTemp.startsWith("potion:")){
|
||||
potion = argsTemp.replace("potion:","");
|
||||
}
|
||||
}
|
||||
//legacy ID
|
||||
byte id = -1;
|
||||
if(plugin.legacy.isLegacy()) {
|
||||
for (String argsTemp : args) {
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//check to ensure any extensions are checked
|
||||
try {
|
||||
if (!potion.equals("false")) {
|
||||
PotionMeta potionMeta = (PotionMeta) itm.getItemMeta();
|
||||
assert potionMeta != null;
|
||||
if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) {
|
||||
p.sendMessage(plugin.tex.papi( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (id != -1) {
|
||||
if (itm.getDurability() != id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}catch(Exception exc){
|
||||
//skip if it cannot do unless plugin.debug is enabled
|
||||
plugin.debug(exc,p);
|
||||
}
|
||||
if (itm.getAmount() >= new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])).getAmount()) {
|
||||
int amt = itm.getAmount() - new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])).getAmount();
|
||||
itm.setAmount(amt);
|
||||
p.getInventory().setItem(f, amt > 0 ? itm : null);
|
||||
plugin.econ.depositPlayer(p, Double.parseDouble(args[0]));
|
||||
p.updateInventory();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.other;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public DataTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("set-data=")){
|
||||
e.commandTagUsed();
|
||||
if(e.args.length == 3){
|
||||
plugin.panelData.setUserData(getOffline(e.args[2]),e.args[0],plugin.tex.papiNoColour(e.panel,e.p,e.args[1]),true);
|
||||
return;
|
||||
}
|
||||
//this will overwrite data. set-data= [data point] [data value] [optional player]
|
||||
plugin.panelData.setUserData(e.p.getUniqueId(),e.args[0],plugin.tex.papiNoColour(e.panel,e.p,e.args[1]),true);
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("add-data=")){
|
||||
e.commandTagUsed();
|
||||
if(e.args.length == 3){
|
||||
plugin.panelData.setUserData(getOffline(e.args[2]),e.args[0],plugin.tex.papiNoColour(e.panel,e.p,e.args[1]),false);
|
||||
return;
|
||||
}
|
||||
//this will not overwrite existing data. add-data= [data point] [data value] [optional player]
|
||||
plugin.panelData.setUserData(e.p.getUniqueId(),e.args[0],plugin.tex.papiNoColour(e.panel,e.p,e.args[1]),false);
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("math-data=")){
|
||||
e.commandTagUsed();
|
||||
if(e.args.length == 3){
|
||||
plugin.panelData.doDataMath(getOffline(e.args[2]),e.args[0],plugin.tex.papiNoColour(e.panel,e.p,e.args[1]));
|
||||
return;
|
||||
}
|
||||
//only works if data is number, goes math-data= [data point] [operator:number] [optional player] eg, math-data= -1 OR /3
|
||||
plugin.panelData.doDataMath(e.p.getUniqueId(),e.args[0],plugin.tex.papiNoColour(e.panel,e.p,e.args[1]));
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("clear-data=")){
|
||||
e.commandTagUsed();
|
||||
//will clear all data for player clear-data= [playerName]
|
||||
plugin.panelData.clearData(e.p.getUniqueId());
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("del-data=")){
|
||||
e.commandTagUsed();
|
||||
if(e.args.length == 3){
|
||||
plugin.panelData.delUserData(getOffline(e.args[1]),e.args[0]);
|
||||
return;
|
||||
}
|
||||
//this will remove data. del-data= [data point] [optional player]
|
||||
plugin.panelData.delUserData(e.p.getUniqueId(),e.args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private UUID getOffline(String playerName){
|
||||
//making this a separate function as it is long and deprecated
|
||||
return Bukkit.getOfflinePlayer(playerName).getUniqueId();
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.other;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PlaceholderTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public PlaceholderTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("placeholder=")) {
|
||||
e.commandTagUsed();
|
||||
//placeholder is placeholder= [%placeholder%:value]
|
||||
String cmd;
|
||||
cmd = String.join(" ",e.raw);
|
||||
|
||||
if(e.panel == null){
|
||||
return;
|
||||
}
|
||||
|
||||
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
|
||||
for(int i = 0; i < cm.length; i++){
|
||||
if(cm[i].equals('[')){
|
||||
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
|
||||
//do not change the placeholder
|
||||
String placeholder = contents.substring(0,contents.indexOf(':'));
|
||||
//only convert placeholders for the value
|
||||
String value = plugin.tex.papi(e.panel,e.p,contents.substring(contents.indexOf(':')+1));
|
||||
e.panel.placeholders.addPlaceholder(placeholder,value);
|
||||
i = i+contents.length()-1;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("add-placeholder=")) {
|
||||
e.commandTagUsed();
|
||||
//this will only run the placeholder command if the placeholder doesn't yet exist in the panel
|
||||
String cmd;
|
||||
cmd = String.join(" ",e.raw);
|
||||
|
||||
if (e.panel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
|
||||
for (int i = 0; i < cm.length; i++) {
|
||||
if (cm[i].equals('[')) {
|
||||
String contents = cmd.substring(i + 1, i + cmd.substring(i).indexOf(']'));
|
||||
//do not change the placeholder
|
||||
String placeholder = contents.substring(0, contents.indexOf(':'));
|
||||
//only convert placeholders for the value
|
||||
if (!e.panel.placeholders.keys.containsKey(placeholder)) {
|
||||
//only convert placeholders for the value
|
||||
String value = plugin.tex.papi(e.panel, e.p, contents.substring(contents.indexOf(':') + 1));
|
||||
e.panel.placeholders.addPlaceholder(placeholder, value);
|
||||
}
|
||||
i = i + contents.length() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.other;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class SpecialTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public SpecialTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("open=")) {
|
||||
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();
|
||||
|
||||
Panel openPanel = null;
|
||||
for(Panel pane : plugin.panelList){
|
||||
if(pane.getName().equals(panelName)){
|
||||
openPanel = pane.copy();
|
||||
}
|
||||
}
|
||||
if(openPanel == null){
|
||||
return;
|
||||
}
|
||||
|
||||
Character[] cm = ArrayUtils.toObject(cmd.toCharArray());
|
||||
for(int i = 0; i < cm.length; i++){
|
||||
if(cm[i].equals('[')){
|
||||
String contents = cmd.substring(i+1, i+cmd.substring(i).indexOf(']'));
|
||||
//do not change the placeholder
|
||||
String placeholder = contents.substring(0,contents.indexOf(':'));
|
||||
//only convert placeholders for the value
|
||||
String value = plugin.tex.papi(e.panel,e.p,contents.substring(contents.indexOf(':')+1));
|
||||
openPanel.placeholders.addPlaceholder(placeholder,value);
|
||||
i = i+contents.length()-1;
|
||||
}
|
||||
}
|
||||
openPanel.open(e.p);
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("teleport=")) {
|
||||
e.commandTagUsed();
|
||||
if (e.args.length == 5) {
|
||||
float x, y, z, yaw, pitch; //pitch is the heads Y axis and yaw is the X axis
|
||||
x = Float.parseFloat(e.args[0]);
|
||||
y = Float.parseFloat(e.args[1]);
|
||||
z = Float.parseFloat(e.args[2]);
|
||||
yaw = Float.parseFloat(e.args[3]);
|
||||
pitch = Float.parseFloat(e.args[4]);
|
||||
e.p.teleport(new Location(e.p.getWorld(), x, y, z, yaw, pitch));
|
||||
} else if (e.args.length <= 3) {
|
||||
float x, y, z;
|
||||
x = Float.parseFloat(e.args[0]);
|
||||
y = Float.parseFloat(e.args[1]);
|
||||
z = Float.parseFloat(e.args[2]);
|
||||
e.p.teleport(new Location(e.p.getWorld(), x, y, z));
|
||||
} else {
|
||||
try {
|
||||
Player otherplayer = Bukkit.getPlayer(e.args[3]);
|
||||
float x, y, z;
|
||||
x = Float.parseFloat(e.args[0]);
|
||||
y = Float.parseFloat(e.args[1]);
|
||||
z = Float.parseFloat(e.args[2]);
|
||||
assert otherplayer != null;
|
||||
otherplayer.teleport(new Location(otherplayer.getWorld(), x, y, z));
|
||||
} catch (Exception tpe) {
|
||||
plugin.tex.sendMessage(e.p,plugin.config.getString("config.format.notitem"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("delay=")) {
|
||||
e.commandTagUsed();
|
||||
//if player uses op= it will perform command as op
|
||||
final int delaySeconds = Integer.parseInt(e.args[0]);
|
||||
String finalCommand = String.join(" ",e.args).replace(e.args[0],"");
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
plugin.commandTags.runCommand(e.panel, e.p, finalCommand);
|
||||
} catch (Exception ex) {
|
||||
//if there are any errors, cancel so that it doesn't loop errors
|
||||
plugin.debug(ex, e.p);
|
||||
this.cancel();
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskTimer(plugin, 20L * delaySeconds, 20); //20 ticks == 1 second
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.standard;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.PanelCommandEvent;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class BasicTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public BasicTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("cpc")){
|
||||
e.commandTagUsed();
|
||||
//this will close the current inventory
|
||||
e.p.closeInventory();
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("refresh")) {
|
||||
e.commandTagUsed();
|
||||
plugin.createGUI.openGui(plugin.openPanels.getOpenPanel(e.p.getName()), e.p, 0, 0);
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("console=")) {
|
||||
e.commandTagUsed();
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String.join(" ",e.args));
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("send=")) {
|
||||
e.commandTagUsed();
|
||||
e.p.chat(String.join(" ",e.args));
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("sudo=")) {
|
||||
e.commandTagUsed();
|
||||
e.p.chat("/" + String.join(" ",e.args));
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("msg=")) {
|
||||
e.commandTagUsed();
|
||||
e.p.sendMessage(String.join(" ",e.args));
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("op=")) {
|
||||
e.commandTagUsed();
|
||||
//if player uses op= it will perform command as op
|
||||
boolean isop = e.p.isOp();
|
||||
try {
|
||||
e.p.setOp(true);
|
||||
Bukkit.dispatchCommand(e.p,String.join(" ",e.args));
|
||||
e.p.setOp(isop);
|
||||
} catch (Exception exc) {
|
||||
e.p.setOp(isop);
|
||||
plugin.debug(exc,e.p);
|
||||
e.p.sendMessage(plugin.tag + plugin.tex.papi( plugin.config.getString("config.format.error") + " op=: Error in op command!"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("sound=")) {
|
||||
e.commandTagUsed();
|
||||
try {
|
||||
e.p.playSound(e.p.getLocation(), Sound.valueOf(e.args[0]), 1F, 1F);
|
||||
} catch (Exception s) {
|
||||
plugin.debug(s, e.p);
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.args[0]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("stopsound=")) {
|
||||
e.commandTagUsed();
|
||||
try {
|
||||
e.p.stopSound(Sound.valueOf(e.args[0]));
|
||||
} catch (Exception ss) {
|
||||
plugin.debug(ss, e.p);
|
||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.args[0]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("event=")) {
|
||||
e.commandTagUsed();
|
||||
PanelCommandEvent commandEvent = new PanelCommandEvent(e.p, e.args[0], e.panel);
|
||||
Bukkit.getPluginManager().callEvent(commandEvent);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.standard;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class BungeeTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public BungeeTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("server=")){
|
||||
e.commandTagUsed();
|
||||
//this contacts bungee and tells it to send the server change command
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(e.args[0]);
|
||||
Player player = Bukkit.getPlayerExact(e.p.getName());
|
||||
assert player != null;
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.tags.standard;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemTags implements Listener {
|
||||
CommandPanels plugin;
|
||||
public ItemTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("give-item=")){
|
||||
e.commandTagUsed();
|
||||
ItemStack itm = plugin.itemCreate.makeCustomItemFromConfig(null,plugin.openPanels.getOpenPanel(e.p.getName()).getConfig().getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, false);
|
||||
e.p.getInventory().addItem(itm);
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("setitem=")){
|
||||
e.commandTagUsed();
|
||||
//if player uses setitem= [custom item] [slot] it will change the item slot to something, used for placeable items
|
||||
//make a section in the panel called "custom-item" then whatever the title of the item is, put that here
|
||||
ConfigurationSection panelCF = plugin.openPanels.getOpenPanel(e.p.getName()).getConfig();
|
||||
ItemStack s = plugin.itemCreate.makeItemFromConfig(null,panelCF.getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, true);
|
||||
e.p.getOpenInventory().getTopInventory().setItem(Integer.parseInt(e.args[1]), s);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,9 +4,10 @@ import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Commandpanelcustom implements Listener {
|
||||
CommandPanels plugin;
|
||||
|
@ -6,7 +6,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PanelDataLoader {
|
||||
|
@ -11,7 +11,8 @@ import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CpIngameEditCommand implements CommandExecutor {
|
||||
CommandPanels plugin;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package me.rockyhawk.commandpanels.interactives;
|
||||
|
||||
import me.rockyhawk.commandpanels.classresources.CommandTags;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTags;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@ -35,7 +35,7 @@ public class CommandpanelUserInput implements Listener {
|
||||
e.setCancelled(true);
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
new CommandTags(plugin).commandTags(null,e.getPlayer(), plugin.tex.papi(null,e.getPlayer(),command), command); //I have to do this to run regular Bukkit voids in an ASYNC Event
|
||||
new CommandTags(plugin).runCommand(null,e.getPlayer(), command); //I have to do this to run regular Bukkit voids in an ASYNC Event
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
|
||||
import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
33
src/me/rockyhawk/commandpanels/interactives/OpenOnJoin.java
Normal file
33
src/me/rockyhawk/commandpanels/interactives/OpenOnJoin.java
Normal file
@ -0,0 +1,33 @@
|
||||
package me.rockyhawk.commandpanels.interactives;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class OpenOnJoin implements Listener {
|
||||
CommandPanels plugin;
|
||||
public OpenOnJoin(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
@EventHandler
|
||||
public void onWorldLogin(PlayerJoinEvent e){
|
||||
//only opens when the player first logins
|
||||
openOnJoin(e.getPlayer(),"open-on-login.");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldJoin(PlayerChangedWorldEvent e){
|
||||
//only opens when the player changes the world internally
|
||||
openOnJoin(e.getPlayer(),"open-on-join.");
|
||||
}
|
||||
|
||||
private void openOnJoin(Player p, String joinType){
|
||||
if(plugin.config.contains(joinType + p.getWorld().getName())){
|
||||
String command = "open= " + plugin.config.getString(joinType + p.getWorld().getName());
|
||||
plugin.commandTags.runCommand(null,p, command);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,5 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -21,6 +8,14 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Sets/Gets NBT tags from ItemStacks
|
||||
* Spigot: https://www.spigotmc.org/threads/269621/
|
||||
|
@ -1,8 +1,8 @@
|
||||
package me.rockyhawk.commandpanels.legacy;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents_Legacy;
|
||||
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents;
|
||||
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents_Legacy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
@ -7,7 +7,10 @@ import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class OpenPanelsLoader {
|
||||
CommandPanels plugin;
|
||||
@ -102,7 +105,7 @@ public class OpenPanelsLoader {
|
||||
break;
|
||||
}
|
||||
if(val == 2){
|
||||
plugin.commandTags.commandTags(panel,Bukkit.getPlayer(playerName), plugin.tex.papi(panel,Bukkit.getPlayer(playerName),command), command);
|
||||
plugin.commandTags.runCommand(panel,Bukkit.getPlayer(playerName), command);
|
||||
}
|
||||
}
|
||||
}catch(Exception s){
|
||||
|
@ -5,9 +5,11 @@ import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class UtilsPanelsLoader implements Listener {
|
||||
|
@ -49,7 +49,7 @@ public class HotbarItemLoader {
|
||||
}
|
||||
if(panel.getConfig().contains("open-with-item.commands")){
|
||||
for(String command : panel.getConfig().getStringList("open-with-item.commands")){
|
||||
plugin.commandTags.commandTags(panel,p, plugin.tex.papi(null,p,command),command);
|
||||
plugin.commandTags.runCommand(panel,p, command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -84,7 +84,7 @@ public class HotbarItemLoader {
|
||||
}
|
||||
if(panel.getConfig().contains("open-with-item.commands")){
|
||||
for(String command : panel.getConfig().getStringList("open-with-item.commands")){
|
||||
plugin.commandTags.commandTags(panel,p, plugin.tex.papi(null,p,command),command);
|
||||
plugin.commandTags.runCommand(panel,p, command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -67,11 +67,10 @@ public class Commandpanelblocks implements CommandExecutor {
|
||||
String materialNameFormatted = blockType.getType().toString().substring(0, 1).toUpperCase() + blockType.getType().toString().substring(1).toLowerCase();
|
||||
materialNameFormatted = materialNameFormatted.replaceAll("_"," ");
|
||||
sender.sendMessage(plugin.tex.papi(plugin.tag + ChatColor.WHITE + args[1] + ChatColor.GREEN + " will now open when right clicking " + ChatColor.WHITE + materialNameFormatted));
|
||||
return true;
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(args.length == 1){
|
||||
@ -102,11 +101,10 @@ public class Commandpanelblocks implements CommandExecutor {
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.nopanel")));
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
if(sender.hasPermission("commandpanel.block.list")){
|
||||
@ -126,11 +124,10 @@ public class Commandpanelblocks implements CommandExecutor {
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.papi(plugin.tag) + ChatColor.RED + "No panel blocks found.");
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.papi(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,13 +43,13 @@ public class PanelBlockOnClick implements Listener {
|
||||
e.setCancelled(true);
|
||||
if(plugin.blockConfig.contains("blocks." + configLocation + ".commands")){
|
||||
for(String command : plugin.blockConfig.getStringList("blocks." + configLocation + ".commands")){
|
||||
plugin.commandTags.commandTags(null,p, plugin.tex.papi(null,p,command),command);
|
||||
plugin.commandTags.runCommand(null,p, command);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//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");
|
||||
plugin.commandTags.commandTags(null,p, plugin.tex.papi(null,p, command), command);
|
||||
plugin.commandTags.runCommand(null,p, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user