Money plug in to buy enchanted Item

Discussion in 'Plugin Requests' started by AGreenPig, Jun 12, 2019.

  1. Offline

    AGreenPig

    Version :
    1.14
    What I need:
    I don't even know if this is possible but... I would need a plug in with some commands:
    /talon
    /talon buy <number>
    /talon sell <number>
    /talon take <Player> <number> (only for Admins)
    /talon give <Player> <number> (only for Admins)
    /talon <Player>(only for Admins)

    I want it kind of to be like an Economy plug in in that every player automaticly has a vitual Account of "Talons".

    If someone types /talon he gets his balance of talons that he has( something like: "You have <number> Talons."

    If someone types /talon buy <number> he gets <number> Talons in phisical Form. What I mean is a diamond Called "Talon" with unbraking 1 (sothat you can't just rename any Diamond)that can't be re-crafted into a Pickaxe for e.g.(of course the command only works if he has Talons left).

    With /talons sell <number> it's the other way around. You lose the phisical Talons in your inventory and get the same amount virtually(again, only if you have some).

    The /talon give or take command is just so that the admins can change the virtual balance of each player.

    /talon <Player> is again only for Admins so that they can see the balance of each player.


    I know this is a lot, and I don't even now if it's possible, but if someone could try it, I would be very happy.
     
  2. Offline

    Kars

  3. Offline

    AGreenPig

    So from what I was able to understand from the Plug in it's allmost right. The one Thing I don't really Like ist that the Money is a Item that you can get as a normal, non Admin Player. I would really Like it if the Money would be a different Item. Of coure you cant create New items with plugins, but I would Like an Item that only admins can get(the unbreaking 1 Diamond).

    Thanks for the effort though...
     
  4. Offline

    AGreenPig

    Edit: would IT be possible to make a unbreaking 1 clock, Not Diamond? I don't really think anyone will try to Programm this Plug in,but If so...clock please
     
  5. Offline

    AGreenPig

    Hi! so... I started trying to programm this plugin myself, but I ran inst some problems(the console says"Could not load 'plugins/Talon.jar' in folder 'plugins'").can someone help me?Please?
    Btw..its just a prototyp and does not have all the features I want yet...Because Its my first Plug in and I am a noob, I would like to save the talons of each player in the config file... now I don't know where the problem is I will send my whole code...be carefull..its messy:p

    Main:

    Code:
    package com.agreenpig.talon.main;
    
    
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.agreenpig.talon.command.HelpCommand;
    import com.agreenpig.talon.command.SetCommand;
    import com.agreenpig.talon.command.TalonCommand;
    import com.agreenpig.talon.listeners.JoinListener;
    
    public class Main extends JavaPlugin{
      
       private static Main plugin;
       @Override
       public void onEnable() {
         plugin= this;
        
         getLogger().info("Talon wunde aktiviert");
        
         PluginManager pm= getServer().getPluginManager();
         JoinListener listner=new JoinListener(plugin);
         pm.registerEvents(listner, plugin);
        
         getCommand("talon").setExecutor(new TalonCommand());
         getCommand("talonHelp").setExecutor(new HelpCommand());
         getCommand("talonSet").setExecutor(new SetCommand());
        
        
       }
       public void onDissable() {
        
         getLogger().info("Talon wurde ausgeschalten");
       }
       public static Main getPlugin() {
         return plugin;
       }
      
      
    }
    
    Listner:
    Code:
    package com.agreenpig.talon.listeners;
    
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    import com.agreenpig.talon.main.Main;
    
    public class JoinListener implements Listener{
       
        public JoinListener(Main plugin) {
           
        }
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            FileConfiguration config= Main.getPlugin().getConfig();
            config.set(event.getPlayer().getName(), "0");
            Main.getPlugin().saveConfig();
        }
    }
    

    Help Command:
    Code:
    package com.agreenpig.talon.command;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import com.agreenpig.talon.main.Main;
    
    
    
    public class HelpCommand implements CommandExecutor{
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg) {
         Player player= (Player) sender;
        
         if (sender instanceof Player) {
           player.sendMessage(ChatColor.GOLD+"=============Talon==============\n/talon (zeigt dir, wie viele Talons du hast)");
         }
         else {
           Main.getPlugin().getLogger().info("=============Talon==============\n/talon (zeigt dir, wie viele Talons du hast)");
         }
         return true;
       }
    }
    
    
    SetCommand:
    Code:
    package com.agreenpig.talon.command;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    import com.agreenpig.talon.main.Main;
    
    
    
    public class SetCommand implements CommandExecutor {
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg) {
         Player player= (Player) sender;
         FileConfiguration config= Main.getPlugin().getConfig();
           if (arg.length==2) {
             if (Main.getPlugin().getConfig().contains(arg[1])) {
               if (arg[2].charAt(0)=='-'||arg[2].length()>=11) {
                 if (sender instanceof Player) {
                   player.sendMessage(ChatColor.RED+"Nur werte über 0 und unter 999999999999 sind erlaubt!");
                 }
                 else {
                   Main.getPlugin().getLogger().info("Nur werte über 0 und unter 999999999999 sind erlaubt!");
                 }
               }
               else {
                 config.set(arg[1], arg[2]);
                 Main.getPlugin().saveConfig();
               }
             }
             else {
               if (sender instanceof Player) {
                 player.sendMessage(ChatColor.RED+"Dieser Spieler muss erst joinen um seinen account ändern zu können");
               }
               else {
                 Main.getPlugin().getLogger().info("Dieser Spieler muss erst joinen um seinen account ändern zu können");
               }
             }
           }
           else {
             if (sender instanceof Player) {
               player.sendMessage(ChatColor.RED+"Benutze bitte: "+ChatColor.GOLD+"/talon set <Player> <TalonAmount>");
             }
             else {
               Main.getPlugin().getLogger().info("Benutze bitte: /talon set <Player> <TalonAmount>");
             }
           }
        
         return true;
       }
    }
    
    
    TalonCommand:
    Code:
    package com.agreenpig.talon.command;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import com.agreenpig.talon.main.Main;
    
    public class TalonCommand implements CommandExecutor{
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg) {
         Player player= (Player) sender;
         if (arg.length==0) {
           if (sender instanceof Player) {
             player.sendMessage(ChatColor.GOLD+"DuHast "+ChatColor.YELLOW+Main.getPlugin().getConfig().getString(player.getName()+ChatColor.GOLD+" Talons!"));
           }
           else {
             Main.getPlugin().getLogger().info("Das kannst du nur als Spieler");
           }
         }  
        
         return true;
       }
      
    }
    
    
    and the plugin.yml
    Code:
    name: Talon
    main: com.agreenpig.talon.Main
    version: 1.0
    
    commands:
       talon:
         description: Zeigt dir dein Geld
       talonHelp:
         description: Gibt dir Hilfe
       talonSet:
         description: Setzt Das Geld Eines Spielers.
    
    PS: I'm austrian and some parts like Messages are in german...I don't think that is a big problem thogh because it is just a message.

    I would love it if someone could Help me!
     
    Last edited: Jun 15, 2019
  6. Offline

    Eccentric_Gamer

    Did you make a plugin.yml? Google it for more info.
     
  7. Offline

    AGreenPig

    Yup Here. Saved as plugin.yml
     
  8. Online

    timtower Ninja on the waves Moderator

    @AGreenPig Make a thread in plugin development please
     
  9. Offline

    wand555

    Hey @AGreenPig
    I created the plugin already and if you want I can explain the code to you.

    Follow up:
    Main (open)

    Code:
    package me.wand555.Talon;
    
    import java.io.File;
    
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.permissions.PermissionAttachment;
    import org.bukkit.permissions.PermissionAttachmentInfo;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Talon extends JavaPlugin {
       private TalonCommandExecutor myTalonCommandExecutor;
       public HashMap<UUID, PermissionAttachment> playerPermissions = new HashMap<>();
      
      
       public static Talon plugin;
      
       public Talon() {
         plugin = this;
       }
      
      
      
       @Override
       public void onEnable() {
         super.onEnable();
         myTalonCommandExecutor = new TalonCommandExecutor(this);
         getCommand("talon").setExecutor(myTalonCommandExecutor);
         new TalonCraftEvent(this);
         new TalonPermsEvent(this);
         this.getConfig().options().copyDefaults(true);
         this.saveConfig();
       }
       @Override
       public void onDisable() {
         playerPermissions.clear();
         super.onDisable();
        
       }
      
      
       public static void setUpPermission(Player player) {
         PermissionAttachment attachment = player.addAttachment(plugin);
         plugin.playerPermissions.put(player.getUniqueId(), attachment);
        
         for(String groups : plugin.getConfig().getConfigurationSection("Groups").getKeys(false)) { //loop through all groups
           for(String permissions : plugin.getConfig().getStringList("Groups." + groups + ".permissions")) { //get permissions
             attachment.setPermission(permissions, true);
           }
         }
         Talon.addPerm(player.getUniqueId());
       }
      
       public static void removePermission(Player player, String permission) {
         for (PermissionAttachmentInfo paInfo : player.getEffectivePermissions()) {
           if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(plugin)) {
             paInfo.getAttachment().unsetPermission(permission);
           }
         }
         Talon.deletePerm(player.getUniqueId());
       }
      
       public static boolean isInteger(String s) {
        return isInteger(s,8);
       }
    
       public static boolean isInteger(String s, int radix) {
        if(s.isEmpty()) return false;
        for(int i = 0; i < s.length(); i++) {
        if(i == 0 && s.charAt(i) == '-') {
        if(s.length() == 1) return false;
        else continue;
        }
        if(Character.digit(s.charAt(i),radix) < 0) return false;
        }
        return true;
       }
      
       public static void checkOrdner() {
         File file = new File("plugins//Talon");
         if(!(file.exists())) {
           file.mkdir();
         }
       }
      
       public static void saveCustomYml(FileConfiguration ymlConfig, File ymlFile) {
        try {
        ymlConfig.save(ymlFile);
        } catch (IOException e) {
        e.printStackTrace();
        }
       }
      
       public static Integer getTalon(UUID uuid) {
         Talon.checkOrdner();
         File file = new File("plugins//Talon", "talon.yml");
         FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
         int talon = cfg.getInt(uuid.toString() + " .talon");
         return talon;
       }
      
      
       public static void addTalon(UUID uuid, String name, int amount) {
         Talon.checkOrdner();
         File file = new File("plugins//Talon", "talon.yml");
         FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
         int talon = cfg.getInt(uuid.toString() + " .talon");
         talon = amount + talon;
         cfg.set(uuid.toString() + " .talon", talon);
         cfg.set(uuid.toString() + " .username", name);
         Talon.saveCustomYml(cfg, file);
       }
      
       public static boolean removeTalon(UUID uuid, String name, int amount) {
         Talon.checkOrdner();
         File file = new File("plugins//Talon", "talon.yml");
         FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
         int talon = cfg.getInt(uuid.toString() + " .talon");
         if((talon - amount) >= 0) {
           talon = talon - amount;
           cfg.set(uuid.toString() + " .talon", talon);
           cfg.set(uuid.toString() + " .username", name);
           Talon.saveCustomYml(cfg, file);
           return true;
         }
         else {
           return false;
         }
       }
      
       public static void addPerm(UUID uuid) {
         Talon.checkOrdner();
         File file = new File("plugins//Talon", "talon.yml");
         FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
         cfg.set(uuid.toString() + " .permission", true);
         Talon.saveCustomYml(cfg, file);
       }
      
       public static void deletePerm(UUID uuid) {
         Talon.checkOrdner();
         File file = new File("plugins//Talon", "talon.yml");
         FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
         cfg.set(uuid.toString() + " .permission", false);
         Talon.saveCustomYml(cfg, file);
       }
      
       public static boolean hasPerm(UUID uuid) {
         Talon.checkOrdner();
         File file = new File("plugins//Talon", "talon.yml");
         FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
         return(cfg.getBoolean(uuid.toString() + " .permission"));
       }
      
       public static void InvtoBankTalon(UUID uuid, String name, int amount, Inventory inv) {
         Player player = Bukkit.getPlayer(uuid);
        
         Talon.checkOrdner();
         File file = new File("plugins//Talon", "talon.yml");
         FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
        
         if(inv.containsAtLeast(Talon.physicalCurrencyCreator(uuid), amount) == true) {
           int talon = cfg.getInt(uuid.toString() + " .talon");
           //int talon_vorher = talon;
           talon = talon + amount;
           cfg.set(uuid.toString() + " .talon", talon);
           cfg.set(uuid.toString() + " .username", name);
           Talon.saveCustomYml(cfg, file);
           for(int i=0; i<amount; i++) {
             inv.removeItem(Talon.physicalCurrencyCreator(uuid));
           }
           player.sendMessage("Erfolgreich " + amount + " Talon transferiert.");
           player.sendMessage("Du hast nun " + talon + " Talon auf deinem Konto.");
         }
         else {
           player.sendMessage("Nicht genügend Talon im Inventar.");
         }
       }
      
       public static void BanktoInvTalon(UUID uuid, String name, int amount, Inventory inv) {
         Player player = Bukkit.getPlayer(uuid);
        
         Talon.checkOrdner();
         File file = new File("plugins//Talon", "talon.yml");
         FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
         if(inv.firstEmpty() == -1 ) {
           if(!(inv.contains(Talon.physicalCurrencyCreator(uuid)))) {
             player.sendMessage("Kein Platz im Inventar.");
           }
           else {
             int talon = cfg.getInt(uuid.toString() + " .talon");
             if(talon >= amount) {
               for(int i=0; i<amount; i++) {
                 inv.addItem(Talon.physicalCurrencyCreator(uuid));
                 talon--;
                 cfg.set(uuid.toString() + " .talon", talon);
                 cfg.set(uuid.toString() + " .username", name);
                 Talon.saveCustomYml(cfg, file);
               }  
             }
             else {
               player.sendMessage("Du hast nur " + talon + " Talon auf deinem Konto.");
             }
           }
          
         }
         else {
           int talon = cfg.getInt(uuid.toString() + " .talon");
           if(talon >= amount) {
             for(int i=0; i<amount; i++) {
               inv.addItem(Talon.physicalCurrencyCreator(uuid));
               talon--;
               cfg.set(uuid.toString() + " .talon", talon);
               cfg.set(uuid.toString() + " .username", name);
               Talon.saveCustomYml(cfg, file);
             }  
           }
           else {
             player.sendMessage("Du hast nur " + talon + " Talon auf deinem Konto.");
           }
         }  
       }
    
       public static ItemStack physicalCurrencyCreator(UUID uuid) {
         ItemStack diamond = new ItemStack(Material.DIAMOND, 1);
         ItemMeta meta = diamond.getItemMeta();
         meta.setDisplayName("Talon");
         ArrayList<String> itemdesc = new ArrayList<String>();
         itemdesc.add("Physikalische Währung");
         meta.setLore(itemdesc);
         meta.addEnchant(Enchantment.DURABILITY, 1, true);
         meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
        
         diamond.setItemMeta(meta);
        
         return(diamond);
       }  
    }
    


    Commands (open)

    Code:
    package me.wand555.Talon;
    
    import org.bukkit.Bukkit;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class TalonCommandExecutor implements CommandExecutor {
        private Talon plugin;
     
        public TalonCommandExecutor(Talon plugin) {
            this.plugin = plugin;
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = null;
            if(sender instanceof Player) {
                player = (Player) sender;
            }
            if(cmd.getName().equalsIgnoreCase("talon")) {
                if(!(player==null)) {
                    if(args.length == 0) {     
                        player.sendMessage("Du hast aktuell " + Talon.getTalon(player.getUniqueId()) + " Talon.");
                    }
                    else if(args.length == 1) {
                        String target = args[0];
                        Player target_player = Bukkit.getServer().getPlayer(args[0]);
                        if(player == target_player) {
                            player.sendMessage("Deine eigene Talon kannst du mit /talon aufrufen.");
                        }
                        else {
                            player.sendMessage(target + " hat " + Talon.getTalon(target_player.getUniqueId()) + " Talon.");
                        }
                     
                    }
                    else if(args.length == 2 && args[0].equalsIgnoreCase("sell")) {
                        Talon.InvtoBankTalon(player.getUniqueId(), player.getName(), Integer.valueOf(args[1]), player.getInventory());
                    }
                    else if(args.length == 2 && args[0].equalsIgnoreCase("buy")) {
                        Talon.BanktoInvTalon(player.getUniqueId(), player.getName(), Integer.valueOf(args[1]), player.getInventory());
                    }
                 
                 
                    else if(args.length == 3 && args[0].equalsIgnoreCase("give") && Talon.isInteger(args[2]) == true) {
                        if(player.hasPermission("talon.admin") || player.isOp() == true) {
                            String target = args[1];
                            Player target_player = Bukkit.getServer().getPlayer(args[1]);
                         
                            Talon.addTalon(target_player.getUniqueId(), target_player.getName(), Integer.valueOf(args[2]));
                            if(player == target_player) {
                                player.sendMessage("Du hast dir selber " + Integer.valueOf(args[2]) + " Talon hinzugefügt.");
                            }
                            else {
                                player.sendMessage(target + " wurde " + Integer.valueOf(args[2]) + " Geld hinzugefügt.");
                                target_player.sendMessage(player.getName() + " hat dir " + Integer.valueOf(args[2]) + " Geld hinzugefügt.");
                            }
                        }
                        else {
                            player.sendMessage("Du hast dafür keine Berechtigung.");
                        }
                     
                     
                    }
                    else if(args.length == 3 && args[0].equalsIgnoreCase("take") && Talon.isInteger(args[2]) == true) {
                        if(player.hasPermission("talon.admin") || player.isOp() == true) {
                            String target = args[1];
                            Player target_player = Bukkit.getServer().getPlayer(args[1]);
                         
                            if(Talon.removeTalon(target_player.getUniqueId(), target_player.getName(), Integer.valueOf(args[2])) == true) {
                                if(player == target_player) {
                                    player.sendMessage("Du hast dir selber " + Integer.valueOf(args[2]) + " Talon abgezogen.");
                                }
                                else {
                                    player.sendMessage(target + " wurde " + Integer.valueOf(args[2]) + " Geld abgezogen.");
                                    target_player.sendMessage(player.getName() + " hat dir " + Integer.valueOf(args[2]) + " Geld abgezogen.");
                                }
                            }
                            else {
                                player.sendMessage(target_player.getName() + " besitzt nur " + Talon.getTalon(target_player.getUniqueId()) + " Talon.");
                            }
                         
                         
                        }
                        else {
                            player.sendMessage("Du hast dafür keine Berechtigung.");
                        }
                     
                     
                    }
                    else if(args.length == 3 && args[0].equalsIgnoreCase("give") && args[1].equalsIgnoreCase("permission")) {
                        if(player.isOp() == true) {
                            String target = args[2];
                            Player target_player = Bukkit.getServer().getPlayer(args[2]);
                            if(target_player.hasPermission("talon.admin")) {
                                player.sendMessage(target + " hat bereits die Berechtigung.");
                            }
                            else {
                                Talon.setUpPermission(target_player);
                                if(player == target_player) {
                                    player.sendMessage("Du hast dir die Berechtigung gegeben.");
                                }
                                else {
                                    player.sendMessage("Du hast " + target + " die Berechtigung gegeben.");
                                    target_player.sendMessage(player.getName() + " hat dir die Berechtigung gegeben.");
                                }
                            }
                        }
                        else  {
                            player.sendMessage("Du musst OP haben, um diesen Befehl auszuführen.");
                        }
                    }
                    else if(args.length == 3 && args[0].equalsIgnoreCase("remove") && args[1].equalsIgnoreCase("permission")) {
                        if(player.isOp() == true) {
                            String target = args[2];
                            Player target_player = Bukkit.getServer().getPlayer(args[2]);
                            if(target_player.hasPermission("talon.admin")) {
                                //plugin.playerPermissions.remove(target_player.getUniqueId());
                                Talon.removePermission(target_player, "talon.admin");
                                if(player == target_player) {
                                    player.sendMessage("Du hast dir die Berechtigung entzogen.");
                                }
                                else {
                                    player.sendMessage("Du hast " + target + " die Berechtigung entzogen.");
                                    target_player.sendMessage(player.getName() + " hat dir die Berechtigung entzogen.");
                                }
                            }
                            else {
                                    player.sendMessage(target + " hat bereits keine Berechtigung.");
                             
                            } 
                        }
                        else {
                            player.sendMessage("Du musst OP haben, um diesen Befehl auszuführen.");
                        }
                         
                    }
                 
                }
            }
         
            return true;
        }
    }
    


    I am fairly new to programming so almighty gods in this forum, please have mercy.
    If anyone has any questions or improvements, don't hesitate to reply.

    You can download the .jar file <Edit by Moderator: Redacted mediafire url>

    EDIT: Fixed an issue where you couldn't get the item when your inventory was full, but the amount still got withdrawn from your account.
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Jun 17, 2019
  10. Offline

    AGreenPig

    @wand555

    Hi! I'm New to programing too! I finished the Plugin my self but it's cool that you was able to so too! I think i personally cant give much critc hence I am so New to this stuff... I sometimes think it's a little bit more cleaned Up If you have more classes and packages, but as I Said, honestly I have no Idea! :eek:

    PS: Just that you know... Your Code is still Vetter by far!(I don't even have perms lol...it was my First Plugin so...)
     
    Last edited: Jun 17, 2019
  11. Offline

    wand555

    @AGreenPig Can I look over your code? I'm interested how you solved the problems.
     
  12. Offline

    AGreenPig

    @wand555
    h/www.dropbox.com/sh/9piljuqchz7jxmz/AABt1zVTIFXX_b4sUh7ej1OTa?dl=0 this is my whole src Folder...It's my very first plugin. It's not even close as technically advanced as yours. Whatever...

    @wand555 I have a question abut your code... what does "new TalonCraftEvent(this);" and
    "new TalonPermsEvent(this);" do? Is it a bukkit method(because it's not declared in your code)? If I write it into Eclipse it gives me an Error :TalonCraftEvent cannot be resolved to a type... So it probably isn't a bukkit event or? idk...

    Ps: have you got an eye infection from my code?:p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 18, 2019
  13. Offline

    wand555

    @AGreenPig I'm registering a new event (Listener) in my onEnable method.
    It's just a listener that gets called when someone tries to craft an item with a Talon (enchanted diamond)

    Code:
    package me.wand555.Talon;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.CraftItemEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class TalonCraftEvent implements Listener {
        public TalonCraftEvent (JavaPlugin plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
        @EventHandler
        public void onTalonCraftEvent(CraftItemEvent event) {
            Player player = (Player) event.getWhoClicked();
            Inventory inv = event.getInventory();
            if(inv.contains(Talon.physicalCurrencyCreator(player.getUniqueId()))) {
                player.sendMessage("Du darfst keine Talon zum Craften benutzen.");
                event.setCancelled(true);
            }
        }
    
    }
    The setCancelled(true) says, that the CraftItemEvent is getting cancelled. Ingame this means that the player can make the crafting recipe for a diamond chestplate with Talon's, but he cannot take the crafted item out of the crafting table.

    The other one is another EventListener that checks whether a player has the permission to perform the commands /give <player> <talon> and /take <player> <talon>
    Code:
    package me.wand555.Talon;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class TalonPermsEvent implements Listener {
        public TalonPermsEvent(JavaPlugin plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
       
        @EventHandler
        public void login(PlayerJoinEvent event) {
            if(Talon.hasPerm(event.getPlayer().getUniqueId()) == true) {
                Talon.setUpPermission(event.getPlayer());
            }
            else {
                Talon.firstLogin(event.getPlayer());
            }
        }
       
        @EventHandler
        public void logout(PlayerQuitEvent event) {
            Talon.plugin.playerPermissions.remove(event.getPlayer().getUniqueId());
        }
    }
    
     
    Last edited: Jun 19, 2019 at 3:32 AM
  14. Offline

    AGreenPig

    @wand555 OK!
    I changed the talons from Diamonds to clocks because they're useless and can't be re-crafted. I didn't know you could make a craft listener:)..

    What about the perms Event?
     
  15. Offline

    wand555

    @AGreenPig Edited the post, didn't see it the first time I read your question :D
    To explain the perms event a little bit more:
    Generally when a player logs in for their first time, their permission value is set to false.
    Screenshot_2.png
    When a player has op and performs the command /talon give permission <player> the <player>' gets the (custom) permission from the config.yml (called talon.admin) and stores it in the permission value as well. And since this is all wanky and also new to me, I tried cheating a bit by just adding the permission value in the talon.yml, I don't know if thats actually needed.
    Now whenever a player performs the command /talon give <player> <amount> or /talon take <player> <amount> a method called hasPermission checks whether the player has the permission to perform the command, or not. The Join (and Quit) Listener are needed, because the permission is stored in a hash map, so when a player leaves and rejoins or the server restarts, these values get deleted (I think).
     

Share This Page