I need help with my plugin, i dont know what's the problem

Discussion in 'Plugin Development' started by TheUncouver, Mar 1, 2015.

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

    TheUncouver

    here it is my plugin, which doesnt work, but i dont know the reason

    Code:java
    1.  
    2. package me.TheUncouver;
    3.  
    4. import static javax.sql.rowset.spi.SyncFactory.getLogger;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.GameMode;
    7. import static org.bukkit.GameMode.SURVIVAL;
    8. import org.bukkit.Material;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.inventory.PlayerInventory;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.potion.PotionEffect;
    15. import org.bukkit.potion.PotionEffectType;
    16.  
    17. /**
    18. * Moderator's plugin
    19. * @author TheUncouver
    20. */
    21. public class Main extends JavaPlugin{
    22. public void onEnable(){
    23. getLogger().info("Plugin activated succesfuly");
    24. }
    25. public void onDisable(){
    26. getLogger().info("Plugin desactivated succesfuly");
    27. }
    28.  
    29. /**
    30.   *
    31.   * @param sender
    32.   * @param cmd
    33.   * @param Label
    34.   * @param args
    35.   * @return
    36.   */
    37. @SuppressWarnings("empty-statement")
    38. public boolean onCommand(Commandsender sender, Command cmd, String Label, String[] args){
    39. if(cmd.getName().equalsIgnoreCase("moderator")){
    40. if(sender instanceof Player){
    41. Player p = (Player) sender;
    42. p.setAllowFlight(true);
    43. p.setFlying(true);
    44. GameMode gameMode;
    45. gameMode = SURVIVAL;
    46. p.hidePlayer(p);
    47. p.getPlayer().sendMessage(ChatColor.RED + "You are now in Mod mode");
    48. p.setCanPickupItems(false);
    49. p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4000, 40000));
    50. p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 4000,40000));
    51. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 4000,40000));
    52. p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 4000,40000));
    53. p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4000,40000));
    54. p.getInventory().clear();
    55. PlayerInventory inventory;
    56. inventory = (PlayerInventory) p.getInventory().addItem(ItemStack(Material.COMPASS, 1));
    57.  
    58.  
    59. }
    60. }else{
    61. sender.sendMessage("This command is only for players");
    62. }
    63. if(cmd.getName().equalsIgnoreCase("h")){
    64. if(sender instanceof Player){
    65. Player p = (Player) sender;
    66. p.showPlayer(p);
    67. p.setAllowFlight(false);
    68. p.setFlying(false);
    69. p.setCanPickupItems(true);
    70. p.removePotionEffect(PotionEffectType.REGENERATION);
    71. p.removePotionEffect(PotionEffectType.SATURATION);
    72. p.removePotionEffect(PotionEffectType.NIGHT_VISION);
    73. p.removePotionEffect(PotionEffectType.FIRE_RESISTANCE);
    74. p.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
    75. p.getInventory().clear();
    76. p.getPlayer().sendMessage(ChatColor.RED + "You are no longer in Mod mode");
    77. }
    78. }else{
    79. sender.sendMessage("This command is only for players");
    80. }
    81. return false;
    82. }
    83.  
    84. private ItemStack[] ItemStack(Material material, int i) {
    85. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    86. }
    87.  
    88. private static class Commandsender {
    89.  
    90. public Commandsender() {
    91. }
    92.  
    93. private void sendMessage(String this_command_is_only_for_players) {
    94. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    95. }
    96. }
    97. }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @TheUncouver Please start with saying what isn't working.
     
  3. Offline

    1Rogue

    You can't implement your own CommandSender object and then expect bukkit to use that instead. You need to use Bukkit's implementation.

    Additionally, stop statically importing getLogger() from a random source, you already have that method in your class for your own plugin logger.
     
  4. Offline

    PreFiXAUT

    @TheUncouver Additionaly -> Check Java Naming Conventions. Your packagename is terrible and why doesn't have it a own package (the plugin)?

    Why? srsly...why????
     
  5. Offline

    TheUncouver

    I've never coded anything on java, and i'm such a noob, it doesnt work, but the plugin activates correctly, and where shall i implement that?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @TheUncouver Try to get some java basics first, makes it way easier to continue with Bukkit.
    And you still haven't told you issue
     
  7. Offline

    TheUncouver

    then tell me exactly what shall i do pls

    well, on netbeans, it doesnt give me any error, and if i start the server, the plugin activates correctly, but none of the commands work

    EDIT by Timtower: merged posts
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Offline

    TheUncouver

    yes

    if(cmd.getName().equalsIgnoreCase("moderator")){
    if(cmd.getName().equalsIgnoreCase("h")){
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    TheUncouver

    how do i register it?
     
  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    timtower Administrator Administrator Moderator

    @MaTaMoR_ I was aiming at the commands part
     
Thread Status:
Not open for further replies.

Share This Page