1
0
Fork 0

Fix UUID handling better

main
Mari 4 years ago
parent 49461a39dc
commit 7fe4e3ce66
  1. 20
      src/main/kotlin/net/deliciousreya/minecraftportal/MinecraftPortalPlugin.kt

@ -72,20 +72,29 @@ class MinecraftPortalPlugin() : JavaPlugin(), Listener
} else { } else {
argsList[1] argsList[1]
} }
val playerString = when { val playerString: String = when {
argsList.size == 2 -> { argsList.size == 2 -> {
argsList[0] val player = server.getPlayer(args[0])
player?.uniqueId?.toString()
?: try {
UUID.fromString(args[0]).toString()
} catch (ex: IllegalArgumentException) {
"bad UUID"
}
} }
sender is Player -> { sender is Player -> {
sender.uniqueId.toString() sender.uniqueId.toString()
} }
else -> { else -> {
null "console"
} }
} }
if (playerString == null) { if (playerString == "console") {
sender.sendMessage("Only players can set their own color with the one-arg form.") sender.sendMessage("Only players can set their own color with the one-arg form.")
return false return false
} else if (playerString == "bad UUID") {
sender.sendMessage("You must pass a UUID or the name of an online player.")
return false
} }
if (colorString == "show") { if (colorString == "show") {
if (sender is Player && playerString == sender.uniqueId.toString()) { if (sender is Player && playerString == sender.uniqueId.toString()) {
@ -109,7 +118,8 @@ class MinecraftPortalPlugin() : JavaPlugin(), Listener
if (sender is Player && playerString == sender.uniqueId.toString()) { if (sender is Player && playerString == sender.uniqueId.toString()) {
sender.sendMessage("Your portals will now be marked with ${portals.getColorFor(playerString).name}.") sender.sendMessage("Your portals will now be marked with ${portals.getColorFor(playerString).name}.")
} else { } else {
sender.sendMessage("Portals created by $playerString will now be marked with ${portals.getColorFor(playerString).name}") val name = server.getOfflinePlayer(UUID.fromString(playerString)).name
sender.sendMessage("Portals created by $name will now be marked with ${portals.getColorFor(playerString).name}")
} }
return true return true
} }

Loading…
Cancel
Save