mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Misc was getting crowded again.
This commit is contained in:
@ -1,14 +1,10 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Item;
|
||||
@ -17,7 +13,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
@ -60,37 +55,6 @@ public final class Misc {
|
||||
return (entity == null || entity.hasMetadata("NPC") || entity instanceof NPC || (mcMMO.isCombatTagEnabled() && entity instanceof HumanEntity && ((HumanEntity) entity).getName().contains("PvpLogger")) || entity.getClass().getName().equalsIgnoreCase("cofh.entity.PlayerFake"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upgrade tier of the item in hand.
|
||||
*
|
||||
* @param inHand The item to check the tier of
|
||||
* @return the tier of the item
|
||||
*/
|
||||
public static int getTier(ItemStack inHand) {
|
||||
int tier = 0;
|
||||
|
||||
if (ItemUtils.isWoodTool(inHand)) {
|
||||
tier = 1;
|
||||
}
|
||||
else if (ItemUtils.isStoneTool(inHand)) {
|
||||
tier = 2;
|
||||
}
|
||||
else if (ItemUtils.isIronTool(inHand)) {
|
||||
tier = 3;
|
||||
}
|
||||
else if (ItemUtils.isGoldTool(inHand)) {
|
||||
tier = 1;
|
||||
}
|
||||
else if (ItemUtils.isDiamondTool(inHand)) {
|
||||
tier = 4;
|
||||
}
|
||||
else if (ModUtils.isCustomTool(inHand)) {
|
||||
tier = ModUtils.getToolFromItemStack(inHand).getTier();
|
||||
}
|
||||
|
||||
return tier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if two locations are near each other.
|
||||
*
|
||||
@ -200,74 +164,6 @@ public final class Misc {
|
||||
}
|
||||
}
|
||||
|
||||
public static void resendChunkRadiusAt(Player player, int radius) {
|
||||
Chunk chunk = player.getLocation().getChunk();
|
||||
int chunkX = chunk.getX();
|
||||
int chunkZ = chunk.getZ();
|
||||
|
||||
for (int x = chunkX - radius; x < chunkX + radius; x++) {
|
||||
for (int z = chunkZ - radius; z < chunkZ + radius; z++) {
|
||||
player.getWorld().refreshChunk(x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to match any player names with the given name, and returns a list of all possibly matches.
|
||||
*
|
||||
* This list is not sorted in any particular order.
|
||||
* If an exact match is found, the returned list will only contain a single result.
|
||||
*
|
||||
* @param partialName Name to match
|
||||
* @return List of all possible names
|
||||
*/
|
||||
public static List<String> matchPlayer(String partialName) {
|
||||
List<String> matchedPlayers = new ArrayList<String>();
|
||||
|
||||
for (OfflinePlayer offlinePlayer : mcMMO.p.getServer().getOfflinePlayers()) {
|
||||
String playerName = offlinePlayer.getName();
|
||||
|
||||
if (partialName.equalsIgnoreCase(playerName)) {
|
||||
// Exact match
|
||||
matchedPlayers.clear();
|
||||
matchedPlayers.add(playerName);
|
||||
break;
|
||||
}
|
||||
if (playerName.toLowerCase().contains(partialName.toLowerCase())) {
|
||||
// Partial match
|
||||
matchedPlayers.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
return matchedPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a matched player name if one was found in the database.
|
||||
*
|
||||
* @param partialName Name to match
|
||||
*
|
||||
* @return Matched name or {@code partialName} if no match was found
|
||||
*/
|
||||
public static String getMatchedPlayerName(String partialName) {
|
||||
if (Config.getInstance().getMatchOfflinePlayers()) {
|
||||
List<String> matches = matchPlayer(partialName);
|
||||
|
||||
if (matches.size() == 1) {
|
||||
partialName = matches.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
Player player = mcMMO.p.getServer().getPlayer(partialName);
|
||||
if (player != null) {
|
||||
partialName = player.getName();
|
||||
}
|
||||
}
|
||||
|
||||
return partialName;
|
||||
}
|
||||
|
||||
public static Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
@ -219,4 +220,60 @@ public final class CommandUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a matched player name if one was found in the database.
|
||||
*
|
||||
* @param partialName Name to match
|
||||
*
|
||||
* @return Matched name or {@code partialName} if no match was found
|
||||
*/
|
||||
public static String getMatchedPlayerName(String partialName) {
|
||||
if (Config.getInstance().getMatchOfflinePlayers()) {
|
||||
List<String> matches = matchPlayer(partialName);
|
||||
|
||||
if (matches.size() == 1) {
|
||||
partialName = matches.get(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Player player = mcMMO.p.getServer().getPlayer(partialName);
|
||||
|
||||
if (player != null) {
|
||||
partialName = player.getName();
|
||||
}
|
||||
}
|
||||
|
||||
return partialName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to match any player names with the given name, and returns a list of all possibly matches.
|
||||
*
|
||||
* This list is not sorted in any particular order.
|
||||
* If an exact match is found, the returned list will only contain a single result.
|
||||
*
|
||||
* @param partialName Name to match
|
||||
* @return List of all possible names
|
||||
*/
|
||||
private static List<String> matchPlayer(String partialName) {
|
||||
List<String> matchedPlayers = new ArrayList<String>();
|
||||
|
||||
for (OfflinePlayer offlinePlayer : mcMMO.p.getServer().getOfflinePlayers()) {
|
||||
String playerName = offlinePlayer.getName();
|
||||
|
||||
if (partialName.equalsIgnoreCase(playerName)) {
|
||||
// Exact match
|
||||
matchedPlayers.clear();
|
||||
matchedPlayers.add(playerName);
|
||||
break;
|
||||
}
|
||||
|
||||
if (playerName.toLowerCase().contains(partialName.toLowerCase())) {
|
||||
// Partial match
|
||||
matchedPlayers.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
return matchedPlayers;
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ public final class CombatUtils {
|
||||
* @param type The type of skill being used
|
||||
*/
|
||||
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, SkillType type) {
|
||||
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); // The higher the weapon tier, the more targets you hit
|
||||
int numberOfTargets = getTier(attacker.getItemInHand()); // The higher the weapon tier, the more targets you hit
|
||||
double damageAmount = Math.max(damage, 1);
|
||||
|
||||
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
||||
@ -581,4 +581,35 @@ public final class CombatUtils {
|
||||
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upgrade tier of the item in hand.
|
||||
*
|
||||
* @param inHand The item to check the tier of
|
||||
* @return the tier of the item
|
||||
*/
|
||||
private static int getTier(ItemStack inHand) {
|
||||
int tier = 0;
|
||||
|
||||
if (ItemUtils.isWoodTool(inHand)) {
|
||||
tier = 1;
|
||||
}
|
||||
else if (ItemUtils.isStoneTool(inHand)) {
|
||||
tier = 2;
|
||||
}
|
||||
else if (ItemUtils.isIronTool(inHand)) {
|
||||
tier = 3;
|
||||
}
|
||||
else if (ItemUtils.isGoldTool(inHand)) {
|
||||
tier = 1;
|
||||
}
|
||||
else if (ItemUtils.isDiamondTool(inHand)) {
|
||||
tier = 4;
|
||||
}
|
||||
else if (ModUtils.isCustomTool(inHand)) {
|
||||
tier = ModUtils.getToolFromItemStack(inHand).getTier();
|
||||
}
|
||||
|
||||
return tier;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user