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