Only fetches name from UUID if necessary
Also fixes some minor warnings
This commit is contained in:
@@ -344,7 +344,7 @@ Other special characters include the following:
|
||||
|
||||
- Spaces/blank characters (` `) will not be checked, and as such, represent any block.
|
||||
- Periods (`.`) represent the portal's *iris* (i.e. the part that opens and closes)
|
||||
- An asterix (`*`) represents the portals's "exit point" (i.e. the block the player will teleport in front of).
|
||||
- An asterix (`*`) represents the portals' "exit point" (i.e. the block the player will teleport in front of).
|
||||
|
||||
##### Underwater Portals
|
||||
|
||||
@@ -377,7 +377,7 @@ Gates are not limited to the shape of a standard nether portal -- they can be th
|
||||
In this case, a simple 5x5 square has been used as a gate.
|
||||
|
||||
Gates are also not limited to [materials](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html) (such
|
||||
as `OBSIDIAN`); they may also use [tags](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Tag.html)) (such
|
||||
as `OBSIDIAN`); they may also use [tags](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Tag.html) (such
|
||||
as `#WOOL`).<br>
|
||||
Note that all tags must be prefaced with a hashtag (`#`), as in `#WOOL`.
|
||||
|
||||
|
@@ -54,7 +54,7 @@ public class Portal {
|
||||
this.network = portalStrings.network();
|
||||
this.name = portalStrings.name();
|
||||
this.portalOwner = portalOwner;
|
||||
this.options = new PortalOptions(options, portalStrings.destination().length() > 0);
|
||||
this.options = new PortalOptions(options, !portalStrings.destination().isEmpty());
|
||||
this.signDrawer = new PortalSignDrawer(this);
|
||||
this.portalOpener = new PortalOpener(this, portalStrings.destination());
|
||||
this.structure = new PortalStructure(this, gate, button);
|
||||
|
@@ -74,7 +74,7 @@ public class PortalActivator {
|
||||
if (portal.getOptions().isRandom()) {
|
||||
//Find possible destinations
|
||||
List<String> destinations = PortalHandler.getDestinations(portal, player, portalNetwork);
|
||||
if (destinations.size() == 0) {
|
||||
if (destinations.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
//Get one random destination
|
||||
@@ -217,7 +217,7 @@ public class PortalActivator {
|
||||
* @return <p>Whether this portal activator's portal is active</p>
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return portal.getOptions().isFixed() || (destinations.size() > 0);
|
||||
return portal.getOptions().isFixed() || (!destinations.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +255,7 @@ public class PortalActivator {
|
||||
}
|
||||
|
||||
//If no destinations are available, just tell the player and quit
|
||||
if (destinations.size() == 0) {
|
||||
if (destinations.isEmpty()) {
|
||||
if (!portal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString(Message.NO_DESTINATION));
|
||||
}
|
||||
|
@@ -171,7 +171,7 @@ public class PortalCreator {
|
||||
String route = "PortalCreator::getNetworkName";
|
||||
|
||||
//Use default network if a proper alternative is not set
|
||||
if (portalStrings.network().length() < 1 || portalStrings.network().length() > getMaxNameNetworkLength()) {
|
||||
if (portalStrings.network().isEmpty() || portalStrings.network().length() > getMaxNameNetworkLength()) {
|
||||
network = Stargate.getDefaultNetwork();
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class PortalCreator {
|
||||
}
|
||||
|
||||
//Check if the user can create portals to this world.
|
||||
if (!bungee && destinationName.length() > 0) {
|
||||
if (!bungee && !destinationName.isEmpty()) {
|
||||
Portal destinationPortal = PortalHandler.getByName(destinationName, network);
|
||||
if (destinationPortal != null && destinationPortal.getWorld() != null) {
|
||||
String world = destinationPortal.getWorld().getName();
|
||||
@@ -294,7 +294,7 @@ public class PortalCreator {
|
||||
String route = "PortalCreator::checkIfNewPortalIsValid";
|
||||
|
||||
//Check if the portal name can fit on the sign with padding (>name<)
|
||||
if (portal.getCleanName().length() < 1 || portal.getCleanName().length() > getMaxNameNetworkLength()) {
|
||||
if (portal.getCleanName().isEmpty() || portal.getCleanName().length() > getMaxNameNetworkLength()) {
|
||||
Stargate.debug(route, String.format("Name length error. %s is too long.",
|
||||
portal.getCleanName()));
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString(Message.CREATION_NAME_LENGTH));
|
||||
|
@@ -251,7 +251,7 @@ public class PortalHandler {
|
||||
}
|
||||
|
||||
//Can not create a non-fixed always-on portal
|
||||
if (portalOptions.get(PortalOption.ALWAYS_ON) && destinationName.length() == 0) {
|
||||
if (portalOptions.get(PortalOption.ALWAYS_ON) && destinationName.isEmpty()) {
|
||||
portalOptions.put(PortalOption.ALWAYS_ON, false);
|
||||
}
|
||||
|
||||
|
@@ -255,7 +255,7 @@ public class PortalRegistry {
|
||||
* @param portal <p>The portal to register</p>
|
||||
*/
|
||||
public static void registerPortal(@NotNull Portal portal) {
|
||||
portal.getOptions().setFixed(portal.getDestinationName().length() > 0 || portal.getOptions().isRandom() ||
|
||||
portal.getOptions().setFixed(!portal.getDestinationName().isEmpty() || portal.getOptions().isRandom() ||
|
||||
portal.getOptions().isBungee());
|
||||
|
||||
String portalName = portal.getCleanName();
|
||||
|
@@ -6,8 +6,6 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -15,7 +13,6 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PortalOwner {
|
||||
|
||||
private static final Map<String, OfflinePlayer> fetchedPlayers = new HashMap<>();
|
||||
private UUID ownerUUID;
|
||||
private String ownerName;
|
||||
|
||||
@@ -25,14 +22,8 @@ public class PortalOwner {
|
||||
* @param ownerIdentifier <p>A UUID, or a username for legacy support</p>
|
||||
*/
|
||||
public PortalOwner(@NotNull String ownerIdentifier) {
|
||||
if (fetchedPlayers.containsKey(ownerIdentifier)) {
|
||||
OfflinePlayer player = fetchedPlayers.get(ownerIdentifier);
|
||||
this.ownerUUID = player.getUniqueId();
|
||||
this.ownerName = player.getName();
|
||||
} else {
|
||||
parseIdentifier(ownerIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new portal owner
|
||||
@@ -77,6 +68,12 @@ public class PortalOwner {
|
||||
*/
|
||||
@NotNull
|
||||
public String getName() {
|
||||
if (this.ownerUUID != null && this.ownerName == null) {
|
||||
this.ownerName = fetchName();
|
||||
if (this.ownerName == null) {
|
||||
this.ownerName = "UNKNOWN!";
|
||||
}
|
||||
}
|
||||
return ownerName;
|
||||
}
|
||||
|
||||
@@ -108,14 +105,11 @@ public class PortalOwner {
|
||||
*/
|
||||
private void parseIdentifier(@NotNull String ownerIdentifier) {
|
||||
UUID ownerUUID = null;
|
||||
String ownerName;
|
||||
String ownerName = null;
|
||||
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);
|
||||
fetchedPlayers.put(ownerIdentifier, offlineOwner);
|
||||
ownerName = offlineOwner.getName();
|
||||
} catch (IllegalArgumentException exception) {
|
||||
//Invalid as UUID and username, so just keep it as owner name and hope the server owner fixes it
|
||||
ownerName = ownerIdentifier;
|
||||
@@ -129,4 +123,14 @@ public class PortalOwner {
|
||||
this.ownerUUID = ownerUUID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of a player
|
||||
*
|
||||
* @return <p>The player to get the name of</p>
|
||||
*/
|
||||
@Nullable
|
||||
private String fetchName() {
|
||||
return Bukkit.getServer().getOfflinePlayer(ownerUUID).getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user