removePotionEffect HELP!

Discussion in 'Plugin Development' started by Schaakmatth, Apr 22, 2014.

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

    Schaakmatth

    hello i have maked a plugin that gives you speed but now i want to left click and remove the effect but it doesnt work please help me!
    this is my code:
    Code:java
    1. package me.Matthijs.speedbone;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Material;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.Action;
    15. import org.bukkit.event.player.PlayerInteractEvent;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.inventory.meta.ItemMeta;
    18. import org.bukkit.plugin.PluginDescriptionFile;
    19. import org.bukkit.plugin.PluginManager;
    20. import org.bukkit.plugin.java.JavaPlugin;
    21. import org.bukkit.potion.PotionEffect;
    22. import org.bukkit.potion.PotionEffectType;
    23.  
    24. public class SpeedBone extends JavaPlugin implements Listener{
    25. public final Logger logger = Logger.getLogger("Minecraft");
    26. public static SpeedBone plugin;
    27.  
    28.  
    29. @Override
    30. public void onEnable() {
    31. PluginDescriptionFile pdfFile = this.getDescription();
    32. this.logger.info(pdfFile.getName() + " V " + pdfFile.getVersion() + " [SpeedWand] Aan!");
    33. PluginManager pm = this.getServer().getPluginManager();
    34. getServer().getPluginManager().registerEvents(this, this);
    35. pm.addPermission(new Permissions().speedbone);
    36.  
    37.  
    38. }
    39.  
    40. @Override
    41. public void onDisable() {
    42. PluginDescriptionFile pdfFile = this.getDescription();
    43. this.logger.info(pdfFile.getName() + " [SpeedBone] Uit!");
    44. getServer().getPluginManager().removePermission(new Permissions().speedbone);
    45. }
    46.  
    47.  
    48. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    49.  
    50. if(commandLabel.equalsIgnoreCase("speedbone")){
    51. if(sender.hasPermission(new Permissions().speedbone)) {
    52. sender.sendMessage(ChatColor.RED + "Gebruikt!");
    53. } else{
    54. sender.sendMessage(ChatColor.RED + "Sorry maar dit kun jij niet doen!");
    55. }
    56. ItemStack speedbone = new ItemStack(Material.BONE, 1);
    57.  
    58. ItemMeta im = speedbone.getItemMeta();
    59.  
    60. im.setDisplayName(ChatColor.BLUE + "SpeedBone");
    61.  
    62. List<String> lorelist = new ArrayList<String>();
    63. lorelist.add(ChatColor.DARK_RED + "Rechts klikken om speed te krijgen!");
    64. lorelist.add(ChatColor.DARK_RED + "Links klikken om speed te verwijderen");
    65. im.setLore(lorelist);
    66.  
    67. speedbone.setItemMeta(im);
    68.  
    69. Player player = (Player) sender;
    70.  
    71. player.getInventory().addItem(speedbone);
    72. } else{
    73. if(commandLabel.equalsIgnoreCase("author")){
    74. Player player = (Player) sender;
    75. player.sendMessage(ChatColor.BLUE + "[url="http://www.youtube.com/onlydutchgamingnl"]www.youtube.com/onlydutchgamingnl[/url]");
    76. }
    77. return true;
    78. }
    79. return false;
    80. }
    81.  
    82. @EventHandler
    83. public void onPlayerInteract(PlayerInteractEvent e){
    84. Player player = e.getPlayer();
    85.  
    86. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    87. if (player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("speedbone")) {
    88. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 4));
    89. player.sendMessage(ChatColor.GOLD + "Je hebt nu Speed!");
    90.  
    91. }
    92. if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
    93. if (player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("speedbone")) {
    94. player.removePotionEffect(PotionEffectType.SPEED);
    95. player.sendMessage(ChatColor.GOLD + "Je bent nu je speed kwijt!");
    96. }
    97. }
    98.  
    99.  
    100.  
    101.  
    102.  
    103. }
    104. }
    105. }
    106.  
     
  2. Offline

    stink123456

    You made the if leftClick statement inside of the right click statement, this way it will never excecute
    move a closing bracket from under the leftclick statement above it.
     
  3. Offline

    Schaakmatth

    ? post the code please?
     
  4. Offline

    Gater12

    Schaakmatth
    Follow the logic of your code. You placed the left click check in your right click check. Thus it will never run because it needs to pass the right click check first.
    Put the check outside the block of the right click check.
     
  5. Offline

    Schaakmatth

    im dutch and i can not speak really good ENGLISH SO PLEASE WRITE THE CODE!
     
  6. Offline

    SuppaTim

    I'm going to translate it now:
    Kijk naar de logica van je code, je hebt je 'linker-klik' check in je 'rechter-klik' check gedaan. Op deze manier word de tweede check, dus die van de linker-klik, nooit uitgevoerd. Verplaats een } zodat je twee aparte 'blokken' hebt.
     
    coolguy4744 likes this.
  7. Offline

    Schaakmatth

    ok dankje maar ze doen het allebei niet als ik op me server kom en ik rechtsklik of linksklik er gebeurt niks? SuppaTim
    hier is mijn nieuwe code
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e){
    3. Player player = e.getPlayer();
    4.  
    5. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. if (player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("speedbone")) {
    7. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 3));
    8. player.sendMessage(ChatColor.GOLD + "Je hebt nu Speed!");
    9.  
    10.  
    11.  
    12. if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
    13. if (player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("speedbone")) {
    14. player.removePotionEffect(PotionEffectType.SPEED);
    15. player.sendMessage(ChatColor.GOLD + "Je hebt nu geen speed meer!");
    16.  
     
  8. Offline

    tryy3

    You never closed the if statements, so the left click is still inside right click!

    Code:java
    1. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    2. if (player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("speedbone")) {
    3. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 3));
    4. player.sendMessage(ChatColor.GOLD + "Je hebt nu Speed!");
    5. }
    6. }
    7.  
    8.  
    9.  
    10. if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
    11. if (player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("speedbone")) {
    12. player.removePotionEffect(PotionEffectType.SPEED);
    13. player.sendMessage(ChatColor.GOLD + "Je hebt nu geen speed meer!");
    14. }
    15. }
     
Thread Status:
Not open for further replies.

Share This Page