CHANGE: The placeholders are now usable internally in the plugin, even if PlaceholderAPI is not available.

FIX: Playerheads, Base64 Heads are now also available with 1.8 - 1.12
This commit is contained in:
JaTiTV 2022-05-17 21:04:23 +02:00
parent 32c1219bb2
commit ddfea4eba6
15 changed files with 137 additions and 98 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId>
<artifactId>CommandGUI_V2</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
<packaging>jar</packaging>
<name>CommandGUI</name>

View File

@ -10,6 +10,8 @@ import de.jatitv.commandguiv2.Spigot.objects.guis.Gui;
import de.jatitv.commandguiv2.Spigot.gui.OpenGUI;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.system.Papi;
import de.jatitv.commandguiv2.Spigot.system.Placeholder;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.items.ItemVersion;
import net.t2code.lib.Spigot.Lib.messages.send;
@ -149,12 +151,12 @@ public class GUIListener implements Listener {
for (String msg : slot.message) {
if (Main.PaPi) {
if (slot.cost_Enable) {
player.sendMessage(Replace.replacePrice(prefix, player, msg, slot.price + " " + SelectConfig.Currency));
} else player.sendMessage(Replace.replace(prefix, player, msg.replace("[prefix]", prefix)));
player.sendMessage(Replace.replacePrice(prefix, player, Placeholder.replace(msg, player), slot.price + " " + SelectConfig.Currency));
} else player.sendMessage(Replace.replace(prefix, player, Placeholder.replace(msg, player)));
} else {
if (slot.cost_Enable) {
player.sendMessage(Replace.replacePrice(prefix, msg, slot.price + " " + SelectConfig.Currency));
} else player.sendMessage(Replace.replace(prefix, msg.replace("[prefix]", prefix)));
player.sendMessage(Replace.replacePrice(prefix, Placeholder.replace(msg, player), slot.price + " " + SelectConfig.Currency));
} else player.sendMessage(Replace.replace(prefix, Placeholder.replace(msg, player)));
}
}
}

View File

@ -14,13 +14,9 @@ public class ItemChange {
Integer slot;
if (SelectConfig.UseItem_InventorySlotEnforce) {
slot = SelectConfig.UseItem_InventorySlot;
} else {
if (Events.useItemSlotHashMap.get(player.getName()) == null) {
slot = SelectConfig.UseItem_InventorySlot;
} else {
slot = Events.useItemSlotHashMap.get(player.getName());
}
}
if (!SelectConfig.UseItem_Enable) {
return;

View File

@ -40,7 +40,10 @@ public class Events implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent e) {
useItemHashMap.put(e.getPlayer().getName(), SelectDatabase.selectItemStatus(e.getPlayer()));
useItemSlotHashMap.put(e.getPlayer().getName(), SelectDatabase.selectSlot(e.getPlayer()));
Integer i = SelectDatabase.selectSlot(e.getPlayer());
if (i == null) {
useItemSlotHashMap.put(e.getPlayer().getName(), SelectConfig.UseItem_InventorySlot);
} else useItemSlotHashMap.put(e.getPlayer().getName(), i);
if (CGuiAPI.JoinDisable) {
send.debug(Main.plugin, "JoinDisable");
@ -169,7 +172,7 @@ public class Events implements Listener {
return;
}
if (!legacy()) {
if (!Main.legacy) {
if (!topInventoryIsEmpty(player)) return;
}
@ -292,12 +295,6 @@ public class Events implements Listener {
}
}
private static boolean legacy() {
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12 || MCVersion.minecraft1_13 || MCVersion.minecraft1_14 || MCVersion.minecraft1_15 || NMSVersion.v1_16_R1) {
return true;
} else return false;
}
private static boolean topInventoryIsEmpty(Player p) {
return p.getOpenInventory().getTopInventory().isEmpty();
}

View File

@ -8,6 +8,8 @@ import de.jatitv.commandguiv2.Spigot.system.database.MySQL;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
import net.t2code.lib.Spigot.Lib.minecraftVersion.NMSVersion;
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
@ -27,6 +29,7 @@ public final class Main extends JavaPlugin {
}
private static Boolean enable = false;
public static Boolean legacy = false;
public static String prefix = "§8[§4C§9GUI§8]";
@ -57,6 +60,9 @@ public final class Main extends JavaPlugin {
plugin = this;
autor = plugin.getDescription().getAuthors();
version = plugin.getDescription().getVersion();
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12 || MCVersion.minecraft1_13 || MCVersion.minecraft1_14 || MCVersion.minecraft1_15 || NMSVersion.v1_16_R1) {
legacy = true;
}
if (pluginNotFound("T2CodeLib", 96388, Util.getRequiredT2CodeLibVersion())) return;
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
if (PluginCheck.papi()) {

View File

@ -123,13 +123,9 @@ public class Commands {
Integer slot = null;
if (SelectConfig.UseItem_InventorySlotEnforce) {
slot = SelectConfig.UseItem_InventorySlot;
} else {
if (Events.useItemSlotHashMap.get(player.getName()) == null) {
slot = SelectConfig.UseItem_InventorySlot;
} else {
slot = Events.useItemSlotHashMap.get(player.getName());
}
}
send.debug(Main.plugin, String.valueOf(slot));
if (player.getInventory().getItem(slot - 1) == null) {
SelectDatabase.setItemStatusTrue(player);

View File

@ -36,7 +36,9 @@ public class ConfigCreate {
Config.set("Plugin.Currency", "$", yamlConfiguration);
Config.set("Plugin.DefaultGUI", "default", yamlConfiguration);
Config.set("Storage.Type", "SQLITE", yamlConfiguration);
if (Main.legacy){
Config.set("Storage.Type", "YML", yamlConfiguration);
} else Config.set("Storage.Type", "SQLITE", yamlConfiguration);
Config.set("Storage.MySQL.IP", "localhost", yamlConfiguration);
Config.set("Storage.MySQL.Port", 3306, yamlConfiguration);
Config.set("Storage.MySQL.Database", "database", yamlConfiguration);
@ -133,11 +135,15 @@ public class ConfigCreate {
Config.set("Toggle.Items.OnOrYes.Item.Base64.Enable", false, yamlConfiguration);
Config.set("Toggle.Items.OnOrYes.Item.Base64.Base64Value", "", yamlConfiguration);
Config.set("Toggle.Items.OnOrYes.Item.Material", ItemVersion.getGreenWool().getType().toString(), yamlConfiguration);
if (Main.legacy) {
Config.set("Toggle.Items.OnOrYes.Item.Material", "WOOL,5", yamlConfiguration);
} else Config.set("Toggle.Items.OnOrYes.Item.Material", ItemVersion.getGreenWool().getType().toString(), yamlConfiguration);
Config.set("Toggle.Items.OffOrNo.Item.Base64.Enable", false, yamlConfiguration);
Config.set("Toggle.Items.OffOrNo.Item.Base64.Base64Value", "", yamlConfiguration);
Config.set("Toggle.Items.OffOrNo.Item.Material", ItemVersion.getRedWool().getType().toString(), yamlConfiguration);
if (Main.legacy) {
Config.set("Toggle.Items.OffOrNo.Item.Material", "WOOL,14", yamlConfiguration);
} else Config.set("Toggle.Items.OffOrNo.Item.Material", ItemVersion.getRedWool().getType().toString(), yamlConfiguration);
Config.set("Toggle.Permission.Commands.True", "luckperms user [player] permission set [perm] true", yamlConfiguration);
Config.set("Toggle.Permission.Commands.False", "luckperms user [player] permission set [perm] false", yamlConfiguration);

View File

@ -21,7 +21,7 @@ public class CreateFunctions {
0, 0.0, Arrays.asList(), false, "");
createFunction("SupportDiscord", false, 1, true, true, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg3M2MxMmJmZmI1MjUxYTBiODhkNWFlNzVjNzI0N2NiMzlhNzVmZjFhODFjYmU0YzhhMzliMzExZGRlZGEifX19",
false, "", (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) ? "TNT" : "",
false, "", "",
"&3Support Discord", Arrays.asList("&8-----------------", "&bIf you need help setting up the plugin,", "&bfeel free to contact me on the Suport Discord.",
"&8-----------------", "&eIf you find any errors or bugs,", "&eplease contact me so I can fix them.", "&8-----------------", "&5Discord: §7http://dc.t2code.net"),
false, false, "", false, 0.0, false, false,

View File

@ -6,6 +6,8 @@ import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.objects.guis.Gui;
import de.jatitv.commandguiv2.Spigot.objects.functions.Function;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.system.Papi;
import de.jatitv.commandguiv2.Spigot.system.Placeholder;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.items.ItemVersion;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
@ -25,7 +27,11 @@ public class GuiBuilder {
private static String prefix = Util.getPrefix();
protected static void item(Function function, Integer slot, Player player, Inventory inventory) {
ItemStack item = new ItemStack(Material.valueOf(function.item.toUpperCase().replace(".", "_")));
ItemStack item;
if (Main.legacy && function.item.toUpperCase().contains(",")) {
String[] split = function.item.toUpperCase().split(",");
item = new ItemStack(Material.valueOf(split[0]), 1, Short.parseShort(split[1]));
} else item = new ItemStack(Material.valueOf(function.item.toUpperCase().replace(".", "_")));
ItemMeta itemMeta = item.getItemMeta();
setDisplayNameAndLore(itemMeta, player, function);
item.setItemMeta(itemMeta);
@ -38,7 +44,11 @@ public class GuiBuilder {
}
protected static void item(String material, Function function, Integer slot, Player player, Inventory inventory) {
ItemStack item = new ItemStack(Material.valueOf(material));
ItemStack item;
if (Main.legacy && material.contains(",")) {
String[] split = material.split(",");
item = new ItemStack(Material.valueOf(split[0]), 1, Short.parseShort(split[1]));
} else item = new ItemStack(Material.valueOf(material));
ItemMeta itemMeta = item.getItemMeta();
setDisplayNameAndLore(itemMeta, player, function);
item.setItemMeta(itemMeta);
@ -53,11 +63,11 @@ public class GuiBuilder {
private static void setDisplayNameAndLore(ItemMeta itemMeta, Player player, Function slot) {
if (Main.PaPi) {
itemMeta.setDisplayName(Replace.replace(prefix, player, slot.name.replace("[player]", player.getName())));
itemMeta.setLore(Replace.replacePrice(prefix, player, slot.lore, slot.price + " " + SelectConfig.Currency));
itemMeta.setDisplayName(Replace.replace(prefix, player, Placeholder.replace(slot.name, player)));
itemMeta.setLore(Replace.replacePrice(prefix, player, Placeholder.replace(slot.lore, player), slot.price + " " + SelectConfig.Currency));
} else {
itemMeta.setDisplayName(Replace.replace(prefix, slot.name.replace("[player]", player.getName())));
itemMeta.setLore(Replace.replacePrice(prefix, slot.lore, slot.price + " " + SelectConfig.Currency));
itemMeta.setDisplayName(Replace.replace(prefix, Placeholder.replace(slot.name,player)));
itemMeta.setLore(Replace.replacePrice(prefix, Placeholder.replace(slot.lore,player), slot.price + " " + SelectConfig.Currency));
}
}
@ -109,7 +119,7 @@ public class GuiBuilder {
public static void fillItem(Inventory inventory, Gui gui) {
ItemStack glass;
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
glass = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, Short.valueOf(gui.guiFillItemItem));
glass = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, Short.parseShort(gui.guiFillItemItem));
} else glass = new ItemStack(Material.valueOf(gui.guiFillItemItem.toUpperCase().replace(".", "_")));
ItemMeta itemMetaglass = glass.getItemMeta();
itemMetaglass.setDisplayName(" ");

View File

@ -102,13 +102,6 @@ public class OpenGUI {
}
} else {
if (function.playerHead_Enable) {
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
send.player(player, prefix + "§c Playerheads are only available from version §61.13§c! §7- §bGUI: §6" +
Replace.replace(prefix, gui.guiName).toString() + " §bSlot: §6" + (slot.slot + 1) + " §7- " + Replace.replace(prefix, function.name));
send.error(plugin, "Playerheads are only available from version 1.13!");
send.console(prefix + " §bGUI: §6" + Replace.replace(prefix, gui.guiName).toString() + " §bSlot: §6" +
(slot.slot + 1) + " §7- " + Replace.replace(prefix, function.name));
} else {
if (function.base64_Enable) {
GuiBuilder.base64(function, slot.slot, player, inventory);
} else {
@ -118,7 +111,6 @@ public class OpenGUI {
GuiBuilder.playerHead(function, slot.slot, player, inventory, function.playerName);
}
}
}
} else {
GuiBuilder.item(function, slot.slot, player, inventory);
}

View File

@ -83,7 +83,7 @@ public class Load {
}
if (PluginCheck.papi()) {
new Placeholder().register();
new Papi().register();
}
try {

View File

@ -0,0 +1,56 @@
// This claas was created by JaTiTV
package de.jatitv.commandguiv2.Spigot.system;
import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events;
import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class Papi extends PlaceholderExpansion {
@Override
public String getIdentifier() {
return "commandgui";
}
@Override
public String getAuthor() {
return Main.plugin.getDescription().getAuthors().toString();
}
@Override
public String getVersion() {
return Main.plugin.getDescription().getVersion();
}
@Override
public boolean canRegister() {
return true;
}
@Override
public boolean persist() {
return true;
}
@Override
public String onPlaceholderRequest(Player p, String params) {
if (params.contains("useitem_boolean")) {
Placeholder.useitem_boolean(p);
}
if (params.contains("useitem")) {
Placeholder.useitem(p);
}
if (params.contains("slot")) {
Placeholder.slot(p);
}
return null;
}
}

View File

@ -1,56 +1,38 @@
// This claas was created by JaTiTV
package de.jatitv.commandguiv2.Spigot.system;
import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events;
import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
public class Placeholder extends PlaceholderExpansion {
import java.util.ArrayList;
import java.util.List;
@Override
public String getIdentifier() {
return "commandgui";
}
@Override
public String getAuthor() {
return Main.plugin.getDescription().getAuthors().toString();
}
@Override
public String getVersion() {
return Main.plugin.getDescription().getVersion();
}
@Override
public boolean canRegister() {
return true;
}
@Override
public boolean persist() {
return true;
}
@Override
public String onPlaceholderRequest(Player p, String params) {
if (params.contains("useitem_boolean")) {
return Events.useItemHashMap.get(p.getName()).toString();
}
if (params.contains("useitem")) {
public class Placeholder {
public static String useitem(Player p) {
if (Events.useItemHashMap.get(p.getName())) {
return SelectConfig.placeholderTrue;
} else return SelectConfig.placeholderFalse;
}
if (params.contains("slot")){
public static String useitem_boolean(Player p) {
return Events.useItemHashMap.get(p.getName()).toString();
}
public static String slot(Player p) {
return Events.useItemSlotHashMap.get(p.getName()).toString();
}
return null;
public static String replace(String input, Player player) {
return input.replace("[player]", player.getName()).replace("%commandgui_useitem%", useitem(player))
.replace("%commandgui_useitem_boolean%", useitem_boolean(player)).replace("%commandgui_useitem_slot%", slot(player));
}
public static List<String> replace(List<String> input, Player player) {
ArrayList<String> rp = new ArrayList<String>();
for (String s : input) {
rp.add(s.replace("[player]", player.getName()).replace("%commandgui_useitem%", useitem(player))
.replace("%commandgui_useitem_boolean%", useitem_boolean(player)).replace("%commandgui_useitem_slot%", slot(player)));
}
return rp;
}
}

View File

@ -28,13 +28,9 @@ public class UseItem {
if (protection(player, false)) return;
if (SelectConfig.UseItem_InventorySlotEnforce) {
slot = SelectConfig.UseItem_InventorySlot;
} else {
if (Events.useItemSlotHashMap.get(player.getName()) == null) {
slot = SelectConfig.UseItem_InventorySlot;
} else {
slot = Events.useItemSlotHashMap.get(player.getName());
}
}
if (SelectConfig.UseItem_InventorySlot_FreeSlot) {
player.getInventory().addItem(itemStack(player));
} else {

View File

@ -2,7 +2,7 @@ package de.jatitv.commandguiv2;
public class Util {
private static Integer configVersion = 5;
private static double requiredT2CodeLibVersion = 10.3;
private static double requiredT2CodeLibVersion = 11.8;
private static String Prefix = "§8[§4C§9GUI§8]";
private static Integer SpigotID = 90671;
private static Integer BstatsID = 10840;