help my pls

Discussion in 'Spigot Plugin Development' started by GDG_COEN_1407, May 11, 2016.

  1. HELP MY PLS

    package gdg.coen1407.Minetopia.GADJET;

    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Arrays;
    import java.util.Date;
    import java.util.List;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Server;
    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.HumanEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.scheduler.BukkitScheduler;

    public class Strafblad implements Listener
    {
    private Main plugin;

    public Strafblad(Main plugin)
    {
    this.plugin = plugin;
    }

    public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, String[] args)
    {
    Player p = (Player)sender;
    if (!(sender instanceof Player)) {
    sender.sendMessage(ChatColor.RED + "Sorry, Je bent geen speler! :(");
    return true;
    }
    if (cmd.getName().equalsIgnoreCase("strafblad")) {
    if (sender.hasPermission("mt.straf.staff")) {
    if (args.length == 0) {
    p.sendMessage(ChatColor.RED + "Sorry. Gebruik /strafblad <Add> <Speler> <Reden>!");
    p.sendMessage(ChatColor.RED + "Of gebruik /strafblad <Get> <Speler>!");
    p.sendMessage(ChatColor.RED + "Of gebruik '/strafblad rem'!");
    p.sendMessage(ChatColor.RED + "LETOP! Bij een Reden toevoegen van het eerste commando!");
    p.sendMessage(ChatColor.RED + "Mag je GEEN spaties in je reden hebben! Gebruik een ',' of te wel een komma INPLAATSVAN een spatie!");
    p.sendMessage (ChatColor.BLUE + "Deze Plugin Is gemaakt door coen1407 Youtube kanaal Godgamersnl!");
    return true;
    }

    if (args.length < 1)
    {
    p.sendMessage(ChatColor.RED + "Sorry. Gebruik /strafblad <Add> <Speler> <Reden>!");
    p.sendMessage(ChatColor.RED + "Of gebruik /strafblad <Get> <Speler>!");
    p.sendMessage(ChatColor.RED + "Of gebruik '/strafblad rem'!");
    p.sendMessage(ChatColor.RED + "LETOP! Bij een Reden toevoegen van het eerste commando!");
    p.sendMessage(ChatColor.RED + "Mag je GEEN spaties in je reden hebben! Gebruik een ',' of te wel een komma INPLAATSVAN een spatie!");
    p.sendMessage (ChatColor.BLUE + "Deze Plugin Is gemaakt door coen1407 Youtube kanaal Godgamersnl!");
    return true;
    }
    if (args[0].equalsIgnoreCase("Get"))
    {
    if (this.plugin.getConfig().getList(args[1]).toString() == null) {
    p.sendMessage(ChatColor.RED + "Deze speler heeft geen strafblad!");
    }
    else
    {
    new SimpleDateFormat("HH:mm");
    new Date();

    ItemStack servers = new ItemStack(Material.PAPER, 1);
    ItemMeta serversMeta = servers.getItemMeta();
    serversMeta.setDisplayName(ChatColor.AQUA + "Strafblad");
    serversMeta.setLore(Arrays.asList(new String[] { ChatColor.AQUA + "Dit zijn de redens waarom " + args[1] + " een strafblad heeft:", ChatColor.WHITE + this.plugin.getConfig().getList(args[1]).toString().replaceAll(",", " "), ChatColor.AQUA + "Is de lijst leeg? Dan heeft hij/zij geen strafblad!" }));
    servers.setItemMeta(serversMeta);
    p.getInventory().addItem(new ItemStack[] { servers });
    p.sendMessage(ChatColor.AQUA + "Je hebt de strafblad van " + args[1] + " succes vol ontvangen!");
    }
    }

    if (args[0].equalsIgnoreCase("add"))
    {
    new SimpleDateFormat("HH:mm");
    new Date();
    List<?> playersInConfig = this.plugin.getConfig().getStringList(args[1]);
    playersInConfig.add(args[0] + " -");
    this.plugin.getConfig().set(args[1], playersInConfig);

    this.plugin.saveConfig();
    this.plugin.reloadConfig();
    p.sendMessage(ChatColor.GREEN + "Strafblad succes vol toegevoegd op speler: " + args[1] + " Reden: " + args[2]);
    }

    if (args[0].equalsIgnoreCase("Rem")) {
    p.getItemInHand().setItemMeta(null);
    this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable()
    {
    public void run() {
    ItemStack is = new ItemStack(Material.PAPER);

    if (((HumanEntity)sender).getInventory().contains(is)) {
    ((HumanEntity)sender).getInventory().remove(is);
    sender.sendMessage(ChatColor.GREEN + "Strafblad succes vol verwijderd uit je inventory!");
    } else {
    sender.sendMessage(ChatColor.RED + "Je hebt geen strafblad in je inventory!");
    }
    }
    }
    , 60L);
    }

    }

    }
    else
    {
    p.sendMessage(ChatColor.RED + "Je hebt hier geen toestemming voor!");
    }

    return true;
    }
    }
     
    #1 GDG_COEN_1407, May 11, 2016
    Last edited: May 11, 2016
  2. wat?
     
    • Agree Agree x 3
  3. What....? That doesn't look like valid Java, can you post your whole class please? And the error that you're getting?
     
    • Agree Agree x 2
    • Like Like x 1
  4. You're asking us to halp your pls but we don't even know what's the problem... Actually, there are lots of problems! Which one are you trying to solve?
     
    • Agree Agree x 1
  5. You're using ambiguous list types, your casting before an instanceof check, you're turning a list into a string, instead of iterating over every value inside it, you have your onCommand method inside a class that doesn't implement the interface CommandExecutor... Where did you learn java?
     
  6. 1st, learn basic java
    2nd, use the code tag to post code.
     
  7. end the error
    he method add(capture#3-of ?) in the type List<capture#3-of ?> is not applicable for the arguments (String)
     
  8. add code tags [ code ] your code [ /code ]
    and what is your code even doing?
     
  9. Like I said, you're using ambiguous list types. Learn java. The reason that when you define a list you can add the angle brackets isn't just to make it a wildcard list, you should be using List<String> to make it a string list
     
  10. Found one bug
    this part the main needs to be the same as your class name.
    Code (Text):

    private Main plugin;

    public Strafblad(Main plugin)
    {
    this.plugin = plugin;
    }

     
     
  11. I am wrong Don't listen to me
     
  12. Send us your main class.
     
  13. Please use the edit button dear god
     
  14. Why?
     
  15. Because sending 4 messages in a row is spammy and unnecessary
     
    • Agree Agree x 1
    • Funny Funny x 1
  16. Does anyone know what the code is doing?
     
  17. Why put time and energy in this mess? He could simply tell us. He'll come back if he really needs help^^
     
  18. If I new what it was doing i would try to recreate it.
     
  19. you simply didn't implement the command executor in your class.