Moves the portal owner name and owner UUID to the PortalOwner class which makes the TwoTuple unnecessary
This commit is contained in:
parent
485ca284b0
commit
9a0f16e558
@ -1,43 +0,0 @@
|
|||||||
package net.knarcraft.stargate.container;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class allows storing two values of any type
|
|
||||||
*
|
|
||||||
* @param <K> <p>The first type</p>
|
|
||||||
* @param <L> <p>The second type</p>
|
|
||||||
*/
|
|
||||||
public class TwoTuple<K, L> {
|
|
||||||
|
|
||||||
private final K firstValue;
|
|
||||||
private final L secondValue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate a new TwoTuple
|
|
||||||
*
|
|
||||||
* @param firstValue <p>The first value</p>
|
|
||||||
* @param secondValue <p>The second value</p>
|
|
||||||
*/
|
|
||||||
public TwoTuple(K firstValue, L secondValue) {
|
|
||||||
this.firstValue = firstValue;
|
|
||||||
this.secondValue = secondValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the first value
|
|
||||||
*
|
|
||||||
* @return <p>The first value</p>
|
|
||||||
*/
|
|
||||||
public K getFirstValue() {
|
|
||||||
return firstValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the second value
|
|
||||||
*
|
|
||||||
* @return <p>The second value</p>
|
|
||||||
*/
|
|
||||||
public L getSecondValue() {
|
|
||||||
return secondValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -5,6 +5,7 @@ import net.knarcraft.stargate.event.StargateDestroyEvent;
|
|||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalCreator;
|
import net.knarcraft.stargate.portal.PortalCreator;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
import net.knarcraft.stargate.portal.PortalHandler;
|
||||||
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.utility.EconomyHandler;
|
import net.knarcraft.stargate.utility.EconomyHandler;
|
||||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
@ -139,7 +140,7 @@ public class BlockEventListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PortalHandler.unregisterPortal(portal, true);
|
PortalRegistry.unregisterPortal(portal, true);
|
||||||
Stargate.sendSuccessMessage(player, Stargate.getString("destroyMsg"));
|
Stargate.sendSuccessMessage(player, Stargate.getString("destroyMsg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.knarcraft.stargate.listener;
|
|||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
import net.knarcraft.stargate.portal.PortalHandler;
|
||||||
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.utility.EntityHelper;
|
import net.knarcraft.stargate.utility.EntityHelper;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -55,7 +56,7 @@ public class EntityEventListener implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Stargate.destroyedByExplosion()) {
|
if (Stargate.destroyedByExplosion()) {
|
||||||
PortalHandler.unregisterPortal(portal, true);
|
PortalRegistry.unregisterPortal(portal, true);
|
||||||
} else {
|
} else {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
break;
|
break;
|
||||||
|
@ -6,18 +6,15 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a portal in space which points to one or several portals
|
* This class represents a portal in space which points to one or several portals
|
||||||
*/
|
*/
|
||||||
public class Portal {
|
public class Portal {
|
||||||
|
|
||||||
// Gate information
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String network;
|
private final String network;
|
||||||
private final String ownerName;
|
private final PortalOwner portalOwner;
|
||||||
private final UUID ownerUUID;
|
|
||||||
|
|
||||||
private final PortalOptions options;
|
private final PortalOptions options;
|
||||||
private final PortalOpener portalOpener;
|
private final PortalOpener portalOpener;
|
||||||
@ -35,17 +32,15 @@ public class Portal {
|
|||||||
* @param name <p>The name of the portal defined on the sign's first line</p>
|
* @param name <p>The name of the portal defined on the sign's first line</p>
|
||||||
* @param network <p>The network the portal belongs to, defined on the sign's third</p>
|
* @param network <p>The network the portal belongs to, defined on the sign's third</p>
|
||||||
* @param gate <p>The gate type to use for this portal</p>
|
* @param gate <p>The gate type to use for this portal</p>
|
||||||
* @param ownerUUID <p>The UUID of the gate's owner</p>
|
* @param portalOwner <p>The portal's owner</p>
|
||||||
* @param ownerName <p>The name of the gate's owner</p>
|
|
||||||
* @param options <p>A map containing all possible portal options, with true for the ones enabled</p>
|
* @param options <p>A map containing all possible portal options, with true for the ones enabled</p>
|
||||||
*/
|
*/
|
||||||
public Portal(PortalLocation portalLocation, BlockLocation button, String destination, String name, String network,
|
public Portal(PortalLocation portalLocation, BlockLocation button, String destination, String name, String network,
|
||||||
Gate gate, UUID ownerUUID, String ownerName, Map<PortalOption, Boolean> options) {
|
Gate gate, PortalOwner portalOwner, Map<PortalOption, Boolean> options) {
|
||||||
this.location = portalLocation;
|
this.location = portalLocation;
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.ownerUUID = ownerUUID;
|
this.portalOwner = portalOwner;
|
||||||
this.ownerName = ownerName;
|
|
||||||
this.options = new PortalOptions(options, destination.length() > 0);
|
this.options = new PortalOptions(options, destination.length() > 0);
|
||||||
this.signDrawer = new PortalSignDrawer(this);
|
this.signDrawer = new PortalSignDrawer(this);
|
||||||
this.portalOpener = new PortalOpener(this, destination);
|
this.portalOpener = new PortalOpener(this, destination);
|
||||||
@ -180,25 +175,14 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this portal's owner
|
* Gets this portal's owner
|
||||||
*
|
*
|
||||||
* <p>The owner is the player which created the portal.</p>
|
* <p>The owner is the player which created the portal.</p>
|
||||||
*
|
*
|
||||||
* @return <p>The name of this portal's owner</p>
|
* @return <p>This portal's owner</p>
|
||||||
*/
|
*/
|
||||||
public String getOwnerName() {
|
public PortalOwner getOwner() {
|
||||||
return ownerName;
|
return portalOwner;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the UUID of this portal's owner
|
|
||||||
*
|
|
||||||
* <p>The owner is the player which created the portal.</p>
|
|
||||||
*
|
|
||||||
* @return <p>The UUID of this portal's owner</p>
|
|
||||||
*/
|
|
||||||
public UUID getOwnerUUID() {
|
|
||||||
return ownerUUID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -208,10 +192,10 @@ public class Portal {
|
|||||||
* @return <p>True if the player is the owner of this portal</p>
|
* @return <p>True if the player is the owner of this portal</p>
|
||||||
*/
|
*/
|
||||||
public boolean isOwner(Player player) {
|
public boolean isOwner(Player player) {
|
||||||
if (this.ownerUUID != null) {
|
if (this.portalOwner.getUUID() != null) {
|
||||||
return player.getUniqueId().compareTo(this.ownerUUID) == 0;
|
return player.getUniqueId().compareTo(this.portalOwner.getUUID()) == 0;
|
||||||
} else {
|
} else {
|
||||||
return player.getName().equalsIgnoreCase(this.ownerName);
|
return player.getName().equalsIgnoreCase(this.portalOwner.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,8 +152,9 @@ public class PortalCreator {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.portal = new Portal(portalLocation, null, destinationName, portalName,
|
PortalOwner owner = new PortalOwner(player);
|
||||||
network, gate, player.getUniqueId(), player.getName(), portalOptions);
|
this.portal = new Portal(portalLocation, null, destinationName, portalName, network, gate, owner,
|
||||||
|
portalOptions);
|
||||||
return validatePortal(denyMessage, event.getLines(), deny);
|
return validatePortal(denyMessage, event.getLines(), deny);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package net.knarcraft.stargate.portal;
|
|||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.container.BlockLocation;
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||||
import net.knarcraft.stargate.container.TwoTuple;
|
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -11,7 +10,6 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -101,16 +99,6 @@ public class PortalHandler {
|
|||||||
return destinations;
|
return destinations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Un-registers the given portal
|
|
||||||
*
|
|
||||||
* @param portal <p>The portal to un-register</p>
|
|
||||||
* @param removeAll <p>Whether to remove the portal from the list of all portals</p>
|
|
||||||
*/
|
|
||||||
public static void unregisterPortal(Portal portal, boolean removeAll) {
|
|
||||||
PortalRegistry.unregisterPortal(portal, removeAll);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a portal
|
* Registers a portal
|
||||||
*
|
*
|
||||||
@ -397,51 +385,59 @@ public class PortalHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens all always open portals
|
* Opens all always-on portals
|
||||||
*
|
*
|
||||||
* @return <p>A TwoTuple where the first value is the number of always open portals and the second value is the total number of portals</p>
|
* @return <p>The number of always open portals enabled</p>
|
||||||
*/
|
*/
|
||||||
public static TwoTuple<Integer, Integer> openAlwaysOpenPortals() {
|
public static int openAlwaysOpenPortals() {
|
||||||
int portalCount = 0;
|
int alwaysOpenCount = 0;
|
||||||
int openCount = 0;
|
|
||||||
for (Iterator<Portal> iterator = PortalRegistry.getAllPortals().iterator(); iterator.hasNext(); ) {
|
|
||||||
Portal portal = iterator.next();
|
|
||||||
if (portal == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify portal integrity/register portal
|
|
||||||
PortalStructure structure = portal.getStructure();
|
|
||||||
if (!structure.wasVerified() && (!structure.isVerified() || !structure.checkIntegrity())) {
|
|
||||||
destroyInvalidPortal(portal);
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
portalCount++;
|
|
||||||
|
|
||||||
|
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||||
//Open the gate if it's set as always open or if it's a bungee gate
|
//Open the gate if it's set as always open or if it's a bungee gate
|
||||||
if (portal.getOptions().isFixed() && (Stargate.enableBungee && portal.getOptions().isBungee() ||
|
if (portal.getOptions().isFixed() && (Stargate.enableBungee && portal.getOptions().isBungee() ||
|
||||||
portal.getPortalActivator().getDestination() != null && portal.getOptions().isAlwaysOn())) {
|
portal.getPortalActivator().getDestination() != null && portal.getOptions().isAlwaysOn())) {
|
||||||
portal.getPortalOpener().openPortal(true);
|
portal.getPortalOpener().openPortal(true);
|
||||||
openCount++;
|
alwaysOpenCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new TwoTuple<>(openCount, portalCount);
|
return alwaysOpenCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys a portal which has failed its integrity test
|
* Tries to verify all portals and un-registers non-verifiable portals
|
||||||
|
*/
|
||||||
|
public static void verifyAllPortals() {
|
||||||
|
List<Portal> invalidPortals = new ArrayList<>();
|
||||||
|
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||||
|
//Try and verify the portal. Invalidate it if it cannot be validated
|
||||||
|
PortalStructure structure = portal.getStructure();
|
||||||
|
if (!structure.wasVerified() && (!structure.isVerified() || !structure.checkIntegrity())) {
|
||||||
|
invalidPortals.add(portal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Un-register any invalid portals found
|
||||||
|
for (Portal portal : invalidPortals) {
|
||||||
|
unregisterInvalidPortal(portal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Un-registers a portal which has failed its integrity tests
|
||||||
*
|
*
|
||||||
* @param portal <p>The portal of the star portal</p>
|
* @param portal <p>The portal of the star portal</p>
|
||||||
*/
|
*/
|
||||||
private static void destroyInvalidPortal(Portal portal) {
|
private static void unregisterInvalidPortal(Portal portal) {
|
||||||
// DEBUG
|
//Show debug information
|
||||||
for (RelativeBlockVector control : portal.getGate().getLayout().getControls()) {
|
for (RelativeBlockVector control : portal.getGate().getLayout().getControls()) {
|
||||||
if (!portal.getBlockAt(control).getBlock().getType().equals(portal.getGate().getControlBlock())) {
|
Block block = portal.getBlockAt(control).getBlock();
|
||||||
Stargate.debug("loadAllPortals", "Control Block Type == " + portal.getBlockAt(control).getBlock().getType().name());
|
//Log control blocks not matching the gate layout
|
||||||
|
if (!block.getType().equals(portal.getGate().getControlBlock())) {
|
||||||
|
Stargate.debug("PortalHandler::destroyInvalidPortal", "Control Block Type == " +
|
||||||
|
block.getType().name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PortalHandler.unregisterPortal(portal, false);
|
PortalRegistry.unregisterPortal(portal, false);
|
||||||
Stargate.logger.info(Stargate.getString("prefix") + "Destroying stargate at " + portal);
|
Stargate.logger.info(Stargate.getString("prefix") + "Destroying stargate at " + portal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
102
src/main/java/net/knarcraft/stargate/portal/PortalOwner.java
Normal file
102
src/main/java/net/knarcraft/stargate/portal/PortalOwner.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package net.knarcraft.stargate.portal;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The portal owner represents the owner of a portal
|
||||||
|
*/
|
||||||
|
public class PortalOwner {
|
||||||
|
|
||||||
|
private UUID ownerUUID;
|
||||||
|
private String ownerName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new portal owner
|
||||||
|
*
|
||||||
|
* @param ownerIdentifier <p>A UUID, or a username for legacy support</p>
|
||||||
|
*/
|
||||||
|
public PortalOwner(String ownerIdentifier) {
|
||||||
|
parseIdentifier(ownerIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new portal owner
|
||||||
|
*
|
||||||
|
* @param player <p>The player which is the owner of the portal</p>
|
||||||
|
*/
|
||||||
|
public PortalOwner(Player player) {
|
||||||
|
this.ownerUUID = player.getUniqueId();
|
||||||
|
this.ownerName = player.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the UUID of this owner
|
||||||
|
*
|
||||||
|
* @return <p>The UUID of this owner, or null if a UUID is not available</p>
|
||||||
|
*/
|
||||||
|
public UUID getUUID() {
|
||||||
|
return ownerUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of this owner
|
||||||
|
*
|
||||||
|
* @return <p>The name of this owner</p>
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return ownerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the one identifier used for saving the owner
|
||||||
|
*
|
||||||
|
* <p>If the UUID is available, a string representation of the UUID will be returned. If not, the owner's name will
|
||||||
|
* be returned.</p>
|
||||||
|
*
|
||||||
|
* @return <p>The owner's identifier</p>
|
||||||
|
*/
|
||||||
|
public String getIdentifier() {
|
||||||
|
if (ownerUUID != null) {
|
||||||
|
return ownerUUID.toString();
|
||||||
|
} else {
|
||||||
|
return ownerName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the identifier of a portal's owner
|
||||||
|
*
|
||||||
|
* <p>The identifier should be a valid UUID, but can be a username of max 16 characters for legacy support. Strings
|
||||||
|
* longer than 16 characters not parse-able as a UUID will silently fail by setting the owner name to the
|
||||||
|
* identifier.</p>
|
||||||
|
*
|
||||||
|
* @param ownerIdentifier <p>The identifier for a portal's owner</p>
|
||||||
|
*/
|
||||||
|
private void parseIdentifier(String ownerIdentifier) {
|
||||||
|
UUID ownerUUID = null;
|
||||||
|
String ownerName;
|
||||||
|
if (ownerIdentifier.length() > 16) {
|
||||||
|
//If more than 16 characters, the string cannot be a username, so it's probably a UUID
|
||||||
|
try {
|
||||||
|
ownerUUID = UUID.fromString(ownerIdentifier);
|
||||||
|
OfflinePlayer offlineOwner = Bukkit.getServer().getOfflinePlayer(ownerUUID);
|
||||||
|
ownerName = offlineOwner.getName();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
//Invalid as UUID and username, so just keep it as owner name and hope the server owner fixes it
|
||||||
|
ownerName = ownerIdentifier;
|
||||||
|
Stargate.debug("loadAllPortals", "Invalid stargate owner string: " + ownerIdentifier);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Old username from the pre-UUID times. Just keep it as the owner name
|
||||||
|
ownerName = ownerIdentifier;
|
||||||
|
}
|
||||||
|
this.ownerName = ownerName;
|
||||||
|
this.ownerUUID = ownerUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,8 +2,11 @@ package net.knarcraft.stargate.utility;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
|
import net.knarcraft.stargate.portal.PortalOwner;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The economy helper class has helper functions for player payment
|
* The economy helper class has helper functions for player payment
|
||||||
*/
|
*/
|
||||||
@ -24,15 +27,15 @@ public final class EconomyHelper {
|
|||||||
public static boolean cannotPayTeleportFee(Portal entrancePortal, Player player, int cost) {
|
public static boolean cannotPayTeleportFee(Portal entrancePortal, Player player, int cost) {
|
||||||
boolean success;
|
boolean success;
|
||||||
|
|
||||||
//Try to charge the player
|
//Try to charge the player. Paying the portal owner is only possible if a UUID is available
|
||||||
if (entrancePortal.getGate().getToOwner()) {
|
if (entrancePortal.getGate().getToOwner()) {
|
||||||
success = entrancePortal.getOwnerUUID() != null && EconomyHandler.chargePlayerIfNecessary(player,
|
UUID ownerUUID = entrancePortal.getOwner().getUUID();
|
||||||
entrancePortal.getOwnerUUID(), cost);
|
success = ownerUUID != null && EconomyHandler.chargePlayerIfNecessary(player, ownerUUID, cost);
|
||||||
} else {
|
} else {
|
||||||
success = EconomyHandler.chargePlayerIfNecessary(player, cost);
|
success = EconomyHandler.chargePlayerIfNecessary(player, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insufficient Funds
|
//Send the insufficient funds message
|
||||||
if (!success) {
|
if (!success) {
|
||||||
sendInsufficientFundsMessage(entrancePortal.getName(), player, cost);
|
sendInsufficientFundsMessage(entrancePortal.getName(), player, cost);
|
||||||
entrancePortal.getPortalOpener().closePortal(false);
|
entrancePortal.getPortalOpener().closePortal(false);
|
||||||
@ -43,16 +46,17 @@ public final class EconomyHelper {
|
|||||||
sendDeductMessage(entrancePortal.getName(), player, cost);
|
sendDeductMessage(entrancePortal.getName(), player, cost);
|
||||||
|
|
||||||
if (entrancePortal.getGate().getToOwner()) {
|
if (entrancePortal.getGate().getToOwner()) {
|
||||||
Player gateOwner;
|
PortalOwner owner = entrancePortal.getOwner();
|
||||||
if (entrancePortal.getOwnerUUID() != null) {
|
Player portalOwner;
|
||||||
gateOwner = Stargate.server.getPlayer(entrancePortal.getOwnerUUID());
|
if (owner.getUUID() != null) {
|
||||||
|
portalOwner = Stargate.server.getPlayer(owner.getUUID());
|
||||||
} else {
|
} else {
|
||||||
gateOwner = Stargate.server.getPlayer(entrancePortal.getOwnerName());
|
portalOwner = Stargate.server.getPlayer(owner.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Notify the gate owner of received payment
|
//Notify the gate owner of received payment
|
||||||
if (gateOwner != null) {
|
if (portalOwner != null) {
|
||||||
sendObtainMessage(entrancePortal.getName(), gateOwner, cost);
|
sendObtainMessage(entrancePortal.getName(), portalOwner, cost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -2,16 +2,14 @@ package net.knarcraft.stargate.utility;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.container.BlockLocation;
|
||||||
import net.knarcraft.stargate.container.TwoTuple;
|
|
||||||
import net.knarcraft.stargate.portal.Gate;
|
import net.knarcraft.stargate.portal.Gate;
|
||||||
import net.knarcraft.stargate.portal.GateHandler;
|
import net.knarcraft.stargate.portal.GateHandler;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
import net.knarcraft.stargate.portal.PortalHandler;
|
||||||
import net.knarcraft.stargate.portal.PortalLocation;
|
import net.knarcraft.stargate.portal.PortalLocation;
|
||||||
import net.knarcraft.stargate.portal.PortalOptions;
|
import net.knarcraft.stargate.portal.PortalOptions;
|
||||||
|
import net.knarcraft.stargate.portal.PortalOwner;
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
|
||||||
@ -20,7 +18,6 @@ import java.io.File;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,12 +87,7 @@ public final class PortalFileHelper {
|
|||||||
builder.append(portal.getNetwork()).append(':');
|
builder.append(portal.getNetwork()).append(':');
|
||||||
|
|
||||||
//Name is saved as a fallback if the UUID is unavailable
|
//Name is saved as a fallback if the UUID is unavailable
|
||||||
UUID owner = portal.getOwnerUUID();
|
builder.append(portal.getOwner().getIdentifier());
|
||||||
if (owner != null) {
|
|
||||||
builder.append(portal.getOwnerUUID().toString());
|
|
||||||
} else {
|
|
||||||
builder.append(portal.getOwnerName());
|
|
||||||
}
|
|
||||||
|
|
||||||
//Save all the portal options
|
//Save all the portal options
|
||||||
savePortalOptions(portal, builder);
|
savePortalOptions(portal, builder);
|
||||||
@ -209,12 +201,13 @@ public final class PortalFileHelper {
|
|||||||
*/
|
*/
|
||||||
private static void doPostLoadTasks(World world) {
|
private static void doPostLoadTasks(World world) {
|
||||||
//Open any always-on portals. Do this here as it should be more efficient than in the loop.
|
//Open any always-on portals. Do this here as it should be more efficient than in the loop.
|
||||||
TwoTuple<Integer, Integer> portalCounts = PortalHandler.openAlwaysOpenPortals();
|
PortalHandler.verifyAllPortals();
|
||||||
|
int portalCount = PortalRegistry.getAllPortals().size();
|
||||||
|
int openCount = PortalHandler.openAlwaysOpenPortals();
|
||||||
|
|
||||||
//Print info about loaded stargates so that admins can see if all stargates loaded
|
//Print info about loaded stargates so that admins can see if all stargates loaded
|
||||||
Stargate.logger.info(String.format("%s{%s} Loaded %d stargates with %d set as always-on",
|
Stargate.logger.info(String.format("%s{%s} Loaded %d stargates with %d set as always-on",
|
||||||
Stargate.getString("prefix"), world.getName(), portalCounts.getSecondValue(),
|
Stargate.getString("prefix"), world.getName(), portalCount, openCount));
|
||||||
portalCounts.getFirstValue()));
|
|
||||||
|
|
||||||
//Re-draw the signs in case a bug in the config prevented the portal from loading and has been fixed since
|
//Re-draw the signs in case a bug in the config prevented the portal from loading and has been fixed since
|
||||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||||
@ -257,45 +250,18 @@ public final class PortalFileHelper {
|
|||||||
String network = (portalData.length > 9 && !portalData[9].isEmpty()) ? portalData[9] : Stargate.getDefaultNetwork();
|
String network = (portalData.length > 9 && !portalData[9].isEmpty()) ? portalData[9] : Stargate.getDefaultNetwork();
|
||||||
String ownerString = (portalData.length > 10) ? portalData[10] : "";
|
String ownerString = (portalData.length > 10) ? portalData[10] : "";
|
||||||
|
|
||||||
//Try to get owner as UUID
|
//Get the owner from the owner string
|
||||||
TwoTuple<UUID, String> nameAndUUID = getPortalOwnerUUIDAndName(ownerString);
|
PortalOwner owner = new PortalOwner(ownerString);
|
||||||
|
|
||||||
//Create the new portal
|
//Create the new portal
|
||||||
Portal portal = new Portal(portalLocation, button, destination, name, network, gate,
|
Portal portal = new Portal(portalLocation, button, destination, name, network, gate, owner,
|
||||||
nameAndUUID.getFirstValue(), nameAndUUID.getSecondValue(), PortalHandler.getPortalOptions(portalData));
|
PortalHandler.getPortalOptions(portalData));
|
||||||
|
|
||||||
//Register the portal, and close it in case it wasn't properly closed when the server stopped
|
//Register the portal, and close it in case it wasn't properly closed when the server stopped
|
||||||
PortalHandler.registerPortal(portal);
|
PortalHandler.registerPortal(portal);
|
||||||
portal.getPortalOpener().closePortal(true);
|
portal.getPortalOpener().closePortal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the portal UUID and name from the saved owner string
|
|
||||||
*
|
|
||||||
* @param ownerString <p>The saved owner string. Should be a UUID, or a player name if legacy</p>
|
|
||||||
* @return <p>A two-tuple containing the UUID and owner name. The UUID might be null if the ownerString was not a UUID</p>
|
|
||||||
*/
|
|
||||||
private static TwoTuple<UUID, String> getPortalOwnerUUIDAndName(String ownerString) {
|
|
||||||
UUID ownerUUID = null;
|
|
||||||
String ownerName;
|
|
||||||
if (ownerString.length() > 16) {
|
|
||||||
//If more than 16 characters, the string cannot be a username, so it's probably a UUID
|
|
||||||
try {
|
|
||||||
ownerUUID = UUID.fromString(ownerString);
|
|
||||||
OfflinePlayer offlineOwner = Bukkit.getServer().getOfflinePlayer(ownerUUID);
|
|
||||||
ownerName = offlineOwner.getName();
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
//Invalid as UUID and username, so just keep it as owner name and hope the server owner fixes it
|
|
||||||
ownerName = ownerString;
|
|
||||||
Stargate.debug("loadAllPortals", "Invalid stargate owner string: " + ownerString);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//Old username from the pre-UUID times. Just keep it as the owner name
|
|
||||||
ownerName = ownerString;
|
|
||||||
}
|
|
||||||
return new TwoTuple<>(ownerUUID, ownerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks a portal with an invalid gate by changing its sign and writing to the console
|
* Marks a portal with an invalid gate by changing its sign and writing to the console
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user