Szymon Gutomski

make this skript to plugin 1.21.1

📎 1 file 35,060 chars
📄
pasted-code-1790375244595.txt
txt 1024 lines
▶
on load:
	wait 5 ticks
	send "&aSkrypt Pomyślnie załadowany&8 | &aAutor: xSlodziaczekk" to console and all players

command /adminpanel []:
	aliases: /admin-panel
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		delete {xslodziaczek-apczat::%uuid of player%}
		if arg-1 is set:
			set {xslodziakk-apcel::%uuid of player%} to name of arg-1
			oknoGraczaAp(player)
			stop
		panelAp(player)

command /odbanuj :
	aliases: /aodbanuj
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/odbanuj 
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		set {_c} to szukajKaryAp("ban", arg-1)
		if {_c} is "":
			send "&cTen gracz nie ma bana."
			stop
		zdejmijKareAp(player, "ban", {_c})

command /odcisz :
	aliases: /aodcisz
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/odcisz 
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		set {_c} to szukajKaryAp("mute", arg-1)
		if {_c} is "":
			send "&cTen gracz nie jest wyciszony."
			stop
		zdejmijKareAp(player, "mute", {_c})

command /aban   :
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/aban   
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		set {_t} to arg-2 in lower case
		if {_t} is not "perm":
			if czasAp({_t}) is 0 seconds:
				send "&cZły format czasu. Przykład: &f30m&c, &f2h&c, &f7d&c, &fperm"
				stop
		ukarzAp(player, arg-1, "ban", arg-3, {_t})

command /abanip   :
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/abanip   
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		set {_t} to arg-2 in lower case
		if {_t} is not "perm":
			if czasAp({_t}) is 0 seconds:
				send "&cZły format czasu. Przykład: &f30m&c, &f2h&c, &f7d&c, &fperm"
				stop
		ukarzAp(player, arg-1, "banip", arg-3, {_t})

command /amute   :
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/amute   
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		set {_t} to arg-2 in lower case
		if {_t} is not "perm":
			if czasAp({_t}) is 0 seconds:
				send "&cZły format czasu. Przykład: &f30m&c, &f2h&c, &f7d&c, &fperm"
				stop
		ukarzAp(player, arg-1, "mute", arg-3, {_t})

command /akick  :
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/akick  
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		ukarzAp(player, arg-1, "kick", arg-2, "")

command /awarn  :
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/awarn  
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		ukarzAp(player, arg-1, "warn", arg-2, "")

command /aostrzezenia  []:
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/aostrzezenia  [wyczysc]
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		set {_u} to "%uuid of arg-1%"
		if arg-2 is "wyczysc":
			delete {xslodziakk-apwarny::%{_u}%}
			delete {xslodziack-apwarnlista::%{_u}%::*}
			send "&aWyczyszczono ostrzeżenia &f%name of arg-1%&a."
			stop
		set {_w} to {xslodziakk-apwarny::%{_u}%}
		if {_w} isn't set:
			set {_w} to 0
		send "&7"
		send "&6&lOSTRZEŻENIA &f%name of arg-1% &8(&7%{_w}%&8)"
		loop {xslodziack-apwarnlista::%{_u}%::*}:
			send "&8 » %loop-value%"
		send "&7"

command /abany:
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		wypiszKaryAp(player, "ban")

command /awyciszenia:
	aliases: /amuty
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		wypiszKaryAp(player, "mute")

command /ahistoria :
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/ahistoria 
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		set {_u} to "%uuid of arg-1%"
		if {xslodziacek-aphist::%{_u}%::*} isn't set:
			send "&aTen gracz nie ma żadnych kar."
			stop
		send "&7"
		send "&c&lHISTORIA KAR &f%name of arg-1%"
		loop {xslodziacek-aphist::%{_u}%::*}:
			send "&8 » %loop-value%"
		send "&7"

command /aogloszenie :
	permission: xslodziak.adminpanel
	permission message: &cBrak dostępu.
	usage: &c/aogloszenie 
	executable by: players
	trigger:
		if straznikAp() is not "xSlodziaczekk":
			stop
		ogloszenieAp(player, arg-1)

on inventory click:
	set {_u} to "%uuid of player%"
	set {_m} to {xslodziacek-apmenu::%{_u}%}
	if {_m} isn't set:
		stop
	cancel event
	if clicked inventory is not event-inventory:
		stop
	set {_s} to index of clicked slot
	if {_m} is "panel":
		if {_s} is 9:
			przelaczAp(player, "vanish")
		else if {_s} is 11:
			przelaczAp(player, "fly")
		else if {_s} is 13:
			przelaczAp(player, "god")
		else if {_s} is 15:
			if gamemode of player is creative:
				set gamemode of player to survival
			else:
				set gamemode of player to creative
			message "&aTryb gry: &f%gamemode of player%"
		else if {_s} is 17:
			heal player
			feed player
			extinguish player
			message "&aUleczono."
		else if {_s} is 27:
			wait a tick
			czatAp(player, "gracz", "nick gracza")
			stop
		else if {_s} is 29:
			wait a tick
			presetyAp(player, "ogl")
			stop
		else if {_s} is 31:
			wait a tick
			listaKarAp(player, "ban")
			stop
		else if {_s} is 33:
			wait a tick
			listaKarAp(player, "mute")
			stop
		else if {_s} is 35:
			wait a tick
			serwerAp(player)
			stop
		else:
			stop
		play sound "ui.button.click" to player
		wait a tick
		panelAp(player)
		stop
	if {_m} is "serwer":
		if {_s} is 18:
			wait a tick
			panelAp(player)
			stop
		if {_s} is 10:
			set time in world of player to 7:00
			message "&aUstawiono dzień."
		else if {_s} is 12:
			set time in world of player to 20:00
			message "&aUstawiono noc."
		else if {_s} is 14:
			set weather in world of player to clear
			message "&aUstawiono słońce."
		else if {_s} is 16:
			loop 100 times:
				broadcast ""
			broadcast "&8 » &7Czat został wyczyszczony przez &f%name of player%"
		else:
			stop
		play sound "ui.button.click" to player
		stop
	if {_m} is "lista-ban" or "lista-mute":
		if {_s} is 45:
			wait a tick
			panelAp(player)
			stop
		set {_c} to {slodziak-apsloty::%{_u}%::%{_s}%}
		if {_c} isn't set:
			stop
		set {_k} to {_m}
		replace all "lista-" with "" in {_k}
		zdejmijKareAp(player, {_k}, {_c})
		wait a tick
		listaKarAp(player, {_k})
		stop
	if {_m} is "gracz":
		if {_s} is 36:
			wait a tick
			panelAp(player)
			stop
		set {_c} to celAp(player)
		if {_c} isn't set:
			send "&cGracz wyszedł z serwera."
			wait a tick
			panelAp(player)
			stop
		if {_s} is 9:
			wait a tick
			presetyAp(player, "ban")
		else if {_s} is 11:
			wait a tick
			presetyAp(player, "mute")
		else if {_s} is 13:
			wait a tick
			presetyAp(player, "kick")
		else if {_s} is 15:
			wait a tick
			presetyAp(player, "warn")
		else if {_s} is 17:
			przelaczAp({_c}, "freeze")
			if {slodziaczek-apflagi::%uuid of {_c}%::freeze} is set:
				message "&aZamrożono &f%name of {_c}%&a."
				send title "&b&lZAMROŻONY" with subtitle "&7Nie ruszaj się" to {_c} for 3 seconds
			else:
				message "&aOdmrożono &f%name of {_c}%&a."
			wait a tick
			oknoGraczaAp(player)
		else if {_s} is 27:
			close player's inventory
			teleport player to {_c}
		else if {_s} is 29:
			close player's inventory
			teleport {_c} to player
		else if {_s} is 31:
			wait a tick
			open {_c}'s inventory to player
		else if {_s} is 33:
			wait a tick
			open ender chest of {_c} to player
		else if {_s} is 35:
			heal {_c}
			feed {_c}
			extinguish {_c}
			message "&aUleczono &f%name of {_c}%&a."
		stop
	if {_s} is 18:
		wait a tick
		if {_m} is "ogl":
			panelAp(player)
		else:
			oknoGraczaAp(player)
		stop
	if {_s} is 17:
		wait a tick
		if {_m} is "ogl":
			czatAp(player, "ogl", "treść ogłoszenia")
		else if {_m} is "ban":
			if click type is right mouse button:
				czatAp(player, "powod-banip", "powód")
			else:
				czatAp(player, "powod-ban", "powód")
		else:
			czatAp(player, "powod-%{_m}%", "powód")
		stop
	if {_s} is 9, 11, 13 or 15:
		set {_i} to ({_s} - 7) / 2
		if {_m} is "ogl":
			ogloszenieAp(player, presetAp("ogl", {_i}, "powod"))
			close player's inventory
			stop
		set {_c} to celAp(player)
		if {_c} isn't set:
			send "&cGracz wyszedł z serwera."
			stop
		set {_mm} to {_m}
		if {_m} is "ban":
			if click type is right mouse button:
				set {_mm} to "banip"
		close player's inventory
		ukarzAp(player, {_c}, {_mm}, presetAp({_m}, {_i}, "powod"), presetAp({_m}, {_i}, "czas"))

on inventory drag:
	if {xslodziacek-apmenu::%uuid of player%} is set:
		cancel event

on inventory close:
	delete {xslodziacek-apmenu::%uuid of player%}

on chat:
	set {_u} to "%uuid of player%"
	set {_co} to {xslodziaczek-apczat::%{_u}%}
	if {_co} is set:
		cancel event
		delete {xslodziaczek-apczat::%{_u}%}
		set {_w} to message
		wait a tick
		if {_w} is "anuluj":
			if {_co} is "gracz" or "ogl":
				panelAp(player)
			else:
				oknoGraczaAp(player)
			stop
		czatWpisAp(player, {_co}, {_w})
		stop
	if mutAp(player) is true:
		cancel event
		set {_z} to zostaloAp("mute", {_u})
		send "&cJesteś wyciszony. &7Powód: &f%{xslodziaczek-apmute::%{_u}%::powod}%&7, zostało: &f%{_z}%" to player

on command:
	if mutAp(player) is false:
		stop
	if command is "msg", "tell", "w", "r", "m", "me", "whisper" or "reply":
		cancel event
		send "&cJesteś wyciszony."

on connect:
	set {_u} to "%uuid of player%"
	set {_ip} to kluczIpAp(ip of player)
	set {_r} to ""
	if {slodziak-apbanlista::%{_u}%} is set:
		set {_r} to {_u}
	else if {xslodziak-apbanip::%{_ip}%} is set:
		set {_r} to {xslodziak-apbanip::%{_ip}%}
		if {slodziak-apbanlista::%{_r}%} isn't set:
			delete {xslodziak-apbanip::%{_ip}%}
			stop
	if {_r} is "":
		stop
	if {xslodziak-apban::%{_r}%::do} is set:
		if {xslodziak-apban::%{_r}%::do} < now:
			usunBanAp({_r})
			stop
	kick player due to ekranBanaAp({_r})

on join:
	set {_u} to "%uuid of player%"
	if {slodziaczek-apflagi::%{_u}%::vanish} is set:
		loop all players:
			if loop-player doesn't have permission "xslodziak.adminpanel":
				hide player from loop-player
	if {slodziaczek-apflagi::%{_u}%::fly} is set:
		set flight mode of player to true
	if player has permission "xslodziak.adminpanel":
		stop
	loop all players:
		if {slodziaczek-apflagi::%uuid of loop-player%::vanish} is set:
			hide loop-player from player

on quit:
	set {_u} to "%uuid of player%"
	delete {xslodziacek-apmenu::%{_u}%}
	delete {xslodziaczek-apczat::%{_u}%}
	delete {xslodziack-apbuf::%{_u}%::*}

on damage:
	if victim is a player:
		if {slodziaczek-apflagi::%uuid of victim%::god} is set:
			cancel event

on player move:
	if {slodziaczek-apflagi::%uuid of player%::freeze} is set:
		cancel event

function czatAp(p: player, co: text, tekst: text):
	set {xslodziaczek-apczat::%uuid of {_p}%} to {_co}
	close {_p}'s inventory
	message "&aWpisz na czacie %{_tekst}%:" to {_p}
	message "&aW przeciwnym razie, wpisz ""Anuluj"" aby Anulować" to {_p}

function czatWpisAp(p: player, co: text, w: text):
	set {_u} to "%uuid of {_p}%"
	if {_co} is "gracz":
		replace all " " with "" in {_w}
		loop all players:
			if name of loop-player is {_w}:
				set {_c} to loop-player
		if {_c} isn't set:
			send "&cNie ma takiego gracza online." to {_p}
			panelAp({_p})
			stop
		set {xslodziakk-apcel::%{_u}%} to name of {_c}
		oknoGraczaAp({_p})
		stop
	if {_co} is "ogl":
		ogloszenieAp({_p}, {_w})
		stop
	set {_c} to celAp({_p})
	if {_c} isn't set:
		send "&cGracz wyszedł z serwera." to {_p}
		panelAp({_p})
		stop
	if {_co} starts with "powod-":
		set {_k} to {_co}
		replace all "powod-" with "" in {_k}
		if {_k} is "kick" or "warn":
			ukarzAp({_p}, {_c}, {_k}, {_w}, "")
			stop
		set {xslodziack-apbuf::%{_u}%::powod} to {_w}
		czatAp({_p}, "czas-%{_k}%", "czas (np. 30m, 2h, 7d lub perm)")
		stop
	set {_k} to {_co}
	replace all "czas-" with "" in {_k}
	replace all " " with "" in {_w}
	set {_w} to {_w} in lower case
	if {_w} is not "perm":
		if czasAp({_w}) is 0 seconds:
			send "&cZły format czasu." to {_p}
			oknoGraczaAp({_p})
			stop
	ukarzAp({_p}, {_c}, {_k}, {xslodziack-apbuf::%{_u}%::powod}, {_w})
	delete {xslodziack-apbuf::%{_u}%::*}

function czasAp(t: text) :: timespan:
	if length of {_t} < 2:
		return 0 seconds
	set {_j} to last character of {_t}
	set {_n} to first (length of {_t} - 1) characters of {_t}
	set {_n} to {_n} parsed as integer
	if {_n} isn't set:
		return 0 seconds
	if {_n} < 1:
		return 0 seconds
	if {_j} is "d":
		return "%{_n}% days" parsed as timespan
	if {_j} is "h":
		return "%{_n}% hours" parsed as timespan
	if {_j} is "m":
		return "%{_n}% minutes" parsed as timespan
	if {_j} is "s":
		return "%{_n}% seconds" parsed as timespan
	return 0 seconds

function czasTekstAp(t: text) :: text:
	if {_t} is "perm" or "":
		return "na zawsze"
	set {_j} to last character of {_t}
	set {_n} to first (length of {_t} - 1) characters of {_t}
	if {_j} is "d":
		return "%{_n}% dni"
	if {_j} is "h":
		return "%{_n}% godz."
	if {_j} is "m":
		return "%{_n}% min."
	return "%{_n}% sek."

function celAp(p: player) :: player:
	set {_n} to {xslodziakk-apcel::%uuid of {_p}%}
	loop all players:
		if name of loop-player is {_n}:
			return loop-player

function mutAp(p: player) :: boolean:
	set {_u} to "%uuid of {_p}%"
	if {slodziaczek-apmutelista::%{_u}%} isn't set:
		return false
	if {xslodziaczek-apmute::%{_u}%::do} is set:
		if {xslodziaczek-apmute::%{_u}%::do} < now:
			delete {xslodziaczek-apmute::%{_u}%::*}
			delete {slodziaczek-apmutelista::%{_u}%}
			return false
	return true

function zostaloAp(k: text, u: text) :: text:
	if {_k} is "ban":
		set {_d} to {xslodziak-apban::%{_u}%::do}
	else:
		set {_d} to {xslodziaczek-apmute::%{_u}%::do}
	if {_d} isn't set:
		return "na zawsze"
	set {_s} to (unix timestamp of {_d}) - (unix timestamp of now)
	if {_s} < 1:
		return "0 sek."
	set {_s} to floor({_s})
	set {_dn} to floor({_s} / 86400)
	set {_h} to floor(mod({_s}, 86400) / 3600)
	set {_m} to floor(mod({_s}, 3600) / 60)
	set {_sk} to mod({_s}, 60)
	set {_w} to ""
	if {_dn} > 0:
		set {_w} to "%{_dn}% dni %{_h}% godz. %{_m}% min. "
	else if {_h} > 0:
		set {_w} to "%{_h}% godz. %{_m}% min. "
	else if {_m} > 0:
		set {_w} to "%{_m}% min. "
	return "%{_w}%%{_sk}% sek."

function ekranBanaAp(u: text) :: text:
	set {_p} to {xslodziak-apban::%{_u}%::powod}
	set {_a} to {xslodziak-apban::%{_u}%::kto}
	set {_z} to zostaloAp("ban", {_u})
	set {_typ} to "Zwykły ban"
	if {xslodziak-apban::%{_u}%::ip} is set:
		set {_typ} to "Ban na IP"
	set {_d} to {xslodziak-apban::%{_u}%::do}
	if {_d} is set:
		set {_kon} to {_d} formatted as "dd.MM.yyyy HH:mm"
	else:
		set {_kon} to "nigdy"
	set {_e} to "&c&lZOSTAŁEŚ ZBANOWANY%nl%%nl%&7Powód: &f%{_p}%%nl%&7Typ: &f%{_typ}%%nl%&7Nałożył: &f%{_a}%%nl%%nl%&7Do unbana zostało: &e%{_z}%%nl%&7Wygasa: &f%{_kon}%%nl%%nl%&8Niesłuszny ban? Odwołaj się u administracji."
	return {_e}

function kluczIpAp(ip: text) :: text:
	replace all ":" with "-" in {_ip}
	return {_ip}

function usunBanAp(u: text):
	set {_ip} to {xslodziak-apban::%{_u}%::ip}
	if {_ip} is set:
		delete {xslodziak-apbanip::%{_ip}%}
	delete {xslodziak-apban::%{_u}%::*}
	delete {slodziak-apbanlista::%{_u}%}

function ukarzAp(p: player, c: player, k: text, powod: text, czas: text):
	set {_⠅⠁⠗⠁} to "⠭⠎⠇⠕⠙⠵⠊⠁⠉⠵⠑⠅⠅"
	if {_c} is {_p}:
		send "&cNie możesz ukarać siebie." to {_p}
		stop
	if {_c} has permission "xslodziak.adminpanel":
		send "&cNie możesz ukarać administratora." to {_p}
		stop
	set {_u} to "%uuid of {_c}%"
	set {_n} to name of {_c}
	set {_a} to name of {_p}
	set {_ct} to czasTekstAp({_czas})
	set {_dt} to now formatted as "dd.MM.yyyy HH:mm"
	if {_k} is "banip":
		set {_k} to "ban"
		set {_ipban} to true
		set {_nk} to "&4Ban na IP"
	else if {_k} is "ban":
		set {_nk} to "&cBan"
	else if {_k} is "mute":
		set {_nk} to "&7Wyciszenie"
	else if {_k} is "kick":
		set {_nk} to "&6Wyrzucenie"
	else:
		set {_nk} to "&eOstrzeżenie"
		add "&f%{_powod}% &8| &7%{_a}% &8| &7%{_dt}%" to {xslodziack-apwarnlista::%{_u}%::*}
	if {_k} is "ban" or "mute":
		add "%{_nk}% &8| &f%{_powod}% &8| &7%{_ct}% &8| &7%{_a}% &8| &7%{_dt}%" to {xslodziacek-aphist::%{_u}%::*}
	else:
		add "%{_nk}% &8| &f%{_powod}% &8| &7%{_a}% &8| &7%{_dt}%" to {xslodziacek-aphist::%{_u}%::*}
	if {_k} is "ban":
		usunBanAp({_u})
		set {slodziak-apbanlista::%{_u}%} to {_u}
		if {_ipban} is set:
			set {_ip} to kluczIpAp(ip of {_c})
			set {xslodziak-apban::%{_u}%::ip} to {_ip}
			set {xslodziak-apbanip::%{_ip}%} to {_u}
		set {xslodziak-apban::%{_u}%::nick} to {_n}
		set {xslodziak-apban::%{_u}%::powod} to {_powod}
		set {xslodziak-apban::%{_u}%::kto} to {_a}
		if {_czas} is not "perm":
			set {_ts} to czasAp({_czas})
			set {xslodziak-apban::%{_u}%::do} to {_ts} from now
		kick {_c} due to ekranBanaAp({_u})
		broadcast "&8 » &c%{_n}% &7został zbanowany na &f%{_ct}%&7. Powód: &f%{_powod}%"
	else if {_k} is "mute":
		delete {xslodziaczek-apmute::%{_u}%::*}
		set {slodziaczek-apmutelista::%{_u}%} to {_u}
		set {xslodziaczek-apmute::%{_u}%::nick} to {_n}
		set {xslodziaczek-apmute::%{_u}%::powod} to {_powod}
		set {xslodziaczek-apmute::%{_u}%::kto} to {_a}
		if {_czas} is not "perm":
			set {_ts} to czasAp({_czas})
			set {xslodziaczek-apmute::%{_u}%::do} to {_ts} from now
		send "&7" to {_c}
		send "&c&lZOSTAŁEŚ WYCISZONY" to {_c}
		send "&8 » &7Powód: &f%{_powod}%" to {_c}
		send "&8 » &7Czas: &f%{_ct}%" to {_c}
		send "&8 » &7Nałożył: &f%{_a}%" to {_c}
		send "&7" to {_c}
		broadcast "&8 » &c%{_n}% &7został wyciszony na &f%{_ct}%&7. Powód: &f%{_powod}%"
	else if {_k} is "kick":
		set {_e} to "&c&lZOSTAŁEŚ WYRZUCONY%nl%%nl%&7Powód: &f%{_powod}%%nl%&7Wyrzucił: &f%{_a}%%nl%%nl%&8Możesz od razu wrócić na serwer."
		kick {_c} due to {_e}
		broadcast "&8 » &c%{_n}% &7został wyrzucony. Powód: &f%{_powod}%"
	else:
		add 1 to {xslodziakk-apwarny::%{_u}%}
		set {_ile} to {xslodziakk-apwarny::%{_u}%}
		send "&7" to {_c}
		send "&6&lOTRZYMAŁEŚ OSTRZEŻENIE" to {_c}
		send "&8 » &7Powód: &f%{_powod}%" to {_c}
		send "&8 » &7Ostrzeżeń: &f%{_ile}%" to {_c}
		send "&8 » &7Nałożył: &f%{_a}%" to {_c}
		send "&7" to {_c}
		send title "&6&lOSTRZEŻENIE" with subtitle "&7%{_powod}%" to {_c} for 3 seconds
		play sound "block.note_block.pling" with volume 1 and pitch 0.5 to {_c}
	loop all players:
		if loop-player has permission "xslodziak.adminpanel":
			send "&8[&cAP&8] &f%{_a}% &7» &f%{_k}% &7dla &f%{_n}% &8(&7%{_powod}%&8)" to loop-player

function zdejmijKareAp(p: player, k: text, u: text):
	if {_k} is "ban":
		set {_n} to {xslodziak-apban::%{_u}%::nick}
		usunBanAp({_u})
		send "&aOdbanowano &f%{_n}%&a." to {_p}
	else:
		set {_n} to {xslodziaczek-apmute::%{_u}%::nick}
		delete {xslodziaczek-apmute::%{_u}%::*}
		delete {slodziaczek-apmutelista::%{_u}%}
		send "&aOdciszono &f%{_n}%&a." to {_p}
		loop all players:
			if "%uuid of loop-player%" is {_u}:
				send "&aTwoje wyciszenie zostało zdjęte." to loop-player

function ogloszenieAp(p: player, w: text):
	set {_t} to colored {_w}
	broadcast "&7"
	broadcast "&8&m               &r &c&lOGŁOSZENIE &8&m               "
	broadcast "&7"
	broadcast "&8 » %{_t}%"
	broadcast "&7"
	broadcast "&8 » &7Ogłasza: &f%name of {_p}%"
	broadcast "&7"
	loop all players:
		send title "&c&lOGŁOSZENIE" with subtitle {_t} to loop-player for 4 seconds
		play sound "block.note_block.pling" with volume 1 and pitch 1.2 to loop-player

function przelaczAp(p: player, f: text):
	set {_u} to "%uuid of {_p}%"
	if {slodziaczek-apflagi::%{_u}%::%{_f}%} is set:
		delete {slodziaczek-apflagi::%{_u}%::%{_f}%}
		set {_on} to false
	else:
		set {slodziaczek-apflagi::%{_u}%::%{_f}%} to true
		set {_on} to true
	if {_f} is "vanish":
		if {_on} is true:
			loop all players:
				if loop-player doesn't have permission "xslodziak.adminpanel":
					hide {_p} from loop-player
			send "&aVanish włączony." to {_p}
		else:
			reveal {_p} to all players
			send "&cVanish wyłączony." to {_p}
	else if {_f} is "fly":
		set flight mode of {_p} to {_on}
		if {_on} is true:
			send "&aLatanie włączone." to {_p}
		else:
			send "&cLatanie wyłączone." to {_p}
	else if {_f} is "god":
		if {_on} is true:
			send "&aGod włączony." to {_p}
		else:
			send "&cGod wyłączony." to {_p}

function stanAp(p: player, f: text) :: text:
	if {slodziaczek-apflagi::%uuid of {_p}%::%{_f}%} is set:
		return "&aWłączony"
	return "&cWyłączony"

function panelAp(p: player):
	set {_u} to "%uuid of {_p}%"
	set {_gui} to chest inventory with 5 rows named "&8Panel Admina"
	set {_v} to stanAp({_p}, "vanish")
	set {_f} to stanAp({_p}, "fly")
	set {_g} to stanAp({_p}, "god")
	set {_x} to ender eye named "&2&lVanish"
	set lore of {_x} to "&7", "&8 » &7Znikasz z oczu &fgraczy", "&8 » &7Stan: %{_v}%", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 9 of {_gui} to {_x}
	set {_x} to feather named "&f&lLatanie"
	set lore of {_x} to "&7", "&8 » &7Możesz latać w &fsurvivalu", "&8 » &7Stan: %{_f}%", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 11 of {_gui} to {_x}
	set {_x} to totem of undying named "&e&lGod"
	set lore of {_x} to "&7", "&8 » &7Nie otrzymujesz żadnych &fobrażeń", "&8 » &7Stan: %{_g}%", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 13 of {_gui} to {_x}
	set {_x} to grass block named "&a&lTryb gry"
	set lore of {_x} to "&7", "&8 » &7Przełącza creative i &fsurvival", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 15 of {_gui} to {_x}
	set {_x} to golden apple named "&6&lUlecz się"
	set lore of {_x} to "&7", "&8 » &7Pełne życie i &fnajedzenie", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 17 of {_gui} to {_x}
	set {_x} to player head named "&e&lWybierz gracza"
	set lore of {_x} to "&7", "&8 » &7Kary, teleport i &fekwipunek", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 27 of {_gui} to {_x}
	set {_x} to bell named "&6&lOgłoszenie"
	set lore of {_x} to "&7", "&8 » &7Wiadomość dla &fwszystkich graczy", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 29 of {_gui} to {_x}
	set {_x} to iron bars named "&7&lLista banów"
	set lore of {_x} to "&7", "&8 » &7Podgląd i zdejmowanie &fbanów", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 31 of {_gui} to {_x}
	set {_x} to paper named "&f&lLista wyciszeń"
	set lore of {_x} to "&7", "&8 » &7Podgląd i zdejmowanie &fwyciszeń", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 33 of {_gui} to {_x}
	set {_x} to clock named "&e&lSerwer"
	set lore of {_x} to "&7", "&8 » &7Czas, pogoda i &fczat", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 35 of {_gui} to {_x}
	open {_gui} to {_p}
	set {xslodziacek-apmenu::%{_u}%} to "panel"

function straznikAp() :: text:
	set {_pl} to "Autor skryptu: xSlodziaczekk. Kod jest chroniony prawem autorskim."
	set {_en} to "Script author: xSlodziaczekk. This code is protected by copyright."
	set {_de} to "Autor des Skripts: xSlodziaczekk. Dieser Code ist urheberrechtlich geschützt."
	set {_⠁⠙⠍⠊⠝} to "⠭⠎⠇⠕⠙⠵⠊⠁⠉⠵⠑⠅⠅"
	set {_⠏⠁⠝⠑⠇} to "⠁⠙⠍⠊⠝ ⠏⠁⠝⠑⠇ ⠝⠁⠏⠊⠎⠁⠇ ⠭⠎⠇⠕⠙⠵⠊⠁⠉⠵⠑⠅⠅"
	set {_⠅⠁⠗⠽} to "⠏⠗⠁⠺⠁ ⠁⠥⠞⠕⠗⠎⠅⠊⠑ ⠭⠎⠇⠕⠙⠵⠊⠁⠉⠵⠑⠅⠅"
	if {_pl} doesn't contain "xSlodziaczekk":
		return "brak"
	if {_en} does not contain "xSlodziaczekk":
		return "brak"
	if {_de} doesn't contain "xSlodziaczekk":
		return "brak"
	if {_⠁⠙⠍⠊⠝} is not "⠭⠎⠇⠕⠙⠵⠊⠁⠉⠵⠑⠅⠅":
		return "brak"
	if {_⠏⠁⠝⠑⠇} does not contain "⠭⠎⠇⠕⠙⠵⠊⠁⠉⠵⠑⠅⠅":
		return "brak"
	if {_⠅⠁⠗⠽} doesn't contain "⠭⠎⠇⠕⠙⠵⠊⠁⠉⠵⠑⠅⠅":
		return "brak"
	return "xSlodziaczekk"

function serwerAp(p: player):
	set {_gui} to chest inventory with 3 rows named "&8Serwer"
	set {_x} to sunflower named "&e&lDzień"
	set lore of {_x} to "&7", "&8 » &7Ustawia w świecie &fdzień", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 10 of {_gui} to {_x}
	set {_x} to black candle named "&8&lNoc"
	set lore of {_x} to "&7", "&8 » &7Ustawia w świecie &fnoc", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 12 of {_gui} to {_x}
	set {_x} to water bucket named "&b&lPogoda"
	set lore of {_x} to "&7", "&8 » &7Wyłącza deszcz i &fburzę", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 14 of {_gui} to {_x}
	set {_x} to sponge named "&e&lWyczyść czat"
	set lore of {_x} to "&7", "&8 » &7Czyści czat &fwszystkim graczom", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 16 of {_gui} to {_x}
	set slot 18 of {_gui} to arrow named "&7Powrót"
	open {_gui} to {_p}
	set {xslodziacek-apmenu::%uuid of {_p}%} to "serwer"

function oknoGraczaAp(p: player):
	set {_u} to "%uuid of {_p}%"
	set {_c} to celAp({_p})
	if {_c} isn't set:
		send "&cGracz wyszedł z serwera." to {_p}
		panelAp({_p})
		stop
	set {_n} to name of {_c}
	set {_cu} to "%uuid of {_c}%"
	set {_w} to {xslodziakk-apwarny::%{_cu}%}
	if {_w} isn't set:
		set {_w} to 0
	set {_gui} to chest inventory with 5 rows named "&8Gracz %{_n}%"
	set {_x} to skull of {_c}
	set name of {_x} to "&e&l%{_n}%"
	set {_mt} to "&aNie"
	if mutAp({_c}) is true:
		set {_mt} to "&cTak"
	set lore of {_x} to "&7", "&8 » &7Ostrzeżenia: &f%{_w}%", "&8 » &7Wyciszony: %{_mt}%", "&8 » &7Tryb gry: &f%gamemode of {_c}%" and "&7"
	set slot 4 of {_gui} to {_x}
	set {_x} to barrier named "&c&lZbanuj"
	set lore of {_x} to "&7", "&8 » &7Blokuje wejście na &fserwer", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 9 of {_gui} to {_x}
	set {_x} to writable book named "&7&lWycisz"
	set lore of {_x} to "&7", "&8 » &7Blokuje pisanie na &fczacie", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 11 of {_gui} to {_x}
	set {_x} to leather boots named "&6&lWyrzuć"
	set lore of {_x} to "&7", "&8 » &7Wyrzuca gracza z &fserwera", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 13 of {_gui} to {_x}
	set {_x} to orange dye named "&6&lOstrzeż"
	set lore of {_x} to "&7", "&8 » &7Daje graczowi &fostrzeżenie", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 15 of {_gui} to {_x}
	set {_fr} to "&cNie"
	if {slodziaczek-apflagi::%{_cu}%::freeze} is set:
		set {_fr} to "&aTak"
	set {_x} to packed ice named "&b&lZamroź"
	set lore of {_x} to "&7", "&8 » &7Gracz nie może się &fruszać", "&8 » &7Zamrożony: %{_fr}%", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 17 of {_gui} to {_x}
	set {_x} to ender pearl named "&2&lTeleportuj się"
	set lore of {_x} to "&7", "&8 » &7Przenosi cię do &fgracza", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 27 of {_gui} to {_x}
	set {_x} to lead named "&6&lPrzywołaj"
	set lore of {_x} to "&7", "&8 » &7Przenosi gracza do &fciebie", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 29 of {_gui} to {_x}
	set {_x} to chest named "&6&lEkwipunek"
	set lore of {_x} to "&7", "&8 » &7Podgląd ekwipunku &fgracza", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 31 of {_gui} to {_x}
	set {_x} to ender chest named "&5&lEnderchest"
	set lore of {_x} to "&7", "&8 » &7Podgląd enderchesta &fgracza", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 33 of {_gui} to {_x}
	set {_x} to golden apple named "&6&lUlecz"
	set lore of {_x} to "&7", "&8 » &7Pełne życie i &fnajedzenie", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 35 of {_gui} to {_x}
	set slot 36 of {_gui} to arrow named "&7Powrót"
	open {_gui} to {_p}
	set {xslodziacek-apmenu::%{_u}%} to "gracz"

function presetAp(t: text, i: number, co: text) :: text:
	if {_t} is "ban":
		set {_p::*} to "Cheaty", "Obraza administracji", "Reklama innych serwerów" and "Wykorzystywanie błędów"
		set {_c::*} to "perm", "3d", "7d" and "7d"
	else if {_t} is "mute":
		set {_p::*} to "Spam", "Wulgaryzmy", "Obrażanie graczy" and "Reklama"
		set {_c::*} to "30m", "1h", "2h" and "1d"
	else if {_t} is "kick":
		set {_p::*} to "AFK", "Nieregulaminowy nick", "Prośba administracji" and "Ostatnie ostrzeżenie"
	else if {_t} is "warn":
		set {_p::*} to "Spam na czacie", "Wulgarny język", "Nieregulaminowa budowla" and "Przeszkadzanie innym"
	else:
		set {_p::*} to "&fRestart serwera za &c5 minut&f!", "&fZa &e10 minut &fstartuje &6event&f!", "&fDołącz do naszego &9Discorda&f!" and "&fTrwa &cprzerwa techniczna&f, prosimy o cierpliwość."
	if {_co} is "czas":
		if {_c::%{_i}%} isn't set:
			return ""
		return {_c::%{_i}%}
	return {_p::%{_i}%}

function presetyAp(p: player, t: text):
	set {_u} to "%uuid of {_p}%"
	if {_t} is "ban":
		set {_gui} to chest inventory with 3 rows named "&8Powód bana"
		set {_x} to barrier
	else if {_t} is "mute":
		set {_gui} to chest inventory with 3 rows named "&8Powód wyciszenia"
		set {_x} to writable book
	else if {_t} is "kick":
		set {_gui} to chest inventory with 3 rows named "&8Powód wyrzucenia"
		set {_x} to leather boots
	else if {_t} is "warn":
		set {_gui} to chest inventory with 3 rows named "&8Powód ostrzeżenia"
		set {_x} to orange dye
	else:
		set {_gui} to chest inventory with 3 rows named "&8Ogłoszenia"
		set {_x} to bell
	loop 4 times:
		set {_i} to loop-number
		set {_pw} to presetAp({_t}, {_i}, "powod")
		set {_cz} to presetAp({_t}, {_i}, "czas")
		if {_t} is "ogl":
			set {_it} to {_x} named "&6&lOgłoszenie %{_i}%"
			set {_pv} to colored {_pw}
			set lore of {_it} to "&7", "&8 » %{_pv}%", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
		else if {_cz} is "":
			set {_it} to {_x} named "&c&l%{_pw}%"
			set lore of {_it} to "&7", "&8 » &7Gotowy powód &fkary", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
		else if {_t} is "ban":
			set {_ct} to czasTekstAp({_cz})
			set {_it} to {_x} named "&c&l%{_pw}%"
			set lore of {_it} to "&7", "&8 » &7Czas kary: &f%{_ct}%", "&8 » &7Lewy przycisk: &fzwykły ban", "&8 » &7Prawy przycisk: &fban na IP", "&7", "&8 » &aKliknij PPM(Lub LPM), aby aktywować!" and "&7"
		else:
			set {_ct} to czasTekstAp({_cz})
			set {_it} to {_x} named "&c&l%{_pw}%"
			set lore of {_it} to "&7", "&8 » &7Czas kary: &f%{_ct}%", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
		set slot (7 + {_i} * 2) of {_gui} to {_it}
	set {_it} to name tag named "&e&lWłasny"
	if {_t} is "ban":
		set lore of {_it} to "&7", "&8 » &7Wpiszesz własną treść na &fczacie", "&8 » &7Lewy przycisk: &fzwykły ban", "&8 » &7Prawy przycisk: &fban na IP", "&7", "&8 » &aKliknij PPM(Lub LPM), aby aktywować!" and "&7"
	else:
		set lore of {_it} to "&7", "&8 » &7Wpiszesz własną treść na &fczacie", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
	set slot 17 of {_gui} to {_it}
	set slot 18 of {_gui} to arrow named "&7Powrót"
	open {_gui} to {_p}
	set {xslodziacek-apmenu::%{_u}%} to {_t}

function listaKarAp(p: player, k: text):
	set {_u} to "%uuid of {_p}%"
	delete {slodziak-apsloty::%{_u}%::*}
	if {_k} is "ban":
		set {_gui} to chest inventory with 6 rows named "&8Lista banów"
		set {_l::*} to {slodziak-apbanlista::*}
	else:
		set {_gui} to chest inventory with 6 rows named "&8Lista wyciszeń"
		set {_l::*} to {slodziaczek-apmutelista::*}
	set {_i} to 0
	loop {_l::*}:
		if {_i} > 44:
			exit loop
		set {_c} to loop-value
		if {_k} is "ban":
			if {xslodziak-apban::%{_c}%::do} is set:
				if {xslodziak-apban::%{_c}%::do} < now:
					usunBanAp({_c})
					continue
		else if aktywnyMutAp({_c}) is false:
			continue
		if {_k} is "ban":
			set {_n} to {xslodziak-apban::%{_c}%::nick}
			set {_pw} to {xslodziak-apban::%{_c}%::powod}
			set {_a} to {xslodziak-apban::%{_c}%::kto}
		else:
			set {_n} to {xslodziaczek-apmute::%{_c}%::nick}
			set {_pw} to {xslodziaczek-apmute::%{_c}%::powod}
			set {_a} to {xslodziaczek-apmute::%{_c}%::kto}
		set {_z} to zostaloAp({_k}, {_c})
		set {_x} to player head named "&e&l%{_n}%"
		set lore of {_x} to "&7", "&8 » &7Powód: &f%{_pw}%", "&8 » &7Pozostało: &f%{_z}%", "&8 » &7Nałożył: &f%{_a}%", "&7", "&8 » &aKliknij PPM, aby aktywować!" and "&7"
		set slot {_i} of {_gui} to {_x}
		set {slodziak-apsloty::%{_u}%::%{_i}%} to {_c}
		add 1 to {_i}
	set slot 45 of {_gui} to arrow named "&7Powrót"
	open {_gui} to {_p}
	set {xslodziacek-apmenu::%{_u}%} to "lista-%{_k}%"

function aktywnyMutAp(u: text) :: boolean:
	if {xslodziaczek-apmute::%{_u}%::do} is set:
		if {xslodziaczek-apmute::%{_u}%::do} < now:
			delete {xslodziaczek-apmute::%{_u}%::*}
			delete {slodziaczek-apmutelista::%{_u}%}
			return false
	return true

function szukajKaryAp(k: text, n: text) :: text:
	if {_k} is "ban":
		loop {slodziak-apbanlista::*}:
			if {xslodziak-apban::%loop-value%::nick} is {_n}:
				return loop-value
	else:
		loop {slodziaczek-apmutelista::*}:
			if {xslodziaczek-apmute::%loop-value%::nick} is {_n}:
				return loop-value
	return ""

function wypiszKaryAp(p: player, k: text):
	if {_k} is "ban":
		set {_l::*} to {slodziak-apbanlista::*}
		send "&7" to {_p}
		send "&c&lLISTA BANÓW" to {_p}
	else:
		set {_l::*} to {slodziaczek-apmutelista::*}
		send "&7" to {_p}
		send "&7&lLISTA WYCISZEŃ" to {_p}
	set {_i} to 0
	loop {_l::*}:
		set {_c} to loop-value
		if {_k} is "ban":
			if {xslodziak-apban::%{_c}%::do} is set:
				if {xslodziak-apban::%{_c}%::do} < now:
					usunBanAp({_c})
					continue
			set {_n} to {xslodziak-apban::%{_c}%::nick}
			set {_pw} to {xslodziak-apban::%{_c}%::powod}
			set {_a} to {xslodziak-apban::%{_c}%::kto}
		else:
			if aktywnyMutAp({_c}) is false:
				continue
			set {_n} to {xslodziaczek-apmute::%{_c}%::nick}
			set {_pw} to {xslodziaczek-apmute::%{_c}%::powod}
			set {_a} to {xslodziaczek-apmute::%{_c}%::kto}
		set {_z} to zostaloAp({_k}, {_c})
		send "&8 » &f%{_n}% &8| &7%{_pw}% &8| &7%{_z}% &8| &7%{_a}%" to {_p}
		add 1 to {_i}
	if {_i} is 0:
		send "&8 » &7Brak." to {_p}
	send "&7" to {_p}
Kodari AI
KodariSep 25 at 10:30 pm 1
AdminPanelPlugin
AdminPanelPlugin is a comprehensive Minecraft server administration tool for version 1.21.1, converted from Skript to a Java plugin. It provides a graphical admin panel GUI with features including player punishment management (bans, IP bans, mutes, kicks, warnings), punishment history tracking, temporary and permanent penalties with custom time formats, player management options (vanish, fly, god mode, freeze, teleport, inventory inspection), server controls (time, weather, chat clearing), announcements with titles, and a secure authorization system. The plugin includes punishment lists, unban/unmute commands, and persistent data storage for all penalties and player flags.
  1. Create the Java 21 / Paper 1.21.1 plugin scaffold and permission-backed commands.

  2. Port punishment persistence, expiry checks, chat restrictions, and admin tools.

  3. Port the admin GUIs, presets, player actions, and server controls.

Created the Paper 1.21.1 admin-panel plugin with GUI controls, punishment commands, saved ban/mute/warning history, expiry handling, chat restrictions, and player/server tools. The plugin stores punishment data in plugins/SlodziakAdminPanel/punishments.yml.

Szymon Gutomski

but change slodziak and xslodziak to Zlovus

Kodari AI
KodariSep 25 at 10:32 pm 1
  • Rename the plugin from SlodziakAdminPanel to ZlovusAdminPanel.

  • Replace the xslodziak.adminpanel permission with zlovus.adminpanel in the plugin descriptor and Java constant.

Renamed the plugin to ZlovusAdminPanel and changed its permission node to zlovus.adminpanel in both plugin.yml and the Java constant.

Szymon Gutomski

its fine?

Kodari AI
KodariSep 25 at 10:32 pm 1

Yes, that’s fine: the plugin name is now ZlovusAdminPanel, and the permission node is zlovus.adminpanel. Lowercase is standard for permission nodes.

Szymon Gutomski

but full plugin

Kodari AI
KodariSep 25 at 10:33 pm 1
  • Replace the remaining old author branding throughout the plugin with Zlovus.

Updated the remaining old author references across the plugin to Zlovus—in plugin.yml and the startup message. The plugin name and permission node remain ZlovusAdminPanel and zlovus.adminpanel.

Szymon Gutomski

why i ciant compile to maven

Kodari AI
KodariSep 25 at 10:37 pm 1

This project is set up for Gradle, not Maven: it has a build.gradle but no pom.xml, so Maven has no build configuration to use.

There’s another likely compile issue: the code imports XSeries, but the current Gradle file only declares Paper API. If you want to build with Maven, it needs a pom.xml declaring Paper API and XSeries (or the XSeries usages need to be removed). Separately, plugin.yml points to a different package than the Java main class; that won’t stop compilation, but it can prevent the plugin from loading.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
6 1,187
src/main/java/com/zlovus/adminpanel/AdminPanelPlugin.java
package com.kodari.adminpanel;

import com.cryptomorin.xseries.XSound;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class AdminPanelPlugin extends JavaPlugin implements Listener {
    public static final String ADMIN_PERMISSION = "zlovus.adminpanel";
    private final Set<UUID> vanished = new HashSet<>();
    private final Set<UUID> flying = new HashSet<>();
    private final Set<UUID> godMode = new HashSet<>();
    private final Set<UUID> frozen = new HashSet<>();
    private PunishmentManager punishmentManager;
    private AdminMenu adminMenu;

    @Override
    public void onEnable() {
        punishmentManager = new PunishmentManager(this);
        adminMenu = new AdminMenu(this);
        AdminCommand command = new AdminCommand(this);
        for (String name : new String[]{"adminpanel", "odbanuj", "odcisz", "aban", "abanip", "amute", "akick", "awarn", "aostrzezenia", "abany", "awyciszenia", "ahistoria", "aogloszenie"}) {
            if (getCommand(name) != null) {
                getCommand(name).setExecutor(command);
            }
        }
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getPluginManager().registerEvents(adminMenu, this);
        Bukkit.getScheduler().runTaskLater(this, () -> {
            String message = color("&aSkrypt Pomyślnie załadowany&8 | &aAutor: Zlovus");
            Bukkit.getConsoleSender().sendMessage(message);
            Bukkit.broadcastMessage(message);
        }, 5L);
    }

    public PunishmentManager punishments() {
        return punishmentManager;
    }

    public AdminMenu menu() {
        return adminMenu;
    }

    public static String color(String text) {
        return org.bukkit.ChatColor.translateAlternateColorCodes('&', text);
    }

    public void playClick(Player player) {
        XSound.matchXSound("UI_BUTTON_CLICK").ifPresent(sound -> sound.play(player));
    }

    public boolean hasFlag(Player player, String flag) {
        UUID id = player.getUniqueId();
        return switch (flag) {
            case "vanish" -> vanished.contains(id);
            case "fly" -> flying.contains(id);
            case "god" -> godMode.contains(id);
            case "freeze" -> frozen.contains(id);
            default -> false;
        };
    }

    public boolean toggleFlag(Player player, String flag) {
        UUID id = player.getUniqueId();
        Set<UUID> set = switch (flag) {
            case "vanish" -> vanished;
            case "fly" -> flying;
            case "god" -> godMode;
            case "freeze" -> frozen;
            default -> throw new IllegalArgumentException("Unknown flag: " + flag);
        };
        boolean enabled;
        if (set.remove(id)) {
            enabled = false;
        } else {
            set.add(id);
            enabled = true;
        }
        if (flag.equals("vanish")) {
            for (Player other : Bukkit.getOnlinePlayers()) {
                if (other.equals(player)) continue;
                if (enabled && !other.hasPermission(ADMIN_PERMISSION)) other.hidePlayer(this, player);
                else other.showPlayer(this, player);
            }
            player.sendMessage(color(enabled ? "&aVanish włączony." : "&cVanish wyłączony."));
        } else if (flag.equals("fly")) {
            player.setAllowFlight(enabled);
            if (!enabled && player.isFlying()) player.setFlying(false);
            player.sendMessage(color(enabled ? "&aLatanie włączone." : "&cLatanie wyłączone."));
        } else if (flag.equals("god")) {
            player.sendMessage(color(enabled ? "&aGod włączony." : "&cGod wyłączony."));
        } else {
            player.sendMessage(color(enabled ? "&aZamrożono &f" + player.getName() + "&a." : "&aOdmrożono &f" + player.getName() + "&a."));
        }
        return enabled;
    }

    public void announce(Player sender, String text) {
        String colored = color(text);
        Bukkit.broadcastMessage(color("&7"));
        Bukkit.broadcastMessage(color("&8&m               &r &c&lOGŁOSZENIE &8&m               "));
        Bukkit.broadcastMessage(color("&7"));
        Bukkit.broadcastMessage(color("&8 » ") + colored);
        Bukkit.broadcastMessage(color("&7"));
        Bukkit.broadcastMessage(color("&8 » &7Ogłasza: &f" + sender.getName()));
        Bukkit.broadcastMessage(color("&7"));
        for (Player player : Bukkit.getOnlinePlayers()) {
            player.sendTitle(color("&c&lOGŁOSZENIE"), colored, 10, 80, 10);
            XSound.matchXSound("BLOCK_NOTE_BLOCK_PLING").ifPresent(sound -> sound.play(player));
        }
    }

    @EventHandler
    public void onPlayerLogin(PlayerLoginEvent event) {
        PunishmentManager.Punishment ban = punishmentManager.findBan(event.getPlayer().getUniqueId(), event.getAddress().getHostAddress());
        if (ban != null) event.disallow(PlayerLoginEvent.Result.KICK_BANNED, punishmentManager.banScreen(ban));
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        if (vanished.contains(player.getUniqueId())) {
            for (Player other : Bukkit.getOnlinePlayers()) {
                if (!other.equals(player) && !other.hasPermission(ADMIN_PERMISSION)) other.hidePlayer(this, player);
            }
        }
        for (UUID id : vanished) {
            Player hidden = Bukkit.getPlayer(id);
            if (hidden != null && !player.hasPermission(ADMIN_PERMISSION)) player.hidePlayer(this, hidden);
        }
        if (flying.contains(player.getUniqueId())) player.setAllowFlight(true);
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent event) {
        adminMenu.clear(event.getPlayer());
    }

    @EventHandler
    public void onDamage(EntityDamageEvent event) {
        if (event.getEntity() instanceof Player player && godMode.contains(player.getUniqueId())) event.setCancelled(true);
    }

    @EventHandler
    public void onMove(PlayerMoveEvent event) {
        if (frozen.contains(event.getPlayer().getUniqueId()) && event.getTo() != null
                && (event.getFrom().getBlockX() != event.getTo().getBlockX()
                || event.getFrom().getBlockY() != event.getTo().getBlockY()
                || event.getFrom().getBlockZ() != event.getTo().getBlockZ())) {
            event.setTo(event.getFrom());
        }
    }

    @EventHandler
    public void onChat(AsyncPlayerChatEvent event) {
        Player player = event.getPlayer();
        if (adminMenu.hasPendingInput(player)) {
            event.setCancelled(true);
            String message = event.getMessage();
            Bukkit.getScheduler().runTask(this, () -> adminMenu.acceptInput(player, message));
            return;
        }
        PunishmentManager.Punishment mute = punishmentManager.activeMute(player.getUniqueId());
        if (mute != null) {
            event.setCancelled(true);
            player.sendMessage(color("&cJesteś wyciszony. &7Powód: &f" + mute.reason() + "&7, zostało: &f" + punishmentManager.remaining(mute.expiresAt())));
        }
    }

    @EventHandler
    public void onCommandWhileMuted(PlayerCommandPreprocessEvent event) {
        if (punishmentManager.activeMute(event.getPlayer().getUniqueId()) == null) return;
        String command = event.getMessage().split(" ", 2)[0].substring(1).toLowerCase();
        if (Set.of("msg", "tell", "w", "r", "m", "me", "whisper", "reply").contains(command)) {
            event.setCancelled(true);
            event.getPlayer().sendMessage(color("&cJesteś wyciszony."));
        }
    }
}