First commit
This commit is contained in:
25
src/net/mc_pandacraft/java/util/MemoryUtil.java
Normal file
25
src/net/mc_pandacraft/java/util/MemoryUtil.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package net.mc_pandacraft.java.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class MemoryUtil {
|
||||
public static String humanReadableSize(long octet)
|
||||
{
|
||||
DecimalFormat format = new DecimalFormat("#####0.00");
|
||||
double size = octet;
|
||||
if (size < 1024)
|
||||
return size+"o";
|
||||
size /= 1024;
|
||||
if (size < 1024)
|
||||
return format.format(size)+"kio";
|
||||
size /= 1024;
|
||||
if (size < 1024)
|
||||
return format.format(size)+"Mio";
|
||||
size /= 1024;
|
||||
if (size < 1024)
|
||||
return format.format(size)+"Gio";
|
||||
size /= 1024;
|
||||
|
||||
return format.format(size)+"Tio";
|
||||
}
|
||||
}
|
36
src/net/mc_pandacraft/java/util/TimeUtil.java
Normal file
36
src/net/mc_pandacraft/java/util/TimeUtil.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package net.mc_pandacraft.java.util;
|
||||
|
||||
public class TimeUtil {
|
||||
public static String durationToString (long msec_time, boolean dec_seconde)
|
||||
{
|
||||
int j = 0, h = 0, m = 0, s = 0;
|
||||
long msec = msec_time;
|
||||
|
||||
j = (int) (msec / (1000 * 60 * 60 * 24));
|
||||
msec -= (1000 * 60 * 60 * 24) * j;
|
||||
h = (int) (msec / (1000 * 60 * 60));
|
||||
msec -= (1000 * 60 * 60) * h;
|
||||
m = (int) (msec / (1000 * 60));
|
||||
msec -= (1000 * 60) * m;
|
||||
s = (int) (msec / 1000);
|
||||
msec -= 1000 * s;
|
||||
|
||||
String result = "";
|
||||
if (j>0) result = result.concat(j+"j ");
|
||||
if (h>0) result = result.concat(h+"h ");
|
||||
if (m>0) result = result.concat(m+"m ");
|
||||
if (s>0 && !dec_seconde) result = result.concat(s+"s");
|
||||
else if (dec_seconde && (s>0 || msec > 0))
|
||||
{
|
||||
msec += s*1000;
|
||||
result = result.concat((msec/1000D)+"s");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String durationToString (long msec_time)
|
||||
{
|
||||
return durationToString(msec_time, false);
|
||||
}
|
||||
}
|
73
src/net/mc_pandacraft/java/util/bukkit/TextProgressBar.java
Normal file
73
src/net/mc_pandacraft/java/util/bukkit/TextProgressBar.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package net.mc_pandacraft.java.util.bukkit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
public class TextProgressBar {
|
||||
private static String pattern_start = "[";
|
||||
private static String pattern_end = "]";
|
||||
private static ChatColor color_empty = ChatColor.DARK_GRAY;
|
||||
private static ChatColor color_decoration = ChatColor.GOLD;
|
||||
private static ChatColor color_default = ChatColor.RESET;
|
||||
private static String pattern_empty = ".";
|
||||
private static String pattern_full = "|";
|
||||
|
||||
public static String progressBar(double[] values, ChatColor[] colors, double total, int nbCar)
|
||||
{
|
||||
int[] sizes = new int[values.length];
|
||||
|
||||
int max_size = nbCar - pattern_start.length() - pattern_end.length();
|
||||
|
||||
for (int i=0; i<values.length; i++)
|
||||
{
|
||||
double sum_values_before = 0;
|
||||
for (int j = i ; j>=0; j--)
|
||||
sum_values_before += values[j];
|
||||
|
||||
int car_position = NumberConversions.round(max_size * sum_values_before / total);
|
||||
|
||||
// évite les barre de progressions plus grandes que la taille demandée
|
||||
if (car_position > max_size) car_position = max_size;
|
||||
|
||||
int sum_sizes_before = 0;
|
||||
for (int j = i-1 ; j>=0; j--)
|
||||
sum_sizes_before += sizes[j];
|
||||
|
||||
sizes[i] = car_position - sum_sizes_before;
|
||||
}
|
||||
int sum_sizes = 0;
|
||||
|
||||
|
||||
String bar = color_decoration+pattern_start;
|
||||
for (int i=0; i<sizes.length; i++)
|
||||
{
|
||||
sum_sizes += sizes[i];
|
||||
|
||||
ChatColor color = color_default;
|
||||
if (colors != null && i < colors.length && colors[i] != null)
|
||||
color = colors[i];
|
||||
|
||||
bar = bar + color;
|
||||
|
||||
for (int j=0; j<sizes[i]; j++)
|
||||
bar = bar + pattern_full;
|
||||
}
|
||||
|
||||
bar = bar + color_empty;
|
||||
for (int j=0; j<(max_size-sum_sizes); j++)
|
||||
bar = bar + pattern_empty;
|
||||
|
||||
bar = bar + color_decoration + pattern_end;
|
||||
return bar;
|
||||
}
|
||||
|
||||
|
||||
public static String progressBar(double value, ChatColor color, double max, int nbCar)
|
||||
{
|
||||
double[] d = new double[1]; d[0] = value;
|
||||
ChatColor[] c = new ChatColor[1]; c[0] = color;
|
||||
return progressBar(d, c, max, nbCar);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package net.mc_pandacraft.java.util.bukkit.logger;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ThrowableUtil {
|
||||
|
||||
|
||||
public static void displayErrorMessage(Logger l, Throwable t)
|
||||
{
|
||||
l.severe(t.toString()+" : "+t.getMessage());
|
||||
for (StackTraceElement stackEl : t.getStackTrace())
|
||||
{
|
||||
l.severe(stackEl.toString());
|
||||
}
|
||||
if (t.getCause() != null)
|
||||
displayErrorMessage(l, t.getCause());
|
||||
}
|
||||
|
||||
|
||||
}
|
57
src/net/mc_pandacraft/java/util/mysql/DBConnection.java
Normal file
57
src/net/mc_pandacraft/java/util/mysql/DBConnection.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package net.mc_pandacraft.java.util.mysql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class DBConnection {
|
||||
JavaPlugin plugin;
|
||||
Connection conn;
|
||||
String url;
|
||||
String login;
|
||||
String pass;
|
||||
|
||||
public DBConnection(String host, int port, String dbname, String l, String p) throws ClassNotFoundException, SQLException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
url = "jdbc:mysql://"+host+":"+port+"/"+dbname;
|
||||
login = l;
|
||||
pass = p;
|
||||
conn = DriverManager.getConnection(url, login, pass);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void reconnect() throws SQLException
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.createStatement();
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
conn = DriverManager.getConnection(url, login, pass);
|
||||
}
|
||||
}
|
||||
|
||||
public Statement createStatement() throws SQLException
|
||||
{
|
||||
return conn.createStatement();
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql) throws SQLException
|
||||
{
|
||||
return conn.prepareStatement(sql);
|
||||
}
|
||||
|
||||
|
||||
public Connection getConnection()
|
||||
{
|
||||
return conn;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user