Anti-Milk

Discussion in 'Archived: Plugin Requests' started by Byamarro, Dec 9, 2012.

  1. Offline

    Byamarro

    I search for plugin what can turn off milk drinking.
     
  2. Offline

    gomeow

    Someone just needs to compile it.
    Code:java
    1. @EventHandler
    2. public void onDrink(PlayerInteractEvent event) {
    3. if(event.getAction() == Action.RIGHT_CLICK
    4. || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. if(event.getPlayer().getInventory().getItemInHand.getType() == Material.MILK_BUCKET) {
    6. event.setCancelled(true);
    7. }
    8. }
    9. }
     
  3. Offline

    Zigenzag

    Yeah ill compile and test it for you

    After a test the code didn't work. Ill have a little play and see if i can get it to
    i used this code;

    package uk.co.blogspot.zigenzag;

    import java.util.logging.Logger;

    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin{
    public final Logger log = Logger.getLogger("Minecraft");
    public String prefix = "[Anti-Milk] ";
    public final Drink drink = new Drink();

    @Override
    public void onEnable(){
    this.log.info(prefix + "Has been enabled!");
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents(this.drink, this);
    this.log.info(prefix + "Milk can't be drunk anymore!");
    }

    @Override
    public void onDisable(){
    this.log.info(prefix + "Has been disabled!");
    this.log.info(prefix + "Milk can be drunk once more!");
    }
    }
    and for Drink i used;

    package uk.co.blogspot.zigenzag;

    import java.util.logging.Logger;

    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;

    public class Drink implements Listener {
    public final Logger log = Logger.getLogger("Minecraft");

    @EventHandler
    public void onDrink(PlayerInteractEvent event) {
    if(event.getAction() == Action.RIGHT_CLICK_AIR
    || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if(event.getPlayer().getInventory().getItemInHand().getType() == Material.MILK_BUCKET) {
    event.setCancelled(true);
    log.info("Milk drinking stopped!");
    }
    }
    }

    }
    I deoped my self was in survival and nothing

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

    gomeow

    Zigenzag Use the [syntax=java]code here[/syntax] tags.

    Also, sorry, but you did things really weirdly.
    You can make it a lot better and in only 1 class.
    Code:java
    1. package me.gomeow.noMilk;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.block.Action;
    7. import org.bukkit.event.player.PlayerInteractEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class noMilk extends JavaPlugin implements Listener {
    11.  
    12. public void onEnable() {
    13. this.getServer().getPluginManager().registerEvents(this, this);
    14. }
    15.  
    16. @EventHandler
    17. public void onDrinkMilk(PlayerInteractEvent event) {
    18. Action a = event.getAction();
    19. if(a == Action.RIGHT_CLICK_AIR
    20. || a == Action.RIGHT_CLICK_BLOCK) {
    21. if(event.getPlayer().getInventory().getItemInHand().getType()
    22. == Material.MILK_BUCKET) {
    23. if(event.getPlayer().isOp()) return;
    24. event.setCancelled(true);
    25. }
    26. }
    27. }
    28. }

    Here is the download:
    https://www.dropbox.com/s/kxpj0c3j1gfq9b4/noMilk.jar

    And lastly, please give me credit where it is due, obviously I supplied the code.
     
  5. Offline

    zachoooo

    You can't just cancel the interact event, you have to use event.setUseItemInHand(false);
     
  6. Offline

    gomeow

    Why not? It has worked for me in the past?
     
  7. Offline

    CeramicTitan

    because there is not much code you should put it into one class.

    I don't think i matters, this will make it so players can't interact with the milk bucket, and p.setUseItemInHand(false); 1. I'm not even sure if that exists and 2. I think it is pretty much the same thing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  8. Offline

    zachoooo

  9. Offline

    gomeow

    CeramicTitan likes this.
  10. Offline

    Cybermaxke

  11. Offline

    gomeow

  12. Offline

    Cybermaxke

    I didn't use any events. ;)
     
    drtshock likes this.
  13. Offline

    Byamarro

    Both plugins don't help.
    Player after drink milk is cured from every negative effects.


    EDIT 1
    Both plugins makes errors.


    [SEVERE] Error occurred while enabling NoMilkDrink v1.0 (Is it up to date?)
    java.lang.NoClassDefFoundError: net/minecraft/server/v1_4_5/Item
    at me.cybermaxke.nomilkdrink.NoMilkDrink.onEnable(NoMilkDrink.java:13)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:374)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:270)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:252)
    at net.minecraft.server.MinecraftServer.j(MinecraftServer.java:320)
    at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:299)
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:258)
    at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:147)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:398)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    Caused by: java.lang.ClassNotFoundException: net.minecraft.server.v1_4_5.Item
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:34)
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 12 more
     
  14. Offline

    gomeow

    Byamarro sorry, I accidentally exported incorrectly. I will get an updated version to you today
     
  15. Offline

    Cybermaxke

    Only working for 1.4.5. The class paths were changed in that update. ;)
     
  16. Offline

    Byamarro

  17. Offline

    ray73864

    I would just install Skript and then create a skript itself that says when a player tries to drink milk, cancel the event.

    Take you all of about 1min to install Skript, and a further 5mins to create the necessary skript to do this.
     
  18. Offline

    Cybermaxke

  19. Offline

    Byamarro

    Anyone will make it for R0.2?
     
  20. Offline

    Cybermaxke

    Last edited by a moderator: May 30, 2016
  21. Offline

    jacklin213

    y did it take this long to simply put the event in a class and compile =.=
     
  22. Offline

    gomeow

    I DO have a link that IS for 0.2...

    Why did 2 people need to make this?
     
  23. Offline

    Byamarro

    Now it works. Thanks Cyber.


    gomeow
    Your plugin didn't work for meh :(
     
  24. Offline

    Cybermaxke

    No problem. :)
     
  25. Offline

    Byamarro

    UpDate for 1.4.6?
     

Share This Page