Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 81 additions & 47 deletions src/main/java/org/mvplugins/multiverse/portals/MVPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,21 @@

import org.mvplugins.multiverse.portals.utils.MultiverseRegion;

public class MVPortal {
public final class MVPortal {

private static final Collection<Material> INTERIOR_MATERIALS = Arrays.asList(Material.NETHER_PORTAL, Material.GRASS,
Material.VINE, Material.SNOW, Material.AIR, Material.WATER, Material.LAVA);

public static final Pattern PORTAL_NAME_PATTERN = Pattern.compile("[a-zA-Z0-9_-]+");

public static boolean isPortalInterior(Material material) {
return INTERIOR_MATERIALS.contains(material);
}

public static MVPortal loadMVPortalFromConfig(MultiversePortals instance, String name) {
return new MVPortal(instance, name);
}

private final MultiversePortals plugin;
private final PortalsConfig portalsConfig;
private final WorldManager worldManager;
Expand All @@ -59,15 +73,6 @@ public class MVPortal {
private Permission fillPermission;
private Permission exempt;

private static final Collection<Material> INTERIOR_MATERIALS = Arrays.asList(Material.NETHER_PORTAL, Material.GRASS,
Material.VINE, Material.SNOW, Material.AIR, Material.WATER, Material.LAVA);

public static final Pattern PORTAL_NAME_PATTERN = Pattern.compile("[a-zA-Z0-9_-]+");

public static boolean isPortalInterior(Material material) {
return INTERIOR_MATERIALS.contains(material);
}

public MVPortal(LoadedMultiverseWorld world, MultiversePortals instance, String name, String owner, String location) {
this(instance, name);
this.setOwner(owner);
Expand Down Expand Up @@ -136,9 +141,8 @@ private MVPortal(MultiversePortals plugin, String name) {
}
}

ConfigurationSection save() {
this.configHandle.save();
return this.configHandle.getConfig();
public String getName() {
return this.name;
}

/**
Expand All @@ -153,13 +157,41 @@ public StringPropertyHandle getStringPropertyHandle() {
return this.stringPropertyHandle;
}

ConfigurationSection save() {
this.configHandle.save();
return this.configHandle.getConfig();
}

/**
*
* @param owner
* @return
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public boolean setOwner(String owner) {
return this.configHandle.set(configNodes.owner, owner).isSuccess();
}

/**
*
* @return
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public String getOwner() {
return this.configHandle.get(configNodes.owner);
}

/**
* Set the value of teleportNonPlayers
*
* @param teleportNonPlayers The new value
*/
@ApiStatus.AvailableSince("5.1")
public void setTeleportNonPlayers (boolean teleportNonPlayers) {
public void setTeleportNonPlayers(boolean teleportNonPlayers) {
this.configHandle.set(configNodes.teleportNonPlayers, teleportNonPlayers);
}

Expand All @@ -175,32 +207,20 @@ public boolean useSafeTeleporter() {
return this.configHandle.get(configNodes.safeTeleport);
}

public static MVPortal loadMVPortalFromConfig(MultiversePortals instance, String name) {
return new MVPortal(instance, name);
private boolean setCurrency(Material currency) {
return this.configHandle.set(configNodes.currency, currency).isSuccess();
}

public Material getCurrency() {
return this.configHandle.get(configNodes.currency);
}

public double getPrice() {
return this.configHandle.get(configNodes.price);
}

private boolean setCurrency(Material currency) {
return this.configHandle.set(configNodes.currency, currency).isSuccess();
}

private boolean setPrice(double price) {
return this.configHandle.set(configNodes.price, price).isSuccess();
}

public boolean setPortalLocation(String locationString, String worldString) {
LoadedMultiverseWorld world = null;
if (this.worldManager.isWorld(worldString)) {
world = this.worldManager.getLoadedWorld(worldString).getOrNull();
}
return this.setPortalLocation(locationString, world);
public double getPrice() {
return this.configHandle.get(configNodes.price);
}

/**
Expand All @@ -215,6 +235,14 @@ public boolean setPortalLocation(String locationString) {
return this.setPortalLocation(PortalLocation.parseLocation(locationString));
}

public boolean setPortalLocation(String locationString, String worldString) {
LoadedMultiverseWorld world = null;
if (this.worldManager.isWorld(worldString)) {
world = this.worldManager.getLoadedWorld(worldString).getOrNull();
}
return this.setPortalLocation(locationString, world);
}

public boolean setPortalLocation(String locationString, LoadedMultiverseWorld world) {
return this.setPortalLocation(PortalLocation.parseLocation(locationString, world, this.name));
}
Expand All @@ -235,8 +263,11 @@ boolean setPortalLocationInternal(PortalLocation location) {
return true;
}

private boolean setOwner(String owner) {
return this.configHandle.set(configNodes.owner, owner).isSuccess();
public PortalLocation getPortalLocation() {
if (this.location == null) {
this.location = PortalLocation.parseLocation(this.configHandle.get(configNodes.location));
}
return this.location;
}

public boolean setDestination(String destinationString) {
Expand All @@ -253,18 +284,10 @@ public boolean setDestination(DestinationInstance<?, ?> newDestination) {
}

public DestinationInstance<?, ?> getDestination() {
return this.destinationsProvider.parseDestination(this.configHandle.get(configNodes.destination)).getOrNull();
}

public String getName() {
return this.name;
}

public PortalLocation getLocation() {
if (this.location == null) {
this.location = PortalLocation.parseLocation(this.configHandle.get(configNodes.location));
}
return this.location;
return this.destinationsProvider.parseDestination(this.configHandle.get(configNodes.destination))
.onFailure(f ->
Logging.warning("Portal " + this.name + " has an invalid DESTINATION! " + f.getFailureMessage().formatted()))
.getOrNull();
}

public Location getSafePlayerSpawnLocation() {
Expand Down Expand Up @@ -386,7 +409,7 @@ public boolean isFrameValid(Location l) {
// Limit the search to the portal's region, extended by 1 block.
boolean frameValid = false;
{
MultiverseRegion r = getLocation().getRegion();
MultiverseRegion r = getPortalLocation().getRegion();
int useX = (r.getWidth() == 1) ? 0 : 1;
int useY = (r.getHeight() == 1) ? 0 : 1;
int useZ = (r.getDepth() == 1) ? 0 : 1;
Expand Down Expand Up @@ -519,7 +542,8 @@ public boolean setProperty(String property, String value) {
* @deprecated Busscript feature has been removed.
*/
@Deprecated(since = "5.1" , forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "6.0") public String getHandlerScript() {
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
public String getHandlerScript() {
Logging.warning("handle script is deprecated");
return "";
}
Expand All @@ -528,7 +552,8 @@ public boolean setProperty(String property, String value) {
* @deprecated Busscript feature has been removed.
*/
@Deprecated(since = "5.1" , forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "6.0") public void setHandlerScript(String handlerScript) {
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
public void setHandlerScript(String handlerScript) {
Logging.warning("handle script is deprecated");
}

Expand All @@ -540,4 +565,13 @@ public boolean setProperty(String property, String value) {
public boolean isExempt(Player player) {
return false;
}

/**
* @deprecated Use {@link MVPortal#getPortalLocation()} instead.
*/
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
public PortalLocation getLocation() {
return getPortalLocation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void loadPortals() {
if (keys != null) {
for (String pname : keys) {
MVPortal portal = MVPortal.loadMVPortalFromConfig(this, pname);
if (portal.getLocation().isValidLocation()) {
if (portal.getPortalLocation().isValidLocation()) {
this.portalManager.get().addPortal(portal);
} else {
Logging.warning(String.format("Portal '%s' not loaded due to invalid location!", portal.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void playerBucketFill(PlayerBucketFillEvent event) {
} else {
Material fillMaterial = Material.AIR;
Logging.finer("Fill Material: " + fillMaterial);
this.filler.fillRegion(portal.getLocation().getRegion(), event.getBlockClicked().getLocation(), fillMaterial, event.getPlayer());
this.filler.fillRegion(portal.getPortalLocation().getRegion(), event.getBlockClicked().getLocation(), fillMaterial, event.getPlayer());
}
}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ public void playerBucketEmpty(PlayerBucketEmptyEvent event) {
}

Logging.finer("Fill Material: " + fillMaterial);
this.filler.fillRegion(portal.getLocation().getRegion(), translatedLocation, fillMaterial, event.getPlayer());
this.filler.fillRegion(portal.getPortalLocation().getRegion(), translatedLocation, fillMaterial, event.getPlayer());
}
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public void playerInteract(PlayerInteractEvent event) {
fillMaterial = Material.AIR;
}
Logging.finer("Fill Material: " + fillMaterial);
event.setCancelled(this.filler.fillRegion(portal.getLocation().getRegion(), translatedLocation, fillMaterial, event.getPlayer()));
event.setCancelled(this.filler.fillRegion(portal.getPortalLocation().getRegion(), translatedLocation, fillMaterial, event.getPlayer()));
}
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DisplayUtils {

public void showStaticInfo(CommandSender sender, MVPortal portal, String message) {
sender.sendMessage(ChatColor.AQUA + "--- " + message + ChatColor.DARK_AQUA + portal.getName() + ChatColor.AQUA + " ---");
String[] locParts = portal.getLocation().toString().split(":");
String[] locParts = portal.getPortalLocation().toString().split(":");
sender.sendMessage("Coords: " + ChatColor.GOLD + locParts[0] + ChatColor.WHITE + " to " + ChatColor.GOLD + locParts[1] + ChatColor.WHITE + " in " + ChatColor.GOLD + portal.getWorld().getName() );
if (portal.getDestination() == null) {
sender.sendMessage("Destination: " + ChatColor.RED + ChatColor.ITALIC + "NOT SET!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public MVPortal getPortal(Player sender, Location l, boolean checkPermission) {

// Ignore portals the player can't use.
if (!checkPermission || !portalsConfig.getEnforcePortalAccess() || portal.playerCanEnterPortal(sender)) {
PortalLocation portalLoc = portal.getLocation();
PortalLocation portalLoc = portal.getPortalLocation();
if (portalLoc.isValidLocation() && portalLoc.getRegion().containsVector(l)) {
return portal;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public boolean isPortal(Location l) {
public MVPortal getPortal(Location l) {
MultiverseWorld world = this.worldManager.getLoadedWorld(l.getWorld().getName()).getOrNull();
for (MVPortal portal : getNearbyPortals(world, l)) {
MultiverseRegion r = portal.getLocation().getRegion();
MultiverseRegion r = portal.getPortalLocation().getRegion();
if (r != null && r.containsVector(l)) {
return portal;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ private MVPortal removePortal(String portalName, boolean removeFromConfigs, bool
// leaving behind portal blocks (which would take an unsuspecting
// player to the nether instead of their expected destination).

MultiverseRegion region = removed.getLocation().getRegion();
MultiverseRegion region = removed.getPortalLocation().getRegion();
replaceInRegion(removed.getWorld(), region, Material.NETHER_PORTAL, Material.AIR);
}
this.plugin.getServer().getPluginManager().removePermission(removed.getPermission());
Expand Down Expand Up @@ -250,7 +250,7 @@ private List<MVPortal> getPortals(MultiverseWorld world) {
List<MVPortal> all = this.getAllPortals();
List<MVPortal> validItems = new ArrayList<MVPortal>();
for (MVPortal p : all) {
MultiverseWorld portalworld = p.getLocation().getMVWorld();
MultiverseWorld portalworld = p.getPortalLocation().getMVWorld();
if (portalworld != null && portalworld.equals(world)) {
validItems.add(p);
}
Expand All @@ -266,7 +266,7 @@ public List<MVPortal> getPortals(CommandSender sender, MultiverseWorld world) {
List<MVPortal> validItems = new ArrayList<MVPortal>();
if (portalsConfig.getEnforcePortalAccess()) {
for (MVPortal p : all) {
if (p.getLocation().isValidLocation() && p.getLocation().getMVWorld().equals(world) &&
if (p.getPortalLocation().isValidLocation() && p.getPortalLocation().getMVWorld().equals(world) &&
p.playerCanEnterPortal((Player) sender)) {
validItems.add(p);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ private void addToWorldChunkPortals(MultiverseWorld world, MVPortal portal) {

// If this portal spans multiple chunks, we'll add it to each chunk that
// contains part of it.
PortalLocation location = portal.getLocation();
PortalLocation location = portal.getPortalLocation();
Vector min = location.getMinimum();
Vector max = location.getMaximum();
int c1x = blockToChunk(min.getBlockX()), c1z = blockToChunk(min.getBlockZ());
Expand Down Expand Up @@ -381,7 +381,7 @@ private void removeFromWorldChunkPortals(MultiverseWorld world, MVPortal portal)
return;
}

PortalLocation location = portal.getLocation();
PortalLocation location = portal.getPortalLocation();
Vector min = location.getMinimum();
Vector max = location.getMaximum();
int c1x = blockToChunk(min.getBlockX()), c1z = blockToChunk(min.getBlockZ());
Expand Down
Loading