Skip to content

Commit

Permalink
1.1.11 - Don't use MojangAPI for leaderboard commands
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Aug 4, 2021
1 parent 0b1b88a commit 804bce3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "xyz.acrylicstyle.dailyrankingboard"
version = "1.1.10"
version = "1.1.11"

plugins {
java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import com.mojang.brigadier.arguments.IntegerArgumentType
import com.mojang.brigadier.arguments.StringArgumentType
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import com.mojang.brigadier.builder.RequiredArgumentBuilder
import net.minecraft.server.v1_16_R3.ArgumentEntity
import net.minecraft.server.v1_16_R3.ChatComponentText
import net.minecraft.server.v1_16_R3.CommandListenerWrapper
import net.minecraft.server.v1_16_R3.ICompletionProvider
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.craftbukkit.v1_16_R3.CraftServer
Expand Down Expand Up @@ -39,7 +39,6 @@ import xyz.acrylicstyle.dailyranking.plugin.util.InternalUtil.getArmorStandData
import xyz.acrylicstyle.dailyranking.plugin.util.InternalUtil.runOnMain
import xyz.acrylicstyle.dailyranking.plugin.util.InternalUtil.schedule
import xyz.acrylicstyle.dailyranking.plugin.util.PlayerArmorStandData
import xyz.acrylicstyle.mcutil.mojang.MojangAPI
import java.io.File
import java.time.LocalDateTime
import java.util.Timer
Expand Down Expand Up @@ -344,39 +343,47 @@ class DailyRankingBoardPlugin: JavaPlugin(), DailyRankingBoardAPIImpl {
)
.then(literal("add")
.requires { s -> s.bukkitSender.hasPermission("dailyrankingboard.maps.leaderboard.add") }
.then(argument("player", ArgumentEntity.c())
.then(argument("player", StringArgumentType.word())
.suggests { _, builder -> ICompletionProvider.b(UserCacheFile.getUsernames(), builder) }
.then(argument("value", IntegerArgumentType.integer())
.executes { context ->
val game = GameArgument.get(context, "game")
val map = MapArgument.get(game, context, "map")
val player = ArgumentEntity.e(context, "player")
val id = StringArgumentType.getString(context, "player")
val value = IntegerArgumentType.getInteger(context, "value")
val result = map.addLeaderboardEntry(player.uniqueID, value)
if (result == -1) {
context.source.sendFailureMessage(ChatComponentText("このマップは操作できません。"))
val uuid = UserCacheFile.getUUIDByName(id)
if (uuid == null) {
context.source.sendFailureMessage(ChatComponentText("プレイヤーが見つかりません"))
} else {
refreshLeaderboard()
val result = map.addLeaderboardEntry(uuid, value)
if (result == -1) {
context.source.sendFailureMessage(ChatComponentText("このマップは操作できません。"))
} else {
refreshLeaderboard()
}
return@executes result
}
return@executes result
return@executes 0
}
)
)
)
.then(literal("remove")
.requires { s -> s.bukkitSender.hasPermission("dailyrankingboard.maps.leaderboard.remove") }
.then(argument("player", StringArgumentType.word())
.suggests { _, builder -> ICompletionProvider.b(UserCacheFile.getUsernames(), builder) }
.executes { context ->
val game = GameArgument.get(context, "game")
val map = MapArgument.get(game, context, "map")
val id = StringArgumentType.getString(context, "player")
MojangAPI.getUniqueId(id)
.then { uuid ->
map.removeLeaderboardEntry(uuid)
refreshLeaderboard()
context.source.sendMessage(ChatComponentText("${ChatColor.GOLD}${id}${ChatColor.GREEN}の記録をすべて削除しました。"), true)
}.onCatch {
context.source.sendFailureMessage(ChatComponentText("プレイヤーが見つかりません"))
}
val uuid = UserCacheFile.getUUIDByName(id)
if (uuid == null) {
context.source.sendFailureMessage(ChatComponentText("プレイヤーが見つかりません"))
} else {
map.removeLeaderboardEntry(uuid)
refreshLeaderboard()
context.source.sendMessage(ChatComponentText("${ChatColor.GOLD}${id}${ChatColor.GREEN}の記録をすべて削除しました。"), true)
}
return@executes 0
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ object UserCacheFile {
}
}

operator fun set(uuid: UUID, name: String) { cache.set(uuid.toString(), name) }
fun getUsernames() = cache.rawData.values.filterIsInstance<String>()

fun getUUIDByName(name: String): UUID? = cache.rawData.entries.find { entry -> entry.value == name }?.let { UUID.fromString(it.key) }

operator fun set(uuid: UUID, name: String) {
cache.rawData
.entries
.filter { entry -> entry.value == name }
.forEach { cache.set(it.key, null) }
cache.set(uuid.toString(), name)
}

operator fun get(uuid: UUID): String? = cache.getString(uuid.toString())

fun clear() = cache.rawData.clear()
}
2 changes: 1 addition & 1 deletion plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: DailyRankingBoard
main: xyz.acrylicstyle.dailyranking.plugin.DailyRankingBoardPlugin
api-version: 1.13
version: 1.1.10
version: 1.1.11
load: POSTWORLD
softdepend:
- Multiverse-Core
Expand Down

0 comments on commit 804bce3

Please sign in to comment.