Skip to content

Commit

Permalink
Merge pull request #64 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 21, 2024
2 parents 5d33b2a + bcd345e commit 3e6c12d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 36 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.9-SNAPSHOT</version>
<version>4.3.15-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BetterElo</name>
Expand Down
62 changes: 33 additions & 29 deletions src/main/java/betterbox/mine/game/betterelo/BetterElo.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ public void onEnable() {
rewardStates.put("monthly", true);
// Inicjalizacja nagród i ich harmonogramów (kod z metody onEnable z klasy RewardManager)
loadRewards();
pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterElo: onEnable: Planowanie nagród dziennych...");
pluginLogger.log(PluginLogger.LogLevel.INFO,"Scheduling daily ranking rewards...");
scheduleRewards("daily", TimeUnit.DAYS.toMillis(1), false);
pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterElo: onEnable: Planowanie nagród tygodniowych...");
pluginLogger.log(PluginLogger.LogLevel.INFO,"Scheduling weekly ranking rewards...");
scheduleRewards("weekly", TimeUnit.DAYS.toMillis(7), false);
pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterElo: onEnable: Planowanie nagród miesięcznych...");
pluginLogger.log(PluginLogger.LogLevel.INFO,"Scheduling monthly ranking rewards...");
scheduleRewards("monthly", 0, true);

File dataFolder = this.getDataFolder();
Expand Down Expand Up @@ -346,35 +346,39 @@ public void scheduleRewards(String period, long periodMillis, boolean useNextMon
FileConfiguration config = getConfig();
long lastScheduledTime = config.getLong(period + "LastScheduledTime", System.currentTimeMillis());
long delay;
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: scheduleRewards: period: "+period+" periodMillis: "+periodMillis+" LastScheduledTime: "+lastScheduledTime);
if (useNextMonthTime) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(lastScheduledTime);
calendar.add(Calendar.MONTH, 1);
delay = (calendar.getTimeInMillis() - System.currentTimeMillis()) / 1000 * 20;
} else {
delay = (periodMillis - (System.currentTimeMillis() - lastScheduledTime)) / 1000 * 20;
}
try{
pluginLogger.log(PluginLogger.LogLevel.RANKING_REWARDS, "BetterElo: scheduleRewards: period: " + period + " periodMillis: " + periodMillis + " LastScheduledTime: " + lastScheduledTime);
if (useNextMonthTime) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(lastScheduledTime);
calendar.add(Calendar.MONTH, 1);
delay = (calendar.getTimeInMillis() - System.currentTimeMillis()) / 1000 * 20;
} else {
delay = (periodMillis - (System.currentTimeMillis() - lastScheduledTime)) / 1000 * 20;
}

pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: scheduleRewards: period: "+period+" periodMillis: "+periodMillis+" Computed delay: " + delay);
pluginLogger.log(PluginLogger.LogLevel.RANKING_REWARDS, "BetterElo: scheduleRewards: period: " + period + " periodMillis: " + periodMillis + " Computed delay: " + delay);

if (delay < 0) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: scheduleRewards: Negative delay detected, starting rewardAndReschedule");
rewardAndReschedule(period, periodMillis, useNextMonthTime);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: scheduleRewards: BukkitRunnable: rewardAndReschedule done");
return;
}
//saveConfig();
new BukkitRunnable() {
@Override
public void run() {
if (rewardStates.get(period)) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: scheduleRewards: BukkitRunnable: starting rewardAndReschedule");
rewardAndReschedule(period, periodMillis, useNextMonthTime);
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: scheduleRewards: BukkitRunnable: rewardAndReschedule done");
}
if (delay < 0) {
pluginLogger.log(PluginLogger.LogLevel.RANKING_REWARDS, "BetterElo: scheduleRewards: Negative delay detected, starting rewardAndReschedule");
rewardAndReschedule(period, periodMillis, useNextMonthTime);
pluginLogger.log(PluginLogger.LogLevel.INFO, "Ranking "+period+" has finished!");
return;
}
}.runTaskLater(this, delay);
//saveConfig();
new BukkitRunnable() {
@Override
public void run() {
if (rewardStates.get(period)) {
pluginLogger.log(PluginLogger.LogLevel.RANKING_REWARDS, "BetterElo: scheduleRewards: BukkitRunnable: starting rewardAndReschedule");
rewardAndReschedule(period, periodMillis, useNextMonthTime);
pluginLogger.log(PluginLogger.LogLevel.RANKING_REWARDS, "BetterElo: scheduleRewards: BukkitRunnable: rewardAndReschedule done");
}
}
}.runTaskLater(this, delay);
}catch (Exception e){
pluginLogger.log(PluginLogger.LogLevel.ERROR, "BetterElo: scheduleRewards exception: "+e.getMessage());
}
}
public void stopEvent(){
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.stopEvent called");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
case "reroll":
if(sender.isOp() || sender.hasPermission("betterelo.reroll")) {
handleRerollCommand(sender);
}else{
noPermission(sender);
}
break;
case "killallmobs":
Expand Down Expand Up @@ -843,5 +845,8 @@ public void handleAddSpawnerCommand(CommandSender sender, String spawnerName, St
pluginLogger.log(PluginLogger.LogLevel.WARNING, "BetterEloCommand:handleAddSpawnerCommand this is only-player command!");
}
}
private void noPermission(CommandSender sender){
sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " You don't have permission to use that command");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static String dropAverageDamage() {
// Używamy funkcji wykładniczej do zmniejszenia prawdopodobieństwa wyższych wartości
double x = -Math.log(random.nextDouble()) / 10.0; // Dostosuj parametr 10.0, aby zmienić rozkład
//double y = random.
int bonus = (int) Math.round(x * 40); // Skalowanie wyniku
int bonus = (int) Math.round(x * 60); // Skalowanie wyniku

// Ograniczamy wartość bonusu do maksymalnie 60%
bonus = Math.min(bonus, 60);
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/betterbox/mine/game/betterelo/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,11 @@ public boolean isValidAverageDamage (ArrayList<ItemStack> equippedItems){
}
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (player.hasMetadata("avgDmgRerolled")) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick avgDmgRerolled event already handled!");
return;
}
if(event.getCurrentItem()==null){
return;
}
Expand All @@ -1250,7 +1255,7 @@ public void onInventoryClick(InventoryClickEvent event) {
event.setCancelled(true);

}
Player player = (Player) event.getWhoClicked();

ItemStack currentItem = event.getCurrentItem();
Inventory playerInventory = player.getInventory();
ItemStack[] savedInventory = playerInventory.getContents();
Expand Down Expand Up @@ -1340,6 +1345,7 @@ public void onInventoryClick(InventoryClickEvent event) {
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"));
Expand All @@ -1357,6 +1363,13 @@ public void onInventoryClick(InventoryClickEvent event) {
if( guiManager.checkAndRemoveBetterCoins(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));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
player.removeMetadata("avgDmgRerolled", plugin);
}
}, 1L);
break;
}
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, player has no money for the re-roll." );
Expand Down Expand Up @@ -1384,9 +1397,9 @@ public void onInventoryClose(InventoryCloseEvent event) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Checking items in closed GUI");

ItemStack itemInSlot0 = closedInventory.getItem(3);
if (itemInSlot0 != null && itemInSlot0.hasItemMeta()) {
if (itemInSlot0 != null) {
ItemMeta meta = itemInSlot0.getItemMeta();
if (meta.getLore().stream().anyMatch(line -> line.contains("Average Damage"))) {
//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
Expand All @@ -1400,7 +1413,7 @@ public void onInventoryClose(InventoryCloseEvent event) {
pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Inventory full, item dropped at player's location");
closedInventory.clear(3); // Clear the slot
}
}
//}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PluginLogger {

// Enumeracja dla poziomów logowania
public enum LogLevel {
INFO, WARNING, ERROR,CUSTOM_MOBS, DEBUG, DEBUG_LVL2, DEBUG_LVL3,DEBUG_LVL4,CHEATERS ,FLAMETHROWER,DROP,SPAWNERS, ZEPHYR, KILL_EVENT, COMMAND, PLACEHOLDER, BLOCK_BREAK, BLOCK_PLACE, PLAYER_INTERACT, ELYTRA_CHECK, ANTYWEB
INFO, WARNING, ERROR,CUSTOM_MOBS, DEBUG, DEBUG_LVL2, DEBUG_LVL3,DEBUG_LVL4,CHEATERS, RANKING_REWARDS ,FLAMETHROWER,DROP,SPAWNERS, ZEPHYR, KILL_EVENT, COMMAND, PLACEHOLDER, BLOCK_BREAK, BLOCK_PLACE, PLAYER_INTERACT, ELYTRA_CHECK, ANTYWEB
}

public PluginLogger(String folderPath, Set<LogLevel> enabledLogLevels, JavaPlugin plugin) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,9 @@ permissions:
betterelo.flamethrower:
description: flamethrower
default: op
betterelo.reroll:
description: Grants access to /be reroll
default: op



0 comments on commit 3e6c12d

Please sign in to comment.