1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Skript to Java

Discussion in 'Java' started by couger44, May 17, 2019.

  1. couger44

    Supporter

    Joined:
    Feb 19, 2017
    Messages:
    395
    Likes Received:
    13
    What is the java code for this one from skript?

    Code (Skript):
    1. command /dp [<string>]:
    2.     permission: world.dp
    3.     permission message: §cNo permission.
    4.     trigger:
    5.         arg 1 is "si":
    6.             drop 10 enchanted golden apple at {dp.1}'s location
    Code (Java):
    1.  
    2. //How can I do that in java?
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,945
    Likes Received:
    133
    Which part?
     
  3. couger44

    Supporter

    Joined:
    Feb 19, 2017
    Messages:
    395
    Likes Received:
    13
    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.
     
    #3 couger44, May 17, 2019
    Last edited: May 17, 2019
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,945
    Likes Received:
    133
    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.
     
  5. couger44

    Supporter

    Joined:
    Feb 19, 2017
    Messages:
    395
    Likes Received:
    13
    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.
     
  6. novastosha

    novastosha Well-Known Member

    Joined:
    Jan 11, 2019
    Messages:
    105
    Likes Received:
    5
    Wait until i find a soultion
    --- Double Post Merged, May 27, 2019, Original Post Date: May 27, 2019 ---
    Code (Java):
    1.  
    2. package me.test.couger44;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.inventory.meta.ItemMeta;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.event.player.PlayerItemConsumeEvent;
    15.  
    16. public class Test extends JavaPlugin implements Listener, CommandExecutor{
    17.  
    18.     public void onEnable() {
    19.         Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20.     }
    21.     public void onDisable() {
    22.        
    23.     }
    24.    
    25.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
    26.        
    27.         Player p = (Player) sender;
    28.         if(cmd.getName().equalsIgnoreCase("test")) {
    29.            
    30.             ItemStack item = new ItemStack(Material.GOLDEN_APPLE);
    31.             ItemMeta meta = item.getItemMeta();
    32.             meta.setDisplayName("§a"+p.getName()+"'s Apple");
    33.             p.getWorld().dropItem(p.getLocation(), item);
    34.             p.sendMessage("§aA golden apple has been droped");
    35.         }
    36.         return true;
    37.            
    38.         }
    39.     public void onConsume(PlayerItemConsumeEvent e) {
    40.         Player p = e.getPlayer();
    41.        
    42.         if(e.getItem().getItemMeta().getDisplayName() == "§a"+p.getName()+"'s Apple") {
    43.             e.setCancelled(true);
    44.             p.sendMessage("You cannot consume your own apple!");
    45.         }
    46.     }
    47.     }
    48.  
    49.  
    --- Double Post Merged, May 27, 2019 ---
    Btw, made it my self

    U need plugin.yml
     
    #6 novastosha, May 27, 2019
    Last edited: May 27, 2019
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,945
    Likes Received:
    133
    You forgot to set the item meta for the item
    Code (Java):
    1. ItemStack item = new ItemStack(Material.GOLDEN_APPLE);
    2. ItemMeta meta = item.getItemMeta();
    3. meta.setDisplayName("§a"+p.getName()+"'s Apple");
    4. //missing item.setItemMeta(meta);
    5. p.getWorld().dropItem(p.getLocation(), item);
     
  8. novastosha

    novastosha Well-Known Member

    Joined:
    Jan 11, 2019
    Messages:
    105
    Likes Received:
    5
    Yea, thanks for the ShaneBee
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,945
    Likes Received:
    133
    You're welcome
     
  10. novastosha

    novastosha Well-Known Member

    Joined:
    Jan 11, 2019
    Messages:
    105
    Likes Received:
    5
    Code (Java):
    1. package me.test.couger44;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.inventory.meta.ItemMeta;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.event.player.PlayerItemConsumeEvent;
    15.  
    16. public class Test extends JavaPlugin implements Listener, CommandExecutor{
    17.  
    18.     public void onEnable() {
    19.         Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20.     }
    21.     public void onDisable() {
    22.    
    23.     }
    24.  
    25.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
    26.    
    27.         Player p = (Player) sender;
    28.         if(cmd.getName().equalsIgnoreCase("test")) {
    29.             if(p.hasPermission("Ownapple.permission")) {
    30.                 ItemStack item = new ItemStack(Material.GOLDEN_APPLE);
    31.                 ItemMeta meta = item.getItemMeta();
    32.                 Location newloc = p.getLocation().add(p.getLocation(), 5, 0, 3);
    33.                 meta.setDisplayName("§a"+p.getName()+"'s Apple");
    34.                 item.setItemMeta(meta);
    35.                 p.getWorld().dropItem(newloc, item);
    36.                 p.sendMessage("§aA golden apple has been dropped at: X: "+ newloc.getX()+ " Y: "+ newloc.getY()+ " Z: "+ newloc.getZ());
    37.             }else p.sendMessage("§cYou don't have the required permission to execute this command!");
    38.             return true;
    39.            
    40.             }
    41.         return true;
    42.     }
    43.     public void onConsume(PlayerItemConsumeEvent e) {
    44.         Player p = e.getPlayer();
    45.    
    46.         if(e.getItem().getItemMeta().getDisplayName() == "§a"+p.getName()+"'s Apple") {
    47.             e.setCancelled(true);
    48.             p.sendMessage("§cYou cannot consume your own apple!");
    49.         }
    50.     }
    51.     }
    New Code contains adding to coordinates of player (XYZ) Color message Fixed Somthing thanks to Shane Bee, Permmsions
     
    #10 novastosha, May 27, 2019
    Last edited: May 27, 2019
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,945
    Likes Received:
    133
    Item meta needs to be added to the item before you drop it
    Code (Java):
    1. meta.setDisplayName("§a"+p.getName()+"'s Apple");
    2. p.getWorld().dropItem(newloc, item);
    3. item.setItemMeta(meta); // needs to be done before dropping the item or it'll just drop the apple with no meta
     
  12. novastosha

    novastosha Well-Known Member

    Joined:
    Jan 11, 2019
    Messages:
    105
    Likes Received:
    5
    Done im even writing with out testing in eclipse
    --- Double Post Merged, May 27, 2019, Original Post Date: May 27, 2019 ---
    ShaneBee Check the code im too lazy ._.
     
Loading...