WitherHearts

Discussion in 'Plugin Development' started by MrGermanrain, Jul 18, 2013.

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

    MrGermanrain

    I was starting to make a plugin that turns your heart into WitherHearts, but I got stuck.
    I need it so that it disables the damage of the Wither effect.

    Here is my code:
    Code:java
    1. package me.mrgermanrain.wither;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.potion.PotionEffect;
    12. import org.bukkit.potion.PotionEffectType;
    13.  
    14. public class wither extends JavaPlugin{
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static wither plugin;
    17.  
    18. @Override
    19. public void onDisable() {
    20. PluginDescriptionFile pdfFile = this.getDescription();
    21. this.logger.info(pdfFile.getName() + " has been Disabled!");
    22. }
    23.  
    24. @Override
    25. public void onEnable() {
    26. PluginDescriptionFile pdfFile = this.getDescription();
    27. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been Enabled!");
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){
    31. if(commandLabel.equalsIgnoreCase("wh")){
    32. Player player = (Player) sender;
    33. if(sender.hasPermission("wither.change")){
    34. player.addPotionEffect(new PotionEffect(PotionEffectType.WITHER,18000, 0));
    35. player.sendMessage(ChatColor.DARK_RED + "You are withered!");
    36. return true;
    37. }
    38. }
    39. return false;
    40.  
    41. }
    42. }
    43.  



    I have it so that /wh gets you the wither effect, but I didn't know how to remove the damage, I am still new with Java. If someone could finish this I would be very happy :)
     
  2. Offline

    x128

    MrGermanrain
    Post in the plugin development section, this is for requests only.
     
  3. Offline

    MrGermanrain

    Yes, I have half gave up. I was requesting for someone to do this.

    It is not nice to go to the development section and just ask people for code. That's why i'm asking someone else to finish it with full credit towards them.

    Maybe you want to finish it? It could be your first Bukkit Dev plugin.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    x128

    MrGermanrain I already have a BukkitDev plugin :p. I am working on other projects at the moment, but I might come back if you still need help with this one when I finish.
     
  5. Offline

    MrGermanrain

    kai
     
  6. Offline

    chasechocolate

    MrGermanrain cancel EntityDamageEvent if event.getEntity() instanceof Player and event.getCause() == DamageCause.WITHER.
     
  7. Offline

    MrGermanrain

    I have tried this, but I am not exactly sure how to :/
     
  8. Offline

    MiniDigger

    MrGermanrain here you go:
    Code:java
    1. @EventHandler
    2. public void onEntityDamage(EntityDamageEvent event){
    3. if(event.getEntity() instanceof Player && event.getCause() == DamageCause.WITHER){
    4. event.setCanceled(true);
    5. }
    6. }
    7.  
     
  9. Offline

    TnT

    Moved to the correct section.

    MrGermanrain While you're correct that you shouldn't just ask for code, you can always take your best shot at coding up what you want to do, and ask if someone can show you where you've gone wrong. :)
     
  10. Offline

    MrGermanrain

    Thanks :) my big mistake with Java is that I need to figure out how to put 2 commands in 1 plugin, as simple as it sounds, I have only been studying Java for a week :/
     
  11. Offline

    Wingzzz

    You simply go to your onCommand(), and do multiple checks:
    Code:java
    1. if(command.getName().equalsIgnoreCase("command1") {
    2. // do something
    3. } else if(command.getName().equalsIgnoreCase("command2") {
    4. // do something
    5. } else if(command.getName().equalsIgnoreCase("command3") {
    6. // do something
    7. }

    This way you can have different commands. Ensure in your plugin.yml you put your commands in there, as well as when you set the command executor, do it for each command:
    Code:java
    1. getCommand("command1").setExecutor(new MyPluginCommandExecutor(this));
    2. getCommand("command2").setExecutor(new MyPluginCommandExecutor(this));
    3. getCommand("command3").setExecutor(new MyPluginCommandExecutor(this));

    Repeat these steps for desired results.

    NOTE: You can put commands in seperate classes using the same way you do now, just ensure when you set the executor in your main, use the proper classes that correspond to each command:
    Code:java
    1. getCommand("setspawn").setExecutor(new SpawnCommand(this));
    2. getCommand("spawn").setExecutor(new SpawnCommand(this));
    3. getCommand("sethome").setExecutor(new HomeCommand(this));
    4. getCommand("home").setExecutor(new HomeCommand(this));
    5. getCommand("tp").setExecutor(new TeleportCommand(this));
    6. getCommand("tphere").setExecutor(new TeleportCommand(this));


    Just examples ;) Good luck!
     
    MrGermanrain likes this.
  12. Offline

    MrGermanrain

    Thanks :D ill try it right now :)
     
Thread Status:
Not open for further replies.

Share This Page