-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from bluefireoly/scoreboard
Add scoreboard class
- Loading branch information
Showing
9 changed files
with
101 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
fabrikmc-core/src/main/kotlin/net/axay/fabrik/core/scoreboard/Sideboard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.axay.fabrik.core.scoreboard | ||
|
||
import net.axay.fabrik.core.Fabrik | ||
import net.minecraft.scoreboard.Scoreboard | ||
import net.minecraft.scoreboard.ScoreboardCriterion | ||
import net.minecraft.scoreboard.ServerScoreboard | ||
import net.minecraft.text.Text | ||
|
||
class Sideboard( | ||
name: String, | ||
displayName: Text, | ||
lines: List<Text>, | ||
) { | ||
companion object { | ||
val sidebarId = Scoreboard.getDisplaySlotId("sidebar") | ||
} | ||
|
||
private val scoreboard = ServerScoreboard(Fabrik.currentServer) | ||
private val objective = scoreboard.addObjective(name, ScoreboardCriterion.DUMMY, displayName, ScoreboardCriterion.RenderType.INTEGER) | ||
|
||
init { | ||
lines.forEachIndexed { index, line -> | ||
val team = scoreboard.addTeam("team_$index") | ||
team.prefix = line | ||
scoreboard.addPlayerToTeam("§$index", team) | ||
scoreboard.getPlayerScore("§$index", objective).score = lines.size - index | ||
} | ||
|
||
scoreboard.setObjectiveSlot(sidebarId, objective) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/Manager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
package net.axay.fabrik.test | ||
|
||
import net.axay.fabrik.core.Fabrik | ||
import net.axay.fabrik.test.commands.guiCommand | ||
import net.axay.fabrik.test.commands.sideboardCommand | ||
import net.axay.fabrik.test.commands.textTestCommand | ||
|
||
fun init() { | ||
Fabrik.init() | ||
|
||
guiCommand | ||
textTestCommand | ||
sideboardCommand | ||
} |
35 changes: 35 additions & 0 deletions
35
fabrikmc-testmod/src/main/kotlin/net/axay/fabrik/test/commands/SideboardCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.axay.fabrik.test.commands | ||
|
||
import com.mojang.brigadier.arguments.StringArgumentType | ||
import net.axay.fabrik.commands.* | ||
import net.axay.fabrik.core.scoreboard.Sideboard | ||
import net.axay.fabrik.core.text.literal | ||
import net.axay.fabrik.core.text.literalText | ||
|
||
val sideboardCommand = command("sideboard", true) { | ||
argument("example", StringArgumentType.string()) { | ||
simpleSuggests { sideboardExamples.keys } | ||
simpleExecutes { | ||
sideboardExamples[it.getArgument("example")]?.value | ||
} | ||
} | ||
} | ||
|
||
private val sideboardExamples = mapOf( | ||
"simple" to lazy { | ||
Sideboard( | ||
"simple", | ||
literalText("Simple Sideboard") { | ||
color = 0x6DFF41 | ||
}, | ||
listOf( | ||
"Hey wie,".literal, | ||
"geht's?".literal, | ||
" ".literal, | ||
literalText("Farben gehen auch") { | ||
color = 0x57FFF0 | ||
} | ||
) | ||
) | ||
} | ||
) |