Toast Addon

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Perkus

New Member
Feb 14, 2017
5
0
0
25
I'm looking for the ability to create and display toast notifications and control them. I was unable to find any Skript addon that could do this, and it would be really nice to see something like this functional for Skript.

Toast notifications are the little popups in the corner of the screen that popup when you complete advancements and other things.
 
So based on what md_5 said:
"The toast titles however are hardcoded between like 3 different options, so it's not an elegant way to convey information if every message starts with "Advancement Get" / "Challenge Done" or whatever the messages are."

I don't think it would be possible to do custom toasts. It appears its hardcoded to only show toasts for advancements/challenges/recipes.
Its more of a system thing than a custom thing.
 
I understand, although I have seen plugins do this before. They used toast to display private messages, and I've worked with a friend who was working with toast to create different cool actions.

I'm not sure how limited it, but i'll i'd want is to put custom messages, make them popup on an action, and change the specific type of toast that displays.
 
I'd be willing to pay anyone $10 if you could get a simple form of this working in a small addon.
 
skript mirror:
code_language.skript:
import:
    ch.njol.skript.Skript
    org.bukkit.Bukkit
    org.bukkit.NamespacedKey
    com.google.gson.Gson
    com.google.gson.GsonBuilder
    com.google.gson.JsonObject
    org.bukkit.advancement.Advancement
    org.bukkit.advancement.AdvancementProgress

function sendToast(p: player, title: string, stringID: string, icon: string, description: string):
    set {_id} to new NamespacedKey(Skript.getInstance() and {_stringID})
    set {_json} to new JsonObject()
    set {_iconJson} to new JsonObject()

    {_iconJson}.addProperty("item" and {_icon});

    set {_display} to new JsonObject()
    {_display}.add("icon" and {_iconJson});
    {_display}.addProperty("title" and {_title});
    {_display}.addProperty("description" and {_description});
    {_display}.addProperty("background" and "minecraft:textures/gui/advancements/backgrounds/adventure.png");
    {_display}.addProperty("frame" and "goal");
    {_display}.addProperty("announce_to_chat" and false);
    {_display}.addProperty("show_toast" and true);
    {_display}.addProperty("hidden" and true);

    set {_criteria} to new JsonObject()
    set {_trigger} to new JsonObject()

    {_trigger}.addProperty("trigger" and "minecraft:impossible");
    {_criteria}.add("impossible" and {_trigger});

    {_json}.add("criteria" and {_criteria});
    {_json}.add("display" and {_display});

    set {_gson} to new GsonBuilder().setPrettyPrinting().create()
    Bukkit.getUnsafe().loadAdvancement({_id} and {_gson}.toJson({_json}));

    set {_advancement} to Bukkit.getAdvancement({_id})
    set {_progress} to {_p}.getAdvancementProgress({_advancement})

    loop ...{_progress}.getRemainingCriteria():
        {_progress}.awardCriteria(loop-value);

    wait 3 seconds

    loop ...{_progress}.getAwardedCriteria():
        {_progress}.revokeCriteria(loop-value);

    Bukkit.getUnsafe().removeAdvancement({_id});
example usage
code_language.skript:
command /test:
    trigger:
        sendToast(player, "hello world!", "toast", "minecraft:cobblestone", "toast")
 
Last edited:
skript mirror:
code_language.skript:
import:
    ch.njol.skript.Skript
    org.bukkit.Bukkit
    org.bukkit.NamespacedKey
    com.google.gson.Gson
    com.google.gson.GsonBuilder
    com.google.gson.JsonObject
    org.bukkit.advancement.Advancement
    org.bukkit.advancement.AdvancementProgress

function sendToast(p: player, title: string, stringID: string, icon: string, description: string):
    set {_id} to new NamespacedKey(Skript.getInstance() and {_stringID})
    set {_json} to new JsonObject()
    set {_iconJson} to new JsonObject()

    {_iconJson}.addProperty("item" and {_icon});

    set {_display} to new JsonObject()
    {_display}.add("icon" and {_iconJson});
    {_display}.addProperty("title" and {_title});
    {_display}.addProperty("description" and {_description});
    {_display}.addProperty("background" and "minecraft:textures/gui/advancements/backgrounds/adventure.png");
    {_display}.addProperty("frame" and "goal");
    {_display}.addProperty("announce_to_chat" and false);
    {_display}.addProperty("show_toast" and true);
    {_display}.addProperty("hidden" and true);

    set {_criteria} to new JsonObject()
    set {_trigger} to new JsonObject()

    {_trigger}.addProperty("trigger" and "minecraft:impossible");
    {_criteria}.add("impossible" and {_trigger});

    {_json}.add("criteria" and {_criteria});
    {_json}.add("display" and {_display});

    set {_gson} to new GsonBuilder().setPrettyPrinting().create()
    Bukkit.getUnsafe().loadAdvancement({_id} and {_gson}.toJson({_json}));

    set {_advancement} to Bukkit.getAdvancement({_id})
    set {_progress} to {_p}.getAdvancementProgress({_advancement})

    loop ...{_progress}.getRemainingCriteria():
        {_progress}.awardCriteria(loop-value)

    wait 3 seconds

    loop ...{_progress}.getAwardedCriteria():
        {_progress}.revokeCriteria(loop-value);

    Bukkit.getUnsafe().removeAdvancement({_id});
example usage
code_language.skript:
command /test:
    trigger:
        sendToast(player, "hello world!", "toast", "minecraft:cobblestone", "toast")
you did all that work but no custom effect?
 
upload_2018-5-27_17-9-7.png
 
code_language.skript:
# Send Toast effect made by that guy who uses functions in 2018 and Snow-Pyon

# Needs:
# skript-mirror
# skript-json

import:

  java.util.UUID
  ch.njol.skript.Skript
  org.bukkit.Bukkit
  org.bukkit.NamespacedKey
  org.bukkit.advancement.Advancement
  org.bukkit.advancement.AdvancementProgress


effect send toast titled %string% with description %string% and icon %string% [to %players%]:
  trigger:
 
    set {_id} to new NamespacedKey(Skript.getInstance() and UUID.randomUUID().toString())
 
    set {_icon::item} to expression-3
 
    set {_toast::icon} to json form of {_icon::*}
    set {_toast::title} to expression-1
    set {_toast::background} to "minecraft:textures/gui/advancements/backgrounds/adventure.png"
    set {_toast::frame} to "goal"
    set {_toast::announce_to_chat} to false
    set {_toast::show_toast} to true
    set {_toast::hidden} to true

    set {_trigger::trigger} to "minecraft:impossible"
    set {_criteria::impossible} to json form of {_trigger::*}
 
    set {_advancement::criteria} to json form of {_criteria::*}
    set {_advancement::display} to json form of {_toast::*}
 
    Bukkit.getUnsafe().loadAdvancement({_id} and json form of {_advancement::*})
    set {_advancement} to Bukkit.getAdvancement({_id})
 
    loop expressions-4:
   
      set {_progress} to loop-value.getAdvancementProgress({_advancement})
   
      loop ...{_progress}.getRemainingCriteria():
        {_progress}.awardCriteria(loop-value)
   
    wait 3 seconds
 
    loop expressions-4:
 
      set {_progress} to loop-value.getAdvancementProgress({_advancement})
   
      loop ...{_progress}.getAwardedCriteria():
        {_progress}.revokeCriteria(loop-value)
     
    Bukkit.getUnsafe().removeAdvancement({_id})
2b41y8.jpg
 
Last edited:
Function:
- Doesnt require skript mirror
- Explicitly states parameter and its type
- Not overly verbose
- Easy to remember a function name
- Well documented

Custom effect:
- Requires skript mirror
- Excessively verbose
- Hard to remember long syntax
- Not well documented
 
  • Like
Reactions: ShaneBee
Function:
- Doesnt require skript mirror
- Explicitly states parameter and its type
- Not overly verbose
- Easy to remember a function name
- Well documented

Custom effect:
- Requires skript mirror
- Excessively verbose
- Hard to remember long syntax
- Not well documented
You're already using skript-mirror so that's irrelevant. The syntax for custom effects is not hard to remember. For an effect you literally just need
code_language.skript:
effect syntax:
  trigger:
    #code
I fail to see how that is any harder than
code_language.skript:
function syntax():
  # code
and custom syntax is documented fine for easy things like this https://github.com/btk5h/skript-mirror/wiki/Creating-custom-syntax

functions are something that should have never existed in skript
 
skript mirror:
code_language.skript:
import:
    ch.njol.skript.Skript
    org.bukkit.Bukkit
    org.bukkit.NamespacedKey
    com.google.gson.Gson
    com.google.gson.GsonBuilder
    com.google.gson.JsonObject
    org.bukkit.advancement.Advancement
    org.bukkit.advancement.AdvancementProgress

function sendToast(p: player, title: string, stringID: string, icon: string, description: string):
    set {_id} to new NamespacedKey(Skript.getInstance() and {_stringID})
    set {_json} to new JsonObject()
    set {_iconJson} to new JsonObject()

    {_iconJson}.addProperty("item" and {_icon});

    set {_display} to new JsonObject()
    {_display}.add("icon" and {_iconJson});
    {_display}.addProperty("title" and {_title});
    {_display}.addProperty("description" and {_description});
    {_display}.addProperty("background" and "minecraft:textures/gui/advancements/backgrounds/adventure.png");
    {_display}.addProperty("frame" and "goal");
    {_display}.addProperty("announce_to_chat" and false);
    {_display}.addProperty("show_toast" and true);
    {_display}.addProperty("hidden" and true);

    set {_criteria} to new JsonObject()
    set {_trigger} to new JsonObject()

    {_trigger}.addProperty("trigger" and "minecraft:impossible");
    {_criteria}.add("impossible" and {_trigger});

    {_json}.add("criteria" and {_criteria});
    {_json}.add("display" and {_display});

    set {_gson} to new GsonBuilder().setPrettyPrinting().create()
    Bukkit.getUnsafe().loadAdvancement({_id} and {_gson}.toJson({_json}));

    set {_advancement} to Bukkit.getAdvancement({_id})
    set {_progress} to {_p}.getAdvancementProgress({_advancement})

    loop ...{_progress}.getRemainingCriteria():
        {_progress}.awardCriteria(loop-value)

    wait 3 seconds

    loop ...{_progress}.getAwardedCriteria():
        {_progress}.revokeCriteria(loop-value);

    Bukkit.getUnsafe().removeAdvancement({_id});
example usage
code_language.skript:
command /test:
    trigger:
        sendToast(player, "hello world!", "toast", "minecraft:cobblestone", "toast")
Can't understand this condition/effect: {_progress}.awardCriteria(loop-value) (test.sk, line 51: {_progress}.awardCriteria(loop-value)')
 
it shouldn't work though, since he forgot a semicolon there.
oops yeah there should be a semicolon there. it works because the award criteria method returns a boolean so its treating it as a condition which doesnt need a semicolon
 
oops yeah there should be a semicolon there. it works because the award criteria method returns a boolean so its treating it as a condition which doesnt need a semicolon
it doesn't matter what the method returns -- that cannot be determined at parse time (unless you specifically specify the class where the method is, but thats almost never used). Because of that and how skript works, all java calls are assumed to potentially return any type including booleans.