Skip to content

Commit

Permalink
Patch 4.2.60
Browse files Browse the repository at this point in the history
added working command /be reroll command
  • Loading branch information
Grzybol authored Apr 13, 2024
2 parents d5cc519 + b2a589f commit 4120995
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>betterbox.mine.game</groupId>
<artifactId>BetterElo</artifactId>
<version>4.2.22-SNAPSHOT</version>
<version>4.2.61-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/betterbox/mine/game/betterelo/BetterElo.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void onEnable() {
pluginLogger.log(PluginLogger.LogLevel.INFO,"Starting spawners scheduler...");
customMobs.startSpawnerScheduler();

guiManager = new GuiManager(fileRewardManager, pluginLogger, this, dataManager, customMobsFileManager);
guiManager = new GuiManager(fileRewardManager, pluginLogger, this, dataManager, customMobsFileManager, customMobs, this);
getServer().getPluginManager().registerEvents(guiManager, this);
// Rejestracja komendy
betterRanksCheaters = new BetterRanksCheaters(this,pluginLogger);
Expand Down Expand Up @@ -637,7 +637,7 @@ public void run() {
while (iterator.hasNext()) {
Map.Entry<Entity, CustomMobs.CustomMob> entry = iterator.next();
if (entry.getKey().isDead() || !entry.getKey().isValid()) {
pluginLogger.log(PluginLogger.LogLevel.INFO, "BetterElo. mob "+entry.getKey()+" is dead or does not exists, removing from the list and from the spawner "+entry.getValue().spawnerName);
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "BetterElo. mob "+entry.getKey()+" is dead or does not exists, removing from the list and from the spawner "+entry.getValue().spawnerName);
// Mob nie istnieje, więc możemy go usunąć z mapy
customMobs.decreaseMobCount(entry.getValue().spawnerName);
iterator.remove();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
break;
case 1:
switch (args[0].toLowerCase()) {
case "reroll":
handleRerollCommand(sender);
break;
case "killallmobs":
if(!sender.isOp()){
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " You don't have permission to use that command!");
Expand Down Expand Up @@ -666,6 +669,7 @@ private void handleHelpCommand(CommandSender sender){
sender.sendMessage(ChatColor.AQUA + "/be weekly " + ChatColor.GREEN + "- Returns top10 weekly ranking/Zwraca info o top10 rankingu tygodniowego");
sender.sendMessage(ChatColor.AQUA + "/be monthly " + ChatColor.GREEN + "- Returns top10 monthly ranking/Zwraca info o top10 rankingu miesięcznego");
sender.sendMessage(ChatColor.AQUA + "/be event " + ChatColor.GREEN + "- Returns event info/Zwraca info o evencie");
sender.sendMessage(ChatColor.AQUA + "/be reroll " + ChatColor.GREEN + "- Open Re-Roll GUI for AvgDmg bonus items");
if(sender.isOp()){
sender.sendMessage(ChatColor.AQUA + "/be setrewards " + ChatColor.GREEN + "- Opens a GUI for changing the rewards");
sender.sendMessage(ChatColor.AQUA + "/be reload " + ChatColor.GREEN + "- Reloads the config file ");
Expand Down Expand Up @@ -740,6 +744,13 @@ private void handleCreateDropTable(CommandSender sender,String dropTableName){
Player player = (Player) sender;
guiManager.openDroptableGui(player,dropTableName); // Otwieramy główne menu GUI dla gracza
}
public void handleRerollCommand (CommandSender sender){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand.handleRerollCommand called, sender: "+sender);
if(sender instanceof Player){
Player player = (Player) sender;
guiManager.openReRollGui(player);
}
}
public void addAntywebLore(Player player, ItemStack itemStack, int radius) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ public List<ItemStack> loadRewards() {
}
return rewards;
}
public List<ItemStack> loadReRollCost() {
File rewardsFile = new File(plugin.getDataFolder(), "reroll.yml");
if (!rewardsFile.exists()) {
return new ArrayList<>(); // return empty list if the file does not exist
}
FileConfiguration config = YamlConfiguration.loadConfiguration(rewardsFile);
List<ItemStack> rewards = new ArrayList<>();
for (String key : config.getConfigurationSection("items").getKeys(false)) {
ItemStack item = config.getItemStack("items." + key);
if (item != null && item.getType() != Material.AIR) {
rewards.add(item);
}
}
return rewards;
}
public List<ItemStack> loadRewards(Player player) {
File rewardsFile = new File(plugin.getDataFolder(), rewardType + ".yml");
if (!rewardsFile.exists()) {
Expand Down
202 changes: 194 additions & 8 deletions src/main/java/betterbox/mine/game/betterelo/GuiManager.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package betterbox.mine.game.betterelo;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
public class GuiManager implements Listener {
Expand All @@ -24,14 +27,19 @@ public class GuiManager implements Listener {
private String rewardType;
private String dropTable;
private final CustomMobsFileManager mobsFileManager;
private CustomMobs customMobs;
private JavaPlugin plugin;
private Random random = new Random();

private final DataManager dataManager;
public GuiManager(FileRewardManager fileRewardManager, PluginLogger pluginLogger, BetterElo mainClass, DataManager dataManager, CustomMobsFileManager mobsFileManager) {
public GuiManager(FileRewardManager fileRewardManager, PluginLogger pluginLogger, BetterElo mainClass, DataManager dataManager, CustomMobsFileManager mobsFileManager, CustomMobs customMobs, JavaPlugin plugin) {
this.fileRewardManager = fileRewardManager;
this.dataManager = dataManager;
this.pluginLogger = pluginLogger;
this.mainClass = mainClass;
this.mobsFileManager=mobsFileManager;
this.customMobs = customMobs;
this.plugin = plugin;
}
public void openSubGui(Player player) {
Inventory subInv = Bukkit.createInventory(null, 9, "Select Top");
Expand All @@ -51,7 +59,6 @@ public void openMainGui(Player player) {
player.openInventory(inv);
}
public void openDroptableGuiOld(Player player, String dropTableName) {

dropTable= dropTableName;
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.openDroptableGui called. dropTableName:"+dropTableName+", dropTable: "+dropTable);
Inventory inv = Bukkit.createInventory(null, 9, "Set Rewards");
Expand Down Expand Up @@ -96,7 +103,7 @@ public void onInventoryClick(InventoryClickEvent event) {

String title = event.getView().getTitle();
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick called. title:"+title);
if (!Arrays.asList("Set Rewards", "Add Items", "Select Top").contains(title)) {
if (!Arrays.asList("Set Rewards", "Add Items", "Select Top", "AvgDmg bonus change").contains(title)) {
return;
}

Expand All @@ -106,14 +113,15 @@ public void onInventoryClick(InventoryClickEvent event) {
if (currentItem == null || currentItem.getType() == Material.AIR) {
return;
}
Inventory inv;
//String rewardTypeTemp = currentItem.getItemMeta().getDisplayName();
switch (title) {
case "Set Rewards":
event.setCancelled(true);
periodType = currentItem.getItemMeta().getDisplayName();
if(periodType.equals("dropTable")){
List<ItemStack> currentRewards = fileRewardManager.loadRewards();
Inventory inv = Bukkit.createInventory(null, 36, "Add Items");
inv = Bukkit.createInventory(null, 36, "Add Items");
currentRewards.forEach(inv::addItem);
createItem(inv, Material.GREEN_WOOL, 35, "Save", "Save drop table");
player.openInventory(inv);
Expand All @@ -127,7 +135,7 @@ public void onInventoryClick(InventoryClickEvent event) {
pluginLogger.log("GuiManager.onInventoryClick: rewardType:" + rewardType + " periodType:" + periodType);
fileRewardManager.setRewardType(periodType, rewardType);
List<ItemStack> currentRewards = fileRewardManager.loadRewards();
Inventory inv = Bukkit.createInventory(null, 36, "Add Items");
inv = Bukkit.createInventory(null, 36, "Add Items");
currentRewards.forEach(inv::addItem);
createItem(inv, Material.GREEN_WOOL, 35, "Save", "Save rewards");
//createItem(inv, Material.ORANGE_WOOL, 34, "Reset", "Resetuj czas");
Expand Down Expand Up @@ -167,6 +175,184 @@ public void onInventoryClick(InventoryClickEvent event) {
}

}
break;
case "AvgDmg bonus change":
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick Average Damage bonus re-roll");
if(event.getCurrentItem().getType() == Material.GRAY_STAINED_GLASS_PANE){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick re-roll, blank slot manipulated, cancelling..");
event.setCancelled(true);
return;
}
if (currentItem.getType() == Material.GREEN_WOOL && event.getSlot() == 5){
event.setCancelled(true);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick Average Damage bonus re-roll clicked");
Inventory inventory = event.getInventory();
ItemStack item0 = inventory.getItem(3);
if (item0 != null && item0.hasItemMeta()) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, item0: "+item0+", item0.hasItemMeta(): "+item0.hasItemMeta());
ItemMeta meta0 = item0.getItemMeta();
boolean slot0Condition = meta0.getLore().stream().anyMatch(line -> line.contains("Average Damage"));
ItemMeta meta = item0.getItemMeta();
//List<String> lore = meta.getLore();
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, slot0Condition: "+slot0Condition);

if (slot0Condition) {
ItemStack result = item0.clone();
ItemMeta resultMeta = result.getItemMeta();
List<String> lore = new ArrayList<>(resultMeta.getLore());
for (int i = 0; i < lore.size(); i++) {
if (lore.get(i).contains("Average Damage")) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, Average Damage lore line found i: " + i);
if(checkAndRemoveBetterCoins(player)) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, player paid, re-rolling..." );
lore.set(i, customMobs.dropAverageDamage());
break;
}
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, player has no money for the re-roll." );
}
}
resultMeta.setLore(lore);
result.setItemMeta(resultMeta);
inventory.setItem(3, result);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick result placed back in slot 3");

}
}
}
break;


}
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
Inventory closedInventory = event.getInventory();

// Check if the closed inventory is the same one we're interested in
if (event.getView().getTitle().equalsIgnoreCase("AvgDmg bonus change")) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Checking items in closed GUI");

ItemStack itemInSlot0 = closedInventory.getItem(3);
if (itemInSlot0 != null && itemInSlot0.hasItemMeta()) {
ItemMeta meta = itemInSlot0.getItemMeta();
if (meta.getLore().stream().anyMatch(line -> line.contains("Average Damage"))) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Item with 'Average damage' found in slot 0");

// Optional: Directly give back the item to the player's inventory
if (player.getInventory().addItem(itemInSlot0).size() == 0) {
// Item successfully added to player's inventory
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Item returned to player inventory");
closedInventory.clear(3); // Clear the slot after returning item
} else {
// Inventory full, drop item at player's location
player.getWorld().dropItem(player.getLocation(), itemInSlot0);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Inventory full, item dropped at player's location");
closedInventory.clear(3); // Clear the slot
}
}
}
}
}

private void handleReRollEvent(InventoryClickEvent event, Inventory inv) {
if (event.getSlot() == 2) { // Zapobieganie interakcji z wynikowym slotem
event.setCancelled(true);
return;
}

// Asynchroniczne sprawdzenie receptury i aktualizacja slotu wynikowego
Bukkit.getScheduler().runTaskLater(plugin, () -> updateResultSlot(inv), 1L);
}

private void updateResultSlot(Inventory inv) {
ItemStack item0 = inv.getItem(0);
ItemStack item1 = inv.getItem(1);
if (item0 != null && item1 != null && item0.hasItemMeta() && item1.hasItemMeta()) {
ItemMeta meta0 = item0.getItemMeta();
ItemMeta meta1 = item1.getItemMeta();
boolean slot0Condition = meta0.getLore().stream().anyMatch(line -> line.contains("Average Damage"));
boolean slot1Condition = meta1.getDisplayName().equals("test");
if (slot0Condition && slot1Condition) {
ItemStack result = item0.clone();
ItemMeta resultMeta = result.getItemMeta();
List<String> lore = new ArrayList<>(resultMeta.getLore());
for (int i = 0; i < lore.size(); i++) {
if (lore.get(i).contains("Average Damage")) {
lore.set(i, customMobs.dropAverageDamage());
break;
}
}
resultMeta.setLore(lore);
result.setItemMeta(resultMeta);
inv.setItem(2, result);
} else {
inv.setItem(2, new ItemStack(Material.AIR));
}
}
}


public void openCustomSmithingTable(Player player) {
Inventory smithingTable = Bukkit.createInventory(player, InventoryType.SMITHING, "Re-roll Average Damage bonus");

// Ustawienie początkowych przedmiotów w GUI (przykładowo, można ustawić puste sloty lub zablokowane sloty)
ItemStack item1 = new ItemStack(Material.AIR); // Pierwszy slot na materiał
ItemStack item2 = new ItemStack(Material.AIR); // Drugi slot na narzędzie
smithingTable.setItem(0, item1); // Pierwszy slot
smithingTable.setItem(1, item2); // Drugi slot

// Otworzenie ekwipunku dla gracza
player.openInventory(smithingTable);
}

public void openReRollGui(Player player){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.openReRollGui called, player: "+player.getName());
Inventory inv = Bukkit.createInventory(null, 9, "AvgDmg bonus change");
Material blank = Material.GRAY_STAINED_GLASS_PANE;
createItem(inv, blank, 0, "", "");
createItem(inv, blank, 1, "", "");
createItem(inv, blank, 2, "", "");
createItem(inv, blank, 4, "", "");
createItem(inv, Material.GREEN_WOOL, 5, "Re-Roll Average Damage bonus", "Cost: 64x BetterCoin");
createItem(inv, blank, 6, "", "");
createItem(inv, blank, 7, "", "");
createItem(inv, blank, 8, "", "");
//createItem(inv, blank, 0, "", "");
//createItem(inv, Material.EMERALD, 14, "dropTable", "Create new Drop Table");
player.openInventory(inv);
}
public boolean checkAndRemoveBetterCoins(Player player) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveBetterCoins called, player : "+player);
Inventory inventory = player.getInventory();
ItemStack betterCoinStack = getBetterCoinStack();
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveBetterCoins betterCoinStack: "+betterCoinStack);
// Sprawdź, czy gracz ma co najmniej 64 BetterCoin w ekwipunku
if (inventory.containsAtLeast(betterCoinStack, 64)) {
// Usuń 64 sztuki BetterCoin z ekwipunku gracza
inventory.removeItem(betterCoinStack);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveBetterCoins 64 BetterCoin found, removing : "+betterCoinStack);
return true;
}
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveBetterCoins 64 BetterCoin not found");
return false;
}

private ItemStack getBetterCoinStack() {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getBetterCoinStack called");
Material material = Material.HONEYCOMB;
int amount = 1;

ItemStack stack = new ItemStack(material, amount);
ItemMeta meta = stack.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.GOLD+"BetterCoin");
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getBetterCoinStack meta.getDisplayName(): "+meta.getDisplayName());
//Component displayNameComponent = new Component("BetterCoin");
List<String> lore = List.of(ChatColor.YELLOW+ "Valuable currency you can use to buy items.");
meta.setLore(lore);
stack.setItemMeta(meta);
}
return stack;
}
}

0 comments on commit 4120995

Please sign in to comment.