mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
parent
84a6a6daf4
commit
538e2a6002
@ -112,31 +112,37 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
while (!toFetch.isEmpty()) {
|
||||||
if (toFetch.isEmpty()) {
|
try {
|
||||||
if (whenDone != null) {
|
for (int i = 0; i < Math.min(500, toFetch.size()); i++) {
|
||||||
whenDone.run();
|
UUID uuid = toFetch.pop();
|
||||||
}
|
HttpURLConnection connection =
|
||||||
return;
|
(HttpURLConnection) new URL(SQLUUIDHandler.this.PROFILE_URL + uuid.toString().replace("-", ""))
|
||||||
}
|
.openConnection();
|
||||||
for (int i = 0; i < Math.min(500, toFetch.size()); i++) {
|
try (InputStream con = connection.getInputStream()) {
|
||||||
UUID uuid = toFetch.pop();
|
InputStreamReader reader = new InputStreamReader(con);
|
||||||
HttpURLConnection connection =
|
JSONObject response = (JSONObject) SQLUUIDHandler.this.jsonParser.parse(reader);
|
||||||
(HttpURLConnection) new URL(SQLUUIDHandler.this.PROFILE_URL + uuid.toString().replace("-", ""))
|
String name = (String) response.get("name");
|
||||||
.openConnection();
|
if (name != null) {
|
||||||
try (InputStream con = connection.getInputStream()) {
|
add(new StringWrapper(name), uuid);
|
||||||
InputStreamReader reader = new InputStreamReader(con);
|
}
|
||||||
JSONObject response = (JSONObject) SQLUUIDHandler.this.jsonParser.parse(reader);
|
|
||||||
String name = (String) response.get("name");
|
|
||||||
if (name != null) {
|
|
||||||
add(new StringWrapper(name), uuid);
|
|
||||||
}
|
}
|
||||||
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
|
}catch(IOException | ParseException e){
|
||||||
|
PS.debug("Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(INTERVAL * 50);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (IOException | ParseException e) {
|
|
||||||
PS.debug("Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
|
||||||
}
|
}
|
||||||
TaskManager.runTaskLaterAsync(this, SQLUUIDHandler.this.INTERVAL);
|
if (whenDone != null) {
|
||||||
|
whenDone.run();
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -249,8 +249,8 @@ public abstract class HybridUtils {
|
|||||||
@Override
|
@Override
|
||||||
public void run(Object value) {
|
public void run(Object value) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
Iterator<ChunkLoc> iterator = chunks.iterator();
|
||||||
while (System.currentTimeMillis() - start < 20 && !chunks.isEmpty()) {
|
while (System.currentTimeMillis() - start < 20 && !chunks.isEmpty()) {
|
||||||
Iterator<ChunkLoc> iterator = chunks.iterator();
|
|
||||||
final ChunkLoc chunk = iterator.next();
|
final ChunkLoc chunk = iterator.next();
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
regenerateRoad(area, chunk, extend);
|
regenerateRoad(area, chunk, extend);
|
||||||
|
@ -33,6 +33,9 @@ public class StringWrapper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (getClass() != obj.getClass()) {
|
||||||
|
if (obj.getClass() == String.class) {
|
||||||
|
return obj.toString().equalsIgnoreCase(this.value);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (obj.hashCode() != hashCode()) {
|
if (obj.hashCode() != hashCode()) {
|
||||||
@ -42,7 +45,7 @@ public class StringWrapper {
|
|||||||
if ((other.value == null) || (this.value == null)) {
|
if ((other.value == null) || (this.value == null)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return other.value.equalsIgnoreCase(this.value.toLowerCase());
|
return other.value.equalsIgnoreCase(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +28,7 @@ public abstract class UUIDHandlerImplementation {
|
|||||||
public UUIDWrapper uuidWrapper;
|
public UUIDWrapper uuidWrapper;
|
||||||
private boolean cached = false;
|
private boolean cached = false;
|
||||||
private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
|
private BiMap<UUID, StringWrapper> nameMap = uuidMap.inverse();
|
||||||
|
|
||||||
public UUIDHandlerImplementation(UUIDWrapper wrapper) {
|
public UUIDHandlerImplementation(UUIDWrapper wrapper) {
|
||||||
this.uuidWrapper = wrapper;
|
this.uuidWrapper = wrapper;
|
||||||
@ -61,7 +62,7 @@ public abstract class UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void rename(UUID uuid, StringWrapper name) {
|
public void rename(UUID uuid, StringWrapper name) {
|
||||||
this.uuidMap.inverse().remove(uuid);
|
this.nameMap.remove(uuid);
|
||||||
this.uuidMap.put(name, uuid);
|
this.uuidMap.put(name, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ public abstract class UUIDHandlerImplementation {
|
|||||||
if (uuid == null || name == null) {
|
if (uuid == null || name == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
BiMap<UUID, StringWrapper> inverse = this.uuidMap.inverse();
|
BiMap<UUID, StringWrapper> inverse = this.nameMap;
|
||||||
if (inverse.containsKey(uuid)) {
|
if (inverse.containsKey(uuid)) {
|
||||||
if (this.uuidMap.containsKey(name)) {
|
if (this.uuidMap.containsKey(name)) {
|
||||||
continue;
|
continue;
|
||||||
@ -164,11 +165,17 @@ public abstract class UUIDHandlerImplementation {
|
|||||||
replace(offline, uuid, name.value);
|
replace(offline, uuid, name.value);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
StringWrapper oName = this.nameMap.get(offline);
|
||||||
|
if (!oName.equals(name)) {
|
||||||
|
this.uuidMap.remove(name);
|
||||||
|
this.uuidMap.put(name, uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
BiMap<UUID, StringWrapper> inverse = this.uuidMap.inverse();
|
BiMap<UUID, StringWrapper> inverse = this.nameMap;
|
||||||
if (inverse.containsKey(uuid)) {
|
if (inverse.containsKey(uuid)) {
|
||||||
if (this.uuidMap.containsKey(name)) {
|
if (this.uuidMap.containsKey(name)) {
|
||||||
return false;
|
return false;
|
||||||
@ -209,7 +216,7 @@ public abstract class UUIDHandlerImplementation {
|
|||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
StringWrapper name = this.uuidMap.inverse().get(uuid);
|
StringWrapper name = this.nameMap.get(uuid);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
return name.value;
|
return name.value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user