From 60c543e52a49ca80ca57ce96d11f802937e6ee4b Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 8 Oct 2021 01:25:25 +0200 Subject: [PATCH] Adds a new class for keeping track of portal options --- .../stargate/portal/PortalOptions.java | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/main/java/net/knarcraft/stargate/portal/PortalOptions.java diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalOptions.java b/src/main/java/net/knarcraft/stargate/portal/PortalOptions.java new file mode 100644 index 0000000..d2335e8 --- /dev/null +++ b/src/main/java/net/knarcraft/stargate/portal/PortalOptions.java @@ -0,0 +1,141 @@ +package net.knarcraft.stargate.portal; + +import net.knarcraft.stargate.Stargate; + +import java.util.Map; + +/** + * Keeps track of all options for a given portal + */ +public class PortalOptions { + + private final Map options; + private boolean isFixed; + + /** + * Instantiates a new portal options object + * + * @param options

All options to keep track of

+ * @param hasDestination

Whether the portal has a fixed destination

+ */ + public PortalOptions(Map options, boolean hasDestination) { + this.options = options; + + isFixed = hasDestination || this.isRandom() || this.isBungee(); + + if (this.isAlwaysOn() && !isFixed) { + this.options.put(PortalOption.ALWAYS_ON, false); + Stargate.debug("Portal", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false"); + } + + if (this.isRandom() && !this.isAlwaysOn()) { + this.options.put(PortalOption.ALWAYS_ON, true); + Stargate.debug("Portal", "Gate marked as random, set to always-on"); + } + } + + /** + * Gets whether this portal is fixed + * + *

A fixed portal has only one destination which never changes. A fixed portal has a fixed destination, is a + * random portal or is a bungee portal. A fixed portal is always open.

+ * + * @return

Whether this gate is fixed

+ */ + public boolean isFixed() { + return this.isFixed; + } + + /** + * Sets whether this portal is fixed + * + * @param fixed

Whether this gate should be fixed

+ */ + public void setFixed(boolean fixed) { + this.isFixed = fixed; + } + + /** + * Gets whether this portal is always on + * + * @return

Whether this portal is always on

+ */ + public boolean isAlwaysOn() { + return this.options.get(PortalOption.ALWAYS_ON); + } + + /** + * Gets whether this portal is hidden + * + * @return

Whether this portal is hidden

+ */ + public boolean isHidden() { + return this.options.get(PortalOption.HIDDEN); + } + + /** + * Gets whether this portal is private + * + * @return

Whether this portal is private

+ */ + public boolean isPrivate() { + return this.options.get(PortalOption.PRIVATE); + } + + /** + * Gets whether this portal is free + * + * @return

Whether this portal is free

+ */ + public boolean isFree() { + return this.options.get(PortalOption.FREE); + } + + /** + * Gets whether this portal is backwards + * + *

A backwards portal is one where players exit through the back.

+ * + * @return

Whether this portal is backwards

+ */ + public boolean isBackwards() { + return this.options.get(PortalOption.BACKWARDS); + } + + /** + * Gets whether this portal is shown on the network even if it's always on + * + * @return

Whether portal gate is shown

+ */ + public boolean isShown() { + return this.options.get(PortalOption.SHOW); + } + + /** + * Gets whether this portal shows no network + * + * @return

Whether this portal shows no network/p> + */ + public boolean isNoNetwork() { + return this.options.get(PortalOption.NO_NETWORK); + } + + /** + * Gets whether this portal goes to a random location on the network + * + * @return

Whether this portal goes to a random location

+ */ + public boolean isRandom() { + return this.options.get(PortalOption.RANDOM); + } + + /** + * Gets whether this portal is a bungee portal + * + * @return

Whether this portal is a bungee portal

+ */ + public boolean isBungee() { + return this.options.get(PortalOption.BUNGEE); + } + +}