org.bukkit.event.EventException: null

Discussion in 'Plugin Development' started by Khamitov, Jan 11, 2021.

  1. Offline

    Khamitov

    problem
    with error code -org.bukkit.event.EventException: null
    here is the main code

    Code:
    package hahamine.syntax;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import net.md_5.bungee.api.ChatColor;
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class main extends JavaPlugin implements Listener
    {
        public static Plugin plugin;
        public static FileConfiguration config;
       
        public void onEnable() {
            Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "HaHaMiNeSyntax Enabled! Plugin redone player Khamitov - ┬ževk.com/Khamitov0312");
            this.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);
            main.plugin = (Plugin)this;
            ConfigHandler.configInit();
        }
       
        public void onDisable() {
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "HaHaMiNeSyntax Disable! Plugin redone player Khamitov - ┬ževk.com/khamitov0312");
        }
       
        @EventHandler
        public void onCommand(final PlayerCommandPreprocessEvent e) {
            final Player player = e.getPlayer();
            if (e.getMessage().split(" ")[0].contains(":") && !player.hasPermission("hahaminesyntax.allow")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', main.config.getString("Message.HaHaMineSyntax")));
                player.playSound(player.getLocation(), Sounds.VILLAGER_NO.bukkitSound(), 2.0f, 1.0f);
            }
        }
       
        @EventHandler
        public void onCommand1(final PlayerCommandPreprocessEvent e) {
            final Player player = e.getPlayer();
            if (e.getMessage().split(" ")[0].contains(".") && !player.hasPermission("hahaminesyntax.allow")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', main.config.getString("Message.HaHaMineSyntax")));
                player.playSound(player.getLocation(), Sounds.VILLAGER_NO.bukkitSound(), 2.0f, 1.0f);
            }
        }
       
        @EventHandler
        public void onCommand2(final PlayerCommandPreprocessEvent e) {
            final Player player = e.getPlayer();
            if (e.getMessage().split(" ")[0].contains("*") && !player.hasPermission("hahaminesyntax.allow")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', main.config.getString("Message.HaHaMineSyntax")));
                player.playSound(player.getLocation(), Sounds.ZOMBIE_PIG_DEATH.bukkitSound(), 2.0f, 1.0f);
            }
        }
       
       
        public void onCommand3(final PlayerCommandPreprocessEvent e) {
            final Player player = e.getPlayer();
            if (e.getMessage().split(" ")[1].contains(":") && !player.hasPermission("hahaminesyntax.allow")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', main.config.getString("Message.HaHaMineSyntax")));
                player.playSound(player.getLocation(), Sounds.VILLAGER_NO.bukkitSound(), 2.0f, 1.0f);
            }
        }
       
        @EventHandler
        public void onCommand4(final PlayerCommandPreprocessEvent e) {
            final Player player = e.getPlayer();
            if (e.getMessage().split(" ")[1].contains(".") && !player.hasPermission("hahaminesyntax.allow")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', main.config.getString("Message.HaHaMineSyntax")));
                player.playSound(player.getLocation(), Sounds.VILLAGER_NO.bukkitSound(), 2.0f, 1.0f);
            }
        }
       
        @EventHandler
        public void onCommand5(final PlayerCommandPreprocessEvent e) {
            final Player player = e.getPlayer();
            if (e.getMessage().split(" ")[1].contains("*") && !player.hasPermission("hahaminesyntax.allow")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', main.config.getString("Message.HaHaMineSyntax")));
                player.playSound(player.getLocation(), Sounds.ZOMBIE_PIG_DEATH.bukkitSound(), 2.0f, 1.0f);
            }
        }
        @EventHandler
        public void onCommand6(final PlayerCommandPreprocessEvent e) {
            final Player player = e.getPlayer();
            if (e.getMessage().split(" ")[0].contains("u") && !player.hasPermission("hahaminesyntax.allow")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', main.config.getString("Message.HaHaMineSyntax")));
                player.playSound(player.getLocation(), Sounds.ZOMBIE_DEATH.bukkitSound(), 2.0f, 1.0f);
            }
        }
        @EventHandler
        public void onCommand7(final PlayerCommandPreprocessEvent e) {
            final Player player = e.getPlayer();
            if (e.getMessage().split(" ")[1].contains("u") && !player.hasPermission("hahaminesyntax.allow")) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', main.config.getString("Message.HaHaMineSyntax")));
                player.playSound(player.getLocation(), Sounds.ZOMBIE_DEATH.bukkitSound(), 2.0f, 1.0f);
            }
        }
    }
    if necessary, I can throw off other dependencies

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 12, 2021
  2. Offline

    timtower Administrator Moderator

    @Khamitov Where is the error?
    And why do you have all those functions that are almost the same? Why not an if statement?
     
  3. Offline

    Khamitov

    I don't know where the error is. the plugin writes null to the console. and eventually shuts down the server
     
  4. Offline

    timtower Administrator Moderator

  5. Offline

    Khamitov

  6. Offline

    timtower Administrator Moderator

    @Khamitov
    Code:
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    Might want to learn how to read stacktraces.
     
  7. Offline

    Khamitov

    I found a bug.
    the point is that it should work that like.
    /ban * (denied)
    /ban* (denied) but causes the error.
     
  8. Offline

    timtower Administrator Moderator

    @Khamitov But you are not checking the amount of arguments. You are just using everything.
     
  9. Offline

    Khamitov

    I did it using the if function.
    as you said)
     
  10. Offline

    timtower Administrator Moderator

    Did you fix it then or not?
     

Share This Page