Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Snow-Pyon's script snippets (skript-mirror version)

Chat Component Converter

Converts a chat component json to a human-readable text.

Code

string property skript color[s]:
  get:
    if expression-1 contains "_":

      replace all "_" with " " in {_color}
      return {_color}

    else if {_color} isn't "black", "white", "yellow" or "gold":

      return "light %{_color}%"

    else:

      return {_color}
    

expression %jsonobjects% (as|to) [human-]readable text:
  get:

    loop expressions-1:
      put json loop-value in listvar {_json::%loop-index%::*}

      loop tree of {_json::%loop-index%::extra::*}:

        if branch contains "color":

          set {_color} to loop-value-2's skript color
          set {_color} to "<%{_color}%>"

        else if branch contains "text":

          if {_color} isn't set:
            set {_color} to ""
          
          add "%{_color}%%loop-value-2%" to {_full-text::%loop-index-1%::*}
      add join {_full-text::%loop-index-1%::*} by "" to {_output::*}


    return {_output::*}

Usage

on skript load:

  add "<red><bold>Hey! <grey>you aren not permitted to enter this area." to {deniedMessages::*} #WorldGuard message
  add "You created the faction " to {deniedMessages::*} #Factions message

on packet event play_server_chat:

  set {_last-message} to chatcomponent pjson 0 of event-packet as readable text

  loop {deniedMessages::*}:
    if {_last-message} contains loop-value:
      replace all loop-value with "..." in {_last-message}
      cancel event
  set chatcomponent pjson 0 of event-packet to {_last-message} as chat component # Uses the message to component expression

Message to Component

Used for converting a normal text to a chat component (useful when dealing with packets).

Code

expression %strings% (to|as) chat component:
  get:

    loop expressions-1:
      set {_chat-component::extra::1::text} to loop-value
      add (json of listvar {_chat-component::*}) to {_output::*}

    return {_output::*}

Usage

command /test:
  trigger:
   
    set {_packet-container} to new play_server_chat packet
    set chatcomponent pjson 0 of {_packet-container} to "<green>test" as chat component
    send player packet {_packet-container}

Send Actionbar

Used for sending an actionbar to one or more players.

Code

effect send action[ ]bar %string% to %players% [for %-timespan%]:
 trigger:
 
   set {_packet-container} to new play_server_chat
   set chatcomponent pjson 0 of {_packet-container} to expression-1 as chat component
   set "ChatType" penum 0 of {_packet-container} to "GAME_INFO"
   
   if raw expression-3 exists:
    set {_stay-time} to expression-3.getTicks_i()
   else:
    set {_stay-time} to 1
    
   loop {_stay-time} times:
     send packet {_packet-container} to expressions-2
     wait 1 tick

Usage

command /health:
  trigger:
  
    send actionbar "Your health is&7: &c%player's scaled health%" to player for 1 second

Show Animation

Make one or more entities show the given animation.

Code

effect make %entities% [show] [the] (swing their (0¦main|3¦off)[(-| )]hand|1¦take damage|2¦leave bed|4¦critical|5¦magic critical) [effect] [to %-players%]:
  trigger:
  
    set {_packet-container} to new play_server_animation packet
    set int pnum 1 of {_packet-container} to parser mark
    
    loop expressions-1:
    
     set loop-value's world pentity 0 of {_packet-container} to loop-value
     
     set {_viewers::*} to expressions-2
      if {_viewers::*} isn't set:
       set {_viewers::*} to all players
       
      send packet {_packet-container} to {_viewers::*}

Usage

command /swing:
  trigger:
    make player swing their main hand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.