[SOLVED]Blacklisting of blocks chosen in the config.

Discussion in 'Plugin Development' started by MrMag518, Jan 12, 2012.

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

    MrMag518

    Ok, so I've been trying for a good amount of time now to code that damn blacklisting of blocks you choose in the config. But it seem to fail everytime I try. I'll give you the codes:
    SOLVED


    Here's the BlockListener; onBlockPlace:
    Code:java
    1. @Override
    2. public void onBlockPlace(BlockPlaceEvent event) {
    3. if (event.isCancelled())
    4. {
    5. return;
    6. }
    7.  
    8. Player player = event.getPlayer();
    9. Block block = event.getBlock();
    10. Server server = player.getServer();
    11.  
    12.  
    13.  
    14. List<Object> blocks = plugin.config.getList("Place.Blacklist");
    15. if (blocks == null) {
    16. System.out.println("Theres no objects in the placement blacklist.");
    17. return;
    18. }
    19. for(Object i : blocks){
    20. Material material = Material.valueOf((String)i);
    21. if( material == null ){
    22. System.out.println("Invalid object ID: "+(String)i);
    23. continue;
    24. }
    25. if (blocks.contains(i)) {
    26. event.setCancelled(true);
    27. player.sendMessage(ChatColor.RED + "You cannot place "+ block.getType());
    28. break;
    29. }
    30. }


    Here's the code in the main class:

    the statement/declartion (don't know wich :S)

    Code:java
    1. List<Object> BlockPlace = new ArrayList<Object>();
    2. String[] PlaceList = {"1", "46", "7"};


    And heres the config; loadConfig()

    Code:java
    1. config.addDefault("Place.Blacklist", Arrays.asList(PlaceList));
    2. BlockPlace = config.getList("Place.Blacklist");
    3. this.getConfig().options().copyDefaults(true);
    4. saveConfig();


    The error in the console:

    Code:
    20:43:06 [SEVERE] Could not pass event BLOCK_PLACE to iSafe
    java.lang.IllegalArgumentException: No enum const class org.bukkit.Material.1
            at java.lang.Enum.valueOf(Unknown Source)
            at org.bukkit.Material.valueOf(Material.java:14)
            at me.mrmag518.iSafe.iSafeBlockListener.onBlockPlace(iSafeBlockListener.
    java:53)
            at org.bukkit.plugin.java.JavaPluginLoader$32.execute(JavaPluginLoader.j
    ava:483)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:58)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:339)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(Cr
    aftEventFactory.java:100)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(Cr
    aftEventFactory.java:84)
            at net.minecraft.server.ItemBlock.a(ItemBlock.java:97)
            at net.minecraft.server.ItemStack.placeItem(ItemStack.java:83)
            at net.minecraft.server.ItemInWorldManager.interact(ItemInWorldManager.j
    ava:282)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:593)
            at net.minecraft.server.Packet15Place.a(SourceFile:39)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:93)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:527)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    And how the config list looks:

    Code:
    Place:
      Blacklist:
      - '1'
      - '46'
      - '7'
    Also tried:
    Code:java
    1. Object[] PlaceList = {"1", "46", "7"};

    instead of:
    Code:java
    1. String[] PlaceList = {"1", "46", "7"};

    :/

    Someone know what I'm doing wrong?

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

    theguynextdoor

    Im pretty sure that Material.valueOf() wants words, not numbers. Soooo you can either change the config to the *upper case?* worded version of the material, or you can check that if(event.getBlock().getTypeId == blablabla
     
  3. Offline

    MrMag518

    So you mean that I should chane all objects to strings and the material type from ID to name?

    Cant edit my text from android so i quote u from this one instead.. @theguynextdoor

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

    Mukrakiish

    Have you checked out the source in WorldGuard to see how they do blacklisting? They have a fairly indepth blacklist integrated...might be worth a gander.
     
  5. Offline

    theguynextdoor

    Well
    Code:
     if(config.getList("bla.moreBla").contains(blockID)){
    blockID being event.getBlock().getTypeId();
     
  6. Offline

    MrMag518

    @Mukrakiish wg's to complicated for me, and im coding more leightweight
    @theguynextdoor thank you, I'll test it tomorrov when i get on my computer.

    @theguynextdoor LOL, I just found the worlds most easy code for a simple blacklist, thank you; cause it includes some of your advice xD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
Thread Status:
Not open for further replies.

Share This Page