mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
parent
84a6a6daf4
commit
538e2a6002
@ -112,31 +112,37 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
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 =
|
||||
(HttpURLConnection) new URL(SQLUUIDHandler.this.PROFILE_URL + uuid.toString().replace("-", ""))
|
||||
.openConnection();
|
||||
try (InputStream con = connection.getInputStream()) {
|
||||
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);
|
||||
while (!toFetch.isEmpty()) {
|
||||
try {
|
||||
for (int i = 0; i < Math.min(500, toFetch.size()); i++) {
|
||||
UUID uuid = toFetch.pop();
|
||||
HttpURLConnection connection =
|
||||
(HttpURLConnection) new URL(SQLUUIDHandler.this.PROFILE_URL + uuid.toString().replace("-", ""))
|
||||
.openConnection();
|
||||
try (InputStream con = connection.getInputStream()) {
|
||||
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
|
||||
public void run(Object value) {
|
||||
long start = System.currentTimeMillis();
|
||||
Iterator<ChunkLoc> iterator = chunks.iterator();
|
||||
while (System.currentTimeMillis() - start < 20 && !chunks.isEmpty()) {
|
||||
Iterator<ChunkLoc> iterator = chunks.iterator();
|
||||
final ChunkLoc chunk = iterator.next();
|
||||
iterator.remove();
|
||||
regenerateRoad(area, chunk, extend);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user