Plugin not working ..... pls help :)

Discussion in 'Plugin Development' started by BioBG, Apr 21, 2014.

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

    BioBG

    Hi
    After i made some changes to my plugin and he stopped working ....
    I move the event in to new class and cannot get it to work ...
    and the command cant get it to work too ...

    I have no errors in Eclipse and in console, plugin runs with no errors.
    Command and the event do not work in the game.

    I would be very grateful if you help me :)
    Tnx BioBG
    Best regards! :)

    Main:
    Code:java
    1. package me.dragonscraft.info;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11. //import org.bukkit.plugin.PluginManager;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class info extends JavaPlugin implements Listener {
    15.  
    16. public info plugin;
    17. protected static Logger log;
    18.  
    19. public void log(String msg){
    20. this.getLogger().info(msg);
    21. }
    22.  
    23. public void onEnable() {
    24. //getServer().getPluginManager().registerEvents(this, this);
    25. //plugin = this;
    26. //cmd = new deathevent(this);
    27. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Death" + ChatColor.YELLOW + "Point " + ChatColor.WHITE + "is " + ChatColor.GREEN + "Enabled!");
    28. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Death" + ChatColor.YELLOW + "Point " + ChatColor.WHITE + "is " + ChatColor.GREEN + "Created " + ChatColor.WHITE + "by : " + ChatColor.RED + "BioBG");
    29. saveConfig();
    30.  
    31.  
    32. }
    33. public void onDisable() {
    34.  
    35. log.info("DeathPoint has been Disabled!");
    36. Bukkit.getConsoleSender().sendMessage(ChatColor.WHITE + "[" + ChatColor.RED + "Death" + ChatColor.YELLOW + "Point" + ChatColor.WHITE + "]" + ChatColor.WHITE + " has been " + ChatColor.GREEN + "Disabled!");
    37. saveConfig();
    38.  
    39. }
    40.  
    41. // send player location readed from the config
    42. public boolean onCommand(CommandSender sender, Command comand, String commandLabel, String[] args) {
    43. if (sender instanceof Player) {
    44. Player player = (Player) sender;
    45. if (commandLabel.equalsIgnoreCase("deathpoint")) {
    46. // My Code
    47. }}
    48. return false;
    49.  
    50. }}
    51.  
    52.  



    DeathEvent:
    Code:java
    1. package me.dragonscraft.info;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.craftbukkit.v1_7_R2.entity.CraftZombie;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.entity.PlayerDeathEvent;
    13. import org.bukkit.potion.PotionEffect;
    14. import org.bukkit.potion.PotionEffectType;
    15. import java.util.logging.Logger;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class deathevent extends JavaPlugin implements Listener {
    20. public info plugin;
    21. public deathevent(info instance) {
    22. plugin = instance;
    23. }
    24.  
    25. protected static Logger log;
    26.  
    27. public void log(String msg){
    28. this.getLogger().info(msg);
    29. }
    30.  
    31. @EventHandler
    32. public void onPlayerDeath(PlayerDeathEvent event) {
    33.  
    34. // My Code
    35.  
    36. }}


    I have another Class unfinished, work in progress:
    Code:java
    1. package me.dragonscraft.info;
    2.  
    3. import org.bukkit.event.Listener;
    4.  
    5. public class sqlEvents implements Listener {
    6.  
    7. }
    8.  
     
  2. Offline

    Onlineids

    Stacktrace?
     
  3. Offline

    NonameSL

    Onlineids A stacktrace is not need, I can spot a few problems:

    1. You are using log.info when you haven't intalized your Logger yet. just use log(String msg), that method you created is useful.
    2. You cant have 2 classes extending JavaPlugin. deathevent cannot extend JavaPlugin, just make it a listener class.
    3. You are never registering your events in deathevent class. Instead of deathevent(info instance) and info plugin; use:
    deathevent(Plugin plugin){
    this.plugin=plugin;
    Bukkit.getServer().getPluginManager().registerEvents(plugin, this);
    }
    4. Classes in java are usally called DeathEvent and Info instead of lower case names.
     
  4. Offline

    Onlineids

    Not needed, but would help should be common practice to post it along with code when having a problem.
     
  5. Offline

    BioBG

    Code:java
    1. package me.dragonscraft.info;
    2.  
    3. import java.io.File;
    4. import java.io.InputStream;
    5. import java.util.List;
    6. import java.util.Random;
    7. import java.util.logging.Logger;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.Location;
    12. import org.bukkit.Server;
    13. import org.bukkit.World;
    14. import org.bukkit.command.Command;
    15. import org.bukkit.command.CommandSender;
    16. import org.bukkit.configuration.file.FileConfiguration;
    17. import org.bukkit.craftbukkit.v1_7_R2.entity.CraftZombie;
    18. import org.bukkit.entity.Player;
    19. import org.bukkit.event.EventHandler;
    20. import org.bukkit.event.entity.PlayerDeathEvent;
    21. import org.bukkit.event.server.PluginEvent;
    22. import org.bukkit.plugin.Plugin;
    23. import org.bukkit.plugin.PluginDescriptionFile;
    24. import org.bukkit.plugin.PluginLoader;
    25. import org.bukkit.potion.PotionEffect;
    26. import org.bukkit.potion.PotionEffectType;
    27. import org.bukkit.event.Listener;
    28. import org.bukkit.generator.ChunkGenerator;
    29.  
    30.  
    31. public final class deathevent implements Listener {
    32.  
    33. deathevent(Plugin plugin){
    34. Bukkit.getServer().getPluginManager().registerEvents(plugin, this);
    35. }
    36.  
    37. public Logger logger = Logger.getLogger("Minecraft");
    38.  
    39. @EventHandler
    40. public void onPlayerDeath(PlayerDeathEvent event) {
    41.  
    42. Player player = (Player) event.getEntity();
    43. Location loc = event.getEntity().getLocation();
    44. if (player.getKiller() instanceof Player) {
    45. Random rand = new Random();
    46. event.getEntity().sendMessage(ChatColor.GOLD + "[DP] " + ChatColor.DARK_RED + "DeathPoint: X:" + loc.getBlockX() + ", Y:" + loc.getBlockY() + ", Z:" + loc.getBlockZ() + "." );
    47. event.getEntity().sendMessage(ChatColor.GOLD + "[DP] " + ChatColor.DARK_RED + "/DP to check your DeathLocation." );
    48. logger.info("Player " + event.getEntity().getPlayer().getName() + " DeathPoint: X:" + loc.getBlockX() + ", Y:" + loc.getBlockY() + ", Z:" + loc.getBlockZ() + " In World: " + event.getEntity().getWorld().getName());
    49.  
    50. World world = event.getEntity().getPlayer().getWorld();
    51. world.strikeLightningEffect(loc);
    52.  
    53.  
    54. // set player location to the config //
    55. getConfig().set(player.getName() + ".x", player.getLocation().getBlockX());
    56. getConfig().set(player.getName() + ".y", player.getLocation().getBlockY());
    57. getConfig().set(player.getName() + ".z", player.getLocation().getBlockZ());
    58. saveConfig();
    59. // //
    60.  
    61.  
    62. if (rand.nextInt(100) < 50) {
    63. CraftZombie zombie = (CraftZombie)world.spawn(loc, CraftZombie.class);
    64. zombie.setBaby(true);
    65. zombie.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20*5 , 5));
    66. zombie.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20*5 , 5));
    67. zombie.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20*5 , 5));
    68.  
    69. player.getKiller().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20*2, 2));
    70.  
    71. Bukkit.broadcastMessage(ChatColor.GOLD + "[DP] " + ChatColor.DARK_RED + "Играча " + event.getEntity().getPlayer().getName() + " беше убит от " + player.getKiller().getPlayer().getName() + " и се превърна в " + zombie.getType() + " "/* + player.getKiller().getPlayer().getItemInHand().getType()*/ );
    72. logger.info(ChatColor.GOLD + "[DP] " + ChatColor.DARK_RED + "Играча " + event.getEntity().getPlayer().getName() + " беше убит от " + player.getKiller().getPlayer().getName() + " и се превърна в " + zombie.getType() );
    73.  
    74. } else {
    75.  
    76. CraftZombie zombie = (CraftZombie)world.spawn(loc, CraftZombie.class);
    77. zombie.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20*5, 2));
    78. zombie.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20*5, 2));
    79. zombie.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20*5, 2));
    80.  
    81. player.getKiller().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20*2, 2));
    82.  
    83. Bukkit.broadcastMessage(ChatColor.GOLD + "[DP] " + ChatColor.DARK_RED + "Играча " + event.getEntity().getPlayer().getName() + " беше убит от " + player.getKiller().getPlayer().getName() + " и се превърна в " + zombie.getType() + " "/* + player.getKiller().getPlayer().getItemInHand().getType()*/ );
    84. logger.info(ChatColor.GOLD + "[DP] " + ChatColor.DARK_RED + "Играча " + event.getEntity().getPlayer().getName() + " беше убит от " + player.getKiller().getPlayer().getName() + " и се превърна в " + zombie.getType() );
    85. }
    86. }
    87. }
    88.  
    89. }
    90.  


    http://puu.sh/8izP9.png

    how can i fix this ?
     
  6. Offline

    LarsNitro

    plugin.getConfig() instead of getConfig().
     
  7. Offline

    BioBG

    yes i try i but still don't work ...
    "plugin cannot be resolved"

    http://puu.sh/8iAkI.png

    and what "saveConfig();" want ....

    The method saveConfig() is undefined for the type deathevent

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page