Skip to content

Commit

Permalink
added framework for hgive system and hgive guis, fixed reloadprops an…
Browse files Browse the repository at this point in the history
…d reloadhats commands
  • Loading branch information
cytocracy committed Jul 29, 2021
1 parent 54bf478 commit 68f1006
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 77 deletions.
117 changes: 61 additions & 56 deletions src/main/java/me/jakedadream/ParadisuPlugin/events/GuiListeners.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jakedadream.ParadisuPlugin.events;

import me.jakedadream.ParadisuPlugin.modelmanager.HatModelInv;
import me.jakedadream.ParadisuPlugin.modelmanager.PropModelInv;
import me.jakedadream.ParadisuPlugin.modelmanager.modelitemmanager;
import org.bukkit.entity.HumanEntity;
Expand All @@ -22,96 +23,100 @@ public void onClick(InventoryClickEvent e){
player.sendMessage("no");
return;
}
switch (player.getOpenInventory().getTitle()){
case "§3§lProp Models Give GUI":
switch (player.getOpenInventory().getTitle()) {
case "§3§lProp Models Give GUI" -> {
// PropModelInv props = new PropModelInv();
List<Inventory> invss = PropModelInv.getInvs();
switch (e.getRawSlot()){
case 48:
switch (e.getRawSlot()) {
case 48 -> {
e.setCancelled(true);
Inventory currinva = e.getInventory();


int indexa = invss.indexOf(currinva);
indexa -= 1;
if(indexa == -1) {
if (indexa == -1) {
e.setCancelled(true);
break;
}
player.closeInventory();
player.openInventory(invss.get(indexa));

break;
case 50:
}
case 50 -> {
e.setCancelled(true);
Inventory currinvb = e.getInventory();

int indexb = invss.indexOf(currinvb);
indexb += 1;
if (indexb == invss.size()){
if (indexb == invss.size()) {
e.setCancelled(true);
break;
}
player.closeInventory();
player.openInventory(invss.get(indexb));

break;
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
if(e.getCurrentItem() == null){
}
case 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 -> {
if (e.getCurrentItem() == null) {
e.setCancelled(true);
return;
}
int modelData = e.getCurrentItem().getItemMeta().getCustomModelData();
PlayerInventory inv = player.getInventory();
int firstEmpty = inv.firstEmpty();
if (firstEmpty == -1){
if (firstEmpty == -1) {
player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have space in your inventory.");
e.setCancelled(true);
return;
}
player.getInventory().addItem(modelitemmanager.createPropModel(modelData));
e.setCancelled(true);
break;

default:
}
default -> e.setCancelled(true);
}
}
case "§3§lHat Models Give GUI" -> {
List<Inventory> invss = HatModelInv.getInvs();
switch (e.getRawSlot()) {
case 48 -> {
e.setCancelled(true);
Inventory currinva = e.getInventory();
int indexa = invss.indexOf(currinva);
indexa -= 1;
if (indexa == -1){
e.setCancelled(true);
break;
}
player.closeInventory();
player.openInventory(invss.get(indexa));
}
case 50 -> {
e.setCancelled(true);
Inventory currinvb = e.getInventory();
int indexb = invss.indexOf(currinvb);
indexb += 1;
if (indexb == invss.size()) {
e.setCancelled(true);
break;
}
player.closeInventory();
player.openInventory(invss.get(indexb));
}
case 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 -> {
if (e.getCurrentItem() == null) {
e.setCancelled(true);
return;
}
int modelData = e.getCurrentItem().getItemMeta().getCustomModelData();
PlayerInventory inv = player.getInventory();
int firstEmpty = inv.firstEmpty();
if (firstEmpty == -1) {
player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have space in your inventory.");
e.setCancelled(true);
return;
}
player.getInventory().addItem(modelitemmanager.createHatModel(modelData));
e.setCancelled(true);
break;
}
default -> e.setCancelled(true);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package me.jakedadream.ParadisuPlugin.modelmanager;

import me.jakedadream.ParadisuPlugin.paradisumain;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Item;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.List;

public class HatModelInv {
public static List<Inventory> inventories = new ArrayList<>();

public static void createInvs(){
modelitemmanager models = new modelitemmanager();
double dinvSize = 36;
int invSize = 36;

double neededInventories = (paradisumain.getHatModelsConfig().getKeys(false).size() / dinvSize);
int intneededInventories = (int) Math.ceil(neededInventories);

for (int i = 0; i < intneededInventories; i ++){
Inventory inv = Bukkit.createInventory(null, 54, "§3§lHat Models Give GUI");
inventories.add(inv);
}
int modelindex = 1;
for (Inventory i : inventories){
ItemStack previous = new ItemStack(Material.DIAMOND_AXE,1 );

ItemMeta prevMeta = previous.getItemMeta();
assert prevMeta != null;
prevMeta.setCustomModelData(28);
prevMeta.setDisplayName("§b§l←§d§l Go Left");
List<String> prevLore = new ArrayList<>();
prevLore.add("§7Go left a page.");
prevMeta.setLore(prevLore);
previous.setItemMeta(prevMeta);

ItemStack next = new ItemStack(Material.DIAMOND_AXE, 1);
ItemMeta nextMeta = next.getItemMeta();
assert nextMeta != null;
nextMeta.setCustomModelData(48);

nextMeta.setDisplayName("§d§lGo Right §b§l→");
List<String> nextLore = new ArrayList<>();
nextLore.add("§7Go right a page.");
nextMeta.setLore(nextLore);
next.setItemMeta(nextMeta);

i.setItem(48, previous);
i.setItem(50, next);

ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
ItemMeta blankMeta = blank.getItemMeta();
blankMeta.setDisplayName(" ");
blank.setItemMeta(blankMeta);

for (int j = 0; j < 9; j++){
i.setItem(j, blank);
}

i.setItem(45, blank);
i.setItem(46, blank);
i.setItem(47, blank);
i.setItem(49, blank);
i.setItem(51, blank);
i.setItem(52, blank);
i.setItem(53, blank);

int pageindex = 9;
int stop = modelindex + 36;
for (int a = modelindex; a < stop; a++){
if (a > paradisumain.getHatModelsConfig().getKeys(false).size()){
break;
}
ItemStack item = modelitemmanager.createHatModel(a);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(meta.getDisplayName() + " (" + a + ")");
item.setItemMeta(meta);
i.setItem(pageindex, item);
pageindex++;
}
modelindex += 36;
}
}
public static List<Inventory> getInvs() {return inventories;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void createInvs(){
int pageindex = 9;
int stop = modelindex + 36;
for (int a = modelindex; a < stop; a++) {
if (a > paradisumain.filePropModelsConfig.getKeys(false).size()){
if (a > paradisumain.getPropModelsConfig().getKeys(false).size()){
break;
}
ItemStack item = modelitemmanager.createPropModel(a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
case "hgive":
if (player.hasPermission("snw.model")) {

// hat menu
if (args.length == 0) {
player.openInventory(HatModelInv.getInvs().get(0));
} else if (args.length == 1){
PlayerInventory inv = player.getInventory();
int firstEmpty = inv.firstEmpty();
if (firstEmpty == -1){
player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have space in your inventory.");
return false;
}
player.getInventory().addItem(modelitemmanager.createHatModel(Integer.parseInt(args[0])));
}
player.sendMessage("§3[§dParadisu §f§lMODELS §bツ§3] §fOpening the Catalog of Hat Models!");
} else { player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have permission to use that command."); }
return true;
Expand All @@ -72,7 +82,22 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;

case "reloadprops":
if(!(player.hasPermission("snw.model.reload"))){
player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have permission to use that command.");
break;
}
paradisumain.reloadPropModelsConfig();
PropModelInv.createInvs();
player.sendMessage("ok");
break;

case "reloadhats":
if(!(player.hasPermission("snw.model.reload"))){
player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have permission to use that command.");
break;
}
paradisumain.reloadHatModelsConfig();
HatModelInv.createInvs();
player.sendMessage("ok");
break;

Expand All @@ -88,9 +113,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
// ------------------------------------------------------------------------------------------------------------------------------------------------
if (args[0].equals("prop")) {
//
String sectionname = randstring;
paradisumain.getPropModelsConfig().createSection(sectionname);
ConfigurationSection cs = paradisumain.filePropModelsConfig.getConfigurationSection(sectionname);
paradisumain.getPropModelsConfig().createSection(randstring);
ConfigurationSection cs = paradisumain.filePropModelsConfig.getConfigurationSection(randstring);

// cs.set("custommodeldata", int_random);

Expand Down Expand Up @@ -124,11 +148,43 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
//
} else if (args[0].equals("hat")) {
//
paradisumain.getHatModelsConfig().createSection(randstring);
// paradisumain.getPropModelsConfig().createSection(sectionname);
// ConfigurationSection cs = paradisumain.filePropModelsConfig.getConfigurationSection(sectionname);
ConfigurationSection cs = paradisumain.getHatModelsConfig().getConfigurationSection(randstring);
// cs.set("custommodeldata", int_random);

cs.set("displayname", "Unset Hat Name");
cs.set("enchantslot1", "Enchantment.LUCK");
cs.set("enchantslot2", "Enchantment.LUCK");
cs.set("enchantslot3", "Enchantment.LUCK");

cs.set("enchantslot1level", 0);
cs.set("enchantslot2level", 0);
cs.set("enchantslot3level", 0);

cs.set("lore1", "DEFAULT LORE 1");
cs.set("lore2", "DEFAULT LORE 2");
cs.set("lore3", "DEFAULT LORE 3");
cs.set("lore4", "DEFAULT LORE 4");
cs.set("lore5", "DEFAULT LORE 5");
cs.set("lore6", "DEFAULT LORE 6");
cs.set("lore7", "DEFAULT LORE 7");
cs.set("lore8", "DEFAULT LORE 8");
cs.set("lore9", "DEFAULT LORE 9");
cs.set("lore10", "DEFAULT LORE 10");

cs.set("unbreakable", false);
cs.set("hideunbreakable", false);
cs.set("hideenchants", false);
//
paradisumain.saveHatModelsConfig();
//
player.sendMessage("§3[§dParadisu §f§lMODELS §bツ§3] §fNew hat Section created!");




player.sendMessage("§3[§dParadisu §f§lMODELS §bツ§3] §fNew Model Section created!");
//
} else {player.sendMessage("§3[§dParadisu §f§lMODELS §bツ§3] §7Please specify between Props & Hats.");}
} else {player.sendMessage("§3[§dParadisu §f§lMODELS §bツ§3] §7Too many args.");}
Expand Down
Loading

0 comments on commit 68f1006

Please sign in to comment.