Minor code formatting changes

Updated some classes to ensure code formatting consistency is kept
throughout the entire project.
This commit is contained in:
ShadowRanger 2015-03-02 11:37:01 +11:00
parent c254442056
commit a548578819
6 changed files with 55 additions and 30 deletions

View File

@ -8,7 +8,9 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockPlaceListener implements Listener {
public class BlockPlaceListener implements Listener
{
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event)
{
@ -20,12 +22,14 @@ public class BlockPlaceListener implements Listener {
BorderData border = Config.Border(world.getName());
if (border == null) return;
if (!border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) {
if (!border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound()))
{
event.setCancelled(true);
}
}
public void unregister() {
public void unregister()
{
HandlerList.unregisterAll(this);
}
}

View File

@ -19,27 +19,33 @@ import java.util.concurrent.Callable;
* from http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
*/
public class NameFetcher implements Callable<Map<UUID, String>> {
public class NameFetcher implements Callable<Map<UUID, String>>
{
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
private final JSONParser jsonParser = new JSONParser();
private final List<UUID> uuids;
public NameFetcher(List<UUID> uuids) {
public NameFetcher(List<UUID> uuids)
{
this.uuids = ImmutableList.copyOf(uuids);
}
@Override
public Map<UUID, String> call() throws Exception {
public Map<UUID, String> call() throws Exception
{
Map<UUID, String> uuidStringMap = new HashMap<UUID, String>();
for (UUID uuid: uuids) {
for (UUID uuid: uuids)
{
HttpURLConnection connection = (HttpURLConnection) new URL(PROFILE_URL+uuid.toString().replace("-", "")).openConnection();
JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
String name = (String) response.get("name");
if (name == null) {
if (name == null)
{
continue;
}
String cause = (String) response.get("cause");
String errorMessage = (String) response.get("errorMessage");
if (cause != null && cause.length() > 0) {
if (cause != null && cause.length() > 0)
{
throw new IllegalStateException(errorMessage);
}
uuidStringMap.put(uuid, name);

View File

@ -20,52 +20,61 @@ import java.util.concurrent.Callable;
* slightly modified to fix name case mismatches for single name lookup
*/
public class UUIDFetcher implements Callable<Map<String, UUID>> {
public class UUIDFetcher implements Callable<Map<String, UUID>>
{
private static final double PROFILES_PER_REQUEST = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser jsonParser = new JSONParser();
private final List<String> names;
private final boolean rateLimiting;
public UUIDFetcher(List<String> names, boolean rateLimiting) {
public UUIDFetcher(List<String> names, boolean rateLimiting)
{
this.names = ImmutableList.copyOf(names);
this.rateLimiting = rateLimiting;
}
public UUIDFetcher(List<String> names) {
public UUIDFetcher(List<String> names)
{
this(names, true);
}
public Map<String, UUID> call() throws Exception {
public Map<String, UUID> call() throws Exception
{
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
for (int i = 0; i < requests; i++) {
for (int i = 0; i < requests; i++)
{
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
writeBody(connection, body);
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array) {
for (Object profile : array)
{
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");
String name = (String) jsonProfile.get("name");
UUID uuid = UUIDFetcher.getUUID(id);
uuidMap.put(name.toLowerCase(), uuid);
}
if (rateLimiting && i != requests - 1) {
if (rateLimiting && i != requests - 1)
{
Thread.sleep(100L);
}
}
return uuidMap;
}
private static void writeBody(HttpURLConnection connection, String body) throws Exception {
private static void writeBody(HttpURLConnection connection, String body) throws Exception
{
OutputStream stream = connection.getOutputStream();
stream.write(body.getBytes());
stream.flush();
stream.close();
}
private static HttpURLConnection createConnection() throws Exception {
private static HttpURLConnection createConnection() throws Exception
{
URL url = new URL(PROFILE_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
@ -76,18 +85,21 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
return connection;
}
private static UUID getUUID(String id) {
private static UUID getUUID(String id)
{
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" +id.substring(20, 32));
}
public static byte[] toBytes(UUID uuid) {
public static byte[] toBytes(UUID uuid)
{
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
byteBuffer.putLong(uuid.getLeastSignificantBits());
return byteBuffer.array();
}
public static UUID fromBytes(byte[] array) {
public static UUID fromBytes(byte[] array)
{
if (array.length != 16) {
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
}
@ -97,7 +109,8 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
return new UUID(mostSignificant, leastSignificant);
}
public static UUID getUUIDOf(String name) throws Exception {
public static UUID getUUIDOf(String name) throws Exception
{
return new UUIDFetcher(Arrays.asList(name)).call().get(name.toLowerCase());
}
}

View File

@ -209,5 +209,4 @@ public class WBCommand implements CommandExecutor
commands.remove("commands");
return commands;
}
}

View File

@ -27,7 +27,8 @@ public class WorldBorder extends JavaPlugin
// keep an eye on teleports, to redirect them to a spot inside the border if necessary
getServer().getPluginManager().registerEvents(new WBListener(), this);
if (Config.preventBlockPlace()) {
if (Config.preventBlockPlace())
{
enableBlockPlaceListener(true);
}
@ -64,11 +65,13 @@ public class WorldBorder extends JavaPlugin
}
public void enableBlockPlaceListener(boolean enable) {
if (enable) {
if (enable)
{
getServer().getPluginManager().registerEvents(this.blockPlaceListener = new BlockPlaceListener(), this);
} else {
}
else
{
blockPlaceListener.unregister();
}
}
}

View File

@ -259,7 +259,7 @@ public class WorldFileData
}
// crude chunk map PNG image output, for debugging
// crude chunk map PNG image output, for debugging
private void testImage(CoordXZ region, List<Boolean> data) {
int width = 32;
int height = 32;