mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 22:16:22 +00:00
Remove HuskHomes exceptions
This commit is contained in:
1 parent
23a7b2a903
commit
6a8851a446
12 files changed
+32
-51
No files matched your search
@@ -124,7 +124,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
}
|
}
|
||||||
getLoggingAdapter().log(Level.INFO, "Successfully loaded plugin configuration settings & locales");
|
getLoggingAdapter().log(Level.INFO, "Successfully loaded plugin configuration settings & locales");
|
||||||
} else {
|
} else {
|
||||||
throw new HuskHomesInitializationException("Failed to load plugin configuration settings and/or locales");
|
throw new IllegalStateException("Failed to load plugin configuration settings and/or locales");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the database
|
// Initialize the database
|
||||||
@@ -138,7 +138,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
if (initialized.get()) {
|
if (initialized.get()) {
|
||||||
getLoggingAdapter().log(Level.INFO, "Successfully established a connection to the database");
|
getLoggingAdapter().log(Level.INFO, "Successfully established a connection to the database");
|
||||||
} else {
|
} else {
|
||||||
throw new HuskHomesInitializationException("Failed to establish a connection to the database. " + "Please check the supplied database credentials in the config file");
|
throw new IllegalStateException("Failed to establish a connection to the database. " + "Please check the supplied database credentials in the config file");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the network messenger if proxy mode is enabled
|
// Initialize the network messenger if proxy mode is enabled
|
||||||
@@ -262,7 +262,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (HuskHomesInitializationException exception) {
|
} catch (IllegalStateException exception) {
|
||||||
getLoggingAdapter().log(Level.SEVERE, exception.getMessage());
|
getLoggingAdapter().log(Level.SEVERE, exception.getMessage());
|
||||||
initialized.set(false);
|
initialized.set(false);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
@@ -357,7 +357,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
@Override
|
@Override
|
||||||
public Messenger getMessenger() {
|
public Messenger getMessenger() {
|
||||||
if (messenger == null) {
|
if (messenger == null) {
|
||||||
throw new HuskHomesException("Attempted to access network messenger when it was not initialized");
|
throw new IllegalStateException("Attempted to access network messenger when it was not initialized");
|
||||||
}
|
}
|
||||||
return messenger;
|
return messenger;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package net.william278.huskhomes.hook;
|
|||||||
|
|
||||||
import dev.unnm3d.rediseconomy.api.RedisEconomyAPI;
|
import dev.unnm3d.rediseconomy.api.RedisEconomyAPI;
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesInitializationException;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class RedisEconomyHook extends VaultEconomyHook {
|
public class RedisEconomyHook extends VaultEconomyHook {
|
||||||
@@ -12,7 +11,7 @@ public class RedisEconomyHook extends VaultEconomyHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initialize() throws HuskHomesInitializationException {
|
public boolean initialize() {
|
||||||
RedisEconomyAPI api = RedisEconomyAPI.getAPI();
|
RedisEconomyAPI api = RedisEconomyAPI.getAPI();
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
economy = api.getCurrencyByName(plugin.getSettings().redisEconomyName);
|
economy = api.getCurrencyByName(plugin.getSettings().redisEconomyName);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.william278.huskhomes.hook;
|
|||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import net.william278.huskhomes.BukkitHuskHomes;
|
import net.william278.huskhomes.BukkitHuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesInitializationException;
|
|
||||||
import net.william278.huskhomes.player.BukkitPlayer;
|
import net.william278.huskhomes.player.BukkitPlayer;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -22,7 +21,7 @@ public class VaultEconomyHook extends EconomyHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initialize() throws HuskHomesInitializationException {
|
public boolean initialize() {
|
||||||
final RegisteredServiceProvider<Economy> economyProvider = ((BukkitHuskHomes) plugin).getServer()
|
final RegisteredServiceProvider<Economy> economyProvider = ((BukkitHuskHomes) plugin).getServer()
|
||||||
.getServicesManager().getRegistration(Economy.class);
|
.getServicesManager().getRegistration(Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.william278.huskhomes.player;
|
|||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.william278.huskhomes.BukkitHuskHomes;
|
import net.william278.huskhomes.BukkitHuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesException;
|
|
||||||
import net.william278.huskhomes.position.Location;
|
import net.william278.huskhomes.position.Location;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.teleport.TeleportResult;
|
import net.william278.huskhomes.teleport.TeleportResult;
|
||||||
@@ -73,7 +72,7 @@ public class BukkitPlayer extends OnlineUser {
|
|||||||
@Override
|
@Override
|
||||||
public Position getPosition() {
|
public Position getPosition() {
|
||||||
return new Position(BukkitAdapter.adaptLocation(player.getLocation())
|
return new Position(BukkitAdapter.adaptLocation(player.getLocation())
|
||||||
.orElseThrow(() -> new HuskHomesException("Failed to get the position of a BukkitPlayer (null)")),
|
.orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
|
||||||
plugin.getServerName());
|
plugin.getServerName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public interface HuskHomes {
|
|||||||
* @return the {@link Messenger} implementation
|
* @return the {@link Messenger} implementation
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
Messenger getMessenger() throws HuskHomesException;
|
Messenger getMessenger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link RandomTeleportEngine} that manages random teleports
|
* The {@link RandomTeleportEngine} that manages random teleports
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package net.william278.huskhomes;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates an exception caused by HuskHomes' plugin logic occurred
|
|
||||||
*/
|
|
||||||
public class HuskHomesException extends RuntimeException {
|
|
||||||
|
|
||||||
public HuskHomesException(@NotNull String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HuskHomesException(@NotNull String message, @NotNull Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package net.william278.huskhomes;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates an exception occurred while initialising the HuskHomes plugin
|
|
||||||
*/
|
|
||||||
public class HuskHomesInitializationException extends HuskHomesException {
|
|
||||||
public HuskHomesInitializationException(@NotNull String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.william278.huskhomes;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ValidationException extends IllegalArgumentException {
|
||||||
|
|
||||||
|
public ValidationException(@NotNull ValidationError error) {
|
||||||
|
super("Error validating position: " + error.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ValidationError {
|
||||||
|
NAME_LENGTH,
|
||||||
|
NAME_TAKEN,
|
||||||
|
NAME_CHARACTERS,
|
||||||
|
NAME_RESERVED,
|
||||||
|
DESCRIPTION_LENGTH,
|
||||||
|
DESCRIPTION_CHARACTERS
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.william278.huskhomes.database;
|
package net.william278.huskhomes.database;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesException;
|
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.player.User;
|
import net.william278.huskhomes.player.User;
|
||||||
@@ -274,7 +273,7 @@ public abstract class Database {
|
|||||||
return getWarps().thenApplyAsync(warps -> warps.stream()
|
return getWarps().thenApplyAsync(warps -> warps.stream()
|
||||||
.filter(warp -> warp.server.equals(server))
|
.filter(warp -> warp.server.equals(server))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
} catch (HuskHomesException e) {
|
} catch (IllegalStateException e) {
|
||||||
return getWarps().thenApplyAsync(warps -> warps.stream()
|
return getWarps().thenApplyAsync(warps -> warps.stream()
|
||||||
.filter(warp -> plugin.getWorlds().stream().anyMatch(world -> world.equals(warp.world)))
|
.filter(warp -> plugin.getWorlds().stream().anyMatch(world -> world.equals(warp.world)))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
@@ -301,7 +300,7 @@ public abstract class Database {
|
|||||||
return getPublicHomes().thenApplyAsync(homes -> homes.stream()
|
return getPublicHomes().thenApplyAsync(homes -> homes.stream()
|
||||||
.filter(home -> home.server.equals(server))
|
.filter(home -> home.server.equals(server))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
} catch (HuskHomesException e) {
|
} catch (IllegalStateException e) {
|
||||||
return plugin.getDatabase().getPublicHomes().thenApplyAsync(homes -> homes.stream()
|
return plugin.getDatabase().getPublicHomes().thenApplyAsync(homes -> homes.stream()
|
||||||
.filter(home -> plugin.getWorlds().stream().anyMatch(world -> world.equals(home.world)))
|
.filter(home -> plugin.getWorlds().stream().anyMatch(world -> world.equals(home.world)))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.william278.huskhomes.hook;
|
package net.william278.huskhomes.hook;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesException;
|
|
||||||
import net.william278.huskhomes.player.User;
|
import net.william278.huskhomes.player.User;
|
||||||
import net.william278.huskhomes.position.Home;
|
import net.william278.huskhomes.position.Home;
|
||||||
import net.william278.huskhomes.position.SavedPosition;
|
import net.william278.huskhomes.position.SavedPosition;
|
||||||
@@ -104,7 +103,7 @@ public abstract class MapHook extends PluginHook {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return position.server.equals(plugin.getServerName());
|
return position.server.equals(plugin.getServerName());
|
||||||
} catch (HuskHomesException e) {
|
} catch (IllegalStateException e) {
|
||||||
return plugin.getWorlds().stream()
|
return plugin.getWorlds().stream()
|
||||||
.map(world -> world.uuid)
|
.map(world -> world.uuid)
|
||||||
.anyMatch(uuid -> uuid.equals(position.world.uuid));
|
.anyMatch(uuid -> uuid.equals(position.world.uuid));
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.william278.huskhomes.hook;
|
|||||||
import com.djrapitops.plan.capability.CapabilityService;
|
import com.djrapitops.plan.capability.CapabilityService;
|
||||||
import com.djrapitops.plan.extension.ExtensionService;
|
import com.djrapitops.plan.extension.ExtensionService;
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesInitializationException;
|
|
||||||
import net.william278.huskhomes.database.Database;
|
import net.william278.huskhomes.database.Database;
|
||||||
import net.william278.huskhomes.util.Logger;
|
import net.william278.huskhomes.util.Logger;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -25,7 +24,7 @@ public class PlanHook extends PluginHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initialize() throws HuskHomesInitializationException {
|
public boolean initialize() {
|
||||||
if (!areAllCapabilitiesAvailable()) {
|
if (!areAllCapabilitiesAvailable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.william278.huskhomes.hook;
|
package net.william278.huskhomes.hook;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesInitializationException;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,9 +32,8 @@ public abstract class PluginHook {
|
|||||||
* Initialize the hook and return {@code true} if it could be enabled
|
* Initialize the hook and return {@code true} if it could be enabled
|
||||||
*
|
*
|
||||||
* @return {@code true} if the hook could be enabled
|
* @return {@code true} if the hook could be enabled
|
||||||
* @throws HuskHomesInitializationException if an exception occurred enabling the hook
|
|
||||||
*/
|
*/
|
||||||
public abstract boolean initialize() throws HuskHomesInitializationException;
|
public abstract boolean initialize() ;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getHookName() {
|
public String getHookName() {
|
||||||
|
|||||||
Reference in new issue
Block a user