2021-12-21 04:57:29 +00:00
package de.jatitv.commandguiv2.Spigot.gui ;
import com.mojang.authlib.GameProfile ;
import com.mojang.authlib.properties.Property ;
import de.jatitv.commandguiv2.Spigot.Listener.GUI_Listener ;
import de.jatitv.commandguiv2.Spigot.Main ;
import de.jatitv.commandguiv2.Spigot.Objekte.Slot ;
2022-01-06 01:21:27 +00:00
import de.jatitv.commandguiv2.Spigot.config.languages.SelectMessages ;
2021-12-21 04:57:29 +00:00
import de.jatitv.commandguiv2.Spigot.Objekte.Object ;
2022-01-06 01:21:27 +00:00
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig ;
2021-12-21 04:57:29 +00:00
import de.jatitv.commandguiv2.Util ;
import io.github.solyze.plugmangui.inventories.PluginListGUI ;
import net.t2code.lib.Spigot.Lib.items.ItemVersion ;
import net.t2code.lib.Spigot.Lib.messages.send ;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion ;
import net.t2code.lib.Spigot.Lib.replace.Replace ;
2022-01-13 02:46:08 +00:00
import net.t2code.luckyBox.api.LuckyBoxAPI ;
2021-12-21 04:57:29 +00:00
import org.bukkit.Bukkit ;
import org.bukkit.Material ;
import org.bukkit.entity.Player ;
import org.bukkit.inventory.Inventory ;
import org.bukkit.inventory.InventoryHolder ;
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.meta.ItemMeta ;
import org.bukkit.inventory.meta.SkullMeta ;
import org.bukkit.plugin.Plugin ;
import java.lang.reflect.Field ;
import java.util.UUID ;
public class OpenGUI {
private static Plugin plugin = Main . plugin ;
2022-01-01 02:40:54 +00:00
private static String prefix = Util . getPrefix ( ) ;
2021-12-21 04:57:29 +00:00
public static void openGUI ( Player player , Object gui , String guiString ) {
Long long_ = Long . valueOf ( System . currentTimeMillis ( ) ) ;
switch ( guiString ) {
//case "plugin.PlotSquaredGUI":
// if (Main.PlotSquaredGUI) {
// PlotSquaredGUIapi.openMainGUI(player);
// } else {
// if (player.hasPermission("commandgui.admin")) {
// send.player(player, prefix + " §4PlotSquaredGUI could not be found! §9Please download it here: " +
// "§6https://spigotmc.org/resources/plotsquaredgui.77506/");
// }
// }
// return; todo
case " plugin.PlugManGUI " :
if ( Main . PlugManGUI ) {
player . openInventory ( ( new PluginListGUI ( 54 , 1 ) ) . getInventory ( ) ) ;
} else {
if ( player . hasPermission ( " commandgui.admin " ) ) {
send . player ( player , prefix + " §4PlugManGUI could not be found! §9Please download it here: " +
" §6https://spigotmc.org/resources/plugmangui.87599/ " ) ;
}
}
return ;
2022-01-13 02:28:06 +00:00
case " plugin.T2C-LuckyBox " :
if ( Main . LuckyBox ) {
LuckyBoxAPI . openShop ( player ) ;
} else {
if ( player . hasPermission ( " commandgui.admin " ) ) {
send . player ( player , prefix + " §4T2C-LuckyBox could not be found! §9Please download it here: " +
" §6https://www.spigotmc.org/resources/luckybox.98154/ " ) ;
}
}
return ;
2021-12-21 04:57:29 +00:00
}
if ( MCVersion . minecraft1_13 ) {
GUI_Listener . GUICode = " " ;
} else GUI_Listener . GUICode = " §6§8§9§r " ;
if ( gui . GUI_Enable | | player . hasPermission ( " commandgui.bypass " ) ) {
Inventory inventory ;
if ( Main . PaPi ) {
inventory = Bukkit . createInventory ( ( InventoryHolder ) null , 9 * gui . GUI_Lines , ( Replace . replace ( prefix , player , GUI_Listener . GUICode + gui . GUI_Name ) ) ) ;
} else inventory = Bukkit . createInventory ( ( InventoryHolder ) null , 9 * gui . GUI_Lines , ( Replace . replace ( prefix , GUI_Listener . GUICode + gui . GUI_Name ) ) ) ;
if ( gui . GUI_FillItem_Enable ) {
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 . GUI_FillItem_Item ) ) ;
} else glass = new ItemStack ( Material . valueOf ( gui . GUI_FillItem_Item . toUpperCase ( ) . replace ( " . " , " _ " ) ) ) ;
ItemMeta itemMetaglass = glass . getItemMeta ( ) ;
itemMetaglass . setDisplayName ( " " ) ;
glass . setItemMeta ( itemMetaglass ) ;
glass . setAmount ( 1 ) ;
for ( int i = 0 ; i < 9 * gui . GUI_Lines ; i + + ) {
inventory . setItem ( i , glass ) ;
}
}
for ( Slot slot : gui . GUI_Slots ) {
2022-03-21 21:21:54 +00:00
if ( ! slot . Perm
| | player . hasPermission ( " commandgui.gui. " + gui . Command_Command + " .slot. " + ( slot . Slot + 1 ) )
| | player . hasPermission ( " commandgui.gui. " + gui . Command_Command + " .slot. " + ( slot . Slot + 1 ) + " .see " )
| | player . hasPermission ( " commandgui.admin " ) ) {
if ( slot . Enable ) {
if ( slot . Empty ) {
ItemStack air = new ItemStack ( Material . AIR ) ;
inventory . setItem ( slot . Slot , air ) ;
} else {
if ( slot . 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 . GUI_Name ) . toString ( ) + " §bSlot: §6 " + ( slot . Slot + 1 ) + " §7- " + Replace . replace ( prefix , slot . Name ) ) ;
send . error ( plugin , " Playerheads are only available from version 1.13! " ) ;
send . console ( prefix + " §bGUI: §6 " + Replace . replace ( prefix , gui . GUI_Name ) . toString ( ) + " §bSlot: §6 " + ( slot . Slot + 1 ) + " §7- " + Replace . replace ( prefix , slot . Name ) ) ;
2021-12-21 04:57:29 +00:00
} else {
2022-03-21 21:21:54 +00:00
ItemStack item = ItemVersion . getHeadIS ( ) ;
SkullMeta itemMeta = ( SkullMeta ) item . getItemMeta ( ) ;
if ( slot . Base64_Enable ) {
2021-12-21 04:57:29 +00:00
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 ) ) ;
} else {
itemMeta . setDisplayName ( Replace . replace ( prefix , slot . Name . replace ( " [player] " , player . getName ( ) ) ) ) ;
itemMeta . setLore ( Replace . replacePrice ( prefix , slot . Lore , slot . Price + " " + SelectConfig . Currency ) ) ;
}
2022-03-21 21:21:54 +00:00
GameProfile profile = new GameProfile ( UUID . randomUUID ( ) , " " ) ;
profile . getProperties ( ) . put ( " textures " , new Property ( " textures " , slot . Base64Value ) ) ;
Field profileField = null ;
try {
profileField = itemMeta . getClass ( ) . getDeclaredField ( " profile " ) ;
profileField . setAccessible ( true ) ;
profileField . set ( itemMeta , profile ) ;
} catch ( IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e ) {
e . printStackTrace ( ) ;
}
2021-12-21 04:57:29 +00:00
item . setItemMeta ( itemMeta ) ;
Integer am ;
if ( slot . ItemAmount = = 0 ) {
am = 1 ;
} else am = slot . ItemAmount ;
item . setAmount ( am ) ;
inventory . setItem ( slot . Slot , item ) ;
} else {
2022-03-21 21:21:54 +00:00
if ( slot . PlayerWhoHasOpenedTheGUI ) {
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 ) ) ;
} else {
itemMeta . setDisplayName ( Replace . replace ( prefix , slot . Name . replace ( " [player] " , player . getName ( ) ) ) ) ;
itemMeta . setLore ( Replace . replacePrice ( prefix , slot . Lore , slot . Price + " " + SelectConfig . Currency ) ) ;
}
itemMeta . setOwner ( player . getName ( ) ) ;
item . setItemMeta ( itemMeta ) ;
Integer am ;
if ( slot . ItemAmount = = 0 ) {
am = 1 ;
} else am = slot . ItemAmount ;
item . setAmount ( am ) ;
inventory . setItem ( slot . Slot , item ) ;
2021-12-21 04:57:29 +00:00
} else {
2022-03-21 21:21:54 +00:00
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 ) ) ;
} else {
itemMeta . setDisplayName ( Replace . replace ( prefix , slot . Name . replace ( " [player] " , player . getName ( ) ) ) ) ;
itemMeta . setLore ( Replace . replacePrice ( prefix , player , slot . Lore , slot . Price + " " + SelectConfig . Currency ) ) ;
}
itemMeta . setOwner ( slot . PlayerName ) ;
item . setItemMeta ( itemMeta ) ;
Integer am ;
if ( slot . ItemAmount = = 0 ) {
am = 1 ;
} else am = slot . ItemAmount ;
item . setAmount ( am ) ;
inventory . setItem ( slot . Slot , item ) ;
2021-12-21 04:57:29 +00:00
}
}
}
} else {
2022-03-21 21:21:54 +00:00
ItemStack item = new ItemStack ( Material . valueOf ( slot . Item . toUpperCase ( ) . replace ( " . " , " _ " ) ) ) ;
ItemMeta itemMeta = item . getItemMeta ( ) ;
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 ) ) ;
} else {
itemMeta . setDisplayName ( Replace . replace ( prefix , slot . Name . replace ( " [player] " , player . getName ( ) ) ) ) ;
itemMeta . setLore ( Replace . replacePrice ( prefix , slot . Lore , slot . Price + " " + SelectConfig . Currency ) ) ;
}
item . setItemMeta ( itemMeta ) ;
Integer am ;
if ( slot . ItemAmount = = 0 ) {
am = 1 ;
} else am = slot . ItemAmount ;
item . setAmount ( am ) ;
inventory . setItem ( slot . Slot , item ) ;
2021-12-21 04:57:29 +00:00
}
}
}
}
}
player . openInventory ( inventory ) ;
send . debug ( plugin , " §6 " + player . getName ( ) + " §5Open §6 " + Replace . replace ( prefix , gui . GUI_Name ) + " §5 " + " §7- §e " + ( System . currentTimeMillis ( ) - long_ . longValue ( ) ) + " ms " ) ;
} else player . sendMessage ( SelectMessages . GUIIsDisabled . replace ( " [gui] " , Replace . replace ( prefix , gui . GUI_Name ) ) ) ;
}
}