Use a Skript variable in a java plugin.

  • 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!

sandor_1234

Active Member
Jan 26, 2017
165
5
0
21
So i am trying to grab a variable in my java code and i wanna check if it is set.
I just found this thread:
https://forums.skunity.com/threads/how-get-skript-variable.459/
Which was really helpfull but i never really worked with java before so how would i use / call this function?
This is what i am trying to achieve:
Java:
public void onInteract(PlayerInteractEvent event) {
#if {test::lol::%player%} is set{
#Do stuff
}

}
 
Last edited:
I've explained how to use that method here:
https://github.com/bensku/Skript/issues/781
So i would have do do something like:
Java:
public void onInteract(PlayerInteractEvent event) {
Player p = event.getPlayer();
Object variable = Variables.getVariable("{test::lol::" + p + "}", null, false);
if variable != null{
#My code here
}
}
The {test::lol::" + p + "} part is probably wrong so how would i have to do that?
 
Without the braces, and you might be looking for the player name and not the player object in the string, a player object in a string returns more than its name. Use the Player#getName method for it.
 
Without the braces, and you might be looking for the player name and not the player object in the string, a player object in a string returns more than its name. Use the Player#getName method for it.
Thanks allot for all the usefull information so far!
Currently i have this code:
Java:
public void onInteract(PlayerInteractEvent event) {
Player p = event.getPlayer();
String playerName = p.getName();
Object variable = Variables.getVariable("k::lip::" + playerName, null, false);
if( variable = null){
#do stuff
}
But its not working, do i have to do anything else?
 
Thanks allot for all the usefull information so far!
Currently i have this code:
Java:
public void onInteract(PlayerInteractEvent event) {
Player p = event.getPlayer();
String playerName = p.getName();
Object variable = Variables.getVariable("k::lip::" + playerName, null, false);
if( variable = null){
#do stuff
}
But its not working, do i have to do anything else?
= is for assignation, you're setting the variable "variable" to null there, not comparing it with null. Use two equals (==) for comparison.

Also, Java doesn't use # for comments, it uses // for single line comments or /* comment here */ for multi-line comments.
 
Hmm i used this skript:
code_language.skript:
set {k::lip::%player%} to "test"
But if i use this:
Java:
Object variable = Variables.getVariable("k::lip::" + playerName, null, false);
Bukkit.broadcastMessage(variable);
it just returns "null"
 
Hmm i used this skript:
code_language.skript:
set {k::lip::%player%} to "test"
But if i use this:
Java:
Object variable = Variables.getVariable("k::lip::" + playerName, null, false);
Bukkit.broadcastMessage(variable);
it just returns "null"
try making the player name lower case.