forked from Upstream/CommandPanels
compatibility update
This commit is contained in:
parent
b8ee48a384
commit
df03148d84
6
pom.xml
6
pom.xml
@ -126,7 +126,7 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.12.2</version>
|
||||
<version>2.12.4-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -150,7 +150,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20-R0.1-SNAPSHOT</version>
|
||||
<version>1.20.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -221,7 +221,7 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.7</version>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 3.20.1.1
|
||||
version: 3.21.2.0
|
||||
main: me.rockyhawk.commandpanels.CommandPanels
|
||||
name: CommandPanels
|
||||
author: RockyHawk
|
||||
|
@ -73,12 +73,11 @@ panels:
|
||||
- placeholder= [item:APPLE]
|
||||
- refresh
|
||||
'21':
|
||||
material: POTION
|
||||
material: GOLDEN_APPLE
|
||||
name: '&fClick to heal the player'
|
||||
potion: INSTANT_HEAL
|
||||
lore:
|
||||
- '&7Uses the /heal command so that'
|
||||
- '&7the player needs permission'
|
||||
- '&7Uses the /heal command if'
|
||||
- '&7the player has permission'
|
||||
commands:
|
||||
- heal
|
||||
'24':
|
||||
|
@ -16,7 +16,7 @@ import me.rockyhawk.commandpanels.classresources.placeholders.CreateText;
|
||||
import me.rockyhawk.commandpanels.classresources.placeholders.HexColours;
|
||||
import me.rockyhawk.commandpanels.classresources.placeholders.Placeholders;
|
||||
import me.rockyhawk.commandpanels.commands.*;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandRunner;
|
||||
import me.rockyhawk.commandpanels.completetabs.CpTabComplete;
|
||||
import me.rockyhawk.commandpanels.completetabs.UpdateTabComplete;
|
||||
import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom;
|
||||
@ -35,6 +35,7 @@ import me.rockyhawk.commandpanels.ioclasses.nbt.NBTManager;
|
||||
import me.rockyhawk.commandpanels.ioclasses.legacy.LegacyVersion;
|
||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||
import me.rockyhawk.commandpanels.ioclasses.legacy.PlayerHeads;
|
||||
import me.rockyhawk.commandpanels.ioclasses.potions.LegacyPotionData;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.*;
|
||||
import me.rockyhawk.commandpanels.openwithitem.HotbarItemLoader;
|
||||
import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent;
|
||||
@ -85,7 +86,7 @@ public class CommandPanels extends JavaPlugin{
|
||||
//get alternate classes
|
||||
public PanelDownloader downloader = new PanelDownloader(this);
|
||||
|
||||
public CommandTags commandTags = new CommandTags(this);
|
||||
public CommandRunner commandRunner = new CommandRunner(this);
|
||||
public PanelDataLoader panelData = new PanelDataLoader(this);
|
||||
public Placeholders placeholders = new Placeholders(this);
|
||||
public DebugManager debug = new DebugManager(this);
|
||||
@ -98,6 +99,7 @@ public class CommandPanels extends JavaPlugin{
|
||||
public GetCustomHeads customHeads = new GetCustomHeads(this);
|
||||
public Updater updater = new Updater(this);
|
||||
public PlayerHeads getHeads = new PlayerHeads(this);
|
||||
public LegacyPotionData legacyPotion = new LegacyPotionData(this);
|
||||
public LegacyVersion legacy = new LegacyVersion(this);
|
||||
|
||||
public OpenPanelsLoader openPanels = new OpenPanelsLoader(this);
|
||||
@ -200,7 +202,7 @@ public class CommandPanels extends JavaPlugin{
|
||||
}
|
||||
|
||||
//load in all built in command tags
|
||||
commandTags.registerBuiltInTags();
|
||||
commandRunner.registerBuiltInTags();
|
||||
|
||||
//if refresh-panels set to false, don't load this
|
||||
if(Objects.requireNonNull(config.getString("config.refresh-panels")).equalsIgnoreCase("true")){
|
||||
@ -240,7 +242,7 @@ public class CommandPanels extends JavaPlugin{
|
||||
//save the example_top.yml file and the template.yml file
|
||||
if (!this.panelsf.exists()) {
|
||||
try {
|
||||
if(legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if(legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("exampleLegacy.yml")));
|
||||
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example.yml"));
|
||||
}else {
|
||||
@ -318,14 +320,23 @@ public class CommandPanels extends JavaPlugin{
|
||||
//hiding attributes will add an NBT tag
|
||||
if(hideAttributes) {
|
||||
renamedMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
renamedMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||
renamedMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
//HIDE_ADDITIONAL_TOOLTIP was added into 1.20.5 api
|
||||
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_21) ||
|
||||
(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && legacy.MINOR_VERSION >= 5)){
|
||||
renamedMeta.addItemFlags(ItemFlag.valueOf("HIDE_ADDITIONAL_TOOLTIP"));
|
||||
}
|
||||
//HIDE_POTION_EFFECTS was removed in the 1.20.5 api
|
||||
if(legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||
(legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && legacy.MINOR_VERSION <= 4)){
|
||||
renamedMeta.addItemFlags(ItemFlag.valueOf("HIDE_POTION_EFFECTS"));
|
||||
}
|
||||
//HIDE_ARMOR_TRIM was added into 1.20 api
|
||||
if(legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20)){
|
||||
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20)){
|
||||
renamedMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
|
||||
}
|
||||
//HIDE_DYE was added into 1.17 api
|
||||
if(legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_17)){
|
||||
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_17)){
|
||||
renamedMeta.addItemFlags(ItemFlag.HIDE_DYE);
|
||||
}
|
||||
}
|
||||
@ -460,7 +471,7 @@ public class CommandPanels extends JavaPlugin{
|
||||
p.sendMessage(ChatColor.GOLD + "/cpv " + ChatColor.WHITE + "Display the current version.");
|
||||
}
|
||||
if (p.hasPermission("commandpanel.refresh")) {
|
||||
p.sendMessage(ChatColor.GOLD + "/cpu [player] [position:all] " + ChatColor.WHITE + "Update a panel for a player while it is still open.");
|
||||
p.sendMessage(ChatColor.GOLD + "/cpu <player> [position:all] " + ChatColor.WHITE + "Update a panel for a player while it is still open.");
|
||||
}
|
||||
if (p.hasPermission("commandpanel.update")) {
|
||||
p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart.");
|
||||
@ -470,7 +481,7 @@ public class CommandPanels extends JavaPlugin{
|
||||
p.sendMessage(ChatColor.GOLD + "/cpe <panel file> " + ChatColor.WHITE + "Export panel to the Online Editor.");
|
||||
}
|
||||
if (p.hasPermission("commandpanel.import")) {
|
||||
p.sendMessage(ChatColor.GOLD + "/cpi [file name] [URL] " + ChatColor.WHITE + "Downloads a panel from a raw link online.");
|
||||
p.sendMessage(ChatColor.GOLD + "/cpi <file name> <URL> " + ChatColor.WHITE + "Downloads a panel from a raw link online.");
|
||||
}
|
||||
if (p.hasPermission("commandpanel.list")) {
|
||||
p.sendMessage(ChatColor.GOLD + "/cpl " + ChatColor.WHITE + "Lists the currently loaded panels.");
|
||||
|
@ -45,7 +45,7 @@ public class Utils implements Listener {
|
||||
//if the panel is clicked on the outside area of the GUI
|
||||
if (panel.getConfig().contains("outside-commands")) {
|
||||
try {
|
||||
plugin.commandTags.runCommands(panel,PanelPosition.Top,p, panel.getConfig().getStringList("outside-commands"),e.getClick());
|
||||
plugin.commandRunner.runCommands(panel,PanelPosition.Top,p, panel.getConfig().getStringList("outside-commands"),e.getClick());
|
||||
}catch(Exception s){
|
||||
plugin.debug(s,p);
|
||||
}
|
||||
@ -131,11 +131,11 @@ public class Utils implements Listener {
|
||||
}
|
||||
}
|
||||
if (panel.getConfig().contains("item." + clickedSlot + section + ".multi-paywall")) {
|
||||
plugin.commandTags.runMultiPaywall(panel,position,p,
|
||||
plugin.commandRunner.runMultiPaywall(panel,position,p,
|
||||
panel.getConfig().getStringList("item." + clickedSlot + section + ".multi-paywall"),
|
||||
commands,e.getClick());
|
||||
} else {
|
||||
plugin.commandTags.runCommands(panel, position, p, commands, e.getClick());
|
||||
plugin.commandRunner.runCommands(panel, position, p, commands, e.getClick());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class Panel{
|
||||
public ItemStack getHotbarItem(Player p){
|
||||
if (this.getConfig().contains("open-with-item.pre-load-commands")) {
|
||||
try {
|
||||
plugin.commandTags.runCommands(this,PanelPosition.Top,p, this.getConfig().getStringList("open-with-item.pre-load-commands"));
|
||||
plugin.commandRunner.runCommands(this,PanelPosition.Top,p, this.getConfig().getStringList("open-with-item.pre-load-commands"), null);
|
||||
}catch(Exception s){
|
||||
plugin.debug(s,p);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class ExecuteOpenVoids {
|
||||
//execute commands once the panel opens
|
||||
if (panel.getConfig().contains("commands-on-open")) {
|
||||
try {
|
||||
plugin.commandTags.runCommands(panel,position,p, panel.getConfig().getStringList("commands-on-open"));
|
||||
plugin.commandRunner.runCommands(panel,position,p, panel.getConfig().getStringList("commands-on-open"), null);
|
||||
}catch(Exception s){
|
||||
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands-on-open: " + panel.getConfig().getString("commands-on-open")));
|
||||
}
|
||||
@ -155,7 +155,7 @@ public class ExecuteOpenVoids {
|
||||
public void beforeLoadCommands(Panel panel,PanelPosition pos, Player p){
|
||||
if (panel.getConfig().contains("pre-load-commands")) {
|
||||
try {
|
||||
plugin.commandTags.runCommands(panel,pos,p, panel.getConfig().getStringList("pre-load-commands"));
|
||||
plugin.commandRunner.runCommands(panel,pos,p, panel.getConfig().getStringList("pre-load-commands"), null);
|
||||
}catch(Exception s){
|
||||
plugin.debug(s,p);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class GetCustomHeads {
|
||||
//getting the head from a Player Name
|
||||
public ItemStack getPlayerHead(String name) {
|
||||
byte id = 0;
|
||||
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||
if (plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||
id = 3;
|
||||
}
|
||||
|
||||
@ -123,11 +123,8 @@ public class GetCustomHeads {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
itemStack.setItemMeta(getCustomHead(value).getItemMeta());
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// Handle exceptions
|
||||
if(plugin.debug.consoleDebug) {
|
||||
plugin.debug(e,null);
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
// Ignore as errors should be skipped and no need to show in console
|
||||
}
|
||||
});
|
||||
|
||||
@ -145,7 +142,7 @@ public class GetCustomHeads {
|
||||
} else {
|
||||
propertyMap.put("textures", new Property("textures", b64stringtexture));
|
||||
byte id = 0;
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||
id = 3;
|
||||
}
|
||||
ItemStack head = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);
|
||||
|
@ -106,16 +106,6 @@ public class HasSections {
|
||||
outputValue = false;
|
||||
}
|
||||
|
||||
//the original has sections as TinyTank800 wanted to keep them
|
||||
if(setName.startsWith("hasvalue")) {
|
||||
return compare.equals(value) == outputValue;
|
||||
}
|
||||
if(setName.startsWith("hasperm")) {
|
||||
return p.hasPermission(value) == outputValue;
|
||||
}
|
||||
if(setName.startsWith("hasgreater")) {
|
||||
return (Long.parseLong(compare) >= Long.parseLong(value)) == outputValue;
|
||||
}
|
||||
//the current has section with all the functions implemented inside it
|
||||
if(setName.startsWith("has")) {
|
||||
if(value.endsWith(" HASPERM")) {
|
||||
|
@ -1,15 +1,11 @@
|
||||
package me.rockyhawk.commandpanels.classresources;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBT;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
|
||||
import me.arcaniax.hdb.api.HeadDatabaseAPI;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.MMOItemsAPI;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.manager.ItemManager;
|
||||
import org.bukkit.*;
|
||||
@ -28,7 +24,6 @@ import org.bukkit.inventory.meta.*;
|
||||
import org.bukkit.inventory.meta.trim.ArmorTrim;
|
||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import java.util.*;
|
||||
@ -86,7 +81,7 @@ public class ItemCreation {
|
||||
if (matraw.split("\\s")[0].equalsIgnoreCase("cps=") || matraw.split("\\s")[0].toLowerCase().equals("cpo=")) {
|
||||
skullname = p.getUniqueId().toString();
|
||||
mat = plugin.getHeads.playerHeadString();
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
id = 3;
|
||||
}
|
||||
}
|
||||
@ -94,7 +89,7 @@ public class ItemCreation {
|
||||
if (matraw.split("\\s")[0].equalsIgnoreCase("hdb=")) {
|
||||
skullname = "hdb";
|
||||
mat = plugin.getHeads.playerHeadString();
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
id = 3;
|
||||
}
|
||||
}
|
||||
@ -138,7 +133,7 @@ public class ItemCreation {
|
||||
if (matraw.split("\\s")[1].equalsIgnoreCase("self")) {
|
||||
//if cps= self
|
||||
meta = (SkullMeta) s.getItemMeta();
|
||||
if(!plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||
if(!plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||
try {
|
||||
assert meta != null;
|
||||
meta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(skullname)));
|
||||
@ -286,37 +281,30 @@ public class ItemCreation {
|
||||
|
||||
if (itemSection.contains("potion")) {
|
||||
//if the item is a potion, give it an effect
|
||||
try {
|
||||
PotionMeta potionMeta = (PotionMeta)s.getItemMeta();
|
||||
String[] effectType = plugin.tex.placeholdersNoColour(panel,position,p,itemSection.getString("potion")).split("\\s");
|
||||
assert potionMeta != null;
|
||||
boolean extended = false;
|
||||
boolean upgraded = false;
|
||||
//create data
|
||||
if(effectType.length >= 2){
|
||||
if(effectType[1].equalsIgnoreCase("true")){
|
||||
extended = true;
|
||||
}
|
||||
if(effectType.length == 3){
|
||||
if(effectType[2].equalsIgnoreCase("true")){
|
||||
upgraded = true;
|
||||
}
|
||||
}
|
||||
String[] effectType = plugin.tex.placeholdersNoColour(panel,position,p,itemSection.getString("potion")).split("\\s");
|
||||
//potion legacy or current
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||
(plugin.legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && plugin.legacy.MINOR_VERSION <= 4)){
|
||||
plugin.legacyPotion.applyPotionEffect(p,s,effectType);
|
||||
}else{
|
||||
try {
|
||||
PotionMeta potionMeta = (PotionMeta)s.getItemMeta();
|
||||
assert potionMeta != null;
|
||||
PotionType newData = PotionType.valueOf(effectType[0].toUpperCase());
|
||||
//set meta
|
||||
potionMeta.setBasePotionType(newData);
|
||||
s.setItemMeta(potionMeta);
|
||||
} catch (Exception er) {
|
||||
//don't add the effect
|
||||
plugin.debug(er,p);
|
||||
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + plugin.config.getString("config.format.error") + " potion: " + itemSection.getString("potion")));
|
||||
}
|
||||
PotionData newData = new PotionData(PotionType.valueOf(effectType[0].toUpperCase()),extended,upgraded);
|
||||
//set meta
|
||||
potionMeta.setBasePotionData(newData);
|
||||
s.setItemMeta(potionMeta);
|
||||
} catch (Exception er) {
|
||||
//don't add the effect
|
||||
plugin.debug(er,p);
|
||||
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + plugin.config.getString("config.format.error") + " potion: " + itemSection.getString("potion")));
|
||||
}
|
||||
}
|
||||
if (itemSection.contains("damage")) {
|
||||
//change the damage amount (placeholders accepted)
|
||||
//if the damage is not unbreakable and should be a value
|
||||
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||
if (plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||
try {
|
||||
s.setDurability(Short.parseShort(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage")))));
|
||||
} catch (Exception e) {
|
||||
@ -350,7 +338,7 @@ public class ItemCreation {
|
||||
}
|
||||
}
|
||||
// 1.20 Trim Feature for Player Armor
|
||||
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && itemSection.contains("trim")){
|
||||
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && itemSection.contains("trim")){
|
||||
// trim: <Material> <Pattern>
|
||||
String trim = itemSection.getString("trim");
|
||||
String[] trimList = trim.split("\\s");
|
||||
@ -380,7 +368,7 @@ public class ItemCreation {
|
||||
//check that the panel is already open and not running commands when opening
|
||||
if (itemSection.contains("refresh-commands") && plugin.openPanels.hasPanelOpen(p.getName(), panel.getName(), position)) {
|
||||
try {
|
||||
plugin.commandTags.runCommands(panel,position,p,itemSection.getStringList("refresh-commands"));
|
||||
plugin.commandRunner.runCommands(panel,position,p,itemSection.getStringList("refresh-commands"), null);
|
||||
}catch(Exception ex){
|
||||
plugin.debug(ex,p);
|
||||
}
|
||||
@ -421,7 +409,7 @@ public class ItemCreation {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if (cont.getDurability() != 0 && !cont.getType().toString().equals("SKULL_ITEM")) {
|
||||
file.set("panels." + panelName + ".item." + i + ".ID", cont.getDurability());
|
||||
}
|
||||
@ -440,7 +428,7 @@ public class ItemCreation {
|
||||
if(plugin.getHeads.ifSkullOrHead(cont.getType().toString())){
|
||||
if(!Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") && !Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")) {
|
||||
SkullMeta meta = (SkullMeta) cont.getItemMeta();
|
||||
if (plugin.customHeads.getHeadBase64(cont) != null && !plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||
if (plugin.customHeads.getHeadBase64(cont) != null && !plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||
//inject base64 here, disable for legacy as is not working
|
||||
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + plugin.customHeads.getHeadBase64(cont));
|
||||
} else if (meta.hasOwner()) {
|
||||
@ -461,13 +449,16 @@ public class ItemCreation {
|
||||
file.set("panels." + panelName + ".item." + i + ".banner", null);
|
||||
}
|
||||
try {
|
||||
PotionMeta potionMeta = (PotionMeta) cont.getItemMeta();
|
||||
assert potionMeta != null;
|
||||
PotionData potionData = potionMeta.getBasePotionData();
|
||||
PotionType potionType = potionData.getType(); // Gets the potion type as a string rather than bukkit type
|
||||
boolean level = potionData.isUpgraded(); // Check if the potion is level II
|
||||
boolean extended = potionData.isExtended(); // Check if the potion is extended
|
||||
file.set("panels." + panelName + ".item." + i + ".potion", potionType + " " + extended + " " + level);
|
||||
//potion legacy PotionData or current PotionType
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||
(plugin.legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && plugin.legacy.MINOR_VERSION <= 4)){
|
||||
file.set("panels." + panelName + ".item." + i + ".potion", plugin.legacyPotion.retrievePotionData(cont));
|
||||
}else{
|
||||
PotionMeta potionMeta = (PotionMeta) cont.getItemMeta();
|
||||
assert potionMeta != null;
|
||||
String potionType = potionMeta.getBasePotionType().toString(); // Gets the potion type as a string rather than bukkit type
|
||||
file.set("panels." + panelName + ".item." + i + ".potion", potionType);
|
||||
}
|
||||
}catch(Exception ignore){
|
||||
//not a banner
|
||||
file.set("panels." + panelName + ".item." + i + ".potion", null);
|
||||
@ -483,7 +474,7 @@ public class ItemCreation {
|
||||
}
|
||||
file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName());
|
||||
file.set("panels." + panelName + ".item." + i + ".lore", Objects.requireNonNull(cont.getItemMeta()).getLore());
|
||||
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
|
||||
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
|
||||
file.set("panels." + panelName + ".item." + i + ".customdata", Objects.requireNonNull(cont.getItemMeta()).getCustomModelData());
|
||||
}
|
||||
}catch(Exception n){
|
||||
@ -534,17 +525,14 @@ public class ItemCreation {
|
||||
//check for nbt
|
||||
if(nbtCheck) {
|
||||
try {
|
||||
NBTItem nbtitem1 = new NBTItem(one);
|
||||
NBTItem nbtitem2 = new NBTItem(two);
|
||||
|
||||
if (!nbtitem1.equals(nbtitem2)) {
|
||||
if (!plugin.nbt.hasSameNBT(one, two)) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
//check for damage
|
||||
try {
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if(one.getDurability() != two.getDurability()) {
|
||||
return false;
|
||||
}
|
||||
@ -558,19 +546,21 @@ public class ItemCreation {
|
||||
} catch (Exception ignore) {}
|
||||
//check for potions
|
||||
try {
|
||||
PotionMeta meta1 = (PotionMeta) one.getItemMeta();
|
||||
PotionMeta meta2 = (PotionMeta) two.getItemMeta();
|
||||
//different duration
|
||||
if(meta1.getBasePotionData().isExtended() != meta2.getBasePotionData().isExtended()){
|
||||
return false;
|
||||
}
|
||||
//different upgrade
|
||||
if(meta1.getBasePotionData().isUpgraded() != meta2.getBasePotionData().isUpgraded()){
|
||||
return false;
|
||||
}
|
||||
//different potion type
|
||||
if (meta1.getBasePotionData().getType().compareTo(meta2.getBasePotionData().getType()) != 0){
|
||||
return false;
|
||||
//choose between legacy PotionData (pre 1.20.5) or PotionType
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||
(plugin.legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && plugin.legacy.MINOR_VERSION <= 4)){
|
||||
String potionOne = plugin.legacyPotion.retrievePotionData(one);
|
||||
String potionTwo = plugin.legacyPotion.retrievePotionData(two);
|
||||
if(!potionOne.equals(potionTwo)){
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
//post 1.20.5 compare
|
||||
PotionMeta meta1 = (PotionMeta) one.getItemMeta();
|
||||
PotionMeta meta2 = (PotionMeta) two.getItemMeta();
|
||||
if (meta1.getBasePotionType().toString().compareTo(meta2.getBasePotionType().toString()) != 0){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}catch(Exception ignore){}
|
||||
//check for enchantments
|
||||
|
@ -12,7 +12,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -168,10 +167,16 @@ public class Placeholders {
|
||||
|
||||
// Check if the item is not null and has potion meta
|
||||
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) {
|
||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
|
||||
//Returns the value like this <Type>:<Extended>:<Upgraded> Example SLOWNESS:true:false
|
||||
return potionMeta.getBasePotionData().getType() + ":" + potionMeta.getBasePotionData().isExtended() + ":" + potionMeta.getBasePotionData().isUpgraded();
|
||||
//choose between legacy PotionData (pre 1.20.5) or PotionType
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||
(plugin.legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && plugin.legacy.MINOR_VERSION <= 4)){
|
||||
//Returns the value like this <Type>:<Extended>:<Upgraded> Example SLOWNESS:true:false
|
||||
return plugin.legacyPotion.retrievePotionData(item).replaceAll("\\s",":");
|
||||
}else{
|
||||
//post 1.20.5 compare just return PotionType
|
||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
return potionMeta.getBasePotionType().toString();
|
||||
}
|
||||
} else {
|
||||
return "empty"; // Item is either null or doesn't have potion meta
|
||||
}
|
||||
@ -189,7 +194,7 @@ public class Placeholders {
|
||||
String material;
|
||||
try {
|
||||
material = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getType().toString();
|
||||
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||
if (plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||
//add the ID to the end if it is legacy (eg, material:id)
|
||||
material = material + ":" + p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getData().getData();
|
||||
}
|
||||
@ -241,7 +246,7 @@ public class Placeholders {
|
||||
boolean damaged = false;
|
||||
ItemStack itm = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber));
|
||||
try {
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||
if(itm.getType().getMaxDurability() != 0) {
|
||||
damaged = (itm.getType().getMaxDurability() - itm.getDurability()) < itm.getType().getMaxDurability();
|
||||
}
|
||||
@ -334,7 +339,7 @@ public class Placeholders {
|
||||
try {
|
||||
String point_value = identifier.replace("cp-setdata-", "");
|
||||
String command = "set-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
|
||||
plugin.commandTags.runCommand(panel,position,p, command);
|
||||
plugin.commandRunner.runCommand(panel,position,p, command);
|
||||
return "";
|
||||
}catch (Exception ex){
|
||||
plugin.debug(ex,p);
|
||||
@ -346,7 +351,7 @@ public class Placeholders {
|
||||
try {
|
||||
String point_value = identifier.replace("mathdata-", "");
|
||||
String command = "math-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
|
||||
plugin.commandTags.runCommand(panel,position,p,command);
|
||||
plugin.commandRunner.runCommand(panel,position,p,command);
|
||||
return "";
|
||||
}catch (Exception ex){
|
||||
plugin.debug(ex,p);
|
||||
|
146
src/me/rockyhawk/commandpanels/commandtags/CommandRunner.java
Normal file
146
src/me/rockyhawk/commandpanels/commandtags/CommandRunner.java
Normal file
@ -0,0 +1,146 @@
|
||||
package me.rockyhawk.commandpanels.commandtags;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.commandtags.paywalls.*;
|
||||
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 me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CommandRunner {
|
||||
CommandPanels plugin;
|
||||
|
||||
public CommandRunner(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
//with the click type included, use null for no click type check
|
||||
public void runCommands(Panel panel, PanelPosition position, Player p, List<String> commands, ClickType click) {
|
||||
for (String command : commands) {
|
||||
if(click != null) {
|
||||
command = plugin.commandRunner.hasCorrectClick(command, click);
|
||||
if (command.equals("")) {
|
||||
//click type is wrong
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//do paywall check
|
||||
PaywallEvent paywallEvent = new PaywallEvent(plugin, panel, position, p, command);
|
||||
Bukkit.getPluginManager().callEvent(paywallEvent);
|
||||
if (paywallEvent.PAYWALL_OUTPUT == PaywallOutput.Blocked) {
|
||||
break;
|
||||
}
|
||||
//not a paywall, run as command
|
||||
if (paywallEvent.PAYWALL_OUTPUT == PaywallOutput.NotApplicable) {
|
||||
plugin.commandRunner.runCommand(panel, position, p, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void runCommand(Panel panel, PanelPosition position, Player p, String commandRAW) {
|
||||
CommandTagEvent tags = new CommandTagEvent(plugin, panel, position, p, commandRAW);
|
||||
Bukkit.getPluginManager().callEvent(tags);
|
||||
if (!tags.commandTagUsed) {
|
||||
Bukkit.dispatchCommand(p, plugin.tex.placeholders(panel, position, p, commandRAW.trim()));
|
||||
}
|
||||
}
|
||||
|
||||
public void runMultiPaywall(Panel panel, PanelPosition position, Player p, List<String> paywalls, List<String> commands, ClickType click) {
|
||||
boolean allPaywallsValid = true;
|
||||
|
||||
// New list combining paywalls and commands
|
||||
List<String> allCommands = new ArrayList<>(paywalls);
|
||||
allCommands.addAll(commands);
|
||||
|
||||
for (String command : allCommands) {
|
||||
// Trigger the event but do not remove the payment from the player
|
||||
PaywallEvent paywallEvent = new PaywallEvent(plugin, panel, position, p, command);
|
||||
paywallEvent.doDelete = false;
|
||||
Bukkit.getPluginManager().callEvent(paywallEvent);
|
||||
|
||||
if (paywallEvent.PAYWALL_OUTPUT == PaywallOutput.Blocked) {
|
||||
allPaywallsValid = false; // Set flag to false if any paywall is blocked
|
||||
break; // Exit the loop if any command is blocked by the paywall
|
||||
}
|
||||
}
|
||||
|
||||
// Execute all commands if all paywalls are valid
|
||||
if (allPaywallsValid) {
|
||||
plugin.commandRunner.runCommands(panel, position, p, allCommands, click);
|
||||
}
|
||||
}
|
||||
|
||||
//do this on startup to load listeners
|
||||
public void registerBuiltInTags() {
|
||||
plugin.getServer().getPluginManager().registerEvents(new Paywall(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new ItemPaywall(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new Hasperm(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new XpPaywall(plugin), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(new DataPaywall(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);
|
||||
}
|
||||
|
||||
public String hasCorrectClick(String command, ClickType click) {
|
||||
try {
|
||||
switch (command.split("\\s")[0]) {
|
||||
case "right=": {
|
||||
//if commands is for right-clicking, remove the 'right=' and continue
|
||||
command = command.replace("right= ", "");
|
||||
if (click != ClickType.RIGHT) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "rightshift=": {
|
||||
command = command.replace("rightshift= ", "");
|
||||
if (click != ClickType.SHIFT_RIGHT) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "left=": {
|
||||
command = command.replace("left= ", "");
|
||||
if (click != ClickType.LEFT) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "leftshift=": {
|
||||
command = command.replace("leftshift= ", "");
|
||||
if (click != ClickType.SHIFT_LEFT) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "middle=": {
|
||||
command = command.replace("middle= ", "");
|
||||
if (click != ClickType.MIDDLE) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return command;
|
||||
} catch (Exception ex) {
|
||||
return "";
|
||||
//skip if you can't do this
|
||||
}
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ public class CommandTagEvent extends Event {
|
||||
this.panel = panel1;
|
||||
this.pos = position;
|
||||
|
||||
//do nopapi= tag (donation feature) which will stop PlaceholderAPI placeholders from executing
|
||||
//do nopapi= tag which will stop PlaceholderAPI placeholders from executing
|
||||
boolean doApiPlaceholders = true;
|
||||
if(rawCommand1.startsWith("nopapi= ")){
|
||||
rawCommand1 = rawCommand1.replace("nopapi= ","");
|
||||
|
@ -1,499 +0,0 @@
|
||||
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 me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CommandTags {
|
||||
CommandPanels plugin;
|
||||
|
||||
public CommandTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
//with the click type included
|
||||
public void runCommands(Panel panel, PanelPosition position, Player p, List<String> commands, ClickType click) {
|
||||
for (String command : commands) {
|
||||
command = plugin.commandTags.hasCorrectClick(command, click);
|
||||
if (command.equals("")) {
|
||||
//click type is wrong
|
||||
continue;
|
||||
}
|
||||
|
||||
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, true);
|
||||
if (val == PaywallOutput.Blocked) {
|
||||
break;
|
||||
}
|
||||
if (val == PaywallOutput.NotApplicable) {
|
||||
plugin.commandTags.runCommand(panel, position, p, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void runCommands(Panel panel, PanelPosition position, Player p, List<String> commands) {
|
||||
for (String command : commands) {
|
||||
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, true);
|
||||
if (val == PaywallOutput.Blocked) {
|
||||
break;
|
||||
}
|
||||
if (val == PaywallOutput.NotApplicable) {
|
||||
plugin.commandTags.runCommand(panel, position, p, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void runMultiPaywall(Panel panel, PanelPosition position, Player p, List<String> paywalls, List<String> commands, ClickType click) {
|
||||
boolean allPaywallsValid = paywalls.stream()
|
||||
.map(command -> plugin.commandTags.commandPayWall(panel, p, command, false))
|
||||
.allMatch(val -> val != PaywallOutput.Blocked);
|
||||
|
||||
if (allPaywallsValid) {
|
||||
List<String> cmds = new ArrayList<>();
|
||||
cmds.addAll(paywalls);
|
||||
cmds.addAll(commands);
|
||||
plugin.commandTags.runCommands(panel, position, p, cmds, click);
|
||||
}
|
||||
}
|
||||
|
||||
public void runCommand(Panel panel, PanelPosition position, Player p, String commandRAW) {
|
||||
CommandTagEvent tags = new CommandTagEvent(plugin, panel, position, p, commandRAW);
|
||||
Bukkit.getPluginManager().callEvent(tags);
|
||||
if (!tags.commandTagUsed) {
|
||||
Bukkit.dispatchCommand(p, plugin.tex.placeholders(panel, position, 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);
|
||||
}
|
||||
|
||||
public String hasCorrectClick(String command, ClickType click) {
|
||||
try {
|
||||
switch (command.split("\\s")[0]) {
|
||||
case "right=": {
|
||||
//if commands is for right clicking, remove the 'right=' and continue
|
||||
command = command.replace("right= ", "");
|
||||
if (click != ClickType.RIGHT) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "rightshift=": {
|
||||
command = command.replace("rightshift= ", "");
|
||||
if (click != ClickType.SHIFT_RIGHT) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "left=": {
|
||||
command = command.replace("left= ", "");
|
||||
if (click != ClickType.LEFT) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "leftshift=": {
|
||||
command = command.replace("leftshift= ", "");
|
||||
if (click != ClickType.SHIFT_LEFT) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "middle=": {
|
||||
command = command.replace("middle= ", "");
|
||||
if (click != ClickType.MIDDLE) {
|
||||
return "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return command;
|
||||
} catch (Exception ex) {
|
||||
return "";
|
||||
//skip if you can't do this
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public PaywallOutput commandPayWall(Panel panel, Player p, String rawCommand, boolean removal) { //return 0 means no funds, 1 is they passed and 2 means paywall is not this command
|
||||
|
||||
//create new instance of command but with placeholders parsed
|
||||
switch (rawCommand.split("\\s")[0]) {
|
||||
default: {
|
||||
return PaywallOutput.NotApplicable;
|
||||
}
|
||||
case "paywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses paywall= [price]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) {
|
||||
if (removal) plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1]));
|
||||
if (plugin.config.getBoolean("purchase.currency.enable") && removal) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
}
|
||||
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")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendString(p, plugin.tag + ChatColor.RED + "Paying Requires Vault and an Economy to work!");
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, p);
|
||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
case "hasperm=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses hasperm= [perm]
|
||||
if (p.hasPermission(String.valueOf(command.split("\\s")[1]))) {
|
||||
if (plugin.config.getBoolean("purchase.permission.enable") && removal) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.permission.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
}
|
||||
return PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.permission.failure")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
case "tokenpaywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses tokenpaywall= [price]
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
final TokenManager api = (TokenManager) Bukkit.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])) {
|
||||
if (removal) {
|
||||
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
||||
}
|
||||
//if the message is empty don't send
|
||||
if (plugin.config.getBoolean("purchase.tokens.enable") && removal) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
}
|
||||
|
||||
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")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendString(p, plugin.tag + ChatColor.RED + "Needs TokenManager to work!");
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, p);
|
||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
case "item-paywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses item-paywall= [Material] [Amount] <id:#> <IGNORENBT> WILL NOT TAKE CUSTOM ITEMS. IGNORENBT lets nbt items through. Useful for spawner edge cases.
|
||||
//player can use item-paywall= [custom-item] [Amount]
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
HashMap<Integer, ItemStack> remCont = new HashMap<>();
|
||||
String[] args = command.split("\\s");
|
||||
try {
|
||||
int id = -1;
|
||||
for (String val : args) {
|
||||
if (val.startsWith("id:")) {
|
||||
id = Integer.parseInt(val.substring(3));
|
||||
}
|
||||
}
|
||||
|
||||
//create the item to be removed
|
||||
ItemStack sellItem;
|
||||
if (Material.matchMaterial(args[1]) == null) {
|
||||
sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false);
|
||||
sellItem.setAmount(Integer.parseInt(args[2]));
|
||||
} else {
|
||||
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]));
|
||||
}
|
||||
//this is not a boolean because it needs to return an int
|
||||
PaywallOutput removedItem = PaywallOutput.Blocked;
|
||||
//This is here for when people want to take nbt items like spawners with types in a check for spawners.
|
||||
boolean ignoreNBT = command.contains("IGNORENBT");
|
||||
|
||||
int remainingAmount = sellItem.getAmount();
|
||||
//loop through items in the inventory
|
||||
for (int f = 0; f < 36; f++) {
|
||||
|
||||
if (cont.get(f) == null) {
|
||||
//skip slot if empty
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack itm = cont.get(f);
|
||||
|
||||
if (Material.matchMaterial(args[1]) == null) {
|
||||
//if custom item is a mmo item (1.14+ for the API)
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + args[1] + ".material").startsWith("mmo=")) {
|
||||
String customItemMaterial = panel.getConfig().getString("custom-item." + args[1] + ".material");
|
||||
String mmoType = customItemMaterial.split("\\s")[1];
|
||||
String mmoID = customItemMaterial.split("\\s")[2];
|
||||
|
||||
if (plugin.isMMOItem(itm, mmoType, mmoID)) {
|
||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount());
|
||||
remainingAmount -= add.getAmount();
|
||||
if (removal) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue; //This stops the other custom item section from reading and adding false numbers.
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
plugin.debug(ex, p);
|
||||
}
|
||||
|
||||
//item-paywall is a custom item as it is not a material
|
||||
if (plugin.itemCreate.isIdentical(sellItem, itm, Objects.requireNonNull(panel.getConfig().getConfigurationSection("custom-item." + args[1])).contains("nbt"))) {
|
||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount());
|
||||
remainingAmount -= add.getAmount();
|
||||
if (removal) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
//if the item is a standard material
|
||||
if (itm.getType() == sellItem.getType()) {
|
||||
if(itm.hasItemMeta() && !ignoreNBT){
|
||||
//If item has custom meta continue to next item.
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check if the item matches the id set. If not continue to next in loop.
|
||||
if (id != -1 && itm.getDurability() != id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Adding item to the remove list then checking if we have reached the required amount.
|
||||
ItemStack add = new ItemStack(itm.getType(), itm.getAmount());
|
||||
remainingAmount -= add.getAmount();
|
||||
if (removal) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (remainingAmount <= 0) {
|
||||
for(Map.Entry<Integer, ItemStack> entry : remCont.entrySet()) {
|
||||
ItemStack remItem = entry.getValue();
|
||||
|
||||
//Check if its the last item in the loop and only subtract the remaining amount.
|
||||
if (sellItem.getAmount() < remItem.getAmount()) {
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
if (removal)
|
||||
p.getInventory().getItem(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
} else {
|
||||
if (removal)
|
||||
cont.get(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
} else { //If its anywhere but the last in loop just get rid of the items.
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
if (removal) p.getInventory().setItem(entry.getKey(), null);
|
||||
//p.getInventory().remove(entry.getValue());
|
||||
//p.getInventory().getItem(entry.getKey()).setAmount(0);
|
||||
p.updateInventory();
|
||||
} else {
|
||||
if (removal) cont.remove(entry.getValue());
|
||||
//cont.get(entry.getKey()).setAmount(0);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
}
|
||||
|
||||
if (removal) sellItem.setAmount(sellItem.getAmount() - remItem.getAmount());
|
||||
}
|
||||
|
||||
removedItem = PaywallOutput.Passed;
|
||||
}
|
||||
|
||||
//send message and return
|
||||
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")));
|
||||
}
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.item.enable") && removal) {
|
||||
//item was removed
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
}
|
||||
}
|
||||
return removedItem;
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, p);
|
||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
case "xp-paywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses xp-paywall= <price> <levels:points>
|
||||
try {
|
||||
int balance;
|
||||
if (command.split("\\s")[2].startsWith("level")) {
|
||||
balance = p.getLevel();
|
||||
} else {
|
||||
balance = getPlayerExp(p);
|
||||
}
|
||||
if (balance >= Integer.parseInt(command.split("\\s")[1])) {
|
||||
if (command.split("\\s")[2].startsWith("level")) {
|
||||
if (removal) p.setLevel(p.getLevel() - Integer.parseInt(command.split("\\s")[1]));
|
||||
} else {
|
||||
if (removal) removePlayerExp(p, Integer.parseInt(command.split("\\s")[1]));
|
||||
}
|
||||
//if the message is empty don't send
|
||||
if (plugin.config.getBoolean("purchase.xp.enable") && removal) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.xp.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
}
|
||||
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")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, p);
|
||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
case "data-paywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses data-paywall= <data> <amount>
|
||||
try {
|
||||
if (Double.parseDouble(plugin.panelData.getUserData(p.getUniqueId(), command.split("\\s")[1])) >= Double.parseDouble(command.split("\\s")[2])) {
|
||||
if (removal)
|
||||
plugin.panelData.doDataMath(p.getUniqueId(), command.split("\\s")[1], "-" + plugin.tex.placeholdersNoColour(panel, PanelPosition.Top, p, command.split("\\s")[2]));
|
||||
//if the message is empty don't send
|
||||
if (plugin.config.getBoolean("purchase.data.enable")) {
|
||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.data.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
||||
}
|
||||
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")));
|
||||
}
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, p);
|
||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
||||
return PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Experience math is a bit doggy doo doo so these will help to calculate values
|
||||
// Calculate total experience up to a level
|
||||
|
||||
// @author thelonelywolf@https://github.com/TheLonelyWolf1
|
||||
// @date 06 August 2021
|
||||
private int getExpAtLevel(int level) {
|
||||
if (level <= 16) {
|
||||
return (int) (Math.pow(level, 2) + 6 * level);
|
||||
} else if (level <= 31) {
|
||||
return (int) (2.5 * Math.pow(level, 2) - 40.5 * level + 360.0);
|
||||
} else {
|
||||
return (int) (4.5 * Math.pow(level, 2) - 162.5 * level + 2220.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate amount of EXP needed to level up
|
||||
private int getExpToLevelUp(int level) {
|
||||
if (level <= 15) {
|
||||
return 2 * level + 7;
|
||||
} else if (level <= 30) {
|
||||
return 5 * level - 38;
|
||||
} else {
|
||||
return 9 * level - 158;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate player's current EXP amount
|
||||
private int getPlayerExp(Player player) {
|
||||
int exp = 0;
|
||||
int level = player.getLevel();
|
||||
|
||||
// Get the amount of XP in past levels
|
||||
exp += getExpAtLevel(level);
|
||||
|
||||
// Get amount of XP towards next level
|
||||
exp += Math.round(getExpToLevelUp(level) * player.getExp());
|
||||
|
||||
return exp;
|
||||
}
|
||||
|
||||
// Take EXP
|
||||
private int removePlayerExp(Player player, int exp) {
|
||||
// Get player's current exp
|
||||
int currentExp = getPlayerExp(player);
|
||||
|
||||
// Reset player's current exp to 0
|
||||
player.setExp(0);
|
||||
player.setLevel(0);
|
||||
|
||||
// Give the player their exp back, with the difference
|
||||
int newExp = currentExp - exp;
|
||||
player.giveExp(newExp);
|
||||
|
||||
// Return the player's new exp amount
|
||||
return newExp;
|
||||
}
|
||||
}
|
57
src/me/rockyhawk/commandpanels/commandtags/PaywallEvent.java
Normal file
57
src/me/rockyhawk/commandpanels/commandtags/PaywallEvent.java
Normal file
@ -0,0 +1,57 @@
|
||||
package me.rockyhawk.commandpanels.commandtags;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class PaywallEvent extends Event {
|
||||
|
||||
public final Player p;
|
||||
public final Panel panel;
|
||||
public String[] raw;
|
||||
public String[] args;
|
||||
public String name;
|
||||
public PanelPosition pos;
|
||||
public boolean doDelete = true; //if payment should be removed or not
|
||||
public PaywallOutput PAYWALL_OUTPUT = PaywallOutput.NotApplicable; //the final output
|
||||
|
||||
public PaywallEvent(CommandPanels plugin, Panel panel1, PanelPosition position, Player player, String rawCommand1) {
|
||||
this.p = player;
|
||||
this.panel = panel1;
|
||||
this.pos = position;
|
||||
|
||||
//do nopapi= tag which will stop PlaceholderAPI placeholders from executing
|
||||
boolean doApiPlaceholders = true;
|
||||
if(rawCommand1.startsWith("nopapi= ")){
|
||||
rawCommand1 = rawCommand1.replace("nopapi= ","");
|
||||
doApiPlaceholders = false;
|
||||
}
|
||||
|
||||
String[] split = rawCommand1.split(" ", 2);
|
||||
if(split.length == 1){
|
||||
split = new String[]{split[0],""};
|
||||
}
|
||||
|
||||
this.name = split[0].trim();
|
||||
this.raw = split[1].trim().split("\\s");
|
||||
if(doApiPlaceholders) {
|
||||
this.args = plugin.tex.attachPlaceholders(panel1,pos, player, split[1].trim()).split("\\s");
|
||||
}else{
|
||||
this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setPlaceholders(panel, pos, p,split[1].trim(),false)).split("\\s");
|
||||
this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setPlaceholders(panel, pos, p,split[1].trim(),true)).split("\\s");
|
||||
}
|
||||
}
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DataPaywall implements Listener {
|
||||
CommandPanels plugin;
|
||||
public DataPaywall(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(PaywallEvent e){
|
||||
if(e.name.equalsIgnoreCase("data-paywall=")){
|
||||
//if player uses data-paywall= <data> <amount>
|
||||
try {
|
||||
if (Double.parseDouble(plugin.panelData.getUserData(e.p.getUniqueId(), e.args[0])) >= Double.parseDouble(e.args[1])) {
|
||||
if (e.doDelete)
|
||||
plugin.panelData.doDataMath(e.p.getUniqueId(), e.args[0], "-" + plugin.tex.placeholdersNoColour(e.panel, PanelPosition.Top, e.p, e.args[1]));
|
||||
//if the message is empty don't send
|
||||
if (plugin.config.getBoolean("purchase.data.enable")) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.data.success")).replaceAll("%cp-args%", e.args[0]));
|
||||
}
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.data.enable")) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.data.failure")));
|
||||
}
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, e.p);
|
||||
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Hasperm implements Listener {
|
||||
CommandPanels plugin;
|
||||
public Hasperm(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(PaywallEvent e){
|
||||
if(e.name.equalsIgnoreCase("hasperm=")){
|
||||
//if player uses hasperm= [perm]
|
||||
if (e.p.hasPermission(e.args[0])) {
|
||||
if (plugin.config.getBoolean("purchase.permission.enable") && e.doDelete) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.permission.success")).replaceAll("%cp-args%", e.args[0]));
|
||||
}
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.permission.failure")));
|
||||
}
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ItemPaywall implements Listener {
|
||||
CommandPanels plugin;
|
||||
public ItemPaywall(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(PaywallEvent e){
|
||||
if(e.name.equalsIgnoreCase("item-paywall=")){
|
||||
//if player uses item-paywall= [Material] [Amount] <id:#> <IGNORENBT> WILL NOT TAKE CUSTOM ITEMS. IGNORENBT lets nbt items through. Useful for spawner edge cases.
|
||||
//player can use item-paywall= [custom-item] [Amount]
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(e.p)));
|
||||
HashMap<Integer, ItemStack> remCont = new HashMap<>();
|
||||
try {
|
||||
int id = -1;
|
||||
boolean ignoreNBT = false;
|
||||
for (String val : e.args) {
|
||||
//item ID for legacy minecraft versions
|
||||
if (val.startsWith("id:")) {
|
||||
id = Integer.parseInt(val.substring(3));
|
||||
}
|
||||
//This is here for when people want to take nbt items like spawners with types in a check for spawners.
|
||||
if(val.equals("IGNORENBT")){
|
||||
ignoreNBT = true;
|
||||
}
|
||||
}
|
||||
|
||||
//create the item to be removed
|
||||
ItemStack sellItem;
|
||||
if (Material.matchMaterial(e.args[0]) == null) {
|
||||
sellItem = plugin.itemCreate.makeCustomItemFromConfig(e.panel, PanelPosition.Top, e.panel.getConfig().getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, false);
|
||||
sellItem.setAmount(Integer.parseInt(e.args[1]));
|
||||
} else {
|
||||
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(e.args[1])), Integer.parseInt(e.args[2]));
|
||||
}
|
||||
//this is not a boolean because it needs to return an int
|
||||
PaywallOutput removedItem = PaywallOutput.Blocked;
|
||||
|
||||
int remainingAmount = sellItem.getAmount();
|
||||
//loop through items in the inventory
|
||||
for (int f = 0; f < 36; f++) {
|
||||
|
||||
if (cont.get(f) == null) {
|
||||
//skip slot if empty
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack itm = cont.get(f);
|
||||
|
||||
if (Material.matchMaterial(e.args[0]) == null) {
|
||||
//if custom item is a mmo item (1.14+ for the API)
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && e.panel.getConfig().getString("custom-item." + e.args[0] + ".material").startsWith("mmo=")) {
|
||||
String customItemMaterial = e.panel.getConfig().getString("custom-item." + e.args[0] + ".material");
|
||||
String mmoType = customItemMaterial.split("\\s")[1];
|
||||
String mmoID = customItemMaterial.split("\\s")[2];
|
||||
|
||||
if (plugin.isMMOItem(itm, mmoType, mmoID)) {
|
||||
ItemStack add = new ItemStack(e.p.getInventory().getItem(f).getType(), e.p.getInventory().getItem(f).getAmount());
|
||||
remainingAmount -= add.getAmount();
|
||||
if (e.doDelete) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue; //This stops the other custom item section from reading and adding false numbers.
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
plugin.debug(ex, e.p);
|
||||
}
|
||||
|
||||
//item-paywall is a custom item as it is not a material
|
||||
if (plugin.itemCreate.isIdentical(sellItem, itm, Objects.requireNonNull(e.panel.getConfig().getConfigurationSection("custom-item." + e.args[0])).contains("nbt"))) {
|
||||
ItemStack add = new ItemStack(e.p.getInventory().getItem(f).getType(), e.p.getInventory().getItem(f).getAmount());
|
||||
remainingAmount -= add.getAmount();
|
||||
if (e.doDelete) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
//if the item is a standard material
|
||||
if (itm.getType() == sellItem.getType()) {
|
||||
if(itm.hasItemMeta() && !ignoreNBT){
|
||||
//If item has custom meta continue to next item.
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check if the item matches the id set. If not continue to next in loop.
|
||||
if (id != -1 && itm.getDurability() != id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Adding item to the remove list then checking if we have reached the required amount.
|
||||
ItemStack add = new ItemStack(itm.getType(), itm.getAmount());
|
||||
remainingAmount -= add.getAmount();
|
||||
if (e.doDelete) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (remainingAmount <= 0) {
|
||||
for(Map.Entry<Integer, ItemStack> entry : remCont.entrySet()) {
|
||||
ItemStack remItem = entry.getValue();
|
||||
|
||||
//Check if its the last item in the loop and only subtract the remaining amount.
|
||||
if (sellItem.getAmount() < remItem.getAmount()) {
|
||||
if (plugin.inventorySaver.hasNormalInventory(e.p)) {
|
||||
if (e.doDelete)
|
||||
e.p.getInventory().getItem(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
e.p.updateInventory();
|
||||
} else {
|
||||
if (e.doDelete)
|
||||
cont.get(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
plugin.inventorySaver.inventoryConfig.set(e.p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
} else { //If its anywhere but the last in loop just get rid of the items.
|
||||
if (plugin.inventorySaver.hasNormalInventory(e.p)) {
|
||||
if (e.doDelete) e.p.getInventory().setItem(entry.getKey(), null);
|
||||
//p.getInventory().remove(entry.getValue());
|
||||
//p.getInventory().getItem(entry.getKey()).setAmount(0);
|
||||
e.p.updateInventory();
|
||||
} else {
|
||||
if (e.doDelete) cont.remove(entry.getValue());
|
||||
//cont.get(entry.getKey()).setAmount(0);
|
||||
plugin.inventorySaver.inventoryConfig.set(e.p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
}
|
||||
|
||||
if (e.doDelete) sellItem.setAmount(sellItem.getAmount() - remItem.getAmount());
|
||||
}
|
||||
|
||||
removedItem = PaywallOutput.Passed;
|
||||
}
|
||||
|
||||
//send message and return
|
||||
if (removedItem == PaywallOutput.Blocked) {
|
||||
if (plugin.config.getBoolean("purchase.item.enable")) {
|
||||
//no item was found
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
||||
}
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.item.enable") && e.doDelete) {
|
||||
//item was removed
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[0]));
|
||||
}
|
||||
}
|
||||
e.PAYWALL_OUTPUT = removedItem;
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, e.p);
|
||||
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Paywall implements Listener {
|
||||
CommandPanels plugin;
|
||||
public Paywall(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(PaywallEvent e){
|
||||
if(e.name.equalsIgnoreCase("paywall=")){
|
||||
//if player uses paywall= [price]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
double paywallAmount = Double.parseDouble(e.args[0]);
|
||||
if (plugin.econ.getBalance(e.p) >= paywallAmount) {
|
||||
if (e.doDelete) plugin.econ.withdrawPlayer(e.p, paywallAmount);
|
||||
if (plugin.config.getBoolean("purchase.currency.enable") && e.doDelete) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", e.args[0]));
|
||||
}
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
|
||||
}
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
} else {
|
||||
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "Paying Requires Vault and an Economy to work!");
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, e.p);
|
||||
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class XpPaywall implements Listener {
|
||||
CommandPanels plugin;
|
||||
public XpPaywall(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void commandTag(PaywallEvent e){
|
||||
if(e.name.equalsIgnoreCase("xp-paywall=")){
|
||||
//if player uses xp-paywall= <price> <level:points>
|
||||
try {
|
||||
int balance;
|
||||
if (e.args[1].startsWith("level")) {
|
||||
balance = e.p.getLevel();
|
||||
} else {
|
||||
balance = getPlayerExp(e.p);
|
||||
}
|
||||
if (balance >= Integer.parseInt(e.args[0])) {
|
||||
if (e.args[1].startsWith("level")) {
|
||||
if (e.doDelete) e.p.setLevel(e.p.getLevel() - Integer.parseInt(e.args[0]));
|
||||
} else {
|
||||
if (e.doDelete) removePlayerExp(e.p, Integer.parseInt(e.args[0]));
|
||||
}
|
||||
//if the message is empty don't send
|
||||
if (plugin.config.getBoolean("purchase.xp.enable") && e.doDelete) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.xp.success")).replaceAll("%cp-args%", e.args[0]));
|
||||
}
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||
} else {
|
||||
if (plugin.config.getBoolean("purchase.xp.enable")) {
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.xp.failure")));
|
||||
}
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
} catch (Exception buyc) {
|
||||
plugin.debug(buyc, e.p);
|
||||
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Experience math is a bit doggy doo doo so these will help to calculate values
|
||||
// Calculate total experience up to a level
|
||||
|
||||
// @author thelonelywolf@https://github.com/TheLonelyWolf1
|
||||
// @date 06 August 2021
|
||||
private int getExpAtLevel(int level) {
|
||||
if (level <= 16) {
|
||||
return (int) (Math.pow(level, 2) + 6 * level);
|
||||
} else if (level <= 31) {
|
||||
return (int) (2.5 * Math.pow(level, 2) - 40.5 * level + 360.0);
|
||||
} else {
|
||||
return (int) (4.5 * Math.pow(level, 2) - 162.5 * level + 2220.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate amount of EXP needed to level up
|
||||
private int getExpToLevelUp(int level) {
|
||||
if (level <= 15) {
|
||||
return 2 * level + 7;
|
||||
} else if (level <= 30) {
|
||||
return 5 * level - 38;
|
||||
} else {
|
||||
return 9 * level - 158;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate player's current EXP amount
|
||||
private int getPlayerExp(Player player) {
|
||||
int exp = 0;
|
||||
int level = player.getLevel();
|
||||
|
||||
// Get the amount of XP in past levels
|
||||
exp += getExpAtLevel(level);
|
||||
|
||||
// Get amount of XP towards next level
|
||||
exp += Math.round(getExpToLevelUp(level) * player.getExp());
|
||||
|
||||
return exp;
|
||||
}
|
||||
|
||||
// Take EXP
|
||||
private int removePlayerExp(Player player, int exp) {
|
||||
// Get player's current exp
|
||||
int currentExp = getPlayerExp(player);
|
||||
|
||||
// Reset player's current exp to 0
|
||||
player.setExp(0);
|
||||
player.setLevel(0);
|
||||
|
||||
// Give the player their exp back, with the difference
|
||||
int newExp = currentExp - exp;
|
||||
player.giveExp(newExp);
|
||||
|
||||
// Return the player's new exp amount
|
||||
return newExp;
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
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 me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Arrays;
|
||||
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];
|
||||
String command = String.join(" ",Arrays.copyOfRange(e.raw, 1, e.raw.length));
|
||||
plugin.commandTags.runCommand(e.panel,e.pos,e.p,command);
|
||||
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")));
|
||||
}
|
||||
} 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];
|
||||
String command = String.join(" ",Arrays.copyOfRange(e.raw, 1, e.raw.length));
|
||||
plugin.commandTags.runCommand(e.panel,e.pos,e.p,command);
|
||||
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")));
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
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 me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
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.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")));
|
||||
|
||||
}
|
||||
} 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")) {
|
||||
final 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]));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.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.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.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||
for (String argsTemp : args) {
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
plugin.inventorySaver.addItem(p,new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]),id));
|
||||
}
|
||||
}
|
@ -1,205 +0,0 @@
|
||||
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 me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
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= <total cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP] [custom-data:#]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
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]));
|
||||
}
|
||||
} 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("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 = 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")));
|
||||
} 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%", "$" + Double.parseDouble(e.args[0]) * sold));
|
||||
}
|
||||
} 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")) {
|
||||
final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
||||
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]));
|
||||
plugin.tex.sendString(e.panel, PanelPosition.Top, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//returns false if player does not have item
|
||||
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<>();
|
||||
byte id = -1;
|
||||
String potion = "false";
|
||||
int customData = 0;
|
||||
boolean noCustom = false;
|
||||
for(String argsTemp : args){
|
||||
if(argsTemp.startsWith("potion:")){
|
||||
potion = argsTemp.replace("potion:","");
|
||||
}
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
}
|
||||
if (argsTemp.startsWith("custom-data:")) {
|
||||
customData = Integer.parseInt(argsTemp.replace("custom-data:", ""));
|
||||
}
|
||||
if (argsTemp.contains("NOCUSTOMDATA")) {
|
||||
noCustom = true;
|
||||
}
|
||||
}
|
||||
|
||||
//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;
|
||||
if (itm != null && itm.getType().equals(sellItem.getType())) {
|
||||
remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f);
|
||||
//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 0;
|
||||
}
|
||||
}
|
||||
//Check if the item matches the id set. If not continue to next in loop.
|
||||
if(id != -1 && itm.getDurability() != id){
|
||||
continue;
|
||||
}
|
||||
//Check if noCustom is set and if the item has custom data. If so continue to next in loop.
|
||||
if(noCustom && cont.get(f).hasItemMeta()){
|
||||
if(Objects.requireNonNull(cont.get(f).getItemMeta()).hasCustomModelData()){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//Check if custom model data is set and if the item has that data. If not continue to next in loop.
|
||||
if (customData != 0) {
|
||||
if (!itm.hasItemMeta()) {
|
||||
continue;
|
||||
} else {
|
||||
if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Exception exc){
|
||||
//skip if it cannot do unless plugin.debug is enabled
|
||||
plugin.debug(exc,p);
|
||||
}
|
||||
|
||||
remCont.add(remItm);
|
||||
|
||||
//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(remainingAmount <= 0){
|
||||
int removedItems = 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(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 removedItems;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -66,7 +66,7 @@ public class SpecialTags implements Listener {
|
||||
plugin.openPanels.closePanelForLoader(e.p.getName(),PanelPosition.Bottom);
|
||||
}else if(position == PanelPosition.Top && plugin.openPanels.hasPanelOpen(e.p.getName(),position)){
|
||||
//closing top closes all
|
||||
plugin.commandTags.runCommand(e.panel,e.pos,e.p,"cpc");
|
||||
plugin.commandRunner.runCommand(e.panel,e.pos,e.p,"cpc");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -139,7 +139,7 @@ public class SpecialTags implements Listener {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
plugin.commandTags.runCommand(e.panel,e.pos, e.p, finalCommand);
|
||||
plugin.commandRunner.runCommand(e.panel,e.pos, e.p, finalCommand);
|
||||
} catch (Exception ex) {
|
||||
//if there are any errors, cancel so that it doesn't loop errors
|
||||
plugin.debug(ex, e.p);
|
||||
|
@ -138,7 +138,7 @@ public class BasicTags implements Listener {
|
||||
if(e.name.equalsIgnoreCase("minimessage=")){
|
||||
e.commandTagUsed();
|
||||
//get checks
|
||||
boolean isVersionCompatible = plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18);
|
||||
boolean isVersionCompatible = plugin.legacy.MAJOR_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
|
||||
|
@ -65,7 +65,7 @@ public class OpenFloodgateGUI implements Listener {
|
||||
int clickedButtonId = response.clickedButtonId();
|
||||
String configKey = buttonCommands.get(clickedButtonId);
|
||||
if(fgPanel.contains(configKey + ".commands")) {
|
||||
plugin.commandTags.runCommands(e.getPanel(), PanelPosition.Top, e.getPlayer(), fgPanel.getStringList(configKey + ".commands"));
|
||||
plugin.commandRunner.runCommands(e.getPanel(), PanelPosition.Top, e.getPlayer(), fgPanel.getStringList(configKey + ".commands"), null);
|
||||
}
|
||||
});
|
||||
|
||||
@ -153,7 +153,7 @@ public class OpenFloodgateGUI implements Listener {
|
||||
for (String command : commands) {
|
||||
processedCommands.add(command.replaceAll("%cp-input%", value)); // Replace the placeholder in each command
|
||||
}
|
||||
plugin.commandTags.runCommands(e.getPanel(), PanelPosition.Top, e.getPlayer(), processedCommands); // Execute the processed commands
|
||||
plugin.commandRunner.runCommands(e.getPanel(), PanelPosition.Top, e.getPlayer(), processedCommands, null); // Execute the processed commands
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -96,7 +96,7 @@ public class GenUtils implements Listener {
|
||||
|
||||
file.set("panels." + date + ".title", "&8Generated " + date);
|
||||
file.addDefault("panels." + date + ".command", date);
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||
file.set("panels." + date + ".empty", "STAINED_GLASS_PANE");
|
||||
file.set("panels." + date + ".emptyID", "15");
|
||||
}else{
|
||||
|
@ -115,7 +115,7 @@ public class Commandpanelrefresher implements Listener {
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
for (ItemStack itm : p.getInventory().getContents()) {
|
||||
if (itm != null) {
|
||||
if (plugin.nbt.hasNBT(itm)) {
|
||||
if (plugin.nbt.hasNBT(itm,"CommandPanelsItem")) {
|
||||
p.getInventory().remove(itm);
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class OpenOnJoin implements Listener {
|
||||
String joinString = joinType + (world.isEmpty() ? "" : "."+ world);
|
||||
if(plugin.config.contains(joinString)){
|
||||
String command = "open= " + plugin.config.getString(joinString);
|
||||
plugin.commandTags.runCommand(null, PanelPosition.Top,p, command);
|
||||
plugin.commandRunner.runCommand(null, PanelPosition.Top,p, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class OutsideClickEvent implements Listener {
|
||||
//if the panel is clicked on the outside area of the GUI
|
||||
if (plugin.config.contains("outside-commands")) {
|
||||
try {
|
||||
plugin.commandTags.runCommands(null,PanelPosition.Top,p, plugin.config.getStringList("outside-commands"),e.getClick());
|
||||
plugin.commandRunner.runCommands(null,PanelPosition.Top,p, plugin.config.getStringList("outside-commands"),e.getClick());
|
||||
}catch(Exception s){
|
||||
plugin.debug(s,p);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class UserInputUtils implements Listener {
|
||||
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
plugin.commandTags.runCommands(playerInput.get(e.getPlayer()).panel, PanelPosition.Top,e.getPlayer(), playerInput.get(e.getPlayer()).commands,playerInput.get(e.getPlayer()).click); //I have to do this to run regular Bukkit voids in an ASYNC Event
|
||||
plugin.commandRunner.runCommands(playerInput.get(e.getPlayer()).panel, PanelPosition.Top,e.getPlayer(), playerInput.get(e.getPlayer()).commands,playerInput.get(e.getPlayer()).click); //I have to do this to run regular Bukkit voids in an ASYNC Event
|
||||
playerInput.remove(e.getPlayer());
|
||||
}
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses;
|
||||
package me.rockyhawk.commandpanels.ioclasses.iteminhand;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import org.bukkit.entity.Player;
|
@ -1,4 +1,4 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses;
|
||||
package me.rockyhawk.commandpanels.ioclasses.iteminhand;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import org.bukkit.entity.Player;
|
@ -1,24 +1,47 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses.legacy;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents;
|
||||
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents_Legacy;
|
||||
import org.bukkit.Bukkit;
|
||||
import me.rockyhawk.commandpanels.ioclasses.storagecontents.GetStorageContents;
|
||||
import me.rockyhawk.commandpanels.ioclasses.storagecontents.GetStorageContents_Legacy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LegacyVersion {
|
||||
CommandPanels plugin;
|
||||
public MinecraftVersions LOCAL_VERSION;
|
||||
public MinecraftVersions MAJOR_VERSION; //The major version of the server (eg, converts 1.20.5 to 1.20)
|
||||
public int MINOR_VERSION; //The minor version of the server (1.20.5 to 5)
|
||||
public LegacyVersion(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
LOCAL_VERSION = MinecraftVersions.get(VERSION);
|
||||
String VERSION = plugin.getServer().getBukkitVersion().split("-")[0];
|
||||
MAJOR_VERSION = MinecraftVersions.get(extractMajorVersion(VERSION));
|
||||
MINOR_VERSION = extractMinorVersion(VERSION);
|
||||
}
|
||||
|
||||
public String extractMajorVersion(String version) {
|
||||
String[] parts = version.split("\\.");
|
||||
if (parts.length < 2) {
|
||||
// Handle the case where there aren't enough parts for a "major.major.minor" format.
|
||||
return version; // Return the original version.
|
||||
}
|
||||
return parts[0] + "." + parts[1];
|
||||
}
|
||||
public Integer extractMinorVersion(String version) {
|
||||
String[] parts = version.split("\\.");
|
||||
if (parts.length > 2) {
|
||||
// Take only the third part and convert it to an integer.
|
||||
try {
|
||||
return Integer.parseInt(parts[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0; // Return 0 if there are no parts beyond the first two.
|
||||
}
|
||||
|
||||
|
||||
public ItemStack[] getStorageContents(Inventory i){
|
||||
if(LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if(MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
return new GetStorageContents_Legacy(plugin).getStorageContents(i);
|
||||
}else{
|
||||
return new GetStorageContents(plugin).getStorageContents(i);
|
||||
@ -26,7 +49,7 @@ public class LegacyVersion {
|
||||
}
|
||||
|
||||
public void setStorageContents(Player p, ItemStack[] i){
|
||||
if(LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||
if(MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||
new GetStorageContents_Legacy(plugin).setStorageContents(p,i);
|
||||
}else{
|
||||
new GetStorageContents(plugin).setStorageContents(p,i);
|
||||
|
@ -1,25 +1,20 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses.legacy;
|
||||
|
||||
public enum MinecraftVersions {
|
||||
v1_8( "1_8", 0 ),
|
||||
v1_9( "1_9", 1 ),
|
||||
v1_10( "1_10", 2 ),
|
||||
v1_11( "1_11", 3 ),
|
||||
v1_12( "1_12", 4 ),
|
||||
v1_13( "1_13", 5 ),
|
||||
v1_14( "1_14", 6 ),
|
||||
v1_15( "1_15", 7 ),
|
||||
v1_16( "1_16", 8 ),
|
||||
v1_17( "1_17", 9 ),
|
||||
v1_18( "1_18", 10 ),
|
||||
v1_19( "1_19", 11 ),
|
||||
v1_20( "1_20", 12 ),
|
||||
v1_21( "1_21", 13 ),
|
||||
v1_22( "1_22", 14 ),
|
||||
v1_23( "1_23", 15 ),
|
||||
v1_24( "1_24", 16 ),
|
||||
v1_25( "1_25", 17 ),
|
||||
v1_26( "1_26", 18 );
|
||||
v1_8( "1.8", 0 ),
|
||||
v1_9( "1.9", 1 ),
|
||||
v1_10( "1.10", 2 ),
|
||||
v1_11( "1.11", 3 ),
|
||||
v1_12( "1.12", 4 ),
|
||||
v1_13( "1.13", 5 ),
|
||||
v1_14( "1.14", 6 ),
|
||||
v1_15( "1.15", 7 ),
|
||||
v1_16( "1.16", 8 ),
|
||||
v1_17( "1.17", 9 ),
|
||||
v1_18( "1.18", 10 ),
|
||||
v1_19( "1.19", 11 ),
|
||||
v1_20( "1.20", 12 ),
|
||||
v1_21( "1.21", 13 );
|
||||
|
||||
|
||||
private int order;
|
||||
|
@ -13,7 +13,7 @@ public class PlayerHeads {
|
||||
}
|
||||
|
||||
public String playerHeadString() {
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
return "SKULL_ITEM";
|
||||
}else{
|
||||
return "PLAYER_HEAD";
|
||||
|
@ -3,6 +3,7 @@ package me.rockyhawk.commandpanels.ioclasses.nbt;
|
||||
import de.tr7zw.changeme.nbtapi.NBT;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class NBTManager {
|
||||
@ -11,24 +12,11 @@ public class NBTManager {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
//commandpanel item NBT
|
||||
public boolean hasNBT(ItemStack item){
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
return nbti.hasTag("CommandPanelsItem");
|
||||
}
|
||||
public boolean hasSameNBT(ItemStack one, ItemStack two){
|
||||
NBTItem nbtitem1 = new NBTItem(one);
|
||||
NBTItem nbtitem2 = new NBTItem(two);
|
||||
|
||||
public ItemStack setNBT(ItemStack item){
|
||||
NBT.modify(item, nbt -> {
|
||||
nbt.setString("CommandPanelsItem", "1");
|
||||
});
|
||||
return item;
|
||||
}
|
||||
|
||||
//custom key NBT
|
||||
public String getNBT(ItemStack item, String key){
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
if(!nbti.hasNBTData()) return "";
|
||||
return nbti.getString(key);
|
||||
return nbtitem1.equals(nbtitem2);
|
||||
}
|
||||
|
||||
public ItemStack setNBT(ItemStack item, String key, String value){
|
||||
@ -37,4 +25,15 @@ public class NBTManager {
|
||||
});
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasNBT(ItemStack item, String key){
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
return nbti.hasTag(key);
|
||||
}
|
||||
|
||||
public String getNBT(ItemStack item, String key){
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
if(!nbti.hasNBTData()) return "";
|
||||
return nbti.getString(key);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses.potions;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class LegacyPotionData {
|
||||
private CommandPanels plugin;
|
||||
|
||||
public LegacyPotionData(CommandPanels plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//effect type should be PotionType Extended? Upgraded?
|
||||
public void applyPotionEffect(Player p, ItemStack item, String[] effectType) {
|
||||
try {
|
||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
assert potionMeta != null;
|
||||
boolean extended = false;
|
||||
boolean upgraded = false;
|
||||
|
||||
if (effectType.length >= 2) {
|
||||
extended = effectType[1].equalsIgnoreCase("true");
|
||||
if (effectType.length == 3) {
|
||||
upgraded = effectType[2].equalsIgnoreCase("true");
|
||||
}
|
||||
}
|
||||
|
||||
Class<?> potionDataType = Class.forName("org.bukkit.potion.PotionData");
|
||||
Constructor<?> potionDataConstructor = potionDataType.getConstructor(PotionType.class, boolean.class, boolean.class);
|
||||
Object potionData = potionDataConstructor.newInstance(PotionType.valueOf(effectType[0].toUpperCase()), extended, upgraded);
|
||||
|
||||
Method setBasePotionDataMethod = potionMeta.getClass().getMethod("setBasePotionData", potionDataType);
|
||||
setBasePotionDataMethod.setAccessible(true); // Setting the method as accessible
|
||||
setBasePotionDataMethod.invoke(potionMeta, potionData);
|
||||
|
||||
item.setItemMeta(potionMeta);
|
||||
} catch (Exception er) {
|
||||
plugin.debug(er, p);
|
||||
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + plugin.config.getString("config.format.error") + " incorrect potion"));
|
||||
}
|
||||
}
|
||||
|
||||
//returns PotionType Extended? Upgraded?
|
||||
public String retrievePotionData(ItemStack item) {
|
||||
try {
|
||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
assert potionMeta != null;
|
||||
|
||||
Method getBasePotionDataMethod = potionMeta.getClass().getMethod("getBasePotionData");
|
||||
getBasePotionDataMethod.setAccessible(true); // Set the method as accessible
|
||||
Object potionData = getBasePotionDataMethod.invoke(potionMeta);
|
||||
|
||||
Class<?> potionDataType = Class.forName("org.bukkit.potion.PotionData");
|
||||
Method getTypeMethod = potionDataType.getMethod("getType");
|
||||
Method isUpgradedMethod = potionDataType.getMethod("isUpgraded");
|
||||
Method isExtendedMethod = potionDataType.getMethod("isExtended");
|
||||
|
||||
getTypeMethod.setAccessible(true); // Set the method as accessible
|
||||
isUpgradedMethod.setAccessible(true); // Set the method as accessible
|
||||
isExtendedMethod.setAccessible(true); // Set the method as accessible
|
||||
|
||||
PotionType potionType = (PotionType) getTypeMethod.invoke(potionData);
|
||||
boolean level = (boolean) isUpgradedMethod.invoke(potionData);
|
||||
boolean extended = (boolean) isExtendedMethod.invoke(potionData);
|
||||
|
||||
return potionType.name() + " " + extended + " " + level;
|
||||
} catch (Exception e) {
|
||||
plugin.debug(e, null);
|
||||
return "Failed to retrieve potion data";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses;
|
||||
package me.rockyhawk.commandpanels.ioclasses.storagecontents;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import org.bukkit.entity.Player;
|
@ -1,4 +1,4 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses;
|
||||
package me.rockyhawk.commandpanels.ioclasses.storagecontents;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import org.bukkit.entity.Player;
|
@ -2,12 +2,14 @@ package me.rockyhawk.commandpanels.openpanelsmanager;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@ -27,15 +29,7 @@ public class OpenGUI {
|
||||
|
||||
Inventory i;
|
||||
if(position == PanelPosition.Top) {
|
||||
String title;
|
||||
if(pconfig.contains("custom-title")) {
|
||||
//used for titles in the custom-title section, for has sections
|
||||
String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p);
|
||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("custom-title" + section + ".title"));
|
||||
}else {
|
||||
//regular inventory title
|
||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title"));
|
||||
}
|
||||
String title = getTitle(p, pconfig, panel, position);
|
||||
|
||||
if (isNumeric(pconfig.getString("rows"))) {
|
||||
i = Bukkit.createInventory(p, Integer.parseInt(pconfig.getString("rows")) * 9, title);
|
||||
@ -141,7 +135,7 @@ public class OpenGUI {
|
||||
empty = plugin.itemCreate.makeItemFromConfig(panel,position,pconfig.getConfigurationSection("custom-item." + pconfig.getString("empty")),p,true,true,true);
|
||||
}else{
|
||||
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(pconfig.getString("empty").toUpperCase())), 1,id);
|
||||
empty = plugin.nbt.setNBT(empty);
|
||||
empty = plugin.nbt.setNBT(empty, "CommandPanelsItem", "true");
|
||||
ItemMeta renamedMeta = empty.getItemMeta();
|
||||
assert renamedMeta != null;
|
||||
renamedMeta.setDisplayName(" ");
|
||||
@ -173,7 +167,12 @@ public class OpenGUI {
|
||||
}
|
||||
plugin.openPanels.skipPanelClose.remove(p.getName());
|
||||
} else if (openType == PanelOpenType.Refresh) {
|
||||
//openType 0 will just refresh the panel
|
||||
//openType Refresh will just refresh the panel
|
||||
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_21) ||
|
||||
(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && plugin.legacy.MINOR_VERSION >= 5)){
|
||||
//Title refresh ability added in 1.20.5 api
|
||||
p.getOpenInventory().setTitle(getTitle(p, pconfig, panel, position));
|
||||
}
|
||||
if(position == PanelPosition.Top) {
|
||||
plugin.legacy.setStorageContents(p, plugin.legacy.getStorageContents(i));
|
||||
}
|
||||
@ -218,4 +217,17 @@ public class OpenGUI {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getTitle(Player p, ConfigurationSection pconfig, Panel panel, PanelPosition position){
|
||||
String title;
|
||||
if(pconfig.contains("custom-title")) {
|
||||
//used for titles in the custom-title section, for has sections
|
||||
String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p);
|
||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("custom-title" + section + ".title"));
|
||||
}else {
|
||||
//regular inventory title
|
||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title"));
|
||||
}
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class OpenPanelsLoader {
|
||||
if (panel.getConfig().contains("commands-on-close")) {
|
||||
//execute commands on panel close
|
||||
try {
|
||||
plugin.commandTags.runCommands(panel,position,Bukkit.getPlayer(playerName),panel.getConfig().getStringList("commands-on-close"));
|
||||
plugin.commandRunner.runCommands(panel,position,Bukkit.getPlayer(playerName),panel.getConfig().getStringList("commands-on-close"), null);
|
||||
}catch(Exception s){
|
||||
plugin.debug(s,null);
|
||||
}
|
||||
@ -132,7 +132,7 @@ public class OpenPanelsLoader {
|
||||
|
||||
public boolean isNBTInjected(ItemStack itm){
|
||||
if(itm != null){
|
||||
return plugin.nbt.hasNBT(itm);
|
||||
return plugin.nbt.hasNBT(itm,"CommandPanelsItem");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class UtilsPanelsLoader implements Listener {
|
||||
p.updateInventory();
|
||||
for(ItemStack itm : p.getInventory().getContents()){
|
||||
if(itm != null){
|
||||
if (plugin.nbt.hasNBT(itm)) {
|
||||
if (plugin.nbt.hasNBT(itm, "CommandPanelsItem")) {
|
||||
p.getInventory().remove(itm);
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class HotbarItemLoader {
|
||||
return false;
|
||||
}
|
||||
if(panel.getHotbarSection(p).contains("commands")){
|
||||
plugin.commandTags.runCommands(panel,PanelPosition.Top,p,panel.getHotbarSection(p).getStringList("commands"),click);
|
||||
plugin.commandRunner.runCommands(panel,PanelPosition.Top,p,panel.getHotbarSection(p).getStringList("commands"),click);
|
||||
return true;
|
||||
}
|
||||
panel.open(p, PanelPosition.Top);
|
||||
@ -87,7 +87,7 @@ public class HotbarItemLoader {
|
||||
}
|
||||
if(panel.getHotbarSection(p).contains("commands")){
|
||||
for(String command : panel.getHotbarSection(p).getStringList("commands")){
|
||||
plugin.commandTags.runCommand(panel,PanelPosition.Top,p, command);
|
||||
plugin.commandRunner.runCommand(panel,PanelPosition.Top,p, command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package me.rockyhawk.commandpanels.openwithitem;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.ioclasses.GetItemInHand;
|
||||
import me.rockyhawk.commandpanels.ioclasses.GetItemInHand_Legacy;
|
||||
import me.rockyhawk.commandpanels.ioclasses.iteminhand.GetItemInHand;
|
||||
import me.rockyhawk.commandpanels.ioclasses.iteminhand.GetItemInHand_Legacy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -61,7 +61,7 @@ public class PanelBlockOnClick implements Listener {
|
||||
if(plugin.blockConfig.contains("blocks." + configLocation + ".commands")){
|
||||
if(!isVoid) {
|
||||
for (String command : plugin.blockConfig.getStringList("blocks." + configLocation + ".commands")) {
|
||||
plugin.commandTags.runCommand(null, PanelPosition.Top, p, command);
|
||||
plugin.commandRunner.runCommand(null, PanelPosition.Top, p, command);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -69,7 +69,7 @@ public class PanelBlockOnClick implements Listener {
|
||||
//uses the open= tag because it will open a panel with panel names, but also works with open= features like placeholders
|
||||
if(!isVoid) {
|
||||
String command = "open= " + plugin.blockConfig.getString("blocks." + configLocation + ".panel");
|
||||
plugin.commandTags.runCommand(null, PanelPosition.Top, p, command);
|
||||
plugin.commandRunner.runCommand(null, PanelPosition.Top, p, command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user