コード例 #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));
   }
 }
コード例 #2
0
  private void handleChange(CommandSender sender, String newMob) {
    if (sender instanceof Player) {
      if (su.isUnkown(newMob)) {
        su.sendMessage(
            sender,
            ChatColor.translateAlternateColorCodes(
                    '\u0026', plugin.localization.getString("unknownCreature"))
                .replace("%creature%", newMob));
        return;
      }

      // entityID
      short entityID = su.name2Eid.get(newMob);
      String creature = su.getCreatureName(entityID);
      // Filter spaces (like Zombie Pigman)
      String mobName = creature.toLowerCase().replace(" ", "");

      Player player = (Player) sender;

      int distance = plugin.config.getInt("spawnerCommandReachDistance", 6);
      // If the distance is -1, return
      if (distance != -1) {
        // Get the block
        Block block = su.nmsProvider.getSpawnerFacing(player, distance);
        if (block != null) {
          handleBlockChange(player, block, entityID, mobName);
          return;
        }
      }

      ItemStack itemInHand = su.nmsProvider.getSpawnerItemInHand(player);
      Material itemMaterial;
      try {
        itemMaterial = itemInHand.getType();
      } catch (NullPointerException e) {
        itemMaterial = null;
      }

      if (itemMaterial != null && itemMaterial == Material.MOB_SPAWNER) {
        handleChangeSpawner(player, entityID, mobName, itemInHand);
      } else if (itemMaterial != null && itemMaterial == SilkUtil.SPAWN_EGG) {
        handleChangeEgg(player, entityID, mobName, itemInHand);
      } else {
        su.sendMessage(
            player,
            ChatColor.translateAlternateColorCodes(
                '\u0026', plugin.localization.getString("spawnerNotDeterminable")));
      }
    } else {
      su.sendMessage(
          sender,
          ChatColor.translateAlternateColorCodes(
              '\u0026', plugin.localization.getString("noConsole")));
    }
  }
コード例 #3
0
 private void handleReload(CommandSender sender) {
   if (sender.hasPermission("silkspawners.reload")) {
     plugin.reloadConfigs();
     su.sendMessage(
         sender,
         ChatColor.translateAlternateColorCodes(
             '\u0026', plugin.localization.getString("configsReloaded")));
   } else {
     su.sendMessage(
         sender,
         ChatColor.translateAlternateColorCodes(
             '\u0026', plugin.localization.getString("noPermission")));
   }
 }
コード例 #4
0
 private void handleHelp(CommandSender sender) {
   for (int i = 1; i <= 7; i++) {
     String message =
         ChatColor.translateAlternateColorCodes(
             '\u0026',
             plugin
                 .localization
                 .getString("help" + i)
                 .replace("%version%", plugin.getDescription().getVersion()));
     su.sendMessage(sender, message);
   }
 }
コード例 #5
0
  private void handleGive(CommandSender sender, String receiver, String mob, String amountString) {
    int amount = plugin.config.getInt("defaultAmountGive", 1);

    // Check given amount
    if (amountString != null && !amountString.isEmpty()) {
      amount = su.getNumber(amountString);
      if (amount == -1) {
        su.sendMessage(
            sender,
            ChatColor.translateAlternateColorCodes(
                '\u0026', plugin.localization.getString("useNumbers")));
        return;
      }
    }

    // Check player
    Player player = su.nmsProvider.getPlayer(receiver);
    // Online check
    if (player == null) {
      su.sendMessage(
          sender,
          ChatColor.translateAlternateColorCodes(
              '\u0026', plugin.localization.getString("playerOffline")));
      return;
    }

    // Check if it's an egg or not
    boolean isEgg = su.isEgg(mob);
    String egg = mob;
    if (isEgg) {
      egg = egg.replaceFirst("egg$", "");
    }

    if (isEgg) {
      handleGiveEgg(sender, player, egg, amount);
    } else {
      handleGiveSpawner(sender, player, mob, amount);
    }
  }
コード例 #6
0
  private void handleChangeEgg(
      Player player, short entityID, String mobName, ItemStack itemInHand) {
    if (!player.hasPermission("silkspawners.changetypewithegg." + mobName)) {
      su.sendMessage(
          player,
          ChatColor.translateAlternateColorCodes(
              '\u0026', plugin.localization.getString("noPermissionChangingEgg")));
      return;
    }

    // Call the event and maybe change things!
    SilkSpawnersSpawnerChangeEvent changeEvent =
        new SilkSpawnersSpawnerChangeEvent(
            player,
            null,
            entityID,
            su.getStoredSpawnerItemEntityID(itemInHand),
            itemInHand.getAmount());
    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);
    ItemStack newItem =
        su.setSpawnerType(itemInHand, newEntityID, plugin.localization.getString("spawnerName"));
    su.nmsProvider.setSpawnerItemInHand(player, newItem);
    su.sendMessage(
        player,
        ChatColor.translateAlternateColorCodes(
                '\u0026', plugin.localization.getString("changedEgg"))
            .replace("%creature%", newMob));
  }
コード例 #7
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")));
   }
 }
コード例 #8
0
  @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));
        }
      }
    }
  }
コード例 #9
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onBlockPlace(BlockPlaceEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Block blockPlaced = event.getBlockPlaced();
    // Just mob spawner events
    if (blockPlaced.getType() != Material.MOB_SPAWNER) {
      return;
    }
    Player player = event.getPlayer();
    // If the player can't build here, return
    if (!su.canBuildHere(player, blockPlaced.getLocation())) {
      return;
    }
    // Get the item
    ItemStack item = event.getItemInHand();
    // Get data from item
    short entityID = su.getStoredSpawnerItemEntityID(item);
    boolean defaultID = false;
    // 0 or unknown then fallback
    if (entityID == 0 || !su.knownEids.contains(entityID)) {
      // Default
      defaultID = true;
      entityID = su.getDefaultEntityID();
    }

    // Names
    String creatureName = su.getCreatureName(entityID);
    String spawnerName = creatureName.toLowerCase().replace(" ", "");

    // Check for place permission
    if (!player.hasPermission("silkspawners.place." + spawnerName)) {
      event.setCancelled(true);
      player.sendMessage(
          ChatColor.translateAlternateColorCodes(
                  '\u0026',
                  plugin
                      .localization
                      .getString("noPermissionPlace")
                      .replace("%ID%", Short.toString(entityID)))
              .replace("%creature%", creatureName));
      return;
    }

    // Message default
    if (defaultID) {
      plugin.informPlayer(
          player,
          ChatColor.translateAlternateColorCodes(
              '\u0026', plugin.localization.getString("placingDefault")));
    } else {
      // Else message the type
      plugin.informPlayer(
          player,
          ChatColor.translateAlternateColorCodes(
                  '\u0026', plugin.localization.getString("spawnerPlaced"))
              .replace("%creature%", su.getCreatureName(entityID)));
    }

    su.setSpawnerEntityID(blockPlaced, entityID);
  }
コード例 #10
0
 private void handleList(CommandSender sender) {
   su.showAllCreatures(sender);
 }
コード例 #11
0
 private void handleUnknownArgument(CommandSender sender) {
   su.sendMessage(
       sender,
       ChatColor.translateAlternateColorCodes(
           '\u0026', plugin.localization.getString("unknownArgument")));
 }
コード例 #12
0
  private void handleGiveSpawner(CommandSender sender, Player receiver, String mob, int amount) {
    if (su.isUnkown(mob)) {
      su.sendMessage(
          sender,
          ChatColor.translateAlternateColorCodes(
                  '\u0026', plugin.localization.getString("unknownCreature"))
              .replace("%creature%", mob));
      return;
    }

    short entityID = su.name2Eid.get(mob);
    String creature = su.getCreatureName(entityID);
    // Filter spaces (like Zombie Pigman)
    String mobName = creature.toLowerCase().replace(" ", "");

    // Add spawner
    if (sender.hasPermission("silkspawners.freeitem." + mobName)) {
      // Have space in inventory
      if (receiver.getInventory().firstEmpty() == -1) {
        su.sendMessage(
            sender,
            ChatColor.translateAlternateColorCodes(
                '\u0026', plugin.localization.getString("noFreeSlot")));
        return;
      }
      receiver
          .getInventory()
          .addItem(
              su.newSpawnerItem(
                  entityID, su.getCustomSpawnerName(su.eid2MobID.get(entityID)), amount, false));
      if (sender instanceof Player) {
        Player pSender = (Player) sender;
        if (pSender.getUniqueId() == receiver.getUniqueId()) {
          su.sendMessage(
              sender,
              ChatColor.translateAlternateColorCodes(
                      '\u0026', plugin.localization.getString("addedSpawner"))
                  .replace("%creature%", creature)
                  .replace("%amount%", Integer.toString(amount)));
        } else {
          su.sendMessage(
              sender,
              ChatColor.translateAlternateColorCodes(
                      '\u0026',
                      plugin
                          .localization
                          .getString("addedSpawnerOtherPlayer")
                          .replace("%player%", receiver.getName()))
                  .replace("%creature%", creature)
                  .replace("%amount%", Integer.toString(amount)));
        }
      } else {
        su.sendMessage(
            sender,
            ChatColor.translateAlternateColorCodes(
                    '\u0026',
                    plugin
                        .localization
                        .getString("addedSpawnerOtherPlayer")
                        .replace("%player%", receiver.getName()))
                .replace("%creature%", creature)
                .replace("%amount%", Integer.toString(amount)));
      }
      return;
    }
    su.sendMessage(
        sender,
        ChatColor.translateAlternateColorCodes(
            '\u0026', plugin.localization.getString("noPermissionFreeSpawner")));
  }