Skip to content

Commit

Permalink
Merge pull request #65 from Grzybol/patch-4.3.0
Browse files Browse the repository at this point in the history
Patch 4.3.0
  • Loading branch information
Grzybol authored Apr 27, 2024
2 parents f3be99a + 78a7013 commit e1cf09e
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 14 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.3.15-SNAPSHOT</version>
<version>4.3.25-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down
19 changes: 19 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,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
break;
case 1:
switch (args[0].toLowerCase()) {
case "enchantitem":
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand.onCommand enchantitem called, sender: "+sender);
if(!sender.isOp()){
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " You don't have permission to use that command!");
break;
}
createEncahntItem(sender);
break;
case "reroll":
if(sender.isOp() || sender.hasPermission("betterelo.reroll")) {
handleRerollCommand(sender);
Expand Down Expand Up @@ -755,6 +763,17 @@ public void handleRerollCommand (CommandSender sender){
guiManager.openReRollGui(player);
}
}

private void createEncahntItem(CommandSender sender){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand.createEncahntItem called, sender: "+sender);
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " This command can only be used by online players.");
return ;
}
Player player = (Player) sender;
ItemStack enchantItem = guiManager.getEnchantItem();
player.getInventory().addItem(enchantItem);
}
public void addAntywebLore(Player player, ItemStack itemStack, int radius) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/betterbox/mine/game/betterelo/CustomMobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ static class CustomMob {
}

this.entityType = entityType;
this.helmet = helmet;
this.chestplate = chestplate;
this.leggings = leggings;
this.boots = boots;
if(helmet!=null) {
this.helmet = helmet;
}
if(chestplate!=null) {
this.chestplate = chestplate;
}
if(leggings!=null) {
this.leggings = leggings;
}
if(boots!=null) {
this.boots = boots;
}
this.dropFileManager = dropFileManager;
this.dropTableName = dropTableName;
//this.dropTable = dropFileManager.loadCustomDrops(dropTableName);
Expand Down Expand Up @@ -357,6 +365,9 @@ public void loadCustomMobs() {
CustomMob customMob = fileManager.loadCustomMob(plugin, fileRewardManager, mobFile);
if (customMob != null) {
customMobsMap.put(customMob.getMobName(), customMob);
}else
{
pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.loadCustomMobs could not load custom mob "+customMob);
}
} catch (Exception e) {
pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.loadCustomMobs exception: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,21 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d

if(mobData.contains("dropEMKS")){
dropEMKS = mobData.getBoolean("dropEMKS");
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.loadCustomMob loaded dropEMKS:" + dropEMKS);
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded dropEMKS:" + dropEMKS);
}
if(mobData.contains("EMKSchance")){
EKMSchance = mobData.getDouble("EMKSchance");
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.loadCustomMob loaded EKMSchance:" + EKMSchance);
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded EKMSchance:" + EKMSchance);
}
if(mobData.contains("attackSpeed")){
attackSpeed = mobData.getInt("attackSpeed");
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.loadCustomMob loaded AttackSpeed:" + attackSpeed);
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded AttackSpeed:" + attackSpeed);
}
String entityTypeString = mobData.getString("type");
String mobName = mobData.getString("mobName");
String dropTableName = mobData.getString("dropTable");

pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.loadCustomMob armor:" + armor + ", hp: " + hp + ", speed: " + speed + ", attackDamage: " + attackDamage + ", type: " + entityTypeString+", dropEMKS: "+dropEMKS+", EKMSchance: "+EKMSchance+", dropTablename: "+dropTableName);
pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob armor:" + armor + ", hp: " + hp + ", speed: " + speed + ", attackDamage: " + attackDamage + ", type: " + entityTypeString+", dropEMKS: "+dropEMKS+", EKMSchance: "+EKMSchance+", dropTablename: "+dropTableName);
EntityType entityType = EntityType.valueOf(entityTypeString);

// Wczytanie niestandardowych metadanych i ustawienie spawnerName
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/betterbox/mine/game/betterelo/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ public void onBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
String uuid = player.getUniqueId().toString();
double base = configManager.blockBase;

if(!isEloAllowed(player,player.getLocation())){
pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL2, "Event: onPlayerDeath noElo zone!");
player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo] " + ChatColor.DARK_RED + "No elo reward in this zone!");
return;
}
double playerElo = dataManager.getPoints(uuid,"main");
double pointsEarnedMain = calculatePointsEarnedFromBlock(base,playerElo,blockReward, dataManager.getMaxElo("main"), dataManager.getMinElo("main"));
addPoints(uuid,pointsEarnedMain,"main");
Expand Down Expand Up @@ -1357,10 +1361,13 @@ public void onInventoryClick(InventoryClickEvent event) {
ItemStack result = item0.clone();
ItemMeta resultMeta = result.getItemMeta();
List<String> lore = new ArrayList<>(resultMeta.getLore());
boolean mobDamage=false;
for (int i = 0; i < lore.size(); i++) {
if (lore.get(i).contains("Average Damage")) {
if(lore.get(i).contains("Mob Damage"))
mobDamage=true;
if (lore.get(i).contains("Average Damage") && mobDamage) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, Average Damage lore line found i: " + i);
if( guiManager.checkAndRemoveBetterCoins(player)) {
if( guiManager.checkAndRemoveEnchantItem(player)) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, player paid, re-rolling..." );
lore.set(i, customMobs.dropAverageDamage());
player.setMetadata("avgDmgRerolled", new FixedMetadataValue(plugin, true));
Expand Down
47 changes: 45 additions & 2 deletions src/main/java/betterbox/mine/game/betterelo/GuiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
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.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -120,8 +122,11 @@ private void updateResultSlot(Inventory inv) {
ItemStack result = item0.clone();
ItemMeta resultMeta = result.getItemMeta();
List<String> lore = new ArrayList<>(resultMeta.getLore());
boolean mobDamage = false;
for (int i = 0; i < lore.size(); i++) {
if (lore.get(i).contains("Average Damage")) {
if(lore.get(i).contains("Mob Damage"))
mobDamage=true;
if (lore.get(i).contains("Average Damage")&& mobDamage) {
lore.set(i, customMobs.dropAverageDamage());
break;
}
Expand Down Expand Up @@ -157,7 +162,7 @@ public void openReRollGui(Player player){
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, Material.GREEN_WOOL, 5, "Re-Roll Average Damage bonus", "Cost: 1x "+ChatColor.DARK_PURPLE+""+ChatColor.BOLD+"Enchant Item");
createItem(inv, blank, 6, "", "");
createItem(inv, blank, 7, "", "");
createItem(inv, blank, 8, "", "");
Expand All @@ -180,6 +185,44 @@ public boolean checkAndRemoveBetterCoins(Player player) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveBetterCoins 64 BetterCoin not found");
return false;
}
public boolean checkAndRemoveEnchantItem(Player player) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveEnchantItem called, player : "+player);
Inventory inventory = player.getInventory();
ItemStack enchantItemStack = getEnchantItem();
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveEnchantItem betterCoinStack: "+enchantItemStack);
// Sprawdź, czy gracz ma co najmniej 64 BetterCoin w ekwipunku
if (inventory.containsAtLeast(enchantItemStack, 1)) {
// Usuń 64 sztuki BetterCoin z ekwipunku gracza
inventory.removeItem(enchantItemStack);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveEnchantItem 1 Enchant Item found, removing : "+enchantItemStack);
return true;
}
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveEnchantItem 1 Enchant Item not found");
return false;
}
public ItemStack getEnchantItem(){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getEnchantItem called");
Material material = Material.GHAST_TEAR;
int amount = 1;

ItemStack stack = new ItemStack(material, amount);
ItemMeta meta = stack.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.DARK_PURPLE+""+ ChatColor.BOLD+"Enchant Item");
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getEnchantItem meta.getDisplayName(): "+meta.getDisplayName());
//Component displayNameComponent = new Component("BetterCoin");
List<String> lore = List.of(ChatColor.GRAY+ "Removes current the Average Damage bonus",ChatColor.GRAY+ " from the item and adds new one.");
meta.setLore(lore);
// Dodajemy niestandardowy enchant, który nie wpływa na działanie itemu
meta.addEnchant(Enchantment.LUCK, 1, true);

// Ukrywamy wszystkie informacje o zaklęciach na itemie
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);

stack.setItemMeta(meta);
}
return stack;
}

private ItemStack getBetterCoinStack() {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getBetterCoinStack called");
Expand Down

0 comments on commit e1cf09e

Please sign in to comment.