Skip to content

Commit

Permalink
Added /whitelist status for admins
Browse files Browse the repository at this point in the history
- AdminGui Items page added
  • Loading branch information
DasPhiller committed Jun 19, 2022
1 parent 96f8f08 commit b04e9f8
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
officialMojangMappings()
})
modImplementation("net.fabricmc:fabric-loader:0.14.8")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.55.3+1.19")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.56.0+1.19")
modImplementation("net.fabricmc:fabric-language-kotlin:1.8.0+kotlin.1.7.0")
modImplementation("net.axay:fabrikmc-core:1.8.1")
modImplementation("net.axay:fabrikmc-commands:1.8.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Mixin(TitleScreen.class)
// Mixins HAVE to be written in java due to constraints in the mixin system.
public class ExampleMixin {
public class MainMixin {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
System.out.println("This line is printed by an example mod mixin!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package de.dasphiller.smp.mixin.entity;

import de.dasphiller.smp.MainKt;
import de.dasphiller.smp.mixins.PlayerMixinKt;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import org.checkerframework.checker.units.qual.A;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

Expand All @@ -27,7 +21,7 @@ public class PlayerConnectionMixin {
public void onBroadCast(PlayerList instance, Component message, ResourceKey<ChatType> messageType) {
//just redirecting because I want an empty message here
}
}
}



8 changes: 5 additions & 3 deletions src/main/kotlin/de/dasphiller/smp/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ package de.dasphiller.smp

import de.dasphiller.smp.commands.adminCommand
import de.dasphiller.smp.commands.spawnCommand
import de.dasphiller.smp.commands.whitelistCommand
import de.dasphiller.smp.listener.ConnectionListener
import net.axay.fabrik.core.Fabrik
import net.axay.fabrik.core.text.sendText

fun init() {
ConnectionListener
ConnectionListener.register()
adminCommand
spawnCommand
whitelistCommand
}

fun broadcast(text: String, messageColor: Int = 0xffffff, italic: Boolean = false, bold: Boolean = false) {
fun broadcast(text: String, color: Int = 0xffffff, italic: Boolean = false, bold: Boolean = false) {
Fabrik.currentServer?.playerList?.players?.forEach {
it.sendText {
text(text) {
color = messageColor
this.color = color
this.italic = italic
this.bold = bold
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/de/dasphiller/smp/commands/WhitelistCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.dasphiller.smp.commands

import net.axay.fabrik.commands.command
import net.axay.fabrik.core.Fabrik
import net.axay.fabrik.core.text.sendText

val whitelistCommand = command("whitelist") {
requiresPermissionLevel(4)
literal("status") {
runs {
source.player?.sendText(if (Fabrik.currentServer?.playerList?.isUsingWhitelist!!) "true" else "false")
}
}
}
61 changes: 44 additions & 17 deletions src/main/kotlin/de/dasphiller/smp/gui/AdminGui.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package de.dasphiller.smp.gui

import com.mojang.authlib.GameProfile
import net.axay.fabrik.core.Fabrik
import net.axay.fabrik.core.item.itemStack
import net.axay.fabrik.core.item.setCustomName
import net.axay.fabrik.core.item.setLore
import net.axay.fabrik.core.text.literal
import net.axay.fabrik.core.text.literalText
import net.axay.fabrik.core.text.sendText
import net.axay.fabrik.igui.*
import net.minecraft.network.chat.Component
import net.axay.fabrik.igui.observable.toGuiList
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import java.util.*

val items = arrayListOf<ItemStack>(
itemStack(Items.LIGHT) { count = 64 },
)

fun adminGui(): Gui {
return igui(GuiType.NINE_BY_FIVE, literalText {
Expand All @@ -34,26 +36,20 @@ fun adminGui(): Gui {
}
}
}.guiIcon, 3)
changePageByKey((2 sl 5), itemStack(Items.STRUCTURE_VOID) {
setCustomName("Items") {
bold = true
italic = false
}
}.guiIcon, 1)
}
page(3) {
effectFrom = GuiPage.ChangeEffect.SLIDE_VERTICALLY
effectTo = GuiPage.ChangeEffect.SLIDE_VERTICALLY
placeholder(Slots.All, itemStack(Items.GRAY_STAINED_GLASS_PANE) {
setCustomName("")
}.guiIcon)
changePageByKey((1 sl 1), itemStack(Items.DARK_OAK_DOOR) {
setCustomName {
text("Hauptmenü") {
color = 0x6fa8dc
bold = true
italic = false
}
setLore(listOf(literalText("description") {
italic = false
color = 0xb30003
}))
}
}.guiIcon, 2)
goBack(this)
button((3 sl 2), itemStack(Items.PAPER) {
setCustomName {
text("Toggle Whitelist") {
Expand Down Expand Up @@ -114,5 +110,36 @@ fun adminGui(): Gui {
server?.stopServer()
}
}
page(1) {
effectFrom = GuiPage.ChangeEffect.SLIDE_VERTICALLY
effectTo = GuiPage.ChangeEffect.SLIDE_VERTICALLY
placeholder(Slots.Border, itemStack(Items.GRAY_STAINED_GLASS_PANE) {
setCustomName("")
}.guiIcon)
val compound = compound(
(4 sl 2) rectTo (2 sl 8), items.toGuiList(), iconGenerator = {
itemStack(it.item) {}
}, onClick = { event, element ->
event.player.inventory.add(element)
}
)
goBack(this)
}
}
}

fun goBack(builder: GuiBuilder.PageBuilder) {
builder.changePageByKey((1 sl 1), itemStack(Items.DARK_OAK_DOOR) {
setCustomName {
text("Hauptmenü") {
color = 0x6fa8dc
bold = true
italic = false
}
setLore(listOf(literalText("description") {
italic = false
color = 0xb30003
}))
}
}.guiIcon, 2)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents
import net.minecraft.world.level.GameType

object ConnectionListener {
init {
fun register() {
ServerPlayConnectionEvents.JOIN.register { serverGamePacketListenerImpl, _, _ ->
serverGamePacketListenerImpl.player.sendText {
text("Willkommen auf dem SMP") {
color = 0x8fce00
}
}
serverGamePacketListenerImpl.player.setGameMode(GameType.SURVIVAL)
broadcast("${serverGamePacketListenerImpl.player.displayName.string} hat den Server betreten", 0x8fce00, false, bold = true)
broadcast(
"${serverGamePacketListenerImpl.player.displayName.string} hat den Server betreten",
0x8fce00,
false,
bold = true
)
}
ServerPlayConnectionEvents.DISCONNECT.register { handler, _ ->
broadcast(
Expand Down
8 changes: 1 addition & 7 deletions src/main/kotlin/de/dasphiller/smp/mixins/PlayerMixinKt.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package de.dasphiller.smp.mixins

import de.dasphiller.smp.broadcast
import net.minecraft.network.Connection
import net.minecraft.network.chat.ChatType
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.MutableComponent
import net.minecraft.resources.ResourceKey
import net.minecraft.server.level.ServerPlayer
import net.minecraft.server.players.PlayerList
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo

object PlayerMixinKt {
fun onPlaceNewPlayer(instance: PlayerList) {
broadcast("Willkommen ")

}
}
2 changes: 1 addition & 1 deletion src/main/resources/smp.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"mixins": [
],
"client": [
"ExampleMixin"
"MainMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b04e9f8

Please sign in to comment.