Development Assistance Display text after typing wrong command.

Discussion in 'Plugin Help/Development/Requests' started by SaltyPotato, May 21, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    SaltyPotato

    So, i am making a plugin.

    When i type /pvpwl -- This text shows up

    As you can see all commands are listed there.

    Now what i want, if people types the command wrong, (for example /pvpwl ad instead of /pvpwl add),
    this text would show up


    I hope anyone could help me with this. Thanks in advance
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    SaltyPotato

    Oops, sorry. Here it is:

    Code:
    package me.Endervines.PvP2;
    
    import java.util.Iterator;
    import java.util.List;
    
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
       
        @Override
        public void onEnable() {
            List stringList = this.getConfig().getStringList("Whitelist");
            stringList.add(" ");
            this.getConfig().addDefault("Whitelist", (Object)stringList);
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
    
        }
        @Override
        public void onDisable() {
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player)sender;
            if (cmd.getName().equalsIgnoreCase("pvpwl")) {
                if (sender instanceof Player) {
                    List Whitelist;
                    Iterator iterator;
                    if (args.length == 0) {
                        player.sendMessage("\u00a7c/pvpwl add: \u00a77Add an item to the list");
                        player.sendMessage("\u00a7c/pvpwl remove: \u00a77Remove an item from the list");
                        player.sendMessage("\u00a7c/pvpwl reload: \u00a77Reload the config");
                        player.sendMessage("\u00a7c/pvpwl info: \u00a77Displays plugin information");
                        return true;
                    }
                    if (args[0].equalsIgnoreCase("add")) {
                        if (player.hasPermission("pvpwl.admin") || player.isOp()) {
                            Material mat = player.getItemInHand().getType();
                            List stringList = this.getConfig().getStringList("Whitelist");
                            stringList.add(mat.toString());
                            this.getConfig().set("Whitelist", (Object)stringList);
                            this.saveConfig();
                            player.sendMessage(this.getConfig().getString("added").replaceAll("&", "\u00a7").replace("{item}", mat.toString()));
                            return true;
                        }
                        player.sendMessage(this.getConfig().getString("noperm").replaceAll("&", "\u00a7"));
                    }
                    if (args[0].equalsIgnoreCase("remove")) {
                        if (player.hasPermission("pvpwl.admin") || player.isOp()) {
                            Material mat = player.getItemInHand().getType();
                            if (this.getConfig().getStringList("Whitelist").contains(mat.toString())) {
                                List stringList = this.getConfig().getStringList("Whitelist");
                                stringList.remove(mat.toString());
                                this.getConfig().set("Whitelist", (Object)stringList);
                                this.saveConfig();
                                player.sendMessage(this.getConfig().getString("removed").replaceAll("&", "\u00a7").replace("{item}", mat.toString()));
                                return true;
                            }
                            player.sendMessage(this.getConfig().getString("not-contain").replaceAll("&", "\u00a7"));
                            return true;
                        }
                        player.sendMessage(this.getConfig().getString("noperm").replaceAll("&", "\u00a7"));
                        return true;
                    }
                   
                    if (args[0].equalsIgnoreCase("reload") && (sender.hasPermission("pvpwl.admin") || player.isOp())) {
                        this.reloadConfig();
                        player.sendMessage(this.getConfig().getString("reloaded").replaceAll("&", "\u00a7"));
                        return true;
                    }
                } else {
                    sender.sendMessage("\u00a7cOnly players can do this!");
                    return true;
                }
            }
            return false;
        }
    
        @EventHandler
        public void hitEvent(EntityDamageByEntityEvent event) {
            Player player;
            if (event.getDamager() instanceof Player && (!(player = (Player)event.getDamager()).hasPermission("pvpwl.bypass") || player.isOp()) && player.getItemInHand().getType() != null) {
                Material mat = player.getItemInHand().getType();
                String m = mat.toString();
                if (!this.getConfig().getStringList("Whitelist").contains(m)) {
                    player.sendMessage(this.getConfig().getString("hit").replaceAll("&", "\u00a7").replace("{item}", mat.toString()));
                    event.setCancelled(true);
                }
            }
        }
    }
    
     
  4. Offline

    timtower Administrator Administrator Moderator

    @SaltyPotato You have all those checks for args 0, put code after all those statements that send the wanted message.
     
Thread Status:
Not open for further replies.

Share This Page