Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Working on adding new features
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Oct 24, 2019
1 parent 88bb721 commit b89cff1
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.puyodead1</groupId>
<artifactId>RPBookGUI</artifactId>
<version>2.9.5</version>
<version>2.9.6</version>
<name>RPBookGUI</name>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
} else if (args[0].equalsIgnoreCase("settings")) {
if (player.hasPermission(rpbgConfig.getString("permissions.bookgui settings")) || player.isOp()) {
player.openInventory(Inventories.SettingsInv());
player.openInventory(Inventories.Settings());
return true;
} else {
player.sendMessage(RPBookGUIUtils.ChatColor(rpbgConfig.getString("messages.no permission")));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.github.puyodead1.rpbookgui;

import java.util.HashMap;

import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;

import me.randomhashtags.randompackage.addons.CustomEnchant;
import me.randomhashtags.randompackage.addons.EnchantRarity;
import me.randomhashtags.randompackage.api.CustomEnchants;

public class EnchantConstructor {
private CustomEnchant customEnchant;
private EnchantRarity enchantRarity;
private int enchantLevel;
private ItemStack revealItem;
private int success;
private int destroy;

private static HashMap<String, EnchantConstructor> enchants = new HashMap<String, EnchantConstructor>();

public EnchantConstructor(CustomEnchant customEnchant, EnchantRarity enchantRarity, int enchantLevel, int success, int destroy) {
this.customEnchant = customEnchant;
this.enchantRarity = enchantRarity;
this.enchantLevel = enchantLevel;
this.revealItem = CustomEnchants.getCustomEnchants().getRevealedItem(customEnchant, enchantLevel, success, destroy, true, true);
this.success = success;
this.destroy = destroy;

enchants.put(customEnchant.getIdentifier(), this);

Bukkit.broadcastMessage("EnchantConstructor added: " + customEnchant.getIdentifier() + " " + enchantLevel);
}

public CustomEnchant getCustomEnchant() {
return customEnchant;
}

public void setCustomEnchant(CustomEnchant customEnchant) {
this.customEnchant = customEnchant;
}

public EnchantRarity getEnchantRarity() {
return enchantRarity;
}

public void setEnchantRarity(EnchantRarity enchantRarity) {
this.enchantRarity = enchantRarity;
}

public int getEnchantLevel() {
return enchantLevel;
}

public void setEnchantLevel(int enchantLevel) {
this.enchantLevel = enchantLevel;
}


public ItemStack getRevealItem() {
return revealItem;
}

public int getSuccess() {
return success;
}

public void setSuccess(int success) {
this.success = success;
}

public int getDestroy() {
return destroy;
}

public void setDestroy(int destroy) {
this.destroy = destroy;
}

public static HashMap<String, EnchantConstructor> getEnchants() {
return enchants;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand All @@ -12,6 +13,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import io.github.puyodead1.rpbookgui.EnchantConstructor;
import io.github.puyodead1.rpbookgui.Inventories;
import io.github.puyodead1.rpbookgui.ItemStacks;
import io.github.puyodead1.rpbookgui.RPBookGUI;
Expand All @@ -22,7 +24,7 @@
import me.randomhashtags.randompackage.utils.universal.UMaterial;

public class InventoryClick implements Listener {

private static RandomPackageAPI rpapi = new RandomPackageAPI();

@EventHandler
Expand Down Expand Up @@ -84,15 +86,15 @@ public void InventoryClickEvent(InventoryClickEvent e) {
!RPBookGUI.getPlugin.getConfig().getBoolean("settings.keepinvopen"));

player.closeInventory();
player.openInventory(Inventories.SettingsInv());
player.openInventory(Inventories.Settings());
}
if (ci.getItemMeta().getDisplayName()
.equals(ItemStacks.UsePermissionsSetting().clone().getItemMeta().getDisplayName())) {
RPBookGUI.getPlugin.getConfig().set("settings.usepermissions",
!RPBookGUI.getPlugin.getConfig().getBoolean("settings.usepermissions"));

player.closeInventory();
player.openInventory(Inventories.SettingsInv());
player.openInventory(Inventories.Settings());
}
}

Expand All @@ -107,9 +109,10 @@ public void InventoryClickEvent(InventoryClickEvent e) {
player.openInventory(Inventories.MainGUI());
}
if (e.getCurrentItem().getType().equals(UMaterial.match("BOOK").getMaterial())) {
CustomEnchant ce = rpapi.valueOfCustomEnchant(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
CustomEnchant ce = rpapi.valueOfCustomEnchant(
ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
player.closeInventory();
player.openInventory(Inventories.EnchantInv(ce));
player.openInventory(Inventories.Enchant(ce));
}
}

Expand All @@ -124,9 +127,10 @@ public void InventoryClickEvent(InventoryClickEvent e) {
player.openInventory(Inventories.MainGUI());
}
if (e.getCurrentItem().getType().equals(UMaterial.match("BOOK").getMaterial())) {
CustomEnchant ce = rpapi.valueOfCustomEnchant(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
CustomEnchant ce = rpapi.valueOfCustomEnchant(
ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
player.closeInventory();
player.openInventory(Inventories.EnchantInv(ce));
player.openInventory(Inventories.Enchant(ce));
}
}
/*
Expand All @@ -140,9 +144,10 @@ public void InventoryClickEvent(InventoryClickEvent e) {
player.openInventory(Inventories.MainGUI());
}
if (e.getCurrentItem().getType().equals(UMaterial.match("BOOK").getMaterial())) {
CustomEnchant ce = rpapi.valueOfCustomEnchant(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
CustomEnchant ce = rpapi.valueOfCustomEnchant(
ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
player.closeInventory();
player.openInventory(Inventories.EnchantInv(ce));
player.openInventory(Inventories.Enchant(ce));
}
}

Expand All @@ -157,9 +162,10 @@ public void InventoryClickEvent(InventoryClickEvent e) {
player.openInventory(Inventories.MainGUI());
}
if (e.getCurrentItem().getType().equals(UMaterial.match("BOOK").getMaterial())) {
CustomEnchant ce = rpapi.valueOfCustomEnchant(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
CustomEnchant ce = rpapi.valueOfCustomEnchant(
ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
player.closeInventory();
player.openInventory(Inventories.EnchantInv(ce));
player.openInventory(Inventories.Enchant(ce));
}
}
/*
Expand All @@ -173,9 +179,10 @@ public void InventoryClickEvent(InventoryClickEvent e) {
player.openInventory(Inventories.MainGUI());
}
if (e.getCurrentItem().getType().equals(UMaterial.match("BOOK").getMaterial())) {
CustomEnchant ce = rpapi.valueOfCustomEnchant(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
CustomEnchant ce = rpapi.valueOfCustomEnchant(
ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
player.closeInventory();
player.openInventory(Inventories.EnchantInv(ce));
player.openInventory(Inventories.Enchant(ce));
}
}

Expand All @@ -190,9 +197,10 @@ public void InventoryClickEvent(InventoryClickEvent e) {
player.openInventory(Inventories.MainGUI());
}
if (e.getCurrentItem().getType().equals(UMaterial.match("BOOK").getMaterial())) {
CustomEnchant ce = rpapi.valueOfCustomEnchant(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
CustomEnchant ce = rpapi.valueOfCustomEnchant(
ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
player.closeInventory();
player.openInventory(Inventories.EnchantInv(ce));
player.openInventory(Inventories.Enchant(ce));
}
}
/*
Expand All @@ -206,9 +214,10 @@ public void InventoryClickEvent(InventoryClickEvent e) {
player.openInventory(Inventories.MainGUI());
}
if (e.getCurrentItem().getType().equals(UMaterial.match("BOOK").getMaterial())) {
CustomEnchant ce = rpapi.valueOfCustomEnchant(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
CustomEnchant ce = rpapi.valueOfCustomEnchant(
ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
player.closeInventory();
player.openInventory(Inventories.EnchantInv(ce));
player.openInventory(Inventories.Enchant(ce));
}
}

Expand Down Expand Up @@ -278,12 +287,22 @@ public void InventoryClickEvent(InventoryClickEvent e) {
.replace("{NAME}", ci.getItemMeta().getDisplayName())
.replace("{ITEM}", player.getItemInHand().getType().name())));
} else {
player.getInventory().addItem(ci);
if (!RPBookGUI.getPlugin.getConfig().getBoolean("settings.keep inventory open"))
player.closeInventory();
player.sendMessage(RPBookGUIUtils
.ChatColor(RPBookGUI.getPlugin.getConfig().getString("messages.added book")
.replace("{NAME}", ci.getItemMeta().getDisplayName())));

for(EnchantConstructor ec : EnchantConstructor.getEnchants().values()) {
if(ec.getRevealItem() != ci) {
Bukkit.broadcastMessage("Removing EnchantConstructor: " + ec.getCustomEnchant().getIdentifier() + " " + ec.getEnchantLevel());
EnchantConstructor.getEnchants().remove(ec.getCustomEnchant().getIdentifier());
}
}

player.closeInventory();
player.openInventory(Inventories.SuccessDestroySelection(ci));
// player.getInventory().addItem(ci);
// if (!RPBookGUI.getPlugin.getConfig().getBoolean("settings.keep inventory open"))
// player.closeInventory();
// player.sendMessage(RPBookGUIUtils
// .ChatColor(RPBookGUI.getPlugin.getConfig().getString("messages.added book")
// .replace("{NAME}", ci.getItemMeta().getDisplayName())));
}
}
}
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/io/github/puyodead1/rpbookgui/Inventories.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

Expand All @@ -27,8 +28,6 @@
import me.randomhashtags.randompackage.addons.CustomEnchant;
import me.randomhashtags.randompackage.addons.EnchantRarity;
import me.randomhashtags.randompackage.api.CustomEnchants;
import me.randomhashtags.randompackage.utils.CustomEnchantUtils;
import me.randomhashtags.randompackage.utils.RPStorage;

public class Inventories {

Expand Down Expand Up @@ -300,21 +299,24 @@ public static Inventory HeroicEnchants(ItemStack itemApplyTo) {
inv.setItem(53, ItemStacks.Back().clone());
return inv;
}

public static Inventory EnchantInv(CustomEnchant ce) {
public static Inventory Enchant(CustomEnchant ce) {
EnchantRarity rarity = rpapi.valueOfEnchantRarity(ce);
Inventory inv = Bukkit.createInventory(null, 18, rarity.getNameColors() + ce.getName());
int x = 0;
for (int i = 1; i < ce.getMaxLevel() + 1; i++) {
ItemStack is = CustomEnchants.getCustomEnchants().getRevealedItem(ce, i, 100, 0, true, true).clone();
new EnchantConstructor(ce, rarity, i, 0, 0);
Bukkit.broadcastMessage("EnchantConstructor size: " + EnchantConstructor.getEnchants().size());
inv.setItem(x, is);
x++;
}
Bukkit.broadcastMessage("Final EnchantConstructor size: " + EnchantConstructor.getEnchants().size());
inv.setItem(17, ItemStacks.Back().clone());
return inv;
}

public static Inventory SettingsInv() {
public static Inventory Settings() {
Inventory inv = Bukkit.createInventory(null, 36, "RPBookGUI Settings");

for (int i = 0; i < 10; i++)
Expand All @@ -336,4 +338,25 @@ public static Inventory SettingsInv() {
inv.setItem(22, ItemStacks.Back().clone());
return inv;
}

public static Inventory SuccessDestroySelection(ItemStack book) {
Inventory inv = Bukkit.createInventory(null, 54, "Success & Destry Configuration");
CustomEnchant ce = rpapi.valueOfCustomEnchant(book);
// slot 10 - increase success
// slot 28 - decrease success
// slot 21 - book

ItemStack addSuccess = new ItemStack(Material.GREEN_WOOL);
ItemStack removeSuccess = new ItemStack(Material.RED_WOOL);

inv.setItem(10, addSuccess);
// inv.setItem(21, CustomEnchants.getCustomEnchants().getRevealedItem(ce, EnchantConstructor.getEnchants().get(ce.getName()).getEnchantLevel(), 0, 0, true, true));
inv.setItem(28, removeSuccess);

for(EnchantConstructor ec : EnchantConstructor.getEnchants().values()) {
Bukkit.broadcastMessage(ec.getCustomEnchant().getIdentifier() + " " + ec.getEnchantLevel());
}

return inv;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: RPBookGUI
version: 2.9.5
version: 2.9.6
author: Puyodead1
main: io.github.puyodead1.rpbookgui.RPBookGUI
depend: [RandomPackage]
Expand Down

0 comments on commit b89cff1

Please sign in to comment.