Solved Ban default message

Discussion in 'Plugin Development' started by GodzillaFlame42, Sep 5, 2016.

Thread Status:
Not open for further replies.
  1. @Zombie_Striker There are errors now on plugin for example the red is the error and it has it on every one.
    Main.plugin.getConfig().getString(event.getPlayer().getName() + ".reason");

    Code:
    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    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 org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    public class Ban implements Listener, CommandExecutor {
      
            @SuppressWarnings({ "deprecation" })
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("ban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Ban.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/ban <player> <reason>");
                                    return true;
                            }
                      
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                         
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                         
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                                    Main.plugin.getConfig().set(target.getName() +".reason", msg);
                                    Main.plugin.saveConfig();
                            }
                  
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.YELLOW + target.getName() + ChatColor.GRAY + " has been banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(true);
                                target.kickPlayer(ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName() + ChatColor.GRAY + "                         Reason: " + ChatColor.YELLOW + msg + ChatColor.GRAY + "   Date: " + ChatColor.YELLOW + format.format(now));
                            }
                        }
                    return false;
            }
            Date now = new Date();
            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
    @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event){
            Result r = event.getResult();  
            Main.plugin.getConfig().getString(event.getPlayer().getName() + ".reason");
            event.disallow(Result.KICK_BANNED, ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned from the server                         Date: " + ChatColor.YELLOW + format.format(now));
            }
        }
     
  2. Offline

    Zombie_Striker

    @GodzillaFlame42
    What is the error? There should be a "plugin" field in the main class. Please post the error message and the main class.
     
  3. @Zombie_Striker Nevermind its not there anymore but now how would i do the config.yml?
     
  4. Offline

    Zombie_Striker

  5. @Zombie_Striker How would i like make it. How would i set the config.yml to make it work with what your said to put in the code.

    config.yml:
    Reason:

    like that or something

    Edit: I figured out how to do it and it all works perfectly now thank you for helping me!
     
    Last edited: Sep 11, 2016
  6. Offline

    Zombie_Striker

    @GodzillaFlame42
    If your problem has been solved, mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page