4141
4242import org .mvplugins .multiverse .portals .utils .MultiverseRegion ;
4343
44- public class MVPortal {
44+ public final class MVPortal {
45+
46+ private static final Collection <Material > INTERIOR_MATERIALS = Arrays .asList (Material .NETHER_PORTAL , Material .GRASS ,
47+ Material .VINE , Material .SNOW , Material .AIR , Material .WATER , Material .LAVA );
48+
49+ public static final Pattern PORTAL_NAME_PATTERN = Pattern .compile ("[a-zA-Z0-9_-]+" );
50+
51+ public static boolean isPortalInterior (Material material ) {
52+ return INTERIOR_MATERIALS .contains (material );
53+ }
54+
55+ public static MVPortal loadMVPortalFromConfig (MultiversePortals instance , String name ) {
56+ return new MVPortal (instance , name );
57+ }
58+
4559 private final MultiversePortals plugin ;
4660 private final PortalsConfig portalsConfig ;
4761 private final WorldManager worldManager ;
@@ -59,15 +73,6 @@ public class MVPortal {
5973 private Permission fillPermission ;
6074 private Permission exempt ;
6175
62- private static final Collection <Material > INTERIOR_MATERIALS = Arrays .asList (Material .NETHER_PORTAL , Material .GRASS ,
63- Material .VINE , Material .SNOW , Material .AIR , Material .WATER , Material .LAVA );
64-
65- public static final Pattern PORTAL_NAME_PATTERN = Pattern .compile ("[a-zA-Z0-9_-]+" );
66-
67- public static boolean isPortalInterior (Material material ) {
68- return INTERIOR_MATERIALS .contains (material );
69- }
70-
7176 public MVPortal (LoadedMultiverseWorld world , MultiversePortals instance , String name , String owner , String location ) {
7277 this (instance , name );
7378 this .setOwner (owner );
@@ -136,9 +141,8 @@ private MVPortal(MultiversePortals plugin, String name) {
136141 }
137142 }
138143
139- ConfigurationSection save () {
140- this .configHandle .save ();
141- return this .configHandle .getConfig ();
144+ public String getName () {
145+ return this .name ;
142146 }
143147
144148 /**
@@ -153,13 +157,41 @@ public StringPropertyHandle getStringPropertyHandle() {
153157 return this .stringPropertyHandle ;
154158 }
155159
160+ ConfigurationSection save () {
161+ this .configHandle .save ();
162+ return this .configHandle .getConfig ();
163+ }
164+
165+ /**
166+ *
167+ * @param owner
168+ * @return
169+ *
170+ * @since 5.1
171+ */
172+ @ ApiStatus .AvailableSince ("5.1" )
173+ public boolean setOwner (String owner ) {
174+ return this .configHandle .set (configNodes .owner , owner ).isSuccess ();
175+ }
176+
177+ /**
178+ *
179+ * @return
180+ *
181+ * @since 5.1
182+ */
183+ @ ApiStatus .AvailableSince ("5.1" )
184+ public String getOwner () {
185+ return this .configHandle .get (configNodes .owner );
186+ }
187+
156188 /**
157189 * Set the value of teleportNonPlayers
158190 *
159191 * @param teleportNonPlayers The new value
160192 */
161193 @ ApiStatus .AvailableSince ("5.1" )
162- public void setTeleportNonPlayers (boolean teleportNonPlayers ) {
194+ public void setTeleportNonPlayers (boolean teleportNonPlayers ) {
163195 this .configHandle .set (configNodes .teleportNonPlayers , teleportNonPlayers );
164196 }
165197
@@ -175,32 +207,20 @@ public boolean useSafeTeleporter() {
175207 return this .configHandle .get (configNodes .safeTeleport );
176208 }
177209
178- public static MVPortal loadMVPortalFromConfig ( MultiversePortals instance , String name ) {
179- return new MVPortal ( instance , name );
210+ private boolean setCurrency ( Material currency ) {
211+ return this . configHandle . set ( configNodes . currency , currency ). isSuccess ( );
180212 }
181213
182214 public Material getCurrency () {
183215 return this .configHandle .get (configNodes .currency );
184216 }
185217
186- public double getPrice () {
187- return this .configHandle .get (configNodes .price );
188- }
189-
190- private boolean setCurrency (Material currency ) {
191- return this .configHandle .set (configNodes .currency , currency ).isSuccess ();
192- }
193-
194218 private boolean setPrice (double price ) {
195219 return this .configHandle .set (configNodes .price , price ).isSuccess ();
196220 }
197221
198- public boolean setPortalLocation (String locationString , String worldString ) {
199- LoadedMultiverseWorld world = null ;
200- if (this .worldManager .isWorld (worldString )) {
201- world = this .worldManager .getLoadedWorld (worldString ).getOrNull ();
202- }
203- return this .setPortalLocation (locationString , world );
222+ public double getPrice () {
223+ return this .configHandle .get (configNodes .price );
204224 }
205225
206226 /**
@@ -215,6 +235,14 @@ public boolean setPortalLocation(String locationString) {
215235 return this .setPortalLocation (PortalLocation .parseLocation (locationString ));
216236 }
217237
238+ public boolean setPortalLocation (String locationString , String worldString ) {
239+ LoadedMultiverseWorld world = null ;
240+ if (this .worldManager .isWorld (worldString )) {
241+ world = this .worldManager .getLoadedWorld (worldString ).getOrNull ();
242+ }
243+ return this .setPortalLocation (locationString , world );
244+ }
245+
218246 public boolean setPortalLocation (String locationString , LoadedMultiverseWorld world ) {
219247 return this .setPortalLocation (PortalLocation .parseLocation (locationString , world , this .name ));
220248 }
@@ -235,8 +263,11 @@ boolean setPortalLocationInternal(PortalLocation location) {
235263 return true ;
236264 }
237265
238- private boolean setOwner (String owner ) {
239- return this .configHandle .set (configNodes .owner , owner ).isSuccess ();
266+ public PortalLocation getPortalLocation () {
267+ if (this .location == null ) {
268+ this .location = PortalLocation .parseLocation (this .configHandle .get (configNodes .location ));
269+ }
270+ return this .location ;
240271 }
241272
242273 public boolean setDestination (String destinationString ) {
@@ -253,18 +284,10 @@ public boolean setDestination(DestinationInstance<?, ?> newDestination) {
253284 }
254285
255286 public DestinationInstance <?, ?> getDestination () {
256- return this .destinationsProvider .parseDestination (this .configHandle .get (configNodes .destination )).getOrNull ();
257- }
258-
259- public String getName () {
260- return this .name ;
261- }
262-
263- public PortalLocation getLocation () {
264- if (this .location == null ) {
265- this .location = PortalLocation .parseLocation (this .configHandle .get (configNodes .location ));
266- }
267- return this .location ;
287+ return this .destinationsProvider .parseDestination (this .configHandle .get (configNodes .destination ))
288+ .onFailure (f ->
289+ Logging .warning ("Portal " + this .name + " has an invalid DESTINATION! " + f .getFailureMessage ().formatted ()))
290+ .getOrNull ();
268291 }
269292
270293 public Location getSafePlayerSpawnLocation () {
@@ -386,7 +409,7 @@ public boolean isFrameValid(Location l) {
386409 // Limit the search to the portal's region, extended by 1 block.
387410 boolean frameValid = false ;
388411 {
389- MultiverseRegion r = getLocation ().getRegion ();
412+ MultiverseRegion r = getPortalLocation ().getRegion ();
390413 int useX = (r .getWidth () == 1 ) ? 0 : 1 ;
391414 int useY = (r .getHeight () == 1 ) ? 0 : 1 ;
392415 int useZ = (r .getDepth () == 1 ) ? 0 : 1 ;
@@ -519,7 +542,8 @@ public boolean setProperty(String property, String value) {
519542 * @deprecated Busscript feature has been removed.
520543 */
521544 @ Deprecated (since = "5.1" , forRemoval = true )
522- @ ApiStatus .ScheduledForRemoval (inVersion = "6.0" ) public String getHandlerScript () {
545+ @ ApiStatus .ScheduledForRemoval (inVersion = "6.0" )
546+ public String getHandlerScript () {
523547 Logging .warning ("handle script is deprecated" );
524548 return "" ;
525549 }
@@ -528,7 +552,8 @@ public boolean setProperty(String property, String value) {
528552 * @deprecated Busscript feature has been removed.
529553 */
530554 @ Deprecated (since = "5.1" , forRemoval = true )
531- @ ApiStatus .ScheduledForRemoval (inVersion = "6.0" ) public void setHandlerScript (String handlerScript ) {
555+ @ ApiStatus .ScheduledForRemoval (inVersion = "6.0" )
556+ public void setHandlerScript (String handlerScript ) {
532557 Logging .warning ("handle script is deprecated" );
533558 }
534559
@@ -540,4 +565,13 @@ public boolean setProperty(String property, String value) {
540565 public boolean isExempt (Player player ) {
541566 return false ;
542567 }
568+
569+ /**
570+ * @deprecated Use {@link MVPortal#getPortalLocation()} instead.
571+ */
572+ @ Deprecated (forRemoval = true )
573+ @ ApiStatus .ScheduledForRemoval (inVersion = "6.0" )
574+ public PortalLocation getLocation () {
575+ return getPortalLocation ();
576+ }
543577}
0 commit comments