package net.knarcraft.stargate.config; import net.knarcraft.stargate.Stargate; import net.knarcraft.stargate.portal.PortalSignDrawer; import org.bukkit.ChatColor; import java.util.Map; /** * The Stargate gate config keeps track of all global config values related to gates */ public final class StargateGateConfig { private static final int activeTime = 10; private static final int openTime = 10; private final Map configOptions; /** * Instantiates a new stargate config * * @param configOptions

The loaded config options to use

*/ public StargateGateConfig(Map configOptions) { this.configOptions = configOptions; loadGateConfig(); } /** * Gets the amount of seconds a portal should be open before automatically closing * * @return

The open time of a gate

*/ public int getOpenTime() { return openTime; } /** * Gets the amount of seconds a portal should be active before automatically deactivating * * @return

The active time of a gate

*/ public int getActiveTime() { return activeTime; } /** * Gets the maximum number of gates allowed on each network * * @return

Maximum number of gates for each network

*/ public int maxGatesEachNetwork() { return (int) configOptions.get(ConfigOption.MAX_GATES_EACH_NETWORK); } /** * Gets whether a portal's lastly used destination should be remembered * * @return

Whether a portal's lastly used destination should be remembered

*/ public boolean rememberDestination() { return (boolean) configOptions.get(ConfigOption.REMEMBER_DESTINATION); } /** * Gets whether vehicle teleportation should be handled in addition to player teleportation * * @return

Whether vehicle teleportation should be handled

*/ public boolean handleVehicles() { return (boolean) configOptions.get(ConfigOption.HANDLE_VEHICLES); } /** * Gets whether vehicles with no passengers should be handled * *

The handle vehicles option overrides this option if disabled. This option allows empty passenger * minecarts/boats, but also chest/tnt/hopper/furnace minecarts to teleport through stargates.

* * @return

Whether vehicles without passengers should be handled

*/ public boolean handleEmptyVehicles() { return (boolean) configOptions.get(ConfigOption.HANDLE_EMPTY_VEHICLES); } /** * Gets whether vehicles containing creatures should be handled * *

The handle vehicles option overrides this option if disabled. This option allows creatures (pigs, pandas, * zombies, etc.) to teleport through stargates if in a vehicle.

* * @return

Whether vehicles with creatures should be handled

*/ public boolean handleCreatureTransportation() { return (boolean) configOptions.get(ConfigOption.HANDLE_CREATURE_TRANSPORTATION); } /** * Gets whether vehicles containing a creature, but not a player should be handled * *

The handle vehicles option, and the handle creature transportation option, override this option if disabled. * This option allows creatures (pigs, pandas, zombies, etc.) to teleport through stargates if in a vehicle, even * if no player is in the vehicle. * As it is not possible to check if a creature is allowed through a stargate, they will be able to go through * regardless of whether the initiating player is allowed to enter the stargate. Enabling this is necessary to * teleport creatures using minecarts, but only handleCreatureTransportation is required to teleport creatures * using a boat manned by a player.

* * @return

Whether non-empty vehicles without a player should be handled

*/ public boolean handleNonPlayerVehicles() { return (boolean) configOptions.get(ConfigOption.HANDLE_NON_PLAYER_VEHICLES); } /** * Gets whether leashed creatures should be teleported with a teleporting player * * @return

Whether leashed creatures should be handled

*/ public boolean handleLeashedCreatures() { return (boolean) configOptions.get(ConfigOption.HANDLE_LEASHED_CREATURES); } /** * Gets whether the list of destinations within a network should be sorted * * @return

Whether network destinations should be sorted

*/ public boolean sortNetworkDestinations() { return (boolean) configOptions.get(ConfigOption.SORT_NETWORK_DESTINATIONS); } /** * Gets whether portal entrances should be protected from block breaking * * @return

Whether portal entrances should be protected

*/ public boolean protectEntrance() { return (boolean) configOptions.get(ConfigOption.PROTECT_ENTRANCE); } /** * Gets whether BungeeCord support is enabled * * @return

Whether bungee support is enabled

*/ public boolean enableBungee() { return (boolean) configOptions.get(ConfigOption.ENABLE_BUNGEE); } /** * Gets whether all portals' integrity has to be verified on startup and reload * * @return

Whether portals need to be verified

*/ public boolean verifyPortals() { return (boolean) configOptions.get(ConfigOption.VERIFY_PORTALS); } /** * Gets whether portals should be destroyed by nearby explosions * * @return

Whether portals should be destroyed by explosions

*/ public boolean destroyedByExplosion() { return (boolean) configOptions.get(ConfigOption.DESTROYED_BY_EXPLOSION); } /** * Gets the default portal network to use if no other network is given * * @return

The default portal network

*/ public String getDefaultPortalNetwork() { return (String) configOptions.get(ConfigOption.DEFAULT_GATE_NETWORK); } /** * Loads all config values related to gates */ private void loadGateConfig() { //Load the sign colors loadSignColor((String) configOptions.get(ConfigOption.MAIN_SIGN_COLOR), (String) configOptions.get(ConfigOption.HIGHLIGHT_SIGN_COLOR)); } /** * Loads the correct sign color given a sign color string * * @param mainSignColor

A string representing the main sign color

*/ private void loadSignColor(String mainSignColor, String highlightSignColor) { if (mainSignColor != null && highlightSignColor != null) { try { PortalSignDrawer.setMainColor(ChatColor.valueOf(highlightSignColor.toUpperCase())); PortalSignDrawer.setHighlightColor(ChatColor.valueOf(highlightSignColor.toUpperCase())); } catch (IllegalArgumentException | NullPointerException ignored) { Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK and WHITE"); PortalSignDrawer.setMainColor(ChatColor.BLACK); PortalSignDrawer.setHighlightColor(ChatColor.WHITE); } } } }