Spawner Egg Help?

Discussion in 'Plugin Development' started by slater96, Feb 25, 2012.

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

    slater96

    Hi, I need help making a loop i think or if not a way to make it shorter and easier to manage in my class. The code is:
    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
           
            if(player.getItemInHand().getTypeId() == 383){
                if((int) player.getItemInHand().getData().getData() == 96){
                    if(!player.hasPermission("mobeggs.mooshroom")){
                       
                        event.setCancelled(true);
                            player.sendMessage(ChatColor.YELLOW + "You are not allowed to use" + ChatColor.AQUA + " Mob Eggs!");
                   
                    } else {
                        return;
    This is just for one mob, so when I add all the others it gets quite lengthy so if there's any way to shorten it and still keep each mob with a separate permission then it would help alot. Thanks in advance.

    Bump, any help please.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  2. I'd make that check you have there a method:

    Code:java
    1.  
    2. ...
    3. public boolean canUseEgg(PermEgg egg) {
    4. int eggID = egg.getID()
    5. if((int) player.getItemInHand().getData().getData() == eggID){
    6. if(!player.hasPermission(egg.getPerm())){
    7. return True;
    8. ...
    9. ...
    10. ...
    11. ...
    12.  


    There's obviously a bit more to fill in, such as an ENUM named PermEgg, but you effectively want a static association of integers with Strings (id to perm) and one way of accomplishing such a task is va enums.

    This check should also go inside your 383 check. In addition, get those Magic Numbers outta there! Use a private static final EGG_ITEM_ID or better yet, the bukkit ENUM.

    Just my opinion.
     
    slater96 likes this.
  3. Offline

    slater96

    Thanks for the help. I'm new to java, but would the enum be this.
    Code:
          public static enum PermEgg{
            //
          }
    How do I add the ID and Permission based on the code posted above at //?

    bump any more help would be much appreciated?

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

    slater96

    Hello, I've managed to do the ENUM's how I think they go. I would like adult permissions for each mob type so
    mobeggs.mob.* = adult = ALLOW all monster mobs
    mobeggs.creeper = children
    mobeggs.skeleton - children and so on..

    mobeggs.animal.* = ALLOW all animal mobs
    mobeggs.pig
    and you get the idea..

    Would I be able to do this now I have the ENUM's for it. Thanks, will add the ENUM's below.
    Code:
        public enum EntityCategory{
            ANIMAL,
            MOB,
            NPC,
            UNKNOWN
            }
                 
            public enum EntityType {
            mooshrooom("mooshroom", 96, EntityCategory.ANIMAL),
            skeleton("skeleton", 51, EntityCategory.MOB),
            creeper("creeper", 50, EntityCategory.MOB),
            slime("slime", 55, EntityCategory.MOB),
            zombie("zombie", 54, EntityCategory.MOB),
            spider("spider", 52, EntityCategory.MOB),
            chicken("chicken", 93, EntityCategory.ANIMAL),
            cavespider("cavespider", 59, EntityCategory.MOB),
            cow("cow", 92, EntityCategory.ANIMAL),
            endermen("endermen", 58, EntityCategory.MOB),
            wolf("wolf", 95, EntityCategory.MOB),
            pigzombie("pigzombie", 57, EntityCategory.MOB),
            squid("squid", 94, EntityCategory.ANIMAL),
            ghast("ghast", 56, EntityCategory.MOB),
            magmacube("magmacube", 62, EntityCategory.MOB),
            sheep("sheep", 91, EntityCategory.ANIMAL),
            blaze("blaze", 61, EntityCategory.MOB),
            villager("villager", 120, EntityCategory.NPC),
            silverfish("silverfish", 60, EntityCategory.MOB),
            pig("pig", 90, EntityCategory.ANIMAL);
            EntityType (String perm, int dataId, EntityCategory entityCategory){ 
            }
        }
    bump can anyone help please?

    bump

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

    Milkywayz

    Hey.. just saying.. My plugin does this exact same thing. NOT saying to stop deving this, but as far as spawn eggs go I'm teh master :D, if you want i could help you, but the way you code is different from mine, i used a lot of if's and item durability. My plugin is here. Edit, instead of using individual permissions for each mob, i used a config, its a lot neater, but permissions allows for slightly more control.
     
  6. Offline

    slater96

    Its only my first plugin so i'm trying to learn new stuff but keep the plugin simple and easy to use, but thanks anyway.
     
  7. Offline

    Milkywayz

    Are you planning on releasing it? If not then ill send you my source code. I shouldn't be selfish with my code, its not like you can directly copy it, you would just use the format I'm assuming, Reply if your interested.
     
  8. Offline

    slater96

    Yes I already have released my plugin, it can be found here.
    http://dev.bukkit.org/server-mods/mobeggs/
    Like i said, its only my first plugin and I'm just trying to learn new stuff. I'm not trying to be in competition with other plugins alike, but just want to try improve myself really.

    bump can anyone help me please.

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

    GooseMonkey97

    That looks a LOT like code from my plugin.... (GitHub, line 307 and ahead)
     
Thread Status:
Not open for further replies.

Share This Page