Bug fixes

This commit is contained in:
mathias 2019-06-25 14:39:51 +03:00
parent f30655a2f8
commit baff8a932a
2 changed files with 40 additions and 32 deletions

View file

@ -273,14 +273,13 @@ class Events implements Listener {
URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + event.getName());
HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection();
if (nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
if (nameConnection != null &&
nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream());
String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString();
main.playerPremiumUUID.put(event.getName(), uuid);
nameStream.close();
nameConnection.disconnect();
} else {
nameConnection.disconnect();
}
} catch (Exception exception) {
}
@ -620,14 +619,27 @@ class Events implements Listener {
void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
final AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
maxHealth.setBaseValue(20);
try {
player.setHealth(20);
} catch (Exception e) {
maxHealth.setBaseValue(Double.POSITIVE_INFINITY);
player.setHealth(20);
maxHealth.setBaseValue(20);
}
player.setFoodLevel(20);
player.setFireTicks(0);
player.setRemainingAir(player.getMaximumAir());
player.getActivePotionEffects().clear();
if (player.getLastDamageCause().getCause() != DamageCause.SUICIDE &&
player.getLastDamageCause().getDamage() != Float.MAX_VALUE) {
if (player.getLastDamageCause() != null &&
player.getLastDamageCause().getCause() == DamageCause.SUICIDE &&
player.getLastDamageCause().getDamage() == Float.MAX_VALUE) {
return;
}
Bukkit.getScheduler().runTask(main, new Runnable() {
public void run() {
if (player.getBedSpawnLocation() != null) {
@ -650,7 +662,6 @@ class Events implements Listener {
}
});
}
}
@EventHandler
void onPlayerInteract(PlayerInteractEvent event) {
@ -702,7 +713,8 @@ class Events implements Listener {
URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + main.playerPremiumUUID.get(player.getName()) + "?unsigned=false");
HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection();
if (uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
if (uuidConnection != null &&
uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream());
JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
final String texture = response.get("value").getAsString();
@ -720,8 +732,6 @@ class Events implements Listener {
player.setPlayerProfile(textureProfile);
}
});
} else {
uuidConnection.disconnect();
}
main.playerPremiumUUID.remove(player.getName());
} catch (Exception exception) {

View file

@ -459,7 +459,8 @@ public class Main extends JavaPlugin {
URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection();
if (nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
if (nameConnection != null &&
nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream());
String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString();
nameStream.close();
@ -468,7 +469,8 @@ public class Main extends JavaPlugin {
URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection();
if (uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
if (uuidConnection != null &&
uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream());
JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
final String texture = response.get("value").getAsString();
@ -486,11 +488,7 @@ public class Main extends JavaPlugin {
player.setPlayerProfile(textureProfile);
}
});
} else {
uuidConnection.disconnect();
}
} else {
nameConnection.disconnect();
}
} catch (Exception exception) {
}