mcMMO/src/main/java/com/gmail/nossr50/util/Misc.java

255 lines
10 KiB
Java
Raw Normal View History

2012-04-27 11:47:11 +02:00
package com.gmail.nossr50.util;
import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableSet;
2012-04-27 11:47:11 +02:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
2019-04-05 03:55:25 +02:00
import org.bukkit.entity.*;
2012-04-27 11:47:11 +02:00
import org.bukkit.inventory.ItemStack;
2019-06-21 17:05:57 +02:00
import org.bukkit.util.Vector;
2012-04-27 11:47:11 +02:00
import java.util.Collection;
import java.util.Random;
import java.util.Set;
2014-08-31 19:10:49 +02:00
2013-01-26 23:01:55 +01:00
public final class Misc {
2012-04-27 11:47:11 +02:00
private static Random random = new Random();
2013-06-13 01:26:09 +02:00
2013-01-10 03:44:53 +01:00
public static final int TIME_CONVERSION_FACTOR = 1000;
2013-06-13 01:26:09 +02:00
public static final int TICK_CONVERSION_FACTOR = 20;
public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5;
2013-01-10 03:44:53 +01:00
public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0;
Squashed commit of the following: commit cb3e057dee1f2b29838ab654a526baac1baab7d6 Author: NuclearW <incongruency@gmail.com> Date: Fri Mar 1 00:43:57 2013 -0500 1.4.00 release commit 4f9628d2e4cde31c8946e9a911ee6f10e1fb6b35 Author: NuclearW <incongruency@gmail.com> Date: Fri Mar 1 00:07:30 2013 -0500 \r -> \n commit b2ca22e0477c747143b0f08a28a096967ee6ffd7 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 23:53:56 2013 -0500 Commented-out code shouldn't be done like that. commit 92f131712cc671e3e616c14a22e22769ef6d6d0b Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 23:45:36 2013 -0500 More things we missed. commit 408b03766f6261a03a862a1ab7f5835772feda4a Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 23:20:13 2013 -0500 Format: util through spout and backup lib commit d6bd2c29bbb51bee3607247468cfe145d4f38c9e Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 22:50:08 2013 -0500 The things we missed the first time through... commit 393f0b889aa1b7011ee81ee7b15413d8824b8cfb Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 22:05:29 2013 -0500 Formatting: Skills commit c097a6e188a7b760dd1b4389ed81dca417146b16 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:30:12 2013 -0500 Organize imports. commit 34c3e74be7eb5f983f21d969e30155c5d82c01c1 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:09:45 2013 -0500 Fixed a missing fallthrough comment from ChatCommand commit b4a76c9f022a2fd98bdd8f083accfea03becfd71 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:09:36 2013 -0500 Formatting: datatypes.* through events.* commit 3e57dd41d3265a7c8106c7eb026df926770a4d15 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:56:15 2013 -0500 Fix issue with bad rebase commit e8c8e06b2971555b7334e49128257e3af6f36892 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 17:35:32 2013 -0500 Formatting: DatabaseManager, LeaderboardManager, DatabaseUpdateType, and PlayerStat commit 13ecf1cc41f377a12991e357ac10abdcda24d6de Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:31:43 2013 -0500 Format: listeners.* through runnables.* commit 71686e3c0d96c2dcf25442b91703fadda1ea3bb0 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:13:57 2013 -0500 Format PartyLockCommand commit d50abed10bf94e1a88df3dc5cc07c259aea920ea Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 16:54:08 2013 -0500 Format: base through config.* commit 7004823eeebbae5be7728bf9cafc3b04e57b64cf Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:21:40 2013 -0500 Example of using spaces to align like things commit 534190cfe2481e466fe459d65628550458cc2993 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:12:19 2013 -0500 Capitalization commit 5b61d3ba4c8d81e6f358b0cf4f460abfe9798414 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:07:43 2013 -0500 Updated readme, added standards.md commit 5ec0df70fb82c527420a2f437f27f31bd758f884 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 14:42:16 2013 -0500 Markdown was here, Creole is a loser commit 70d557c59d086b6a5fb5e0e63c0c1d8eb4c8d19c Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 13:46:24 2013 -0500 Move MCStats shading to .metrics.mcstats commit eb9d67e66b1659d6abd2397ecf403343cfeffdda Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 13:37:37 2013 -0500 Move ALL the packages! commit 8ffa9e7b75417b6c7f158613d4b4ffb783dcf2d0 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 12:37:12 2013 -0500 /r/n -> /n
2013-03-01 06:52:01 +01:00
// Sound Pitches & Volumes from CB
/* public static final float ANVIL_USE_PITCH = 0.3F; // Not in CB directly, I went off the place sound values
2016-03-06 22:48:22 +01:00
public static final float ANVIL_USE_VOLUME = 1.0F * Config.getInstance().getMasterVolume(); // Not in CB directly, I went off the place sound values
public static final float FIZZ_VOLUME = 0.5F * Config.getInstance().getMasterVolume();
public static final float POP_VOLUME = 0.2F * Config.getInstance().getMasterVolume();
public static final float BAT_VOLUME = 1.0F * Config.getInstance().getMasterVolume();
public static final float BAT_PITCH = 0.6F;
2016-03-06 22:48:22 +01:00
public static final float GHAST_VOLUME = 1.0F * Config.getInstance().getMasterVolume();
public static final float LEVELUP_PITCH = 0.5F; // Reduced to differentiate between vanilla level-up
public static final float LEVELUP_VOLUME = 0.75F * Config.getInstance().getMasterVolume(); // Use max volume always*/
2014-08-31 19:10:49 +02:00
public static final Set<String> modNames = ImmutableSet.of("LOTR", "BUILDCRAFT", "ENDERIO", "ENHANCEDBIOMES", "IC2", "METALLURGY", "FORESTRY", "GALACTICRAFT", "RAILCRAFT", "TWILIGHTFOREST", "THAUMCRAFT", "GRAVESTONEMOD", "GROWTHCRAFT", "ARCTICMOBS", "DEMONMOBS", "INFERNOMOBS", "SWAMPMOBS", "MARICULTURE", "MINESTRAPPOLATION");
2013-01-26 23:01:55 +01:00
private Misc() {};
/**
* Determines if an entity is an NPC but not a villager
* This method aims to establish compatibility between mcMMO and other plugins which create "NPCs"
*
* It does this by checking the following
* 1) The entity is not a Villager
* 2) The entity can be considered an NPC
*
* In this context, an NPC is a bit hard to define. Various plugins determine what an NPC is in different ways.
* @see Misc::isNPCIncludingVillagers
* @param entity target entity
* @return true if the entity is not a Villager and is not a "NPC"
*/
public static boolean isNPCEntityExcludingVillagers(Entity entity) {
return (!isVillager(entity)
&& isNPCIncludingVillagers(entity)); //Compatibility with some mod..
}
public static boolean isNPCClassType(Entity entity) {
return entity instanceof NPC;
}
public static boolean hasNPCMetadataTag(Entity entity) {
return entity.hasMetadata("NPC");
}
public static boolean isVillager(Entity entity) {
String entityType = entity.getType().toString();
//This weird code is for 1.13 & 1.14 compatibility
return entityType.equalsIgnoreCase("wandering_trader") || entity instanceof Villager;
}
public static boolean isNPCIncludingVillagers(Entity entity) {
return (entity == null
|| (hasNPCMetadataTag(entity))
|| (isNPCClassType(entity))
|| entity.getClass().getName().equalsIgnoreCase("cofh.entity.PlayerFake"));
}
2012-04-27 11:47:11 +02:00
/**
* Determine if two locations are near each other.
*
* @param first The first location
* @param second The second location
* @param maxDistance The max distance apart
2013-08-10 20:10:45 +02:00
* @return true if the distance between {@code first} and {@code second} is less than {@code maxDistance}, false otherwise
2012-04-27 11:47:11 +02:00
*/
public static boolean isNear(Location first, Location second, double maxDistance) {
2014-02-27 16:56:21 +01:00
return (first.getWorld() == second.getWorld()) && (first.distanceSquared(second) < (maxDistance * maxDistance) || maxDistance == 0);
}
2013-01-10 04:43:21 +01:00
/**
* Get the center of the given block.
*
* @param blockState The {@link BlockState} of the block
* @return A {@link Location} lying at the center of the block
*/
public static Location getBlockCenter(BlockState blockState) {
return blockState.getLocation().add(0.5, 0.5, 0.5);
}
public static void dropItems(Location location, Collection<ItemStack> drops) {
for (ItemStack drop : drops) {
dropItem(location, drop);
}
2012-04-27 11:47:11 +02:00
}
/**
* Drop items at a given location.
*
* @param location The location to drop the items at
* @param is The items to drop
* @param quantity The amount of items to drop
*/
2012-05-18 19:40:21 +02:00
public static void dropItems(Location location, ItemStack is, int quantity) {
2012-04-27 11:47:11 +02:00
for (int i = 0; i < quantity; i++) {
2012-05-18 19:40:21 +02:00
dropItem(location, is);
2012-04-27 11:47:11 +02:00
}
}
/**
* Drop an item at a given location.
*
* @param location The location to drop the item at
* @param itemStack The item to drop
2013-12-02 00:43:17 +01:00
* @return Dropped Item entity or null if invalid or cancelled
2012-04-27 11:47:11 +02:00
*/
2013-12-02 00:43:17 +01:00
public static Item dropItem(Location location, ItemStack itemStack) {
if (itemStack.getType() == Material.AIR) {
2013-12-02 00:43:17 +01:00
return null;
}
2012-04-27 11:47:11 +02:00
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack);
mcMMO.p.getServer().getPluginManager().callEvent(event);
2012-04-27 11:47:11 +02:00
Squashed commit of the following: commit cb3e057dee1f2b29838ab654a526baac1baab7d6 Author: NuclearW <incongruency@gmail.com> Date: Fri Mar 1 00:43:57 2013 -0500 1.4.00 release commit 4f9628d2e4cde31c8946e9a911ee6f10e1fb6b35 Author: NuclearW <incongruency@gmail.com> Date: Fri Mar 1 00:07:30 2013 -0500 \r -> \n commit b2ca22e0477c747143b0f08a28a096967ee6ffd7 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 23:53:56 2013 -0500 Commented-out code shouldn't be done like that. commit 92f131712cc671e3e616c14a22e22769ef6d6d0b Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 23:45:36 2013 -0500 More things we missed. commit 408b03766f6261a03a862a1ab7f5835772feda4a Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 23:20:13 2013 -0500 Format: util through spout and backup lib commit d6bd2c29bbb51bee3607247468cfe145d4f38c9e Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 22:50:08 2013 -0500 The things we missed the first time through... commit 393f0b889aa1b7011ee81ee7b15413d8824b8cfb Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 22:05:29 2013 -0500 Formatting: Skills commit c097a6e188a7b760dd1b4389ed81dca417146b16 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:30:12 2013 -0500 Organize imports. commit 34c3e74be7eb5f983f21d969e30155c5d82c01c1 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:09:45 2013 -0500 Fixed a missing fallthrough comment from ChatCommand commit b4a76c9f022a2fd98bdd8f083accfea03becfd71 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:09:36 2013 -0500 Formatting: datatypes.* through events.* commit 3e57dd41d3265a7c8106c7eb026df926770a4d15 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:56:15 2013 -0500 Fix issue with bad rebase commit e8c8e06b2971555b7334e49128257e3af6f36892 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 17:35:32 2013 -0500 Formatting: DatabaseManager, LeaderboardManager, DatabaseUpdateType, and PlayerStat commit 13ecf1cc41f377a12991e357ac10abdcda24d6de Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:31:43 2013 -0500 Format: listeners.* through runnables.* commit 71686e3c0d96c2dcf25442b91703fadda1ea3bb0 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:13:57 2013 -0500 Format PartyLockCommand commit d50abed10bf94e1a88df3dc5cc07c259aea920ea Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 16:54:08 2013 -0500 Format: base through config.* commit 7004823eeebbae5be7728bf9cafc3b04e57b64cf Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:21:40 2013 -0500 Example of using spaces to align like things commit 534190cfe2481e466fe459d65628550458cc2993 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:12:19 2013 -0500 Capitalization commit 5b61d3ba4c8d81e6f358b0cf4f460abfe9798414 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:07:43 2013 -0500 Updated readme, added standards.md commit 5ec0df70fb82c527420a2f437f27f31bd758f884 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 14:42:16 2013 -0500 Markdown was here, Creole is a loser commit 70d557c59d086b6a5fb5e0e63c0c1d8eb4c8d19c Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 13:46:24 2013 -0500 Move MCStats shading to .metrics.mcstats commit eb9d67e66b1659d6abd2397ecf403343cfeffdda Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 13:37:37 2013 -0500 Move ALL the packages! commit 8ffa9e7b75417b6c7f158613d4b4ffb783dcf2d0 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 12:37:12 2013 -0500 /r/n -> /n
2013-03-01 06:52:01 +01:00
if (event.isCancelled()) {
2013-12-02 00:43:17 +01:00
return null;
Squashed commit of the following: commit cb3e057dee1f2b29838ab654a526baac1baab7d6 Author: NuclearW <incongruency@gmail.com> Date: Fri Mar 1 00:43:57 2013 -0500 1.4.00 release commit 4f9628d2e4cde31c8946e9a911ee6f10e1fb6b35 Author: NuclearW <incongruency@gmail.com> Date: Fri Mar 1 00:07:30 2013 -0500 \r -> \n commit b2ca22e0477c747143b0f08a28a096967ee6ffd7 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 23:53:56 2013 -0500 Commented-out code shouldn't be done like that. commit 92f131712cc671e3e616c14a22e22769ef6d6d0b Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 23:45:36 2013 -0500 More things we missed. commit 408b03766f6261a03a862a1ab7f5835772feda4a Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 23:20:13 2013 -0500 Format: util through spout and backup lib commit d6bd2c29bbb51bee3607247468cfe145d4f38c9e Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 22:50:08 2013 -0500 The things we missed the first time through... commit 393f0b889aa1b7011ee81ee7b15413d8824b8cfb Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 22:05:29 2013 -0500 Formatting: Skills commit c097a6e188a7b760dd1b4389ed81dca417146b16 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:30:12 2013 -0500 Organize imports. commit 34c3e74be7eb5f983f21d969e30155c5d82c01c1 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:09:45 2013 -0500 Fixed a missing fallthrough comment from ChatCommand commit b4a76c9f022a2fd98bdd8f083accfea03becfd71 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:09:36 2013 -0500 Formatting: datatypes.* through events.* commit 3e57dd41d3265a7c8106c7eb026df926770a4d15 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:56:15 2013 -0500 Fix issue with bad rebase commit e8c8e06b2971555b7334e49128257e3af6f36892 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 17:35:32 2013 -0500 Formatting: DatabaseManager, LeaderboardManager, DatabaseUpdateType, and PlayerStat commit 13ecf1cc41f377a12991e357ac10abdcda24d6de Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:31:43 2013 -0500 Format: listeners.* through runnables.* commit 71686e3c0d96c2dcf25442b91703fadda1ea3bb0 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:13:57 2013 -0500 Format PartyLockCommand commit d50abed10bf94e1a88df3dc5cc07c259aea920ea Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 16:54:08 2013 -0500 Format: base through config.* commit 7004823eeebbae5be7728bf9cafc3b04e57b64cf Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:21:40 2013 -0500 Example of using spaces to align like things commit 534190cfe2481e466fe459d65628550458cc2993 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:12:19 2013 -0500 Capitalization commit 5b61d3ba4c8d81e6f358b0cf4f460abfe9798414 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:07:43 2013 -0500 Updated readme, added standards.md commit 5ec0df70fb82c527420a2f437f27f31bd758f884 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 14:42:16 2013 -0500 Markdown was here, Creole is a loser commit 70d557c59d086b6a5fb5e0e63c0c1d8eb4c8d19c Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 13:46:24 2013 -0500 Move MCStats shading to .metrics.mcstats commit eb9d67e66b1659d6abd2397ecf403343cfeffdda Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 13:37:37 2013 -0500 Move ALL the packages! commit 8ffa9e7b75417b6c7f158613d4b4ffb783dcf2d0 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 12:37:12 2013 -0500 /r/n -> /n
2013-03-01 06:52:01 +01:00
}
2012-04-27 11:47:11 +02:00
return location.getWorld().dropItem(location, itemStack);
2012-04-27 11:47:11 +02:00
}
2019-06-21 17:05:57 +02:00
/**
* Drop items at a given location.
*
* @param fromLocation The location to drop the items at
2019-06-21 17:05:57 +02:00
* @param is The items to drop
* @param speed the speed that the item should travel
2019-06-21 17:05:57 +02:00
* @param quantity The amount of items to drop
*/
public static void spawnItemsTowardsLocation(Location fromLocation, Location toLocation, ItemStack is, int quantity, double speed) {
2019-06-21 17:05:57 +02:00
for (int i = 0; i < quantity; i++) {
spawnItemTowardsLocation(fromLocation, toLocation, is, speed);
2019-06-21 17:05:57 +02:00
}
}
/**
* Drop an item at a given location.
* This method is fairly expensive as it creates clones of everything passed to itself since they are mutable objects
2019-06-21 17:05:57 +02:00
*
* @param fromLocation The location to drop the item at
* @param toLocation The location the item will travel towards
* @param itemToSpawn The item to spawn
* @param speed the speed that the item should travel
2019-06-21 17:05:57 +02:00
* @return Dropped Item entity or null if invalid or cancelled
*/
public static Item spawnItemTowardsLocation(Location fromLocation, Location toLocation, ItemStack itemToSpawn, double speed) {
if (itemToSpawn.getType() == Material.AIR) {
2019-06-21 17:05:57 +02:00
return null;
}
//Work with fresh copies of everything
ItemStack clonedItem = itemToSpawn.clone();
Location spawnLocation = fromLocation.clone();
Location targetLocation = toLocation.clone();
2019-06-21 17:05:57 +02:00
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(spawnLocation, clonedItem);
2019-06-21 17:05:57 +02:00
mcMMO.p.getServer().getPluginManager().callEvent(event);
//Something cancelled the event so back out
if (event.isCancelled() || event.getItemStack() == null) {
2019-06-21 17:05:57 +02:00
return null;
}
//Use the item from the event
Item spawnedItem = spawnLocation.getWorld().dropItem(spawnLocation, clonedItem);
Vector vecFrom = spawnLocation.clone().toVector().clone();
Vector vecTo = targetLocation.clone().toVector().clone();
//Vector which is pointing towards out target location
Vector direction = vecTo.subtract(vecFrom).normalize();
//Modify the speed of the vector
direction = direction.multiply(speed);
spawnedItem.setVelocity(direction);
return spawnedItem;
2019-06-21 17:05:57 +02:00
}
public static void profileCleanup(String playerName) {
Player player = mcMMO.p.getServer().getPlayerExact(playerName);
if (player != null) {
2014-02-07 18:50:04 +01:00
UserManager.remove(player);
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
}
}
2013-10-18 16:43:37 +02:00
public static void printProgress(int convertedUsers, int progressInterval, long startMillis) {
if ((convertedUsers % progressInterval) == 0) {
mcMMO.p.getLogger().info(String.format("Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / (double) ((System.currentTimeMillis() - startMillis) / TIME_CONVERSION_FACTOR)));
2013-10-18 16:43:37 +02:00
}
}
2014-08-31 19:10:49 +02:00
public static String getModName(String materialName) {
for (String mod : modNames) {
if (materialName.contains(mod)) {
return mod;
}
}
String[] materialSplit = materialName.split("_");
if (materialSplit.length > 1) {
return materialSplit[0].toLowerCase();
}
return "UnknownMods";
}
/**
* Gets a random location near the specified location
*/
public static Location getLocationOffset(Location location, double strength) {
double blockX = location.getBlockX();
double blockZ = location.getBlockZ();
double distance;
distance = strength * random.nextDouble();
blockX = (random.nextBoolean()) ? blockX + (distance) : blockX - (distance);
distance = strength * random.nextDouble();
blockZ = (random.nextBoolean()) ? blockZ + (distance) : blockZ - (distance);
return new Location(location.getWorld(), blockX, location.getY(), blockZ);
}
public static Random getRandom() {
return random;
}
2012-04-27 11:47:11 +02:00
}