Cleanup formatting.

This commit is contained in:
Grant
2012-12-24 16:56:25 -05:00
parent 6b3bde585d
commit 36d5344ded
67 changed files with 894 additions and 849 deletions

View File

@ -504,7 +504,7 @@ public class Combat {
if (Users.getProfile(defender).getGodMode()) {
return false;
}
//It may seem a bit redundant but we need a check here to prevent bleed from being applied in applyAbilityAoE()
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(player, entity, EntityDamageEvent.DamageCause.ENTITY_ATTACK, 1);
mcMMO.p.getServer().getPluginManager().callEvent(ede);

View File

@ -25,7 +25,7 @@ public class Database {
// Scale waiting time by this much per failed attempt
private static final double SCALING_FACTOR = 5;
// Minimum wait in nanoseconds (default 500ms)
private static final long MIN_WAIT = 500*100000L;
@ -37,7 +37,7 @@ public class Database {
// When next to try connecting to Database in nanoseconds
private static long nextReconnectTimestamp = 0L;
// How many connection attemtps have failed
private static int reconnectAttempt = 0;
@ -63,15 +63,15 @@ public class Database {
System.out.println("[mcMMO] Connection to MySQL was a success!");
}
catch (SQLException ex) {
connection = null;
connection = null;
System.out.println("[mcMMO] Connection to MySQL failed!");
ex.printStackTrace();
printErrors(ex);
} catch (ClassNotFoundException ex) {
connection = null;
connection = null;
System.out.println("[mcMMO] MySQL database driver not found!");
ex.printStackTrace();
}
}
}
/**
@ -186,20 +186,20 @@ public class Database {
break;
}
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
// Ignore the error, we're leaving
}
}
if (statement != null) {
if (resultSet != null) {
try {
statement.close();
} catch (SQLException e) {
// Ignore the error, we're leaving
}
}
resultSet.close();
} catch (SQLException e) {
// Ignore the error, we're leaving
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
// Ignore the error, we're leaving
}
}
}
}
@ -211,7 +211,7 @@ public class Database {
*/
public boolean write(String sql) {
if (checkConnected()) {
PreparedStatement statement = null;
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(sql);
statement.executeUpdate();
@ -221,14 +221,14 @@ public class Database {
printErrors(ex);
return false;
} finally {
if (statement != null) {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
printErrors(e);
return false;
}
}
statement.close();
} catch (SQLException e) {
printErrors(e);
return false;
}
}
}
}
@ -270,93 +270,93 @@ public class Database {
/**
* Check connection status and re-establish if dead or stale.
*
* If the very first immediate attempt fails, further attempts
* will be made in progressively larger intervals up to MAX_WAIT
* intervals.
* If the very first immediate attempt fails, further attempts
* will be made in progressively larger intervals up to MAX_WAIT
* intervals.
*
* This allows for MySQL to time out idle connections as needed by
* server operator, without affecting McMMO, while still providing
* protection against a database outage taking down Bukkit's tick
* This allows for MySQL to time out idle connections as needed by
* server operator, without affecting McMMO, while still providing
* protection against a database outage taking down Bukkit's tick
* processing loop due to attemping a database connection each
* time McMMO needs the database.
*
* @return the boolean value for whether or not we are connected
*/
public static boolean checkConnected() {
boolean isClosed = true;
boolean isValid = false;
boolean exists = (connection != null);
boolean isClosed = true;
boolean isValid = false;
boolean exists = (connection != null);
// Initialized as needed later
long timestamp=0;
// If we're waiting for server to recover then leave early
if (nextReconnectTimestamp > 0 && nextReconnectTimestamp > System.nanoTime()) {
return false;
}
if (exists) {
// Initialized as needed later
long timestamp=0;
// If we're waiting for server to recover then leave early
if (nextReconnectTimestamp > 0 && nextReconnectTimestamp > System.nanoTime()) {
return false;
}
if (exists) {
try {
isClosed = connection.isClosed();
} catch (SQLException e) {
isClosed = true;
e.printStackTrace();
printErrors(e);
}
isClosed = connection.isClosed();
} catch (SQLException e) {
isClosed = true;
e.printStackTrace();
printErrors(e);
}
if (!isClosed) {
try {
isValid = connection.isValid(VALID_TIMEOUT);
} catch (SQLException e) {
// Don't print stack trace because it's valid to lose idle connections
// to the server and have to restart them.
isValid = false;
}
isValid = connection.isValid(VALID_TIMEOUT);
} catch (SQLException e) {
// Don't print stack trace because it's valid to lose idle connections
// to the server and have to restart them.
isValid = false;
}
}
}
}
// Leave if all ok
if (exists && !isClosed && isValid) {
// Housekeeping
nextReconnectTimestamp = 0;
reconnectAttempt = 0;
return true;
}
// Cleanup after ourselves for GC and MySQL's sake
if (exists && !isClosed) {
try {
connection.close();
} catch (SQLException ex) {
// This is a housekeeping exercise, ignore errors
}
}
// Leave if all ok
if (exists && !isClosed && isValid) {
// Housekeeping
nextReconnectTimestamp = 0;
reconnectAttempt = 0;
return true;
}
// Try to connect again
connect();
// Cleanup after ourselves for GC and MySQL's sake
if (exists && !isClosed) {
try {
connection.close();
} catch (SQLException ex) {
// This is a housekeeping exercise, ignore errors
}
}
// Leave if connection is good
try {
if (connection != null && !connection.isClosed()) {
// Schedule a database save if we really had an outage
if (reconnectAttempt > 1) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SQLReconnect(plugin), 5);
}
nextReconnectTimestamp = 0;
reconnectAttempt = 0;
return true;
}
} catch (SQLException e) {
// Failed to check isClosed, so presume connection is bad and attempt later
e.printStackTrace();
printErrors(e);
}
// Try to connect again
connect();
reconnectAttempt++;
nextReconnectTimestamp = (long)(System.nanoTime() + Math.min(MAX_WAIT, (reconnectAttempt*SCALING_FACTOR*MIN_WAIT)));
return false;
// Leave if connection is good
try {
if (connection != null && !connection.isClosed()) {
// Schedule a database save if we really had an outage
if (reconnectAttempt > 1) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SQLReconnect(plugin), 5);
}
nextReconnectTimestamp = 0;
reconnectAttempt = 0;
return true;
}
} catch (SQLException e) {
// Failed to check isClosed, so presume connection is bad and attempt later
e.printStackTrace();
printErrors(e);
}
reconnectAttempt++;
nextReconnectTimestamp = (long)(System.nanoTime() + Math.min(MAX_WAIT, (reconnectAttempt*SCALING_FACTOR*MIN_WAIT)));
return false;
}
/**

View File

@ -394,12 +394,12 @@ public class ItemChecks {
*/
public static boolean isStringTool(ItemStack is) {
switch (is.getType()) {
case BOW:
case FISHING_ROD:
return true;
case BOW:
case FISHING_ROD:
return true;
default:
return false;
default:
return false;
}
}

View File

@ -217,7 +217,7 @@ public class Leaderboard {
BufferedReader in = new BufferedReader(file);
int destination;
//How many lines to skip through
//How many lines to skip through
if (pagenumber == 1) {
destination = 0;
}

View File

@ -277,23 +277,23 @@ public class Metrics {
}
/**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*
* @throws IOException
*/
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*
* @throws IOException
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Enable Task, if it is not running
if (taskId < 0) {
start();
}
// Enable Task, if it is not running
if (taskId < 0) {
start();
}
}
}

View File

@ -289,4 +289,3 @@ public class Misc {
}
}
}

View File

@ -408,11 +408,11 @@ public class Permissions {
public boolean party(Player player) {
return player.hasPermission("mcmmo.commands.party");
}
public boolean skillReset(Player player) {
return player.hasPermission("mcmmo.skillreset");
}
/*
* MCMMO.CHAT.*

View File

@ -25,8 +25,8 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutStuff;
public class Skills {
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength();
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength();
private final static int TIME_CONVERSION_FACTOR = 1000;
private final static double MAX_DISTANCE_AWAY = 10.0;
@ -530,7 +530,7 @@ public class Skills {
return;
if (type.getPermissions(player)) {
if(Users.getPlayer(player) == null)
if(Users.getPlayer(player) == null)
return;
Users.getPlayer(player).addXP(type, xp);

View File

@ -372,7 +372,7 @@ public class HashChunkletManager implements ChunkletManager {
// TODO: Make this less messy, as it is, it's kinda... depressing to do it like this.
// Might also make a mess when we move to stacks, but at that point I think I will write a new Manager...
// IMPORTANT! If ChunkletStoreFactory is going to be returning something other than PrimitiveEx we need to remove this, as it will be breaking time for old maps
/*
if(!(storeIn instanceof PrimitiveExChunkletStore)) {
ChunkletStore tempStore = ChunkletStoreFactory.getChunkletStore();
@ -381,7 +381,7 @@ public class HashChunkletManager implements ChunkletManager {
}
storeIn = tempStore;
}
*/
*/
return storeIn;
}

View File

@ -14,20 +14,20 @@ public class NullChunkletManager implements ChunkletManager {
return;
}
@Override
public void unloadChunklet(int cx, int cy, int cz, World world) {
return;
}
@Override
public void unloadChunklet(int cx, int cy, int cz, World world) {
return;
}
@Override
public void loadChunk(int cx, int cz, World world) {
return;
}
@Override
public void loadChunk(int cx, int cz, World world) {
return;
}
@Override
public void unloadChunk(int cx, int cz, World world) {
return;
}
@Override
public void unloadChunk(int cx, int cz, World world) {
return;
}
@Override
public void chunkLoaded(int cx, int cz, World world) {

View File

@ -10,7 +10,7 @@ public interface ChunkManager {
public ChunkStore readChunkStore(World world, int x, int z) throws IOException;
public void writeChunkStore(World world, int x, int z, ChunkStore data);
public void closeChunkStore(World world, int x, int z);
/**
* Loads a specific chunklet
*

View File

@ -112,7 +112,7 @@ public class HashChunkManager implements ChunkManager {
int rx = x >> 5;
int rz = z >> 5;
long key2 = (((long) rx) << 32) | (((long) rz) & 0xFFFFFFFFL);
long key2 = (((long) rx) << 32) | ((rz) & 0xFFFFFFFFL);
mcMMOSimpleRegionFile regionFile = worldRegions.get(key2);
@ -221,9 +221,9 @@ public class HashChunkManager implements ChunkManager {
try {
cx = Integer.parseInt(info[1]);
cz = Integer.parseInt(info[2]);
cz = Integer.parseInt(info[2]);
}
catch(Exception e) {
catch(Exception e) {
return;
}
saveChunk(cx, cz, world);
@ -247,9 +247,9 @@ public class HashChunkManager implements ChunkManager {
try {
cx = Integer.parseInt(info[1]);
cz = Integer.parseInt(info[2]);
cz = Integer.parseInt(info[2]);
}
catch(Exception e) {
catch(Exception e) {
return;
}
unloadChunk(cx, cz, world);

View File

@ -28,7 +28,7 @@ public class PrimitiveChunkStore implements ChunkStore {
public PrimitiveChunkStore(World world, int cx, int cz) {
this.cx = cx;
this.cz = cz;
this.worldUid = world.getUID();
this.worldUid = world.getUID();
this.worldHeight = world != null ? world.getMaxHeight() : 128;
this.xBitShifts = 11;
@ -108,7 +108,7 @@ public class PrimitiveChunkStore implements ChunkStore {
out.writeLong(worldUid.getMostSignificantBits());
out.writeInt(cx);
out.writeInt(cz);
out.writeObject(store);
out.writeObject(store);
dirty = false;
}