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,36 +619,48 @@ class Events implements Listener {
void onPlayerDeath(PlayerDeathEvent event) { void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity(); Player player = event.getEntity();
player.setHealth(20); 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.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 &&
Bukkit.getScheduler().runTask(main, new Runnable() { player.getLastDamageCause().getDamage() == Float.MAX_VALUE) {
public void run() { return;
if (player.getBedSpawnLocation() != null) { }
player.teleport(player.getBedSpawnLocation());
} else {
World world = Bukkit.getWorld("world");
Location spawnLoc = world.getSpawnLocation();
for (double y = spawnLoc.getY(); y <= 256; y++) { Bukkit.getScheduler().runTask(main, new Runnable() {
Location yLoc = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ()); public void run() {
Block coordBlock = world.getBlockAt(yLoc); if (player.getBedSpawnLocation() != null) {
player.teleport(player.getBedSpawnLocation());
} else {
World world = Bukkit.getWorld("world");
Location spawnLoc = world.getSpawnLocation();
if (coordBlock.getType().isTransparent() && for (double y = spawnLoc.getY(); y <= 256; y++) {
coordBlock.getRelative(BlockFace.UP).getType().isTransparent()) { Location yLoc = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ());
player.teleport(yLoc); Block coordBlock = world.getBlockAt(yLoc);
break;
} if (coordBlock.getType().isTransparent() &&
coordBlock.getRelative(BlockFace.UP).getType().isTransparent()) {
player.teleport(yLoc);
break;
} }
} }
} }
}); }
} });
} }
@EventHandler @EventHandler
@ -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) {
} }