Repository reorganisation

Unified kotlin and java into just src/main
Unified the rs09 and core packages
Took all content out of the core package, and placed it into the new content package
Reorganised all source code relating to content to be easier to find and explore
This commit is contained in:
Ceikry
2023-01-26 13:59:28 +00:00
committed by Ryan
parent e4b799c44a
commit a100affda2
3156 changed files with 24205 additions and 30585 deletions
+23
View File
@@ -0,0 +1,23 @@
package core.tools;
public class CP1252 {
private static char[] charMap = {'\u20ac', '\0', '\u201a', '\u0192', '\u201e', '\u2026', '\u2020', '\u2021',
'\u02c6', '\u2030', '\u0160', '\u2039', '\u0152', '\0', '\u017d', '\0', '\0', '\u2018', '\u2019',
'\u201c', '\u201d', '\u2022', '\u2013', '\u2014', '\u02dc', '\u2122', '\u0161', '\u203a', '\u0153',
'\0', '\u017e', '\u0178'};
public static char getFromByte(byte value) {
int out = value & 0xff;
if (out == 0) {
throw new IllegalArgumentException("Non cp1252 character 0x" + Integer.toString(out, 16) + " provided");
}
if (out >= 128 && out < 160) {
int cp1252 = charMap[out - 128];
if (cp1252 == 0) {
cp1252 = 63;
}
out = cp1252;
}
return (char) out;
}
}
@@ -0,0 +1,9 @@
package core.tools
const val START_DIALOGUE = 0
const val END_DIALOGUE = 1000000
/**
* Stage gets set to this by the sendChoices() method if there's more than one option a player can pick when starting a conversation. I.E. multiple simultaneous quests.
*/
const val DIALOGUE_INITIAL_OPTIONS_HANDLE = 1001
+60
View File
@@ -0,0 +1,60 @@
package core.tools
const val RED = "<col=ff0000>"
const val ORANGE = "<col=ff6600>"
const val YELLOW = "<col=ffff00>"
const val GREEN = "<col=66ff33>"
const val BLUE = "<col=3366ff>"
const val PURPLE = "<col=cc00ff>"
fun colorize(line: String): String{
val new = line.replace("%R", RED)
.replace("%O", ORANGE)
.replace("%Y", YELLOW)
.replace("%G", GREEN)
.replace("%B", BLUE)
.replace("%P", PURPLE).append("</col>") + " "
return new
}
fun colorize(line: String, hexColor: String): String{
return line.prepend("<col=$hexColor>").append("</col>")
}
fun String.append(line: String): String{
return this + line
}
fun String.prepend(line: String): String{
return line + this
}
fun String.shuffle(): String{
var new = ""
val old = this.split("").toMutableList()
for(i in this.indices){
val c = old.random()
new += c.toString()
old.remove(c)
}
return new
}
/**
* Prepends 'a' or 'an' to a noun depending on whether it starts with a vowel.
* @author bushtail
* @param noun the noun to check grammar rules against.
* @return either 'a $noun' or 'an $noun' depending on the first letter.
*/
fun prependArticle(noun : String) : String {
if(noun == null) return noun
val exceptions = hashMapOf("unicorn" to "a", "herb" to "an", "hour" to "an")
if(exceptions.contains(noun.lowercase())) {
return "${exceptions[noun.lowercase()]} $noun"
}
return when(noun[0]) {
'a', 'e', 'i', 'o', 'u' -> "an $noun"
else -> "a $noun"
}
}
@@ -0,0 +1,41 @@
package core.tools;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.info.PlayerDetails;
import core.game.node.entity.player.info.login.PlayerParser;
/**
* Represents a class that is used to load a player, or details of it.
*
* @author 'Vexia
*/
public final class PlayerLoader {
/**
* Method used to load the player file.
*
* @param name the name.
* @return the player.
*/
public static Player getPlayerFile(String name) {
final PlayerDetails playerDetails = new PlayerDetails(name);
//playerDetails.parse();
final Player player = new Player(playerDetails);
PlayerParser.parse(player);
// GameWorld.getWorld().getAccountService().loadPlayer(player);
return player;
}
/**
* Method used to load the player details file.
*
* @param name the name.
* @return the details
*/
public static PlayerDetails getPlayerDetailFile(String name) {
final PlayerDetails playerDetails = new PlayerDetails(name);
// playerDetails.parse();
return playerDetails;
}
}
+56
View File
@@ -0,0 +1,56 @@
package core.tools;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
/**
* A class to generate a simple 1024 bit RSA pair
* @author Nikki
*/
public class RSAKeyGen {
public static void main(String[] args) {
try {
KeyFactory factory = KeyFactory.getInstance("RSA");
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey privateKey = keypair.getPrivate();
PublicKey publicKey = keypair.getPublic();
RSAPrivateKeySpec privSpec = factory.getKeySpec(privateKey, RSAPrivateKeySpec.class);
writeKey("rsapriv", privSpec.getModulus(), privSpec.getPrivateExponent());
RSAPublicKeySpec pubSpec = factory.getKeySpec(publicKey, RSAPublicKeySpec.class);
writeKey("rsapub", pubSpec.getModulus(), pubSpec.getPublicExponent());
} catch(Exception e) {
e.printStackTrace();
}
}
public static void writeKey(String file, BigInteger modulus, BigInteger exponent) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write("private static final BigInteger RSA_MODULUS = new BigInteger(\""+modulus.toString()+"\");");
writer.newLine();
writer.newLine();
writer.write("private static final BigInteger RSA_EXPONENT = new BigInteger(\""+exponent.toString()+"\");");
writer.newLine();
writer.flush();
writer.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,300 @@
package core.tools;
import core.game.node.entity.npc.drop.DropFrequency;
import core.game.node.item.ChanceItem;
import core.game.node.item.Item;
import core.game.node.item.WeightedChanceItem;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Represents a class used for random methods.
* @author Vexia
*/
public class RandomFunction {
/**
* The random instance.
*/
public static final Random RANDOM = new Random();
/**
* Method used to ease the access of the random class.
* @param a the minimum random value.
* @param b the maximum random value.
* @return the value as an {@link Double}.
*/
public static final double random(double a, double b) {
final double min = Math.min(a, b);
final double max = Math.max(a, b);
return min + (max - min) * RANDOM.nextDouble();
}
/**
* Method used to ease the access of the random class.
* @param a the minimum random value.
* @param b the maximum random value.
* @return the value as an {@link Integer}.
*/
public static final int random(int a, int b) {
final int n = Math.abs(b - a);
return Math.min(a, b) + (n == 0 ? 0 : random(n));
}
/**
* Method to roll for a random 1/X chance
* @param chance the 1/chance rate for the roll to succeed
* @return true if you hit the roll, false otherwise
*/
public static boolean roll(int chance){
return random(chance + 1) == chance / 2;
}
/**
* Calculates the chance of succeeding at a skilling event
* @param low - Success chance at level 1
* @param high - Success chance at level 99
* @param level - Level required
* @return percent chance of success
*/
public static double getSkillSuccessChance(double low, double high, int level) {
// 99 & 98 numbers should *not* be adjusted for level cap > 99
int value = (int)(Math.floor(low*( (99-level)/98.0 ) ) + Math.floor(high*((level-1)/98.0)) + 1);
return Math.min(Math.max(value / 256D, 0), 1) * 100.0;
}
/**
* Returns either the supplied integer, or -1 times the supplied integer.
* @param value the value.
* @return the integer.
*/
public static int randomSign(int value) {
return RANDOM.nextBoolean() ? value : -value;
}
/**
* Method used to return the integer.
* @param maxValue the value.
* @return the value.
*/
public static final int getRandom(int maxValue) {
return (int) (Math.random() * (maxValue + 1));
}
/**
* Method used to return the random double.
* @param maxValue the value.
* @return the double.
*/
public static final double getRandomDouble(double maxValue) {
return (Math.random() * (maxValue + 1));
}
/**
* Method used to ease the access of the random class.
* @param maxValue the maximum value.
* @return the random integer.
*/
public static final int random(int maxValue) {
if (maxValue <= 0) {
return 0;
}
return RANDOM.nextInt(maxValue);
}
public static final double randomDouble(double maxValue) {
return ThreadLocalRandom.current().nextDouble(0.0,maxValue);
}
public static final double randomDouble(double min, double max){
return ThreadLocalRandom.current().nextDouble(min,max);
}
public static int nextInt(int val)
{
return random(val);
}
/**
* Generates a random number with a distrobution like:
* Where intensity is how intense the peak is (higher = more steep)
* *
* * *
* * *
* * * * *
* * * * * *
*/
public static int normalRandDist(int max, int intensity) {
int sum = 0;
for (int j = 0; j < intensity; j++) {
sum += RANDOM.nextInt(max);
}
return sum/intensity;
}
/**
* Generates a random number with a distribution like:
* *
* * *
* * *
* * * * *
* * * * * *
*/
public static int normalRandDist(int max) {
return (RANDOM.nextInt(max) + RANDOM.nextInt(max))/2;
}
/**
* Generates a random number with a distribution like:
*
* *
* *
* *
* *
* See some results: https://www.desmos.com/calculator/clzv66l7hk
*/
public static int linearDecreaseRand(int max) {
double seed = RANDOM.nextDouble();
double modifier = RANDOM.nextDouble();
return (int) (seed*modifier*max);
}
/**
* Generates a random number likely in the area above val (I think)
*/
public static int normalPlusWeightRandDist(int val, int weight)
{
int normalDistRand = (RANDOM.nextInt(val) + RANDOM.nextInt(val))/2;
return normalDistRand/2 + weight < val ? normalDistRand/2 + weight : normalPlusWeightRandDist(val, weight - 1);
}
/**
* Gets a chance item.
* @param items the items.
* @return the chance.
*/
public static final ChanceItem getChanceItem(final ChanceItem[] items) {
double total = 0;
for (ChanceItem i : items) {
total += i.getChanceRate();
}
final int random = random((int) total);
double subTotal = 0;
List<ChanceItem> choices = new ArrayList<>(20);
for (ChanceItem item : items) {
choices.add(item);
}
Collections.shuffle(choices);
for (ChanceItem i : choices) {
subTotal += i.getChanceRate();
if (random < subTotal) {
return i;
}
}
return null;
}
public static List<Item> rollChanceTable(boolean atLeastOne,List<ChanceItem> table){
final List<Item> rewards = new ArrayList<>(20);
final List<Item> always_rewards = new ArrayList<>(20);
final List<ChanceItem> chanceTable = new ArrayList<ChanceItem>(table);
boolean isAllAlways = false;
if(table.stream().filter(item -> item.getChanceRate() == 1).count() == table.size()){
isAllAlways = true;
}
if(table.size() == 1){
atLeastOne = false;
}
if(!isAllAlways) {
if (atLeastOne) {
while (rewards.isEmpty()) {
Collections.shuffle(chanceTable);
for (ChanceItem item : chanceTable) {
if (item.getChanceRate() == 0.0) {
item.setChanceRate(DropFrequency.rate(item.getDropFrequency()));
}
boolean roll = RandomFunction.random(1, (int) item.getChanceRate()) == 1;
if (item.getChanceRate() != 1) {
if (roll) {
rewards.add(item.getRandomItem());
break;
}
}
}
}
} else {
Collections.shuffle(chanceTable);
for (ChanceItem item : chanceTable) {
if (item.getChanceRate() == 0.0) {
item.setChanceRate(DropFrequency.rate(item.getDropFrequency()));
}
boolean roll = RandomFunction.random(1, (int) item.getChanceRate()) == 1;
if (item.getChanceRate() != 1) {
if (roll) {
rewards.add(item.getRandomItem());
break;
}
}
}
}
}
table.stream().filter(item -> item.getChanceRate() == 1).forEach(item -> {
if(item.getChanceRate() == 0.0){
item.setChanceRate(DropFrequency.rate(item.getDropFrequency()));
}
always_rewards.add(item.getRandomItem());
});
return Stream.concat(rewards.stream(),always_rewards.stream()).collect(Collectors.toList());
}
public static List<Item> rollChanceTable(boolean atLeastOne,ChanceItem... table){
return rollChanceTable(atLeastOne, Arrays.asList(table));
}
public static Item rollWeightedChanceTable(WeightedChanceItem... table){
return rollWeightedChanceTable(new ArrayList<>(Arrays.asList(table)));
}
public static Item rollWeightedChanceTable(List<WeightedChanceItem> table){
int sumOfWeights = table.stream().mapToInt(item -> item.weight).sum();
int rand = random(sumOfWeights);
Collections.shuffle(table);
for(WeightedChanceItem item : table){
if(rand <= item.weight)
return item.getItem();
rand -= item.weight;
}
//We should get here if and only if the weighted chance table is empty.
//System.out.println("ERROR ROLLING WEIGHTED CHANCE: WEIGHT SUM AND INDIVIDUAL WEIGHTS DO NOT MATCH!!");
return null;
}
/**
* Gets a random value from the array.
* @param array The array.
* @return A random element of the array.
*/
public static <T> T getRandomElement(T[] array) {
return (T) array[randomize(array.length)];
}
/**
* Randomizes the value.
* @param value the value to randomize.
* @return The random value.
*/
public static int randomize(int value) {
if (value < 1) {
return 0;
}
return RANDOM.nextInt(value);
}
public static boolean nextBool() {
return RANDOM.nextBoolean();
}
}
+593
View File
@@ -0,0 +1,593 @@
package core.tools;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
import core.net.packet.IoBuffer;
/**
* The string utils.
* @author Emperor
*/
public final class StringUtils {
/**
* The valid characters to be used in names/messages/...
*/
public static final char[] VALID_CHARS = { '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
/**
* Character mapping.
*/
public static char[] mapping = { '\n', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ' };
/**
* The an int array241.
*/
public static int[] anIntArray241 = { 215, 203, 83, 158, 104, 101, 93, 84, 107, 103, 109, 95, 94, 98, 89, 86, 70, 41, 32, 27, 24, 23, -1, -2, 26, -3, -4, 31, 30, -5, -6, -7, 37, 38, 36, -8, -9, -10, 40, -11, -12, 55, 48, 46, 47, -13, -14, -15, 52, 51, -16, -17, 54, -18, -19, 63, 60, 59, -20, -21, 62, -22, -23, 67, 66, -24, -25, 69, -26, -27, 199, 132, 80, 77, 76, -28, -29, 79, -30, -31, 87, 85, -32, -33, -34, -35, -36, 197, -37, 91, -38, 134, -39, -40, -41, 97, -42, -43, 133, 106, -44, 117, -45, -46, 139, -47, -48, 110, -49, -50, 114, 113, -51, -52, 116, -53, -54, 135, 138, 136, 129, 125, 124, -55, -56, 130, 128, -57, -58, -59, 183, -60, -61, -62, -63, -64, 148, -65, -66, 153, 149, 145, 144, -67, -68, 147, -69, -70, -71, 152, 154, -72, -73, -74, 157, 171, -75, -76, 207, 184, 174, 167, 166, 165, -77, -78, -79, 172, 170, -80, -81, -82, 178, -83, 177, 182, -84, -85, 187, 181, -86, -87, -88, -89, 206, 221, -90, 189, -91, 198, 254, 262, 195, 196, -92, -93, -94, -95, -96, 252, 255, 250, -97, 211, 209, -98, -99, 212, -100, 213, -101, -102, -103, 224, -104, 232, 227, 220, 226, -105, -106, 246, 236, -107, 243, -108, -109, 231, 237, 235, -110, -111, 239, 238, -112, -113, -114, -115, -116, 241, -117, 244, -118, -119, 248, -120, 249, -121, -122, -123, 253, -124, -125, -126, -127, 259, 258, -128, -129, 261, -130, -131, 390, 327, 296, 281, 274, 271, 270, -132, -133, 273, -134, -135, 278, 277, -136, -137, 280, -138, -139, 289, 286, 285, -140, -141, 288, -142, -143, 293, 292, -144, -145, 295, -146, -147, 312, 305, 302, 301, -148, -149, 304, -150, -151, 309, 308, -152, -153, 311, -154, -155, 320, 317, 316, -156, -157, 319, -158, -159, 324, 323, -160, -161, 326, -162, -163, 359, 344, 337, 334, 333, -164, -165, 336, -166, -167, 341, 340, -168, -169, 343, -170, -171, 352, 349, 348, -172, -173, 351, -174, -175, 356, 355, -176, -177, 358, -178, -179, 375, 368, 365, 364, -180, -181, 367, -182, -183, 372, 371, -184, -185, 374, -186, -187, 383, 380, 379, -188, -189, 382, -190, -191, 387, 386, -192, -193, 389, -194, -195, 454, 423, 408, 401, 398, 397, -196, -197, 400, -198, -199, 405, 404, -200, -201, 407, -202, -203, 416, 413, 412, -204, -205, 415, -206, -207, 420, 419, -208, -209, 422, -210, -211, 439, 432, 429, 428, -212, -213, 431, -214, -215, 436, 435, -216, -217, 438, -218, -219, 447, 444, 443, -220, -221, 446, -222, -223, 451, 450, -224, -225, 453, -226, -227, 486, 471, 464, 461, 460, -228, -229, 463, -230, -231, 468, 467, -232, -233, 470, -234, -235, 479, 476, 475, -236, -237, 478, -238, -239, 483, 482, -240, -241, 485, -242, -243, 499, 495, 492, 491, -244, -245, 494, -246, -247, 497, -248, 502, -249, 506, 503, -250, -251, 505, -252, -253, 508, -254, 510, -255, -256, 0 };
/**
* Constructs a new {@code StringUtils.java} {@code Object}.
*/
public StringUtils() {
/**
* empty.
*/
}
/**
* Method used to get the formatted number as a string from the integer
* inputed.
* @param amount the ammount.
* @return the string value.
*/
public static String getFormattedNumber(int amount) {
return new DecimalFormat("#,###,##0").format(amount).toString();
}
/**
* Checks if the string contains an invalid character.
* @param name The string.
* @return {@code True} if so.
*/
public static boolean containsInvalidCharacter(String name) {
boolean pass = false;
for (char c : name.toCharArray()) {
for (char vc : VALID_CHARS) {
if (vc == c) {
pass = true;
break;
}
}
if (!pass) {
return true;
}
}
return false;
}
/**
* If a word starts with a e i o u h for grammar = a + n.
* @param word The word.
* @return If the a should have +n {@code true}.
*/
public static boolean isPlusN(String word) {
if (word == null)
return false;
String s = word.toLowerCase();
return s.charAt(0) == 'a' || s.charAt(0) == 'e' || s.charAt(0) == 'i' || s.charAt(0) == 'o' || s.charAt(0) == 'u' || (s.charAt(0) == 'h' && s.length() > 1 && s.charAt(1) != 'e');
}
/**
* Adds an s to make a world plural.
* @param word the word
* @return the plural word
*/
public static String plusS(String word) {
if (word == null) {
return null;
}
if (word.endsWith("s")) {
return word;
}
if (word.endsWith("y")) {
return word.substring(0, word.length() - 1) + "ies";
}
return word + "s";
}
/**
* Method used to get the player name as a long.
* @param s the string.
* @return the long.
*/
public static long getPlayerNameLong(String s) {
long l = 0L;
for (int i = 0; i < s.length() && i < 12; i++) {
char c = s.charAt(i);
l *= 37L;
if (c >= 'A' && c <= 'Z')
l += (1 + c) - 65;
else if (c >= 'a' && c <= 'z')
l += (1 + c) - 97;
else if (c >= '0' && c <= '9')
l += (27 + c) - 48;
}
while (l % 37L == 0L && l != 0L)
l /= 37L;
return l;
}
/**
* Method used to convert the string to a long.
* @param s the string.
* @return the long.
*/
public static long convertStringToLong(String s) {
if (s.length() > 20) {
throw new IllegalArgumentException("String is too long: " + s);
}
long out = 0L;
for (int i = 0; i < s.length(); ++i) {
long m = reducedMapping(s.codePointAt(i));
if (m == -1) {
throw new IllegalArgumentException("Unmapped Character in String: " + s);
}
m <<= ((9 - i) * 6) + 4;
out |= m;
}
return out;
}
/**
* Formats the string as display name.
* @param name The string to format.
* @return The formatted name.
*/
public static String formatDisplayName(String name) {
name = name.replaceAll("_", " ");
name = name.toLowerCase();
StringBuilder newName = new StringBuilder();
boolean wasSpace = true;
for (int i = 0; i < name.length(); i++) {
if (wasSpace) {
newName.append((new String() + name.charAt(i)).toUpperCase());
wasSpace = false;
} else {
newName.append(name.charAt(i));
}
if (name.charAt(i) == ' ') {
wasSpace = true;
}
}
return newName.toString();
}
/**
* Gets the byte for the character.
* @param c The character.
* @return The byte.
*/
private static final byte getByte(char c) {
byte charByte;
if (c > 0 && c < '\200' || c >= '\240' && c <= '\377')
charByte = (byte) c;
else if (c != '\u20AC') {
if (c != '\u201A') {
if (c != '\u0192') {
if (c == '\u201E')
charByte = -124;
else if (c != '\u2026') {
if (c != '\u2020') {
if (c == '\u2021')
charByte = -121;
else if (c == '\u02C6')
charByte = -120;
else if (c == '\u2030')
charByte = -119;
else if (c == '\u0160')
charByte = -118;
else if (c == '\u2039')
charByte = -117;
else if (c == '\u0152')
charByte = -116;
else if (c != '\u017D') {
if (c == '\u2018')
charByte = -111;
else if (c != '\u2019') {
if (c != '\u201C') {
if (c == '\u201D')
charByte = -108;
else if (c != '\u2022') {
if (c == '\u2013')
charByte = -106;
else if (c == '\u2014')
charByte = -105;
else if (c == '\u02DC')
charByte = -104;
else if (c == '\u2122')
charByte = -103;
else if (c != '\u0161') {
if (c == '\u203A')
charByte = -101;
else if (c != '\u0153') {
if (c == '\u017E')
charByte = -98;
else if (c != '\u0178')
charByte = 63;
else
charByte = -97;
} else
charByte = -100;
} else
charByte = -102;
} else
charByte = -107;
} else
charByte = -109;
} else
charByte = -110;
} else
charByte = -114;
} else
charByte = -122;
} else
charByte = -123;
} else
charByte = -125;
} else
charByte = -126;
} else
charByte = -128;
return charByte;
}
/**
* Gets the double value of this string
* @param s The string.
* @return The double value.
*/
public static double getDouble(String s) {
s = s.replaceAll(", ", "").replaceAll(",", "");
StringBuilder sb = new StringBuilder();
char c;
boolean foundStart = false;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if (Character.isDigit(c) || c == '-' || c == '.') {
sb.append(c);
foundStart = true;
} else if (foundStart)
break;
}
try {
double amount = Double.parseDouble(sb.toString());
return amount;
} catch (NumberFormatException e) {
return 0.0;
}
}
public static String[] splitIntoLine(String input, int maxCharInLine) {
StringTokenizer tok = new StringTokenizer(input, " ");
StringBuilder output = new StringBuilder(input.length());
int lineLen = 0;
while (tok.hasMoreTokens()) {
String word = tok.nextToken();
while (word.length() > maxCharInLine) {
output.append(word.substring(0, maxCharInLine - lineLen) + "\n");
word = word.substring(maxCharInLine - lineLen);
lineLen = 0;
}
if (lineLen + word.length() > maxCharInLine) {
output.append("\n");
lineLen = 0;
}
output.append(word + " ");
lineLen += word.length() + 1;
}
// output.split();
// return output.toString();
return output.toString().split("\n");
}
/**
* Gets the hash for the string.
* @param str The string.
* @return The hash.
*/
public static final int getNameHash(String str) {
str = str.toLowerCase();
int hash = 0;
for (int index = 0; index < str.length(); index++)
hash = getByte(str.charAt(index)) + ((hash << 5) - hash);
return hash;
}
/**
* Gets the string value of this string (all html/... removed).
* @param s The string.
* @return The string value.
*/
public static String getString(String s) {
String string = s.replaceAll("\\<.*?>", "").replaceAll("&#160;", "").replaceAll("Discontinued Item:", "");
return string;
}
/**
* Characters used to convert a String to a Long.
*/
public static char[] validChars = { '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
public static int[] anIntArray233 = { 0, 1024, 2048, 3072, 4096, 5120, 6144, 8192, 9216, 12288, 10240, 11264, 16384, 18432, 17408, 20480, 21504, 22528, 23552, 24576, 25600, 26624, 27648, 28672, 29696, 30720, 31744, 32768, 33792, 34816, 35840, 36864, 536870912, 16777216, 37888, 65536, 38912, 131072, 196608, 33554432, 524288, 1048576, 1572864, 262144, 67108864, 4194304, 134217728, 327680, 8388608, 2097152, 12582912, 13631488, 14680064, 15728640, 100663296, 101187584, 101711872, 101974016, 102760448, 102236160, 40960, 393216, 229376, 117440512, 104857600, 109051904, 201326592, 205520896, 209715200, 213909504, 106954752, 218103808, 226492416, 234881024, 222298112, 224395264, 268435456, 272629760, 276824064, 285212672, 289406976, 223346688, 293601280, 301989888, 318767104, 297795584, 298844160, 310378496, 102498304, 335544320, 299892736, 300941312, 301006848, 300974080, 39936, 301465600, 49152, 1073741824, 369098752, 402653184, 1342177280, 1610612736, 469762048, 1476395008, -2147483648, -1879048192, 352321536, 1543503872, -2013265920, -1610612736, -1342177280, -1073741824, -1543503872, 356515840, -1476395008, -805306368, -536870912, -268435456, 1577058304, -134217728, 360710144, -67108864, 364904448, 51200, 57344, 52224, 301203456, 53248, 54272, 55296, 56320, 301072384, 301073408, 301074432, 301075456, 301076480, 301077504, 301078528, 301079552, 301080576, 301081600, 301082624, 301083648, 301084672, 301085696, 301086720, 301087744, 301088768, 301089792, 301090816, 301091840, 301092864, 301093888, 301094912, 301095936, 301096960, 301097984, 301099008, 301100032, 301101056, 301102080, 301103104, 301104128, 301105152, 301106176, 301107200, 301108224, 301109248, 301110272, 301111296, 301112320, 301113344, 301114368, 301115392, 301116416, 301117440, 301118464, 301119488, 301120512, 301121536, 301122560, 301123584, 301124608, 301125632, 301126656, 301127680, 301128704, 301129728, 301130752, 301131776, 301132800, 301133824, 301134848, 301135872, 301136896, 301137920, 301138944, 301139968, 301140992, 301142016, 301143040, 301144064, 301145088, 301146112, 301147136, 301148160, 301149184, 301150208, 301151232, 301152256, 301153280, 301154304, 301155328, 301156352, 301157376, 301158400, 301159424, 301160448, 301161472, 301162496, 301163520, 301164544, 301165568, 301166592, 301167616, 301168640, 301169664, 301170688, 301171712, 301172736, 301173760, 301174784, 301175808, 301176832, 301177856, 301178880, 301179904, 301180928, 301181952, 301182976, 301184000, 301185024, 301186048, 301187072, 301188096, 301189120, 301190144, 301191168, 301193216, 301195264, 301194240, 301197312, 301198336, 301199360, 301201408, 301202432 };
public static byte[] aByteArray235 = { 22, 22, 22, 22, 22, 22, 21, 22, 22, 20, 22, 22, 22, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 3, 8, 22, 16, 22, 16, 17, 7, 13, 13, 13, 16, 7, 10, 6, 16, 10, 11, 12, 12, 12, 12, 13, 13, 14, 14, 11, 14, 19, 15, 17, 8, 11, 9, 10, 10, 10, 10, 11, 10, 9, 7, 12, 11, 10, 10, 9, 10, 10, 12, 10, 9, 8, 12, 12, 9, 14, 8, 12, 17, 16, 17, 22, 13, 21, 4, 7, 6, 5, 3, 6, 6, 5, 4, 10, 7, 5, 6, 4, 4, 6, 10, 5, 4, 4, 5, 7, 6, 10, 6, 10, 22, 19, 22, 14, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 21, 22, 21, 22, 22, 22, 21, 22, 22 };
/**
* Encrypt a string for the client.
*/
public static int encryptPlayerChat(byte[] is, int i_25_, int i_26_, int i_27_, byte[] is_28_) {
try {
i_27_ += i_25_;
int i_29_ = 0;
int i_30_ = i_26_ << 3;
for (; i_27_ > i_25_; i_25_++) {
int i_31_ = 0xff & is_28_[i_25_];
int i_32_ = anIntArray233[i_31_];
int i_33_ = aByteArray235[i_31_];
int i_34_ = i_30_ >> 3;
int i_35_ = i_30_ & 0x7;
i_29_ &= (-i_35_ >> 31);
i_30_ += i_33_;
int i_36_ = ((-1 + (i_35_ - -i_33_)) >> 3) + i_34_;
i_35_ += 24;
is[i_34_] = (byte) (i_29_ = (i_29_ | (i_32_ >>> i_35_)));
if ((i_36_ ^ 0xffffffff) < (i_34_ ^ 0xffffffff)) {
i_34_++;
i_35_ -= 8;
is[i_34_] = (byte) (i_29_ = i_32_ >>> i_35_);
if (i_36_ > i_34_) {
i_34_++;
i_35_ -= 8;
is[i_34_] = (byte) (i_29_ = i_32_ >>> i_35_);
if (i_36_ > i_34_) {
i_35_ -= 8;
i_34_++;
is[i_34_] = (byte) (i_29_ = i_32_ >>> i_35_);
if (i_34_ < i_36_) {
i_35_ -= 8;
i_34_++;
is[i_34_] = (byte) (i_29_ = i_32_ << -i_35_);
}
}
}
}
}
return -i_26_ + ((7 + i_30_) >> 3);
} catch (RuntimeException runtimeexception) {
}
return 0;
}
/**
* Gets an integer value from a string.
* @param s the string.
* @return The value;
*/
public static int getValue(String s) {
s = s.replaceAll(", ", "").replaceAll(",", "");
StringBuilder sb = new StringBuilder();
char c;
boolean foundStart = false;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if (Character.isDigit(c) || c == '-') {
sb.append(c);
foundStart = true;
} else if (foundStart)
break;
}
try {
int amount = Integer.parseInt(sb.toString());
return amount;
} catch (NumberFormatException e) {
return 0;
}
}
/**
* Checks if the account name is valid.
* @param name The account name.
* @return {@code True} if the account name is invalid.
*/
public static boolean invalidAccountName(String name) {
return name.length() > 12 || name.startsWith("_") || name.endsWith("_") || name.contains("__") || containsInvalidCharacter(name);
}
/**
* Converts a long to a string.
* @param l The long.
* @return The string.
*/
public static String longToString(long l) {
int i = 0;
char ac[] = new char[32];
while (l != 0L) {
long l1 = l;
l /= 37L;
ac[11 - i++] = VALID_CHARS[(int) (l1 - l * 37L)];
}
return new String(ac, 12 - i, i);
}
/**
* Packs a GJ2-String.
* @param position The position to start.
* @param buffer The byte-array.
* @param str The string.
* @return The size of the string.
*/
public static final int packGJString2(int position, byte[] buffer, String str) {
int length = str.length();
int offset = position;
for (int index = 0; length > index; index++) {
int character = str.charAt(index);
if (character > 127) {
if (character > 2047) {
buffer[offset++] = (byte) ((character | 919275) >> 12);
buffer[offset++] = (byte) (128 | ((character >> 6) & 63));
buffer[offset++] = (byte) (128 | (character & 63));
} else {
buffer[offset++] = (byte) ((character | 12309) >> 6);
buffer[offset++] = (byte) (128 | (character & 63));
}
} else
buffer[offset++] = (byte) character;
}
return offset - position;
}
/**
* Method used to...
* @param x idk,
* @return the idk.
*/
public static long reducedMapping(int x) {
long out = -1;
if (x >= 97 && x <= 122)
out = x - 96;
else if (x >= 65 && x <= 90)
out = x - 37;
else if (x >= 48 && x <= 57)
out = x - +5;
else if (x == 32)
out = 63L;
return out;
}
/**
* Converts a string to a long.
* @param s The string.
* @return The long.
*/
public static long stringToLong(String s) {
long l = 0L;
for (int i = 0; i < s.length() && i < 12; i++) {
char c = s.charAt(i);
l *= 37L;
if (c >= 'A' && c <= 'Z')
l += (1 + c) - 65;
else if (c >= 'a' && c <= 'z')
l += (1 + c) - 97;
else if (c >= '0' && c <= '9')
l += (27 + c) - 48;
}
while (l % 37L == 0L && l != 0L)
l /= 37L;
return l;
}
/**
* Decrypt player chat.
* @param buffer The buffer
* @param totalChars The total chars
* @return The string
*/
public static String decryptPlayerChat(IoBuffer buffer, int totalChars) {
try {
if (totalChars == 0)
return "";
int charsDecoded = 0;
int i_4_ = 0;
String s = "";
for (;;) {
byte i_7_ = (byte) buffer.get();
if (i_7_ >= 0)
i_4_++;
else
i_4_ = anIntArray241[i_4_];
int i_8_;
if ((i_8_ = anIntArray241[i_4_]) < 0) {
s += (char) (byte) (i_8_ ^ 0xffffffff);
if (totalChars <= ++charsDecoded)
break;
i_4_ = 0;
}
if (((i_7_ & 0x40) ^ 0xffffffff) != -1)
i_4_ = anIntArray241[i_4_];
else
i_4_++;
if ((i_8_ = anIntArray241[i_4_]) < 0) {
s += (char) (byte) (i_8_ ^ 0xffffffff);
if (++charsDecoded >= totalChars)
break;
i_4_ = 0;
}
if ((0x20 & i_7_) == 0)
i_4_++;
else
i_4_ = anIntArray241[i_4_];
if ((i_8_ = anIntArray241[i_4_]) < 0) {
s += (char) (byte) (i_8_ ^ 0xffffffff);
if (totalChars <= ++charsDecoded)
break;
i_4_ = 0;
}
if (((0x10 & i_7_) ^ 0xffffffff) == -1)
i_4_++;
else
i_4_ = anIntArray241[i_4_];
if ((i_8_ = anIntArray241[i_4_]) < 0) {
s += (char) (byte) (i_8_ ^ 0xffffffff);
if (totalChars <= ++charsDecoded)
break;
i_4_ = 0;
}
if (((0x8 & i_7_) ^ 0xffffffff) != -1)
i_4_ = anIntArray241[i_4_];
else
i_4_++;
if ((i_8_ = anIntArray241[i_4_]) < 0) {
s += (char) (byte) (i_8_ ^ 0xffffffff);
if (++charsDecoded >= totalChars)
break;
i_4_ = 0;
}
if ((0x4 & i_7_) == 0)
i_4_++;
else
i_4_ = anIntArray241[i_4_];
if ((i_8_ = anIntArray241[i_4_]) < 0) {
s += (char) (byte) (i_8_ ^ 0xffffffff);
if (totalChars <= ++charsDecoded)
break;
i_4_ = 0;
}
if (((i_7_ & 0x2) ^ 0xffffffff) != -1)
i_4_ = anIntArray241[i_4_];
else
i_4_++;
if ((i_8_ = anIntArray241[i_4_]) < 0) {
s += (char) (byte) (i_8_ ^ 0xffffffff);
if (totalChars <= ++charsDecoded)
break;
i_4_ = 0;
}
if (((i_7_ & 0x1) ^ 0xffffffff) != -1)
i_4_ = anIntArray241[i_4_];
else
i_4_++;
if ((i_8_ = anIntArray241[i_4_]) < 0) {
s += (char) (byte) (i_8_ ^ 0xffffffff);
if (++charsDecoded >= totalChars)
break;
i_4_ = 0;
}
}
return s;
} catch (RuntimeException runtimeexception) {
runtimeexception.printStackTrace();
}
return "";
}
}
+121
View File
@@ -0,0 +1,121 @@
package core.tools
import com.github.ajalt.mordant.rendering.TextColors
import com.github.ajalt.mordant.terminal.*
import core.ServerConstants
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
import java.io.Writer
import java.text.SimpleDateFormat
import java.util.*
/**
* Handles server log printing
* @author Ceikry
* Thanks to the awesome library made by AJ Alt
*/
object SystemLogger {
val t = Terminal()
val formatter = SimpleDateFormat("HH:mm:ss")
var tradeLog: Writer? = null
var tradeLogWriter: BufferedWriter? = null
@JvmStatic
fun initTradeLogger(){
if(!File(ServerConstants.LOGS_PATH + "trade" + File.separator + "test").exists()){
File(ServerConstants.LOGS_PATH + "trade" + File.separator + "test").mkdirs()
}
tradeLog = FileWriter(ServerConstants.LOGS_PATH + "trade" + File.separator + SimpleDateFormat("dd-MM-yyyy").format(System.currentTimeMillis()) + ".log")
tradeLogWriter = BufferedWriter(tradeLog!!)
}
@JvmStatic()
fun flushLogs() {
try {
tradeLogWriter?.flush()
tradeLogWriter?.close()
} catch(ignored: Exception) {}
}
fun getTime(): String{
return "[" + formatter.format(Date(System.currentTimeMillis())) +"]"
}
@JvmStatic
fun logInfo(clazz: Class<*>, vararg messages: String){
for(m in messages){
val msg = "${getTime()}: [${clazz.simpleName}] $m"
if(m.isNotBlank()) {
t.println(msg)
}
}
}
@JvmStatic
fun logErr(clazz: Class<*>, message: String){
val msg = "${getTime()}: [${clazz.simpleName}] $message"
if(message.isNotBlank()) {
t.println(msg)
}
}
@JvmStatic
fun logWarn(clazz: Class<*>, message: String){
val msg = "${getTime()}: [${clazz.simpleName}] $message"
if(message.isNotBlank()) {
t.println(msg)
}
}
@JvmStatic
fun logAlert(clazz: Class<*>, message: String){
val msg = "${getTime()}: [${clazz.simpleName}] $message"
if(message.isNotBlank()) {
t.println(msg)
}
}
@JvmStatic
fun logAI(clazz: Class<*>, message: String){
val msg = "${getTime()}: [${clazz.simpleName}] $message"
if(message.isNotBlank()) {
t.println(msg)
}
}
@JvmStatic
fun logRE(message: String){
if(message.isNotBlank()) t.println("${getTime()}: ${TextColors.gray("[RAND] $message")}")
}
@JvmStatic
fun logGE(message: String){
if(message.isNotBlank()) t.println("${getTime()}: ${TextColors.gray("[ GE] $message")}")
}
@JvmStatic
fun logTrade(message: String){
try {
if (message.isNotBlank()) {
if (tradeLogWriter == null) logWarn(this::class.java, "Trade Logger is null!")
tradeLogWriter?.write("${getTime()}: $message")
tradeLogWriter?.newLine()
}
} catch(ignored: Exception){}
}
@JvmStatic fun logStartup(message: String)
{
logInfo(this::class.java, "[STARTUP] $message")
}
@JvmStatic fun logShutdown(message: String)
{
logInfo(this::class.java,"[SHUTDOWN] $message")
}
fun logMS(s: String) {
if(s.isNotBlank()) t.println("${getTime()}: ${TextColors.gray("[ MS] $s")}")
}
}
+14
View File
@@ -0,0 +1,14 @@
package core.tools
const val tick = 600 //ms
const val second = 1000 //ms
fun secondsToTicks(seconds: Int): Int {
val seconds = seconds * second //seconds -> ms
return seconds / tick //returns an int with the closest number of ticks to the desired number of seconds possible
}
fun ticksToSeconds(ticks: Int): Int {
val ticksMs = ticks * tick
return ticksMs / 1000
}
+73
View File
@@ -0,0 +1,73 @@
package core.tools;
/**
* Used for debugging duration of executing code.
* @author Emperor
*/
public final class TimeStamp {
/**
* The start
*/
private long start;
/**
* The interval.
*/
private long interval;
/**
* Constructs a new {@code TimeStamp} {@code Object}.
*/
public TimeStamp() {
start = System.currentTimeMillis();
interval = start;
}
/**
* Set current interval.
* @return The duration of this interval.
*/
public long interval() {
return interval(true, "");
}
/**
* Set current interval.
* @param debug If we should print out the duration.
* @return The duration of this interval.
*/
public long interval(boolean debug) {
return interval(debug, "");
}
/**
* Set current interval.
* @param debug If we should print out the duration.
* @param info Extra information.
* @return The duration of this interval.
*/
public long interval(boolean debug, String info) {
long current = System.currentTimeMillis();
long difference = current - interval;
if (debug || difference > 100) {
System.out.println("Interval " + info + " - time elapsed=" + difference + "ms.");
}
interval = current;
return difference;
}
/**
* Gets the amount of milliseconds passed since the creation of this object.
* @return The duration.
*/
public long duration(boolean debug, String info) {
long current = System.currentTimeMillis();
long difference = current - start;
if (debug) {
System.out.println("Interval " + info + " - time elapsed=" + difference + "ms.");
}
return difference;
}
}
+139
View File
@@ -0,0 +1,139 @@
package core.tools;
import core.game.world.map.Location;
public class Vector3d {
public double x;
public double y;
public double z;
public Vector3d(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vector3d(double[] t) {
this.x = t[0];
this.y = t[1];
this.z = t[2];
}
public Vector3d(Vector3d v) {
this.x = v.x;
this.y = v.y;
this.z = v.z;
}
public Vector3d(Location l) {
this.x = l.getX();
this.y = l.getY();
this.z = l.getZ();
}
public Vector3d() {
this.x = 0.0;
this.y = 0.0;
this.z = 0.0;
}
public String toString() {
return "(" + this.x + ", " + this.y + ", " + this.z + ")";
}
public final Vector3d add(Vector3d v1, Vector3d v2) {
this.x = v1.x + v2.x;
this.y = v1.y + v2.y;
this.z = v1.z + v2.z;
return this;
}
public final Vector3d add(Vector3d v1) {
this.x += v1.x;
this.y += v1.y;
this.z += v1.z;
return this;
}
public final Vector3d sub(Vector3d v1, Vector3d v2) {
this.x = v1.x - v2.x;
this.y = v1.y - v2.y;
this.z = v1.z - v2.z;
return this;
}
public final Vector3d sub(Vector3d v1) {
this.x -= v1.x;
this.y -= v1.y;
this.z -= v1.z;
return this;
}
public final Vector3d negate(Vector3d v1) {
this.x = -v1.x;
this.y = -v1.y;
this.z = -v1.z;
return this;
}
public final Vector3d negate() {
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
return this;
}
public final Vector3d cross(Vector3d v2) {
this.cross(new Vector3d(this), v2);
return this;
}
public final Vector3d cross(Vector3d v1, Vector3d v2) {
this.x = v1.y*v2.z - v1.z*v2.y;
this.y = v1.z*v2.x - v1.x*v2.z;
this.z = v1.x*v2.y - v1.y*v2.x;
return this;
}
public final double dot(Vector3d v2) {
return (this.x*v2.x + this.y*v2.y + this.z*v2.z);
}
public final double l2norm() {
return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
}
public final Vector3d normalize() {
double norm = this.l2norm();
this.x /= norm;
this.y /= norm;
this.z /= norm;
return this;
}
public static double signedAngle(final Vector3d v1, final Vector3d v2, final Vector3d n) {
return Math.atan2(new Vector3d().cross(v1, v2).dot(n), v1.dot(v2));
}
public boolean equals(final Vector3d v1) {
return (this.x == v1.x && this.y == v1.y && this.z == v1.z);
}
public boolean epsilonEquals(final Vector3d v1, double epsilon) {
double diff;
diff = this.x - v1.x;
if (Double.isNaN(diff)) return false;
if ((diff<0 ? -diff : diff) > epsilon) return false;
diff = this.y - v1.y;
if (Double.isNaN(diff)) return false;
if ((diff<0 ? -diff : diff) > epsilon) return false;
diff = this.z - v1.z;
if (Double.isNaN(diff)) return false;
if ((diff<0 ? -diff : diff) > epsilon) return false;
return true;
}
}
@@ -0,0 +1,33 @@
package core.tools.mysql;
public class Database {
private String host;
private String name;
private String username;
private String password;
public Database(String host, String name, String username, String password) {
this.host = host;
this.name = name;
this.username = username;
this.password = password;
}
public String host() {
return host;
}
public String name() {
return name;
}
public String username() {
return username;
}
public String password() {
return password;
}
}
@@ -0,0 +1,48 @@
package core.tools.mysql;
public class Query {
private String start;
private StringBuilder content;
private String end;
public Query() {
this.start = "";
this.content = new StringBuilder();
this.end = "";
}
public String start(String start) {
this.start = start;
return this.start;
}
public String end(String end) {
this.end = end;
return this.end;
}
public StringBuilder add(String key, String value) {
this.content.append(key + "='" + value + "'").append(",");
return this.content;
}
public StringBuilder add(String key, int value) {
this.content.append(key + "='" + value + "'").append(",");
return this.content;
}
public StringBuilder add(String key, boolean value) {
this.content.append(key + "='" + (value ? 1 : 0) + "'").append(",");
return this.content;
}
public String total() {
StringBuilder total = new StringBuilder();
total.append(this.start);
total.append(this.content.substring(0, this.content.length() - 1));
total.append(this.end);
return total.toString();
}
}
@@ -0,0 +1,107 @@
package core.tools.mysql;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.List;
public class Results {
private ResultSet set;
public Results(ResultSet set) {
this.set = set;
}
public String string(String column) {
try {
String result = set().getString(column);
return result;
} catch (Exception e) {
System.out.println("Column '" + column + "' not found.");
}
return null;
}
public int integer(String column) {
try {
int result = set().getInt(column);
return result;
} catch (Exception e) {
System.out.println("Column '" + column + "' not found.");
}
return -1;
}
public List<String> columns() {
try {
ResultSetMetaData meta = set().getMetaData();
int count = meta.getColumnCount();
List<String> columns = new ArrayList<String>(count);
for (int i = 1; i <= count; i++)
columns.add(meta.getColumnName(i));
return columns;
} catch (Exception e) {
System.out.println("Unable to gather columns.");
}
return null;
}
public boolean empty() {
try {
return !set().next();
} catch (Exception e) {
System.out.println("Error occurred, while checking for results.");
}
return true;
}
public static int[] integers(String[] values) {
int[] integers = new int[values.length];
for (int i = 0; i < integers.length; i++)
integers[i] = Integer.parseInt(values[i]);
return integers;
}
public static double[] doubles(String[] values) {
double[] integers = new double[values.length];
for (int i = 0; i < integers.length; i++)
integers[i] = Double.parseDouble(values[i]);
return integers;
}
public ResultSet set() {
return set;
}
}