Skip to content

Commit

Permalink
2.1!!!
Browse files Browse the repository at this point in the history
Procedural GUIs and new trolls soon™️
  • Loading branch information
Xapu1337 committed Jul 17, 2022
1 parent e50851b commit 9dec562
Show file tree
Hide file tree
Showing 35 changed files with 756 additions and 297 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ buildNumber.properties

# Common working directory
run/

build_out/*
23 changes: 14 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.xapu1337.recodes</groupId>
<artifactId>trollgui</artifactId>
<version>2.01</version>
<version>2.1</version>
<packaging>jar</packaging>

<name>TrollGUI</name>
Expand All @@ -19,7 +19,7 @@

<build>
<directory>
C:\Users\XapuR\OneDrive\spigot-server-test\plugins
${project.basedir}/build_out
</directory>
<plugins>
<plugin>
Expand All @@ -37,7 +37,7 @@
<version>2.0</version>
<configuration>
<warName>ms3</warName>
<outputDirectory>C:\Users\XapuR\OneDrive\spigot-server-test\plugins</outputDirectory>
<outputDirectory>${project.basedir}/build_out</outputDirectory>
</configuration>
</plugin>
<plugin>
Expand All @@ -54,12 +54,12 @@
<relocations>
<relocation>
<pattern>com.cryptomorin.xseries</pattern>
<shadedPattern>me.xapu.trollgui.utils</shadedPattern>
<shadedPattern>me.xapu1337.trollgui.compatability</shadedPattern>
</relocation>

<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>me.xapu.trollgui.utils</shadedPattern>
<shadedPattern>me.xapu1337.trollgui.metrics</shadedPattern>
</relocation>
</relocations>
<filters>
Expand Down Expand Up @@ -103,25 +103,30 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>8.6.0.0.1</version>
<version>9.0.0</version>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>22.0.0</version>
<version>23.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.149</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import me.xapu1337.recodes.trollgui.Inventorys.PlayerSelector;
import me.xapu1337.recodes.trollgui.Inventorys.Settings;
import me.xapu1337.recodes.trollgui.Utilities.UpdateChecker;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/xapu1337/recodes/trollgui/Cores/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class Core extends JavaPlugin implements Listener {
public boolean usingUUID;
public Util utils = new Util();
public Singleton singletons = new Singleton();

public Core() {
if(instance == null)
instance = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package me.xapu1337.recodes.trollgui.Handlers;

import me.xapu1337.recodes.trollgui.Cores.Core;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public abstract class TrollHandler {
public Player caller;
public Player victim;
public TrollItemMetaData metaData;

public TrollHandler(Player caller, Player victim) {
public <T extends TrollHandler> T Init() {
Core.instance.singletons.holdingTrolls.put(this.getClass().getName(), this);
this.metaData = setMetaData();

return (T) this;
}

public abstract TrollItemMetaData setMetaData();

public <T extends TrollHandler> T setPlayers(Player caller, Player victim) {
this.caller = caller;
this.victim = victim;

return (T) this;
}


/**
* The method that gets executed on item click
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package me.xapu1337.recodes.trollgui.Handlers;

import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
import me.xapu1337.recodes.trollgui.Cores.Core;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.Arrays;
import java.util.function.Supplier;

public class TrollItemMetaData {

public boolean isToggable = false;

public boolean isToggled = false;

public String displayName = " - PLACEHOLDER - ";

public String[] lore = { " - PLACEHOLDER - " };

private XMaterial _item;

private ItemStack _itemStack;

private ItemMeta _itemMeta;

public TrollItemMetaData setToggable(boolean toggable) {
isToggable = toggable;
return this;
}

public TrollItemMetaData setToggled(Supplier<Boolean> toggledCallback){
isToggled = toggledCallback.get();

if (isToggled)
_itemMeta.addEnchant(XEnchantment.DURABILITY.getEnchant(), 1, true);
else
_itemMeta.removeEnchant(XEnchantment.DURABILITY.getEnchant());

// Append either disabled or enabled text to current lore

lore = Arrays.copyOf(lore, lore.length + 1);
lore[lore.length - 1] = isToggled ? Core.instance.utils.getConfigPath("MenuItems.trollMenu.extras.isEnabled") : Core.instance.utils.getConfigPath("MenuItems.trollMenu.extras.isDisabled");
_itemMeta.setLore(Arrays.asList(lore));

_itemStack.setItemMeta(_itemMeta);

return this;
}

public TrollItemMetaData setToggled(){
isToggled = !isToggled;

if (isToggled)
_itemMeta.addEnchant(XEnchantment.DURABILITY.getEnchant(), 1, true);
else
_itemMeta.removeEnchant(XEnchantment.DURABILITY.getEnchant());

lore = Arrays.copyOf(lore, lore.length + 1);
lore[lore.length - 1] = isToggled ? Core.instance.utils.getConfigPath("MenuItems.trollMenu.extras.isEnabled") : Core.instance.utils.getConfigPath("MenuItems.trollMenu.extras.isDisabled");
_itemMeta.setLore(Arrays.asList(lore));

_itemStack.setItemMeta(_itemMeta);

return this;
}

public TrollItemMetaData setDisplayName(String displayName){
this.displayName = displayName;

this._itemMeta.setDisplayName(displayName);

_itemStack.setItemMeta(_itemMeta);
return this;
}

public TrollItemMetaData setLore(String ...lore){
this.lore = lore;

_itemMeta.setLore(Arrays
.asList(

lore

)
);

_itemStack.setItemMeta(_itemMeta);

return this;
}

public TrollItemMetaData setConfigData(String itemConfigName){
try {
this.setDisplayName(Core.instance.utils.getConfigPath("MenuItems.trollMenu." + itemConfigName + ".name"));
this.setLore(Core.instance.utils.getConfigPath("MenuItems.trollMenu." + itemConfigName + ".lore").split("\\|"));
} catch (NullPointerException e) {
Bukkit.getLogger().warning("[TrollGUI] Could not find config data for item: " + itemConfigName + " (either .name or .lore is missing)");
e.printStackTrace();
}



return this;
}

public TrollItemMetaData setItem(XMaterial item){
_item = item;

_itemStack = new ItemStack(item.parseMaterial(), 1);

_itemMeta = _itemStack.getItemMeta();

_itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
_itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
_itemMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);

_itemStack.setItemMeta(_itemMeta);
return this;
}

// A function to replace placeholders in the current lore with values
public TrollItemMetaData formatPlaceholders(String placeholders, String ...values){
String[] lore = this.lore;
for (int i = 0; i < lore.length; i++) {
lore[i] = lore[i].replace(placeholders, values[i]);
}
_itemMeta.setLore(Arrays.asList(lore));
_itemStack.setItemMeta(_itemMeta);

return this;
}


// Getters
public XMaterial getItem(){
return _item;
}

public ItemStack getItemStack(){
return _itemStack;
}

public ItemMeta getItemMeta(){
return _itemMeta;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.cryptomorin.xseries.XMaterial;
import me.xapu1337.recodes.trollgui.Cores.Core;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
Expand All @@ -15,7 +14,6 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import sun.jvm.hotspot.oops.Array;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -52,10 +50,10 @@ public PlayerSelector(Player player) {
public void initializeItems(){
ArrayList<Player> players = new ArrayList<>(Core.instance.getServer().getOnlinePlayers());
for(int i = 45; i < 54; i++)
GUI.setItem(i, Core.instance.utils.createItem(XMaterial.GRAY_STAINED_GLASS_PANE, false, " "));
GUI.setItem(48, Core.instance.utils.createItem(XMaterial.OAK_BUTTON, false, Core.instance.utils.getConfigPath("MenuItems.playerSelector.left.name"), Core.instance.utils.getConfigPath("MenuItems.playerSelector.left.lore")));
GUI.setItem(49, Core.instance.utils.createItem(XMaterial.BARRIER, false, Core.instance.utils.getConfigPath("MenuItems.playerSelector.close.name"), Core.instance.utils.getConfigPath("MenuItems.playerSelector.close.lore")));
GUI.setItem(50, Core.instance.utils.createItem(XMaterial.OAK_BUTTON, false, Core.instance.utils.getConfigPath("MenuItems.playerSelector.right.name"), Core.instance.utils.getConfigPath("MenuItems.playerSelector.right.lore")));
GUI.setItem(i, Core.instance.utils.createItem(XMaterial.GRAY_STAINED_GLASS_PANE, " "));
GUI.setItem(48, Core.instance.utils.createItem(XMaterial.OAK_BUTTON, Core.instance.utils.getConfigPath("MenuItems.playerSelector.left.name"), Core.instance.utils.getConfigPath("MenuItems.playerSelector.left.lore")));
GUI.setItem(49, Core.instance.utils.createItem(XMaterial.BARRIER, Core.instance.utils.getConfigPath("MenuItems.playerSelector.close.name"), Core.instance.utils.getConfigPath("MenuItems.playerSelector.close.lore")));
GUI.setItem(50, Core.instance.utils.createItem(XMaterial.OAK_BUTTON, Core.instance.utils.getConfigPath("MenuItems.playerSelector.right.name"), Core.instance.utils.getConfigPath("MenuItems.playerSelector.right.lore")));

if(players != null && !players.isEmpty()) {
for(int i = 0; i < maxItemsPerPage; i++) {
Expand Down Expand Up @@ -95,7 +93,7 @@ public void onInventoryClicked(InventoryClickEvent event) {

if (clickedItem.getType() == XMaterial.PLAYER_HEAD.parseMaterial()) {
Player selectedPlayer = Bukkit.getPlayer(UUID.fromString(clickedItem.getItemMeta().getPersistentDataContainer().get(new NamespacedKey(Core.instance, "uuid"), PersistentDataType.STRING)));
if(selectedPlayer == null) { event.getWhoClicked().sendMessage(Core.instance.utils.getConfigPath("Messages.playerNotAvaliable", true)); return; }
if(selectedPlayer == null) { event.getWhoClicked().sendMessage(Core.instance.utils.getConfigPath("Messages. playerNotAvailable", true).replaceAll("%PLAYER%", clickedItem.getItemMeta().getPersistentDataContainer().get(new NamespacedKey(Core.instance, "uuid"), PersistentDataType.STRING) )); return; }
player.openInventory(new TrollGUI((Player) event.getWhoClicked(), selectedPlayer).getInventory());
} else if (clickedItem.getType() == XMaterial.BARRIER.parseMaterial()) {
player.closeInventory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import me.xapu1337.recodes.trollgui.Cores.Core;
import me.xapu1337.recodes.trollgui.Utilities.Util;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -33,12 +32,12 @@ public Settings() {
Bukkit.getPluginManager().registerEvents(this, Core.instance);
GUI = Bukkit.createInventory(this, 9, centerTitle(Core.instance.utils.getConfigPath("MenuTitles.settings")));
for(int i = 0; i < GUI.getSize(); i++)
GUI.setItem(i, Core.instance.utils.createItem(XMaterial.GRAY_STAINED_GLASS_PANE, false, " "));
GUI.setItem(i, Core.instance.utils.createItem(XMaterial.GRAY_STAINED_GLASS_PANE, "§r"));
initializeItems();
}

public void initializeItems(){
GUI.setItem(4, Core.instance.utils.createItem(XMaterial.REDSTONE_BLOCK, false, Core.instance.utils.getConfigPath("MenuItems.settingsMenu.reload.name"), Core.instance.utils.getConfigPath("MenuItems.settingsMenu.reload.lore")));
GUI.setItem(4, Core.instance.utils.createItem(XMaterial.REDSTONE_BLOCK, Core.instance.utils.getConfigPath("MenuItems.settingsMenu.reload.name"), Core.instance.utils.getConfigPath("MenuItems.settingsMenu.reload.lore")));
}

@Override
Expand Down
Loading

0 comments on commit 9dec562

Please sign in to comment.