Skip to content

Commit 98a2018

Browse files
committed
Added logger so you can turn of the logging
1 parent 4602f52 commit 98a2018

9 files changed

Lines changed: 30 additions & 16 deletions

File tree

Block Visualization/src/main/java/org/broken/arrow/visualization/library/utility/EntityModifications.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ private FallingBlock spawnFallingBlock(final Location loc, final Material materi
9393
} else {
9494
try {
9595
return (FallingBlock) loc.getWorld().getClass().getMethod("spawnFallingBlock", Location.class, Integer.TYPE, Byte.TYPE).invoke(loc.getWorld(), loc, material.getId(), data);
96-
} catch (final ReflectiveOperationException var4) {
97-
var4.printStackTrace();
96+
} catch (final ReflectiveOperationException error) {
97+
log.logError(error,() -> of("Could create a falling block. You probably trying this on to old version of Minecraft as it does only supports 1.8.8 and up, your version: " + serverVersion));
9898
return null;
9999
}
100100
}

Commands/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ description = "Commands"
1414
version = "1.0-SNAPSHOT"
1515

1616
dependencies {
17+
api(project(":log-and-validate"))
1718
api(project(":color-conversion"))
1819
compileOnly(libs.org.spigotmc.spigotapi)
1920
compileOnly(libs.google.findbugs.jsr305)

Commands/src/main/java/org/broken/arrow/command/library/CommandRegister.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.broken.arrow.command.library.command.CommandProperty;
55
import org.broken.arrow.command.library.commandhandler.CommandExecutor;
66
import org.broken.arrow.command.library.commandhandler.CommandRegistering;
7+
import org.broken.arrow.logging.library.Logging;
78
import org.bukkit.Bukkit;
89
import org.bukkit.command.Command;
910
import org.bukkit.command.CommandException;
@@ -24,6 +25,7 @@
2425
* retrieving sub-commands, and registering the main command label.
2526
*/
2627
public class CommandRegister implements CommandRegistering {
28+
private Logging log = new Logging(CommandRegister.class);
2729

2830
private final List<CommandProperty> commands = Collections.synchronizedList(new ArrayList<>());
2931
private String commandLabelMessage;
@@ -353,7 +355,7 @@ public void register(final String fallbackPrefix, final Command command) {
353355

354356
commandMap.register(fallbackPrefix, command);
355357
} catch (final NoSuchFieldException | IllegalAccessException e) {
356-
e.printStackTrace();
358+
log.log(e,() -> Logging.of("It failed to register your command"));
357359
}
358360
}
359361

Database/src/main/java/org/broken/arrow/database/library/core/databases/MySQL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void createMissingDatabase() {
139139
close(create);
140140
}
141141
} catch (SQLException e) {
142-
e.printStackTrace();
142+
log.log(e, () -> of("Failed to connect to the database with the database name: " + databaseName));
143143
}
144144
}
145145

Database/src/main/java/org/broken/arrow/database/library/core/databases/PostgreSQL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private void createMissingDatabase() {
155155
}
156156
}
157157
} catch (SQLException e) {
158-
e.printStackTrace();
158+
log.log(e, () -> of("Failed to connect to the database with the database name: " + databaseName));
159159
}
160160
}
161161

Item Creator/src/main/java/org/broken/arrow/itemcreator/library/SkullCreator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.Base64;
2323
import java.util.UUID;
2424

25+
import static org.broken.arrow.logging.library.Logging.of;
26+
2527
/**
2628
* A library for the Bukkit API to create player skulls
2729
* from names, base64 strings, and texture URLs.
@@ -298,7 +300,7 @@ private static void mutateBlockState(Skull block, String b64) {
298300
}
299301
blockProfileField.set(block, makeProfile(b64));
300302
} catch (NoSuchFieldException | IllegalAccessException e) {
301-
e.printStackTrace();
303+
LOG.log(e, () -> of("Failed to change the skull block"));
302304
}
303305
}
304306

Serialize Utility/src/main/java/org/broken/arrow/serialize/library/utility/converters/Base64ItemStackConverter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.broken.arrow.serialize.library.utility.converters;
22

3+
import org.broken.arrow.logging.library.Logging;
34
import org.bukkit.inventory.ItemStack;
45
import org.bukkit.util.io.BukkitObjectInputStream;
56
import org.bukkit.util.io.BukkitObjectOutputStream;
@@ -10,11 +11,13 @@
1011
import java.io.ByteArrayOutputStream;
1112
import java.io.IOException;
1213

14+
import static org.broken.arrow.logging.library.Logging.of;
15+
1316
/**
1417
* This class provides methods to convert an array of ItemStacks to and from a Base64 string representation.
1518
*/
1619
public class Base64ItemStackConverter {
17-
20+
private static final Logging log = new Logging(Base64ItemStackConverter.class);
1821
private Base64ItemStackConverter() {
1922
}
2023

@@ -41,7 +44,7 @@ public static String itemStackArrayToBase64(@Nonnull final ItemStack[] items) {
4144
// Serialize that array
4245
dataOutput.close();
4346
} catch (final IOException exception) {
44-
exception.printStackTrace();
47+
log.log(exception, () -> of("Failed to convert the items to base64"));
4548
}
4649
return Base64Coder.encodeLines(outputStream.toByteArray());
4750
}
@@ -65,7 +68,7 @@ public static ItemStack[] itemStackArrayFromBase64(@Nonnull final String data) {
6568
}
6669
dataInput.close();
6770
} catch (final IOException | ClassNotFoundException e) {
68-
e.printStackTrace();
71+
log.log(e, () -> of("Failed to convert the itemsfrom base64"));
6972
}
7073
return items;
7174
}

Yaml Utility/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ version = "1.0-SNAPSHOT"
1515

1616

1717
dependencies {
18+
api(project(":log-and-validate"))
1819
api(project(":serialize-utility"))
1920
compileOnly(libs.org.spigotmc.spigotapi)
2021
compileOnly(libs.google.findbugs.jsr305)

Yaml Utility/src/main/java/org/broken/arrow/yaml/library/YamlFileManager.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.broken.arrow.yaml.library;
22

33

4+
import org.broken.arrow.logging.library.Logging;
45
import org.broken.arrow.logging.library.Validate;
56
import org.broken.arrow.serialize.library.utility.serialize.ConfigurationSerializable;
67
import org.broken.arrow.serialize.library.utility.serialize.MethodReflectionUtils;
@@ -42,13 +43,16 @@
4243
import java.util.jar.JarFile;
4344
import java.util.logging.Level;
4445

46+
import static org.broken.arrow.logging.library.Logging.of;
47+
4548
/**
4649
* Helper class to load and save data from one or several files.
4750
* Provides methods for serialization and file operations.
4851
*/
4952
public abstract class YamlFileManager {
53+
private final Logging log = new Logging(YamlFileManager.class);
5054

51-
private FileConfiguration currentConfig;
55+
private FileConfiguration currentConfig;
5256
private File currentConfigFile;
5357
private final File dataFolder;
5458
private boolean shallGenerateFiles;
@@ -159,7 +163,8 @@ public final void update(@Nullable File file, final String resource, final Strin
159163
try {
160164
this.configUpdater.update(getVersion(), resourcePathToFile != null ? resourcePathToFile : this.getPathWithExtension(), file);
161165
} catch (final IOException e) {
162-
e.printStackTrace();
166+
String name = file.getName();
167+
log.log(e, () -> of("Failed to update the file: " + name));
163168
} finally {
164169
currentConfig = YamlConfiguration.loadConfiguration(file);
165170
}
@@ -177,7 +182,7 @@ public void reload() {
177182
load(getFilesInPluginFolder(this.getPath()));
178183
}
179184
} catch (final IOException | InvalidConfigurationException e) {
180-
e.printStackTrace();
185+
log.log(e, () -> of("Failed to reload the config"));
181186
}
182187
}
183188

@@ -313,7 +318,7 @@ private void saveSpecificFile(final String fileToSave, final File folder, final
313318
try {
314319
newDataFolder.createNewFile();
315320
} catch (final IOException e) {
316-
e.printStackTrace();
321+
log.log(e, () -> of("Failed to save the file to disk: "+ fileToSave ));
317322
} finally {
318323
saveData(newDataFolder);
319324
}
@@ -351,7 +356,7 @@ public void saveToFile(@Nonnull final File file, @Nonnull final FileConfiguratio
351356
if (updateData)
352357
update(file);
353358
} catch (final IOException e) {
354-
e.printStackTrace();
359+
log.log(e, () -> of("Could not save data to file " + file.getName()));
355360
}
356361
}
357362

@@ -707,7 +712,7 @@ public List<String> getFilenamesForDirnameFromCP(final String directoryName) {
707712
}
708713
}
709714
} catch (final URISyntaxException e) {
710-
e.printStackTrace();
715+
log.log(e, () -> of("Could not retrieve the file from your plugin jar. From the directory: " + directoryName));
711716
}
712717
} else if (url.getProtocol().equals("jar")) {
713718
getFileFromJar(directoryName, filenames, url);
@@ -739,7 +744,7 @@ private void getFileFromJar(final String directoryName, final List<String> filen
739744
}
740745
}
741746
} catch (final IOException e) {
742-
e.printStackTrace();
747+
log.log(e, () -> of("Could not add the file to the list. From the directory: " + directoryName));
743748
}
744749
}
745750

0 commit comments

Comments
 (0)