Solved Fix-All

Discussion in 'Plugin Development' started by MikeyDesigns, Apr 26, 2017.

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

    MikeyDesigns

    I'm trying to make a fix-all plugin but when I use the command nothing spits out not even an error.

    Command:
    Code:
    if (cmd.getName().equalsIgnoreCase("fixall")) {
                Player puf = (Player) sender;
                PlayerInventory inventory = puf.getInventory();
                if (inventory.contains(256) || inventory.contains(257)
                        || inventory.contains(258) || inventory.contains(259)
                        || inventory.contains(261) || inventory.contains(267)
                        || inventory.contains(268) || inventory.contains(269)
                        || inventory.contains(270) || inventory.contains(271)
                        || inventory.contains(272) || inventory.contains(273)
                        || inventory.contains(274) || inventory.contains(275)
                        || inventory.contains(276) || inventory.contains(277)
                        || inventory.contains(278) || inventory.contains(279)
                        || inventory.contains(283) || inventory.contains(284)
                        || inventory.contains(285) || inventory.contains(286)
                        || inventory.contains(290) || inventory.contains(291)
                        || inventory.contains(292) || inventory.contains(293)
                        || inventory.contains(294) || inventory.contains(298)
                        || inventory.contains(299) || inventory.contains(300)
                        || inventory.contains(301) || inventory.contains(302)
                        || inventory.contains(303) || inventory.contains(304)
                        || inventory.contains(305) || inventory.contains(306)
                        || inventory.contains(307) || inventory.contains(308)
                        || inventory.contains(309) || inventory.contains(310)
                        || inventory.contains(311) || inventory.contains(312)
                        || inventory.contains(313) || inventory.contains(314)
                        || inventory.contains(315) || inventory.contains(316)
                        || inventory.contains(317) || inventory.contains(346)) {
                    for (int inv = 0; inv < inventory.getSize(); inv++) {
                        ItemStack item = inventory.getItem(inv);
                        if (item.getTypeId() == 256 || item.getTypeId() == 257
                                || item.getTypeId() == 257
                                || item.getTypeId() == 258
                                || item.getTypeId() == 259
                                || item.getTypeId() == 261
                                || item.getTypeId() == 267
                                || item.getTypeId() == 268
                                || item.getTypeId() == 269
                                || item.getTypeId() == 270
                                || item.getTypeId() == 271
                                || item.getTypeId() == 272
                                || item.getTypeId() == 273
                                || item.getTypeId() == 274
                                || item.getTypeId() == 275
                                || item.getTypeId() == 276
                                || item.getTypeId() == 277
                                || item.getTypeId() == 278
                                || item.getTypeId() == 279
                                || item.getTypeId() == 283
                                || item.getTypeId() == 284
                                || item.getTypeId() == 285
                                || item.getTypeId() == 286
                                || item.getTypeId() == 290
                                || item.getTypeId() == 291
                                || item.getTypeId() == 292
                                || item.getTypeId() == 293
                                || item.getTypeId() == 294
                                || item.getTypeId() == 298
                                || item.getTypeId() == 299
                                || item.getTypeId() == 300
                                || item.getTypeId() == 301
                                || item.getTypeId() == 302
                                || item.getTypeId() == 303
                                || item.getTypeId() == 304
                                || item.getTypeId() == 305
                                || item.getTypeId() == 306
                                || item.getTypeId() == 307
                                || item.getTypeId() == 308
                                || item.getTypeId() == 309
                                || item.getTypeId() == 310
                                || item.getTypeId() == 311
                                || item.getTypeId() == 312
                                || item.getTypeId() == 313
                                || item.getTypeId() == 314
                                || item.getTypeId() == 315
                                || item.getTypeId() == 316
                                || item.getTypeId() == 317
                                || item.getTypeId() == 346) {
                            item.setDurability((short) ((item.getType()
                                    .getMaxDurability()) - (item.getType()
                                    .getMaxDurability())));
                            puf.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&9&lRepair&8] &7Your inventory has been repaired&8!"));
                        }
                   }
                }
            }
     
    Before you ask I have added it as command to the plugin.yml.
     
  2. Offline

    Zombie_Striker

    @MikeyDesigns
    1. You should no long use IDs as they are no longer supported.
    2. Instead if this, for loop through the inventory and see if the material name ends in "sword", "Axe","Shovel",ect instead of doing the id checks.
    3. 0 durability is the 'maximum' durability. Positive numbers mean the item has been used. Just use 0 instead of calculating it.
     
  3. Offline

    ShaneCraftDev

    @MikeyDesigns
    You at most, you statement iterates 49 times through the players inventory. That's not very efficient. Loose the first if statment and do as Zombie_Striker says; check for a substring from the names of the material type
     
  4. Offline

    MikeyDesigns

    Found out thanks!
     
Thread Status:
Not open for further replies.

Share This Page