Putting mobs into an enum

Discussion in 'Plugin Development' started by javoris767, Jun 22, 2012.

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

    javoris767

    Hello, I'm trying to put mobs in an enum for a config.

    Code:java
    1.  
    2. public enum Mobs {
    3. Blaze(true),
    4. CaveSpider(true),
    5. Chicken(true),
    6. Creeper(true),
    7. Pig(true);
    8. }
    9.  

    This give errors.

    "The constructor MDN.Mobs(boolean) is undefined"
     
  2. Offline

    CorrieKay

    it means theres no constructor that accepts a boolean.

    create one :p

    Also, im not 100% on what youre doing, but using an enum proooooobably isnt the way to go :p
     
  3. Offline

    javoris767

    Code:java
    1. public enum MDN Mobs {
    2. Blaze(true),
    3. CaveSpider(true),
    4. Chicken(true),
    5. Creeper(true),
    6. Pig(true);
    7. }
    8. }

    MDN = the class name
    that and Mobs has and error.
    Basically I'm trying to shorten this
    Code:java
    1. public void LoadConfiguration() {
    2. String blaze = "Broadcast.chicken";
    3. String cavespider = "Broadcast.chicken";
    4. String chicken = "Broadcast.chicken";
    5. String cow = "Broadcast.chicken";
    6. String creeper = "Broadcast.chicken";
    7. String enderman = "Broadcast.chicken";
    8. String mooshroom = "Broadcast.chicken";
    9. String pig = "Broadcast.chicken";
    10. String sheep = "Broadcast.chicken";
    11. String squid = "Broadcast.chicken";
    12. String villager = "Broadcast.chicken";
    13. String wolf = "Broadcast.chicken";
    14. String pigman = "Broadcast.chicken";
    15. String snowgolem = "Broadcast.chicken";
    16. String ghast = "Broadcast.chicken";
    17. String magmacube = "Broadcast.chicken";
    18. String silverfish = "Broadcast.chicken";
    19. String skeleton = "Broadcast.chicken";
    20. String slime = "Broadcast.chicken";
    21. String spider = "Broadcast.chicken";
    22. String zombie = "Broadcast.chicken";
    23. getConfig().addDefault(blaze, Boolean.valueOf(true));
    24. getConfig().addDefault(cavespider, Boolean.valueOf(true));
    25. getConfig().addDefault(chicken, Boolean.valueOf(true));
    26. getConfig().addDefault(cow, Boolean.valueOf(true));
    27. getConfig().addDefault(creeper, Boolean.valueOf(true));
    28. getConfig().addDefault(enderman, Boolean.valueOf(true));
    29. getConfig().addDefault(pig, Boolean.valueOf(true));
    30. getConfig().options().copyDefaults(true);
    31. saveConfig();
     
  4. Offline

    CorrieKay

    if youre looking to add defaults like that, create the yml file, put it in your project next to your plugin.yml, load it as a default, and copydefaults from that entire file.
     
  5. Offline

    javoris767

    I see o.o. One more question. I see some plugins with %p% for player in configs. How do I do that :D

    Also
    Code:
        public void onEntityDeath(EntityDeathEvent event) {
            Entity p = event.getEntity().getKiller();
            Entity e = event.getEntity();
            String BlazeKilled = plugin.getConfig().getString("MobDeathNotifier.BroadcastMessage.Blaze");
            if(e instanceof Blaze) {
                Blaze blaze = (Blaze)e;
                Bukkit.broadcastMessage(BlazeKilled);
    
    Would this be correct?

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

    CorrieKay

    They'd replace the %p% with the playername in code.
    Use the Player Death Event instead, so you don't get notifications whenever everything dies
     
  7. Offline

    javoris767

    This is for if the Blaze dies
     
  8. Offline

    CorrieKay

    well then! that would be correct, i think :p
     
  9. Offline

    javoris767

    Thanks! Where could I use the p and blaze. The warnings are annoying.
     
  10. You can do Entity.getEntityType().getName to get the name of an entity, mayby this is an alternate solution? and you can use String.replaceAll(Patters.quete("%e%"),"to replace whit") to replace a string if its inside another string
     
  11. Offline

    javoris767

    Is that spelled correctly :confused:
     
  12. Offline

    ItsHarry

    String.replace("%p%", player.getName());
     
  13. Offline

    javoris767

    event.getEntity().getKiller();

    isn't able to become a string and

    String cavespider =event.getEntityType().CAVE_SPIDER.getName();
    gets

    "Cannot make a static reference to the non-static method replace(CharSequence, CharSequence) from the type String"
     
  14. event.getEntityType().getName();
     
  15. Offline

    ItsHarry

    ...
    String was just a type, you don't actually type String, you type your own variable such as String s..... >.<
     
  16. Offline

    petteyg359

    Why the heck are you doing Boolean.valueOf(boolean)?
     
  17. Offline

    javoris767

    Little mistake, I changed it.

    I'm getting this error on start up :confused:

    Code:
    182 recipes
    27 achievements
    09:48:49 [INFO] Starting minecraft server version 1.2.5
    09:48:49 [INFO] Loading properties
    09:48:49 [INFO] Starting Minecraft server on *:25565
    09:48:53 [WARNING] **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!
    09:48:53 [WARNING] The server will make no attempt to authenticate usernames. Be
    ware.
    09:48:53 [WARNING] While this makes the game possible to play without internet a
    ccess, it also opens up the ability for hackers to connect with any username the
    y choose.
    09:48:53 [WARNING] To change this, set "online-mode" to "true" in the server.pro
    perties file.
    09:48:54 [INFO] This server is running CraftBukkit version git-Bukkit-1.2.5-R3.0
    -b2203jnks (MC: 1.2.5) (Implementing API version 1.2.5-R3.0)
    09:48:54 [INFO] [MobDeathNotifier] Loading MobDeathNotifier v0.1
    09:48:55 [INFO] Preparing level "world"
    09:48:55 [INFO] Default game type: 0
    09:48:57 [INFO] Preparing start region for level 0 (Seed: 3140422006464814611)
    09:48:58 [INFO] Preparing spawn area: 0%
    09:49:02 [WARNING] ----- Bukkit Auto Updater -----
    09:49:02 [WARNING] Your version of CraftBukkit is out of date. Version 1.2.5-R4.
    0 (build #2222) was released on Sun Jun 10 01:08:56 PDT 2012.
    09:49:02 [WARNING] Details: http://dl.bukkit.org/downloads/craftbukkit/view/0114
    9_1.2.5-R4.0/
    09:49:02 [WARNING] Download: http://dl.bukkit.org/downloads/craftbukkit/get/0114
    9_1.2.5-R4.0/craftbukkit.jar
    09:49:02 [WARNING] ----- ------------------- -----
    09:49:03 [INFO] Preparing spawn area: 0%
    09:49:04 [INFO] Preparing spawn area: 24%
    09:49:05 [INFO] Preparing spawn area: 28%
    09:49:06 [INFO] Preparing spawn area: 36%
    09:49:07 [INFO] Preparing spawn area: 48%
    09:49:08 [INFO] Preparing spawn area: 52%
    09:49:09 [INFO] Preparing spawn area: 56%
    09:49:10 [INFO] Preparing spawn area: 61%
    09:49:11 [INFO] Preparing spawn area: 65%
    09:49:12 [INFO] Preparing spawn area: 69%
    09:49:13 [INFO] Preparing spawn area: 73%
    09:49:15 [INFO] Preparing spawn area: 77%
    09:49:16 [INFO] Preparing spawn area: 85%
    09:49:17 [INFO] Preparing start region for level 1 (Seed: 6069821333313786118)
    09:49:17 [INFO] Preparing spawn area: 0%
    09:49:19 [INFO] Preparing spawn area: 0%
    09:49:20 [INFO] Preparing spawn area: 48%
    09:49:21 [INFO] Preparing spawn area: 52%
    09:49:22 [INFO] [MobDeathNotifier] Enabling MobDeathNotifier v0.1
    09:49:22 [INFO] ÂșlMobDeathNotifier v0.1 Enabled!
    09:49:22 [INFO] Server permissions file permissions.yml is empty, ignoring it
    09:49:22 [INFO] Done (26.980s)! For help, type "help" or "?"
    09:49:44 [SEVERE] Could not pass event EntityDeathEvent to MobDeathNotifier
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:304)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:459)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(C
    raftEventFactory.java:299)
            at net.minecraft.server.EntityChicken.dropDeathLoot(EntityChicken.java:1
    14)
            at net.minecraft.server.EntityLiving.die(EntityLiving.java:781)
            at net.minecraft.server.EntityLiving.damageEntity(EntityLiving.java:677)
     
            at net.minecraft.server.EntityAnimal.damageEntity(SourceFile:124)
            at net.minecraft.server.EntityLiving.aA(EntityLiving.java:277)
            at net.minecraft.server.Entity.F_(Entity.java:268)
            at net.minecraft.server.EntityLiving.F_(EntityLiving.java:435)
            at net.minecraft.server.World.entityJoinedWorld(World.java:1262)
            at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:1
    06)
            at net.minecraft.server.World.playerJoinedWorld(World.java:1244)
            at net.minecraft.server.World.tickEntities(World.java:1151)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:558)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
            at me.javoris767.mdn.MDNListener.onEntityDeath(MDNListener.java:38)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302)
            ... 17 more
    >
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  18. Offline

    Sagacious_Zed Bukkit Docs

    javoris767
    Code:
    Caused by: java.lang.NullPointerException
            at me.javoris767.mdn.MDNListener.onEntityDeath(MDNListener.java:38)
    Something on line 38 in MDNListener.java is null. probably a variable that is not assigned, but could be a method returning null.
     
  19. Offline

    javoris767

    public class MDNListener implements Listener{
    Is line 38 :confused:
     
Thread Status:
Not open for further replies.

Share This Page