Skript to Java

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

couger44

Supporter
Feb 19, 2017
713
31
28
Chile
What is the java code for this one from skript?

code_language.skript:
command /dp [<string>]:
    permission: world.dp
    permission message: §cNo permission.
    trigger:
        arg 1 is "si":
            drop 10 enchanted golden apple at {dp.1}'s location

Java:
//How can I do that in java?
 
Even though I know something about java, in some codes that I did it gave me errors, so I would prefer that all the code previously posted be transformed into java.
I recommend learning Java properly then, because although that is easy to do, that is a heck of a lot to write just because someone wants to transfer that to Java.

Theres tutorials on SpigotMC (in the wiki) on how to create commands, that's the basic part there, the drop part, check the Spigot API docs, its in there as well.

No ones going to spoon feed / re-write your Skript code in java.
 
I asked for the simple reason, that when I used the "drop" effect, I threw the items, the players could pick it up, but when they went to their inventory and threw it away, it was returned.
 
Wait until i find a soultion
[doublepost=1558955807,1558955650][/doublepost]
Java:
package me.test.couger44;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.player.PlayerItemConsumeEvent;

public class Test extends JavaPlugin implements Listener, CommandExecutor{

    public void onEnable() {
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }
    public void onDisable() {
       
    }
   
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
       
        Player p = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("test")) {
           
            ItemStack item = new ItemStack(Material.GOLDEN_APPLE);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName("§a"+p.getName()+"'s Apple");
            p.getWorld().dropItem(p.getLocation(), item);
            p.sendMessage("§aA golden apple has been droped");
        }
        return true;
           
        }
    public void onConsume(PlayerItemConsumeEvent e) {
        Player p = e.getPlayer();
       
        if(e.getItem().getItemMeta().getDisplayName() == "§a"+p.getName()+"'s Apple") {
            e.setCancelled(true);
            p.sendMessage("You cannot consume your own apple!");
        }
    }
    }
[doublepost=1558955853][/doublepost]Btw, made it my self

U need plugin.yml
 
Last edited:
Wait until i find a soultion
[doublepost=1558955807,1558955650][/doublepost]
Java:
package me.test.couger44;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.player.PlayerItemConsumeEvent;

public class Test extends JavaPlugin implements Listener, CommandExecutor{

    public void onEnable() {
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }
    public void onDisable() {
    
    }
 
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
    
        Player p = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("test")) {
        
            ItemStack item = new ItemStack(Material.GOLDEN_APPLE);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName("§a"+p.getName()+"'s Apple");
            p.getWorld().dropItem(p.getLocation(), item);
            p.sendMessage("§aA golden apple has been droped");
        }
        return true;
        
        }
    public void onConsume(PlayerItemConsumeEvent e) {
        Player p = e.getPlayer();
    
        if(e.getItem().getItemMeta().getDisplayName() == "§a"+p.getName()+"'s Apple") {
            e.setCancelled(true);
            p.sendMessage("You cannot consume your own apple!");
        }
    }
    }
[doublepost=1558955853][/doublepost]Btw, made it my self

U need plugin.yml
You forgot to set the item meta for the item
Java:
ItemStack item = new ItemStack(Material.GOLDEN_APPLE);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§a"+p.getName()+"'s Apple");
//missing item.setItemMeta(meta);
p.getWorld().dropItem(p.getLocation(), item);
 
Java:
package me.test.couger44;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.player.PlayerItemConsumeEvent;

public class Test extends JavaPlugin implements Listener, CommandExecutor{

    public void onEnable() {
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }
    public void onDisable() {
    
    }
 
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
    
        Player p = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("test")) {
            if(p.hasPermission("Ownapple.permission")) {
                ItemStack item = new ItemStack(Material.GOLDEN_APPLE);
                ItemMeta meta = item.getItemMeta();
                Location newloc = p.getLocation().add(p.getLocation(), 5, 0, 3);
                meta.setDisplayName("§a"+p.getName()+"'s Apple");
                item.setItemMeta(meta);
                p.getWorld().dropItem(newloc, item);
                p.sendMessage("§aA golden apple has been dropped at: X: "+ newloc.getX()+ " Y: "+ newloc.getY()+ " Z: "+ newloc.getZ());
            }else p.sendMessage("§cYou don't have the required permission to execute this command!");
            return true;
            
            }
        return true;
    }
    public void onConsume(PlayerItemConsumeEvent e) {
        Player p = e.getPlayer();
    
        if(e.getItem().getItemMeta().getDisplayName() == "§a"+p.getName()+"'s Apple") {
            e.setCancelled(true);
            p.sendMessage("§cYou cannot consume your own apple!");
        }
    }
    }

New Code contains adding to coordinates of player (XYZ) Color message Fixed Somthing thanks to Shane Bee, Permmsions
 
Last edited:
Java:
package me.test.couger44;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.player.PlayerItemConsumeEvent;

public class Test extends JavaPlugin implements Listener, CommandExecutor{

    public void onEnable() {
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }
    public void onDisable() {
    
    }
 
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
    
        Player p = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("test")) {
        
            ItemStack item = new ItemStack(Material.GOLDEN_APPLE);
            ItemMeta meta = item.getItemMeta();
            Location newloc = p.getLocation().add(p.getLocation(), 5, 0, 3);
            meta.setDisplayName("§a"+p.getName()+"'s Apple");
            p.getWorld().dropItem(newloc, item);
            item.setItemMeta(meta);
            p.sendMessage("§aA golden apple has been dropped at: X: "+ newloc.getX()+ " Y: "+ newloc.getY()+ " Z: "+ newloc.getZ());
        }
        return true;
        
        }
    public void onConsume(PlayerItemConsumeEvent e) {
        Player p = e.getPlayer();
    
        if(e.getItem().getItemMeta().getDisplayName() == "§a"+p.getName()+"'s Apple") {
            e.setCancelled(true);
            p.sendMessage("§cYou cannot consume your own apple!");
        }
    }
    }

New Code contains adding to coordinates of player (XYZ) Color message Fixed Somthing thanks to Shane Bee
Item meta needs to be added to the item before you drop it
Java:
meta.setDisplayName("§a"+p.getName()+"'s Apple");
p.getWorld().dropItem(newloc, item);
item.setItemMeta(meta); // needs to be done before dropping the item or it'll just drop the apple with no meta
 
Item meta needs to be added to the item before you drop it
Java:
meta.setDisplayName("§a"+p.getName()+"'s Apple");
p.getWorld().dropItem(newloc, item);
item.setItemMeta(meta); // needs to be done before dropping the item or it'll just drop the apple with no meta
Done im even writing with out testing in eclipse
[doublepost=1558989529,1558988821][/doublepost]ShaneBee Check the code im too lazy ._.