Support Multi-materials

Discussion in 'Plugin Development' started by Giorgio, Nov 19, 2012.

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


    Hello everyone how would I support more than one material through the config. Here is what I have, I want to support more than just Diamond sword. here is my code:
      public void onPlayerClick(EntityDamageByEntityEvent event) {
        Player damager = (Player)event.getDamager();
        Entity damaged = event.getEntity();
        ItemStack inHand = damager.getItemInHand();
        if (BanSwordCommand.bsToggled) {
          if ((!(event.getDamager() instanceof Player)) || (!(event.getEntity() instanceof Player))) {
          if (!(event.getEntity() instanceof Player)) {
            damaged = event.getEntity();
          if (((event.getDamager() instanceof Player)) && ((event.getEntity() instanceof Player))) {
            if ((inHand == null) || (inHand.getType() != Material.DIAMOND_SWORD))
            if (inHand.getType() == Material.DIAMOND_SWORD) {
              ((Player)damaged).kickPlayer("The BanSword has spoken!!");
        } else if (!BanSwordCommand.bsToggled) {
  2. so, if you want to support more than 1 value to compare at this point:
    1. if ((inHand == null) || (inHand.getType() != Material.DIAMOND_SWORD))
    2. return;
    3. if (inHand.getType() == Material.DIAMOND_SWORD) {
    4. ((Player)damaged).kickPlayer("The BanSword has spoken!!");
    5. ((OfflinePlayer)damaged).setBanned(true);
    6. }
    , all you need to do it make an list/arraylist
    1. List<Material> supportedMaterials = new ArrayList<material>();

    and loop it when you hit it, like this:
    2. if ((inHand == null)
    3. return
    4. for(Material item:supportedMayerials)
    5. {
    6. if (inHand.getType() == item) {
    7. ((Player)damaged).kickPlayer("The BanSword has spoken!!");
    8. ((OfflinePlayer)damaged).setBanned(true);
    9. return;
    10. }
    11. }

    now its up to you how to insert the proper sword inside the list

    also, its better if your test your code more, its going to spam errors when a zombie or other mob is attacking a player
  3. Offline



    Ok thank you, and yes i will look at my code.

    One thing for the supported materials how would you define what material to use?
    I would we just supported all of them but how do we use them, define it through the config?
Thread Status:
Not open for further replies.

Share This Page