Skip to content

Commit

Permalink
add isLogging() check to everything
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Jul 6, 2024
1 parent 32cd767 commit 974bd55
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
### Fixed:
- Player Heads were not stacking previously, they should now.
### Changes:
- `verbose_logging` in `config.yml` now applies to everything including errors, turn it on if something isn't working.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

val buildNumber: String? = System.getenv("BUILD_NUMBER")

rootProject.version = if (buildNumber != null) "${libs.versions.minecraft.get()}-$buildNumber" else "3.4.4"
rootProject.version = if (buildNumber != null) "${libs.versions.minecraft.get()}-$buildNumber" else "3.4.5"

val isSnapshot = false

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ triumph-cmd = "2.0.0-ALPHA-10"
tirumph-gui = "3.1.7"
jetbrains = "24.1.0"
kyori = "4.17.0"
vital = "5523333"
vital = "1.8.2"

# Paper
paperweight = "1.7.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ private static void runCommands(@NotNull final Player player, @NotNull final Pri
} catch (Exception e) {
commandBuilder.append("1 ");

plugin.getLogger().warning("The prize " + prize.getPrizeName() + " in the " + prize.getCrateName() + " crate has caused an error when trying to run a command.");
plugin.getLogger().warning("Command: " + cmd);
if (MiscUtils.isLogging()) {
plugin.getLogger().warning("The prize " + prize.getPrizeName() + " in the " + prize.getCrateName() + " crate has caused an error when trying to run a command.");
plugin.getLogger().warning("Command: " + cmd);
}
}
} else {
commandBuilder.append(word).append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,15 @@ public final boolean isCrateEventValid(@NotNull final KeyType keyType, final boo
event.callEvent();

if (event.isCancelled()) {
List.of(
"Crate " + this.crate.getName() + " event has been cancelled.",
"A few reasons for why this happened can be found below",
"",
" 1) No valid prizes can be found, Likely a yaml issue.",
" 2) The player does not have the permission to open the crate."
).forEach(this.plugin.getLogger()::warning);
if (MiscUtils.isLogging()) {
List.of(
"Crate " + this.crate.getName() + " event has been cancelled.",
"A few reasons for why this happened can be found below",
"",
" 1) No valid prizes can be found, Likely a yaml issue.",
" 2) The player does not have the permission to open the crate."
).forEach(this.plugin.getLogger()::warning);
}
}

return event.isCancelled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public Prize pickPrize(@NotNull final Player player) {
try {
return prizes.get(random.nextInt(prizes.size()));
} catch (IllegalArgumentException exception) {
this.plugin.getLogger().log(Level.WARNING, "Failed to find prize from the " + name + " crate for player " + player.getName() + ".", exception);
if (MiscUtils.isLogging()) this.plugin.getLogger().log(Level.WARNING, "Failed to find prize from the " + name + " crate for player " + player.getName() + ".", exception);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public static ItemBuilder convertString(String itemString, String section) {
} catch (Exception exception) {
itemBuilder.withType(Material.RED_TERRACOTTA).setDisplayName("<red>Error found!, Prize Name: " + section);

plugin.getLogger().log(Level.WARNING, "An error has occurred with the item builder: ", exception);
if (MiscUtils.isLogging()) plugin.getLogger().log(Level.WARNING, "An error has occurred with the item builder: ", exception);
}

return itemBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static boolean isInventoryFull(@NotNull final Player player) {

return leftover;
} else {
plugin.getLogger().info("Items cannot be null.");
if (MiscUtils.isLogging()) plugin.getLogger().info("Items cannot be null.");
}

return null;
Expand All @@ -174,19 +174,21 @@ private static int getFirstItem(@Nullable final ItemStack item, final boolean ge
}

public static void failedToTakeKey(@NotNull final CommandSender player, @NotNull final String crateName) {
List.of(
"An error has occurred while trying to take a key from a player.",
"Player: " + player.getName(),
"Key: " + crateName
).forEach(plugin.getLogger()::warning);

List.of(
"<red>An issue has occurred when trying to take a key.",
"<red>A list of potential reasons",
"",
" <yellow>-> <light_purple>Not enough keys.",
" <yellow>-> <light_purple>Key is in off hand."
).forEach(line -> player.sendRichMessage(MsgUtils.getPrefix(line)));
if (MiscUtils.isLogging()) {
List.of(
"An error has occurred while trying to take a key from a player.",
"Player: " + player.getName(),
"Key: " + crateName
).forEach(plugin.getLogger()::warning);

List.of(
"<red>An issue has occurred when trying to take a key.",
"<red>A list of potential reasons",
"",
" <yellow>-> <light_purple>Not enough keys.",
" <yellow>-> <light_purple>Key is in off hand."
).forEach(line -> player.sendRichMessage(MsgUtils.getPrefix(line)));
}
}

public static long pickNumber(long min, long max) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void open(Player player, @Suggestion("crates") String crateName, @Suggest
if (crateType == null || crate.getCrateType() == CrateType.menu) {
player.sendRichMessage(Messages.internal_error.getMessage(player));

this.plugin.getLogger().severe("An error has occurred: The crate type is null or Menu for the crate named " + crate.getName());
if (MiscUtils.isLogging()) this.plugin.getLogger().severe("An error has occurred: The crate type is null or Menu for the crate named " + crate.getName());

return;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public void others(CommandSender sender, @Suggestion("crates") String crateName,
if (crateType == null) {
player.sendRichMessage(Messages.internal_error.getMessage(player));

this.plugin.getLogger().severe("An error has occurred: The crate type is null for the crate named " + crate.getName());
if (MiscUtils.isLogging()) this.plugin.getLogger().severe("An error has occurred: The crate type is null for the crate named " + crate.getName());

return;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public void forceopen(CommandSender sender, @Suggestion("crates") String crateNa
if (crateType == null) {
player.sendRichMessage(Messages.internal_error.getMessage(player));

this.plugin.getLogger().severe("An error has occurred: The crate type is null for the crate named " + crate.getName());
if (MiscUtils.isLogging()) this.plugin.getLogger().severe("An error has occurred: The crate type is null for the crate named " + crate.getName());

return;
}
Expand Down Expand Up @@ -258,7 +258,7 @@ public void mass(Player player, @Suggestion("crates") String crateName, @Suggest
if (crateType == null) {
player.sendRichMessage(Messages.internal_error.getMessage(player));

this.plugin.getLogger().severe("An error has occurred: The crate type is null for the crate named " + crate.getName());
if (MiscUtils.isLogging()) this.plugin.getLogger().severe("An error has occurred: The crate type is null for the crate named " + crate.getName());

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ public void run() {

// Send refund notices.
player.sendRichMessage(MsgUtils.getPrefix("<red>An issue has occurred and so a key refund was given."));
plugin.getLogger().log(Level.SEVERE, "An issue occurred when the user " + player.getName() + " was using the " + crate.getName() + " crate and so they were issued a key refund.", exception);

if (MiscUtils.isLogging()) plugin.getLogger().log(Level.SEVERE, "An issue occurred when the user " + player.getName() + " was using the " + crate.getName() + " crate and so they were issued a key refund.", exception);

// Play a sound
crate.playSound(player, player.getLocation(), "stop-sound", "block.anvil.place", Sound.Source.PLAYER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.badbones69.crazycrates.support.placeholders;

import com.badbones69.crazycrates.api.utils.MiscUtils;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import me.clip.placeholderapi.PlaceholderAPI;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -87,7 +88,7 @@ public class PlaceholderAPISupport extends PlaceholderExpansion {
final Crate crate = this.crateManager.getCrateFromName(crateName);

if (crate == null) {
this.plugin.getLogger().warning("Crate: " + crateName + " is not a valid crate name.");
if (MiscUtils.isLogging()) this.plugin.getLogger().warning("Crate: " + crateName + " is not a valid crate name.");

return "N/A";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public boolean addOfflineKeys(@NotNull final UUID uuid, @NotNull final String cr

return true;
} catch (Exception exception) {
this.plugin.getLogger().log(Level.SEVERE, "Could not add keys to offline player with uuid: " + uuid, exception);
if (MiscUtils.isLogging()) this.plugin.getLogger().log(Level.SEVERE, "Could not add keys to offline player with uuid: " + uuid, exception);

return false;
}
Expand Down Expand Up @@ -405,7 +405,7 @@ public boolean takeOfflineKeys(@NotNull final UUID uuid, @NotNull final String c

return true;
} catch (Exception exception) {
this.plugin.getLogger().log(Level.SEVERE, "Could not take keys from offline player with uuid: " + uuid, exception);
if (MiscUtils.isLogging()) this.plugin.getLogger().log(Level.SEVERE, "Could not take keys from offline player with uuid: " + uuid, exception);

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public void reloadCrate(@Nullable final Crate crate) {
this.inventoryManager.purge();
} catch (Exception exception) {
this.brokeCrates.add(crate.getName());
this.plugin.getLogger().log(Level.WARNING, "There was an error while loading the " + crate.getName() + ".yml file.", exception);

if (MiscUtils.isLogging()) this.plugin.getLogger().log(Level.WARNING, "There was an error while loading the " + crate.getName() + ".yml file.", exception);
}
}

Expand Down Expand Up @@ -367,7 +368,8 @@ public void loadCrates() {
}
} catch (Exception exception) {
this.brokeCrates.add(crateName);
this.plugin.getLogger().log(Level.WARNING, "There was an error while loading the " + crateName + ".yml file.", exception);

if (MiscUtils.isLogging()) this.plugin.getLogger().log(Level.WARNING, "There was an error while loading the " + crateName + ".yml file.", exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ public void open(@NotNull final KeyType type, final boolean checkHand) {
final String row_tres = section.getString("types.row-3", "");

if (row_uno.isEmpty() || row_dos.isEmpty() || row_tres.isEmpty()) {
this.plugin.getLogger().warning("One of your tiers in the config is empty.");
this.plugin.getLogger().warning("Tier 1: " + row_uno);
this.plugin.getLogger().warning("Tier 2: " + row_dos);
this.plugin.getLogger().warning("Tier 3:" + row_tres);
if (MiscUtils.isLogging()) {
this.plugin.getLogger().warning("One of your tiers in the config is empty.");
this.plugin.getLogger().warning("Tier 1: " + row_uno);
this.plugin.getLogger().warning("Tier 2: " + row_dos);
this.plugin.getLogger().warning("Tier 3:" + row_tres);
}

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ public void open(@NotNull final KeyType type, final boolean checkHand) {
try {
reward = player.getWorld().dropItem(getLocation().clone().add(.5, 1, .5), display);
} catch (IllegalArgumentException exception) {
this.plugin.getLogger().warning("A prize could not be given due to an invalid display item for this prize.");
this.plugin.getLogger().log(Level.WARNING, "Crate: " + prize.getCrateName() + " Prize: " + prize.getPrizeName(), exception);
if (MiscUtils.isLogging()) {
this.plugin.getLogger().warning("A prize could not be given due to an invalid display item for this prize.");
this.plugin.getLogger().log(Level.WARNING, "Crate: " + prize.getCrateName() + " Prize: " + prize.getPrizeName(), exception);
}

return;
}
Expand Down

0 comments on commit 974bd55

Please sign in to comment.