forked from Upstream/CommandPanels
3.18.6.2
This commit is contained in:
parent
6c4b14b1e7
commit
88151d2613
@ -1,9 +1,8 @@
|
||||
# |------------------------------------------------------------------------
|
||||
# | CommandPanels Config File
|
||||
# | By RockyHawk v5.2
|
||||
# | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/
|
||||
# | https://www.spigotmc.org/resources/67788/
|
||||
# |
|
||||
# | auto-update and minor-updates-only is HEAVILY RECOMMENDED
|
||||
# |------------------------------------------------------------------------
|
||||
config:
|
||||
refresh-panels: true
|
||||
@ -19,7 +18,6 @@ config:
|
||||
disabled-world-message: true
|
||||
panel-snooper: false
|
||||
allow-unsafe-mini-message: false
|
||||
disable-unsafe-mm-warning: false
|
||||
format:
|
||||
tag: '&6[&bCommandPanels&6] '
|
||||
perms: '&cNo permission.'
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 3.18.6.1
|
||||
version: 3.18.6.2
|
||||
main: me.rockyhawk.commandpanels.CommandPanels
|
||||
name: CommandPanels
|
||||
author: RockyHawk
|
||||
|
@ -272,9 +272,6 @@ public class CommandPanels extends JavaPlugin{
|
||||
|
||||
//get tag
|
||||
tag = tex.colour(config.getString("config.format.tag"));
|
||||
if(config.getBoolean("config.allow-unsafe-mini-message") && !config.getBoolean("config.disable-unsafe-mm-warning")){
|
||||
Bukkit.getLogger().warning("[CommandPanels] Allow unsafe MiniMessage detected! Please proceed with caution as no support will be given for it!");
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("[CommandPanels] RockyHawk's CommandPanels v" + this.getDescription().getVersion() + " Plugin Loaded!");
|
||||
}
|
||||
|
@ -44,10 +44,16 @@ public class CommandPanelImport implements CommandExecutor {
|
||||
BufferedInputStream in = null;
|
||||
FileOutputStream fout = null;
|
||||
|
||||
//add extension if not already added
|
||||
if(!fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
|
||||
fileName = fileName + ".yml";
|
||||
}
|
||||
|
||||
//download panel from page contents and add to plugin
|
||||
try {
|
||||
URL fileUrl = new URL(url);
|
||||
in = new BufferedInputStream(fileUrl.openStream());
|
||||
fout = new FileOutputStream(new File(plugin.panelsf, fileName + ".yml"));
|
||||
fout = new FileOutputStream(new File(plugin.panelsf, fileName));
|
||||
byte[] data = new byte[1024];
|
||||
|
||||
int count;
|
||||
|
@ -154,7 +154,7 @@ public class CommandTags {
|
||||
return PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
@ -185,7 +185,7 @@ public class CommandTags {
|
||||
return PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.tokens.enable")) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
@ -319,7 +319,7 @@ public class CommandTags {
|
||||
if (removedItem == PaywallOutput.Blocked) {
|
||||
if (plugin.config.getBoolean("purchase.item.enable")) {
|
||||
//no item was found
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
||||
}
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.item.enable")) {
|
||||
@ -356,7 +356,7 @@ public class CommandTags {
|
||||
return PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.xp.enable")) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.xp.failure")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.xp.failure")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
@ -378,7 +378,7 @@ public class CommandTags {
|
||||
return PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.data.enable")) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.data.failure")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.data.failure")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class BuyCommandTags implements Listener {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", price));
|
||||
} else {
|
||||
String price = e.args[0];
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")).replaceAll("%cp-args%", price));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires Vault and an Economy to work!");
|
||||
@ -62,7 +62,7 @@ public class BuyCommandTags implements Listener {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", price));
|
||||
} else {
|
||||
String price = e.args[0];
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")).replaceAll("%cp-args%", price));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires Vault and an Economy to work!");
|
||||
|
@ -33,7 +33,7 @@ public class BuyItemTags implements Listener {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", e.args[0]));
|
||||
giveItem(e.p, e.args);
|
||||
} else {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")).replaceAll("%cp-args%", e.args[0]));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
|
||||
|
||||
}
|
||||
} else {
|
||||
@ -60,7 +60,7 @@ public class BuyItemTags implements Listener {
|
||||
|
||||
giveItem(e.p,e.args);
|
||||
} else {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")).replaceAll("%cp-args%", e.args[0]));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")));
|
||||
|
||||
}
|
||||
} else {
|
||||
|
@ -29,12 +29,12 @@ public class SellItemTags implements Listener {
|
||||
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]
|
||||
//if player uses sell= it will be eg. sell= <total cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
boolean sold = removeItem(e.p, e.args);
|
||||
if (!sold) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")).replaceAll("%cp-args%", e.args[1]));
|
||||
int sold = removeItem(e.p, e.args, false);
|
||||
if (sold <= 0) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
||||
} else {
|
||||
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + e.args[0]));
|
||||
@ -48,17 +48,17 @@ public class SellItemTags implements Listener {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("sell-all=")){
|
||||
if(e.name.equalsIgnoreCase("sellall=")){
|
||||
e.commandTagUsed();
|
||||
//if player uses sell-all= it will be eg. sell-all= <Per Item Cashback> <item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
int sold = removeAllItem(e.p, e.args);
|
||||
int sold = removeItem(e.p, e.args, true);
|
||||
if (sold <= 0) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")).replaceAll("%cp-args%", e.args[1]));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
||||
} else {
|
||||
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]) * sold);
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + String.valueOf(Double.parseDouble(e.args[0]) * sold)));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + Double.parseDouble(e.args[0]) * sold));
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
|
||||
@ -75,9 +75,9 @@ public class SellItemTags implements Listener {
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
boolean sold = removeItem(e.p, e.args);
|
||||
if (!sold) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")).replaceAll("%cp-args%", e.args[1]));
|
||||
int sold = removeItem(e.p, e.args, false);
|
||||
if (sold <= 0) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
||||
} else {
|
||||
assert api != null;
|
||||
api.addTokens(e.p, Long.parseLong(e.args[0]));
|
||||
@ -94,98 +94,14 @@ public class SellItemTags implements Listener {
|
||||
}
|
||||
|
||||
//returns false if player does not have item
|
||||
private boolean removeItem(Player p, String[] args){
|
||||
private int removeItem(Player p, String[] args, boolean removeAll){
|
||||
//get inventory slots and then an empty list to store slots that have the item to sell
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
List<ItemStack> remCont = new ArrayList<>();
|
||||
|
||||
|
||||
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]));
|
||||
int RemainingAmount = sellItem.getAmount();
|
||||
for (int f = 0; f < 36; f++) {
|
||||
ItemStack itm = cont.get(f);
|
||||
ItemStack remItm;
|
||||
if (itm != null && itm.getType().equals(sellItem.getType())) {
|
||||
remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f);
|
||||
//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.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||
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.colour( 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);
|
||||
}
|
||||
|
||||
remCont.add(remItm);
|
||||
RemainingAmount -= remItm.getAmount();
|
||||
if(RemainingAmount <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(RemainingAmount <= 0){
|
||||
for (int f = 0; f <= remCont.size() - 1; f++) {
|
||||
ItemStack remItm = remCont.get(f);
|
||||
if(f == remCont.size() - 1){
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||
p.getInventory().getItem((int)remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
}else{
|
||||
cont.get((int)remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
} else {
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||
p.getInventory().getItem(remItm.getDurability()).setAmount(0);
|
||||
p.updateInventory();
|
||||
}else{
|
||||
cont.get((int)remItm.getDurability()).setAmount(0);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
}
|
||||
sellItem.setAmount(sellItem.getAmount() - remItm.getAmount());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//returns 0 if player does not have items. Returns number of sold items.
|
||||
private int removeAllItem(Player p, String[] args){
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
List<ItemStack> remCont = new ArrayList<>();
|
||||
|
||||
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), 0);
|
||||
//int RemainingAmount = sellItem.getAmount();
|
||||
//create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount)
|
||||
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), removeAll ? 0 : Integer.parseInt(args[2]));
|
||||
int remainingAmount = removeAll ? 0 : sellItem.getAmount();
|
||||
for (int f = 0; f < 36; f++) {
|
||||
ItemStack itm = cont.get(f);
|
||||
ItemStack remItm;
|
||||
@ -229,24 +145,44 @@ public class SellItemTags implements Listener {
|
||||
}
|
||||
|
||||
remCont.add(remItm);
|
||||
sellItem.setAmount(sellItem.getAmount() + remItm.getAmount());
|
||||
|
||||
//if the remaining amount has been reached, break otherwise sell all
|
||||
if (!removeAll) {
|
||||
remainingAmount -= remItm.getAmount();
|
||||
if (remainingAmount <= 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
sellItem.setAmount(sellItem.getAmount() + remItm.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(sellItem.getAmount() >= 1){
|
||||
if(remainingAmount <= 0){
|
||||
int removedItems = 0;
|
||||
for (int f = 0; f <= remCont.size() - 1; f++) {
|
||||
ItemStack remItm = remCont.get(f);
|
||||
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||
p.getInventory().getItem((int)remItm.getDurability()).setAmount(0);
|
||||
p.updateInventory();
|
||||
}else{
|
||||
cont.get((int)remItm.getDurability()).setAmount(0);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
if(f == remCont.size() - 1){
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||
p.getInventory().getItem(remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
}else{
|
||||
cont.get(remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
} else {
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||
p.getInventory().getItem(remItm.getDurability()).setAmount(0);
|
||||
p.updateInventory();
|
||||
}else{
|
||||
cont.get(remItm.getDurability()).setAmount(0);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
}
|
||||
removedItems += remItm.getAmount();
|
||||
sellItem.setAmount(sellItem.getAmount() - remItm.getAmount());
|
||||
}
|
||||
|
||||
return sellItem.getAmount();
|
||||
return removedItems;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -137,18 +137,17 @@ public class BasicTags implements Listener {
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("minimessage=")){
|
||||
e.commandTagUsed();
|
||||
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18) && Bukkit.getServer().getVersion().contains("Paper")){
|
||||
//get checks
|
||||
boolean isVersionCompatible = plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18);
|
||||
boolean isPaper = Bukkit.getServer().getVersion().contains("Paper");
|
||||
boolean allowUnsafeMiniMessage = plugin.config.getBoolean("config.allow-unsafe-mini-message");
|
||||
//do mini message if conditions are met
|
||||
if (isVersionCompatible && (isPaper || allowUnsafeMiniMessage)) {
|
||||
Audience player = (Audience) e.p; // Needed because the basic Player from the Event can't send Paper's Components
|
||||
Component parsedText = SerializerUtils.serializeText(String.join(" ",e.args));
|
||||
Component parsedText = SerializerUtils.serializeText(String.join(" ", e.args));
|
||||
player.sendMessage(parsedText);
|
||||
}else{
|
||||
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18) && plugin.config.getBoolean("config.allow-unsafe-mini-message")){
|
||||
Audience player = (Audience) e.p; // Needed because the basic Player from the Event can't send Paper's Components
|
||||
Component parsedText = SerializerUtils.serializeText(String.join(" ",e.args));
|
||||
player.sendMessage(parsedText);
|
||||
}else{
|
||||
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "MiniMessage-Feature needs Paper 1.18 or newer to work!");
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "MiniMessage-Feature needs Paper 1.18 or newer to work!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user