Fixes #1697
Fixes #1689
This commit is contained in:
Jesse Boyd 2017-08-18 12:37:26 +10:00
parent 84a6a6daf4
commit 538e2a6002
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 43 additions and 27 deletions

View File

@ -112,13 +112,8 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
while (!toFetch.isEmpty()) {
try {
if (toFetch.isEmpty()) {
if (whenDone != null) {
whenDone.run();
}
return;
}
for (int i = 0; i < Math.min(500, toFetch.size()); i++) {
UUID uuid = toFetch.pop();
HttpURLConnection connection =
@ -132,11 +127,22 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
add(new StringWrapper(name), uuid);
}
}
connection.disconnect();
}
} catch (IOException | ParseException e) {
}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);
try {
Thread.sleep(INTERVAL * 50);
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
}
if (whenDone != null) {
whenDone.run();
}
return;
}
});
}

View File

@ -249,8 +249,8 @@ public abstract class HybridUtils {
@Override
public void run(Object value) {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 20 && !chunks.isEmpty()) {
Iterator<ChunkLoc> iterator = chunks.iterator();
while (System.currentTimeMillis() - start < 20 && !chunks.isEmpty()) {
final ChunkLoc chunk = iterator.next();
iterator.remove();
regenerateRoad(area, chunk, extend);

View File

@ -33,6 +33,9 @@ public class StringWrapper {
return false;
}
if (getClass() != obj.getClass()) {
if (obj.getClass() == String.class) {
return obj.toString().equalsIgnoreCase(this.value);
}
return false;
}
if (obj.hashCode() != hashCode()) {
@ -42,7 +45,7 @@ public class StringWrapper {
if ((other.value == null) || (this.value == null)) {
return false;
}
return other.value.equalsIgnoreCase(this.value.toLowerCase());
return other.value.equalsIgnoreCase(this.value);
}
/**

View File

@ -28,6 +28,7 @@ public abstract class UUIDHandlerImplementation {
public UUIDWrapper uuidWrapper;
private boolean cached = false;
private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
private BiMap<UUID, StringWrapper> nameMap = uuidMap.inverse();
public UUIDHandlerImplementation(UUIDWrapper wrapper) {
this.uuidWrapper = wrapper;
@ -61,7 +62,7 @@ public abstract class UUIDHandlerImplementation {
}
public void rename(UUID uuid, StringWrapper name) {
this.uuidMap.inverse().remove(uuid);
this.nameMap.remove(uuid);
this.uuidMap.put(name, uuid);
}
@ -75,7 +76,7 @@ public abstract class UUIDHandlerImplementation {
if (uuid == null || name == null) {
continue;
}
BiMap<UUID, StringWrapper> inverse = this.uuidMap.inverse();
BiMap<UUID, StringWrapper> inverse = this.nameMap;
if (inverse.containsKey(uuid)) {
if (this.uuidMap.containsKey(name)) {
continue;
@ -164,11 +165,17 @@ public abstract class UUIDHandlerImplementation {
replace(offline, uuid, name.value);
}
return true;
} else {
StringWrapper oName = this.nameMap.get(offline);
if (!oName.equals(name)) {
this.uuidMap.remove(name);
this.uuidMap.put(name, uuid);
}
}
return false;
}
} catch (Exception ignored) {
BiMap<UUID, StringWrapper> inverse = this.uuidMap.inverse();
BiMap<UUID, StringWrapper> inverse = this.nameMap;
if (inverse.containsKey(uuid)) {
if (this.uuidMap.containsKey(name)) {
return false;
@ -209,7 +216,7 @@ public abstract class UUIDHandlerImplementation {
if (uuid == null) {
return null;
}
StringWrapper name = this.uuidMap.inverse().get(uuid);
StringWrapper name = this.nameMap.get(uuid);
if (name != null) {
return name.value;
}