コード例 #1
0
  @EventHandler
  public void onPlayerInteract_Appliance(final PlayerInteractEvent event) {
    if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
      return;
    }
    String applianceType;
    switch (event.getClickedBlock().getTypeId()) { // Check and set appliance type
      case 58:
        applianceType = "CraftingTable";
        break;
      case 61:
        applianceType = "Furnace";
        break;
      case 116:
        applianceType = "EnchantmentTable";
        break;
      case 117:
        applianceType = "BrewingStand";
        break;
      case 23:
        applianceType = "Dispenser";
        break;
      default:
        return;
    }
    if (event
        .getPlayer()
        .hasPermission(
            "madetobreak.exempt."
                + applianceType
                    .toLowerCase())) { // Check if the player is exempted from depleting usage of
                                       // appliance
      return;
    }
    Block blk = event.getClickedBlock();
    Player player = event.getPlayer();
    if (plugin.l.containsKey(blk)) {

      if (plugin.l.get(blk)
          == -1) { // Check if the block is exempted (i.e. is an infinite usage block)
        return;
      } else if (plugin.l.get(blk) == -2) {
        event.setCancelled(true);
        player.sendMessage(
            plugin.colorize(
                plugin.getConfig().getString(applianceType + "Effects.Display_Message")));
        //				player.getWorld().playEffect(loc.add(0, 1, 0), Effect.SMOKE, 4);
        //				player.getWorld().playEffect(loc, Effect.EXTINGUISH, 0);
        //				//TODO: play effects prescribed in config
        return;
      }

      plugin.l.put(blk, plugin.l.get(blk) + 1); // add usage

      if (plugin.l.get(blk)
          >= plugin
              .getConfig()
              .getInt(applianceType + "_Uses")) { // Compares current usage to max usage in config
        // Deploy any effects prescribed in config
        World world = player.getWorld();
        switch (plugin.getConfig().getInt(applianceType + "Effects.Explosion.Setting")) {
          case 0:
            break;
          case 1:
            event.getClickedBlock().setTypeId(0);
            world.createExplosion(blk.getLocation(), 0F);
            plugin.l.remove(blk);
            return;
          case 2:
            event.getClickedBlock().setTypeId(0);
            player
                .getWorld()
                .createExplosion(
                    blk.getLocation(),
                    (float) plugin.getConfig().getInt(applianceType + "Effects.Explosion.Force"));
            plugin.l.remove(blk);
            return;
        } // end of explosion checking
        if (plugin.getConfig().getBoolean(applianceType + "Effects.Disappear")) {
          event.getClickedBlock().setTypeId(0);
          plugin.l.remove(blk);
          return;
        } // end of disappear checking

        plugin.l.put(blk, -2); // place 'broken' value (i.e. -2)
      }

    } else { // It's a new & normal block, put into the map.
      if (plugin.getConfig().getInt(applianceType + "_Uses") == -1) {
        return;
      }
      plugin.l.put(blk, 1);
    }
  }
コード例 #2
0
 public MBListener(MadeToBreak os) {
   plugin = os;
   plugin.getServer().getPluginManager().registerEvents(this, plugin);
 }