Ejemplo n.º 1
0
 private void handleBlockChange(Player player, Block block, short entityID, String mobName) {
   if (!player.hasPermission("silkspawners.changetype." + mobName)) {
     su.sendMessage(
         player,
         ChatColor.translateAlternateColorCodes(
             '\u0026', plugin.localization.getString("noPermissionChangingSpawner")));
     return;
   }
   // Call the event and maybe change things!
   SilkSpawnersSpawnerChangeEvent changeEvent =
       new SilkSpawnersSpawnerChangeEvent(
           player, block, entityID, su.getSpawnerEntityID(block), 1);
   plugin.getServer().getPluginManager().callEvent(changeEvent);
   // See if we need to stop
   if (changeEvent.isCancelled()) {
     return;
   }
   // Get the new ID (might be changed)
   short newEntityID = changeEvent.getEntityID();
   String newMob = su.getCreatureName(entityID);
   if (su.setSpawnerType(
       block,
       newEntityID,
       player,
       ChatColor.translateAlternateColorCodes(
           '\u0026', plugin.localization.getString("changingDeniedWorldGuard")))) {
     su.sendMessage(
         player,
         ChatColor.translateAlternateColorCodes(
                 '\u0026', plugin.localization.getString("changedSpawner"))
             .replace("%creature%", newMob));
   }
 }
Ejemplo n.º 2
0
 private void handleView(CommandSender sender) {
   if (sender instanceof Player) {
     // If the distance is -1, return
     int distance = plugin.config.getInt("spawnerCommandReachDistance", 6);
     if (distance == -1) {
       return;
     }
     // Get the block, returns null for non spawner blocks
     Player player = (Player) sender;
     Block block = su.nmsProvider.getSpawnerFacing(player, distance);
     if (block == null) {
       su.sendMessage(
           player,
           ChatColor.translateAlternateColorCodes(
               '\u0026', plugin.localization.getString("lookAtSpawner")));
       return;
     }
     short entityID = su.getSpawnerEntityID(block);
     if (player.hasPermission("silkspawners.viewtype")) {
       su.sendMessage(
           player,
           ChatColor.translateAlternateColorCodes(
                   '\u0026', plugin.localization.getString("getSpawnerType"))
               .replace("%creature%", su.getCreatureName(entityID)));
     } else {
       su.sendMessage(
           player,
           ChatColor.translateAlternateColorCodes(
               '\u0026', plugin.localization.getString("noPermissionViewType")));
     }
   } else {
     su.sendMessage(
         sender,
         ChatColor.translateAlternateColorCodes(
             '\u0026', plugin.localization.getString("noConsole")));
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Block block = event.getBlock();
    Player player = event.getPlayer();

    // We just want the mob spawner events
    if (block.getType() != Material.MOB_SPAWNER) {
      return;
    }

    // We can't build here? Return then
    if (!su.canBuildHere(player, block.getLocation())) {
      return;
    }

    // Get the entityID from the spawner
    short entityID = su.getSpawnerEntityID(block);

    // Message the player about the broken spawner
    plugin.informPlayer(
        player,
        ChatColor.translateAlternateColorCodes(
                '\u0026', plugin.localization.getString("spawnerBroken"))
            .replace("%creature%", su.getCreatureName(entityID)));

    // If using silk touch, drop spawner itself
    ItemStack tool = player.getItemInHand();
    // Check for SilkTocuh level
    boolean validToolAndSilkTouch = su.isValidItemAndHasSilkTouch(tool);

    // Get the world to drop in
    World world = player.getWorld();

    // Mob
    String mobName = su.getCreatureName(entityID).toLowerCase().replace(" ", "");

    // No drops in creative
    if (plugin.config.getBoolean("noDropsCreative", true)
        && player.getGameMode() == GameMode.CREATIVE) {
      return;
    }

    // Prevent XP farming/duping
    event.setExpToDrop(0);
    // assume not mined
    boolean mined = false;
    // drop XP only when destroyed and not silk picked
    boolean dropXPOnlyOnDestroy = plugin.config.getBoolean("dropXPOnlyOnDestroy", false);

    if (plugin.config.getBoolean("preventXPFarming", true) && block.hasMetadata("mined")) {
      mined = block.getMetadata("mined").get(0).asBoolean();
    }

    // Drop maybe some XP
    if (player.hasPermission("silkspawners.silkdrop." + mobName)
        || player.hasPermission("silkspawners.destroydrop." + mobName)) {
      int addXP = plugin.config.getInt("destroyDropXP");
      // If we have more than 0 XP, drop them
      // either we drop XP for destroy and silktouch or only when
      // destroyed and we have no silktouch
      if (!mined
          && addXP != 0
          && (!dropXPOnlyOnDestroy || !validToolAndSilkTouch && dropXPOnlyOnDestroy)) {
        event.setExpToDrop(addXP);
        // check if we should flag spawners
        if (plugin.config.getBoolean("preventXPFarming", true)) {
          block.setMetadata("mined", new FixedMetadataValue(plugin, true));
        }
      }
    }

    // random drop chance
    String mobID = su.eid2MobID.get(entityID);
    int randomNumber = rnd.nextInt(100);
    int dropChance = 0;

    // silk touch
    if (validToolAndSilkTouch && player.hasPermission("silkspawners.silkdrop." + mobName)) {
      // Calculate drop chance
      if (plugin.mobs.contains("creatures." + mobID + ".silkDropChance")) {
        dropChance = plugin.mobs.getInt("creatures." + mobID + ".silkDropChance", 100);
      } else {
        dropChance = plugin.config.getInt("silkDropChance", 100);
      }
      if (randomNumber < dropChance) {
        // Drop spawner
        world.dropItemNaturally(
            block.getLocation(),
            su.newSpawnerItem(
                entityID, su.getCustomSpawnerName(su.eid2MobID.get(entityID)), 1, false));
      }
      return;
    }

    // no silk touch
    if (player.hasPermission("silkspawners.destroydrop." + mobName)) {
      if (plugin.config.getBoolean("destroyDropEgg", false)) {
        // Calculate drop chance
        randomNumber = rnd.nextInt(100);
        if (plugin.mobs.contains("creatures." + mobID + ".eggDropChance")) {
          dropChance = plugin.mobs.getInt("creatures." + mobID + ".eggDropChance", 100);
        } else {
          dropChance = plugin.config.getInt("eggDropChance", 100);
        }
        if (randomNumber < dropChance) {
          // Drop egg
          world.dropItemNaturally(block.getLocation(), su.newEggItem(entityID));
        }
      }
      // Drop iron bars (or not)
      int dropBars = plugin.config.getInt("destroyDropBars", 0);
      if (dropBars != 0) {
        // Calculate drop chance
        randomNumber = rnd.nextInt(100);
        if (plugin.mobs.contains("creatures." + mobID + ".destroyDropChance")) {
          dropChance = plugin.mobs.getInt("creatures." + mobID + ".destroyDropChance", 100);
        } else {
          dropChance = plugin.config.getInt("destroyDropChance", 100);
        }
        if (randomNumber < dropChance) {
          world.dropItem(block.getLocation(), new ItemStack(Material.IRON_FENCE, dropBars));
        }
      }
    }
  }