diff --git a/src/main/java/pw/kaboom/extras/Events.java b/src/main/java/pw/kaboom/extras/Events.java index 6d8c91a..7738640 100644 --- a/src/main/java/pw/kaboom/extras/Events.java +++ b/src/main/java/pw/kaboom/extras/Events.java @@ -55,6 +55,8 @@ import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.SpawnerSpawnEvent; +import org.bukkit.event.inventory.InventoryClickEvent; + import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -165,6 +167,12 @@ class Events implements Listener { event.setMessage(ChatColor.translateAlternateColorCodes('&', event.getMessage())); } + @EventHandler + void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) { + main.commandMillisList.put(event.getUniqueId(), System.currentTimeMillis()); + main.interactMillisList.put(event.getUniqueId(), System.currentTimeMillis()); + } + @EventHandler void onBlockPhysics(BlockPhysicsEvent event) { Block block = event.getBlock(); @@ -418,6 +426,21 @@ class Events implements Listener { } } + /*@EventHandler + void onInventoryClick(InventoryClickEvent event) { + int length = 0; + for (ItemStack itemStack : event.getClickedInventory().getContents()) { + if (itemStack != null) { + length = length + itemStack.toString().length(); + } + } + System.out.println("inventory"); + System.out.println(length); + if (length > 100000) { + event.getClickedInventory().clear(); + } + }*/ + @EventHandler void onItemSpawn(ItemSpawnEvent event) { ItemStack item = event.getEntity().getItemStack(); @@ -491,30 +514,9 @@ class Events implements Listener { @EventHandler void onPlayerJoin(PlayerJoinEvent event) { - final Player player = event.getPlayer(); + Player player = event.getPlayer(); - Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { - public void run() { - main.getSkin(player.getName(), player); - } - }); - - if (player.getInventory().getContents().length != 0) { - System.out.println("hm"); - for (ItemStack item : player.getInventory().getContents()) { - if (item != null) { - try { - item.getItemMeta(); - } catch (Exception e) { - player.getInventory().remove(item); - } - } - } - } - - main.commandMillisList.put(player.getUniqueId(), System.currentTimeMillis()); - main.interactMillisList.put(player.getUniqueId(), System.currentTimeMillis()); - player.setOp(true); + player.getInventory().clear(); player.sendTitle(ChatColor.GRAY + "Welcome to Kaboom!", "Free OP • Anarchy • Creative", 10, 160, 5); } @@ -525,6 +527,8 @@ class Events implements Listener { @EventHandler void onPlayerLogin(PlayerLoginEvent event) { + final Player player = event.getPlayer(); + if (Bukkit.getOnlinePlayers().size() > 30) { if (main.onlineCount == 5) { event.allow(); @@ -533,13 +537,20 @@ class Events implements Listener { event.disallow(Result.KICK_OTHER, "The server is throttled due to bot attacks. Please try logging in again."); main.onlineCount++; } - } else if (!(event.getHostname().startsWith("play.kaboom.pw") && + /*} else if (!(event.getHostname().startsWith("play.kaboom.pw") && event.getHostname().endsWith(":64518"))) { - event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw"); + event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw");*/ } else { event.allow(); } - System.out.println("\"" + event.getHostname() + "\""); + + player.setOp(true); + + Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { + public void run() { + main.getSkin(player.getName(), player); + } + }); } @EventHandler diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index 118c5d1..6cf97c6 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -3,11 +3,11 @@ package pw.kaboom.extras; import java.io.File; import java.io.InputStreamReader; import java.net.URL; -import java.net.HttpURLConnection; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.UUID; +import javax.net.ssl.HttpsURLConnection; import com.destroystokyo.paper.profile.PlayerProfile; import com.destroystokyo.paper.profile.ProfileProperty; @@ -453,22 +453,28 @@ public class Main extends JavaPlugin { public void getSkin(String name, final Player player) { try { - URL nameurl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); - HttpURLConnection nameconnection = (HttpURLConnection) nameurl.openConnection(); + URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); + HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection(); - if (nameconnection.getResponseCode() == 200) { - InputStreamReader namestream = new InputStreamReader(nameconnection.getInputStream()); - String uuid = new JsonParser().parse(namestream).getAsJsonObject().get("id").getAsString(); - URL uuidurl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); - HttpURLConnection uuidconnection = (HttpURLConnection) uuidurl.openConnection(); + if (nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) { + System.out.println("ok"); + InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream()); + String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString(); + nameStream.close(); + nameConnection.disconnect(); - if (uuidconnection.getResponseCode() == 200) { - InputStreamReader uuidstream = new InputStreamReader(uuidconnection.getInputStream()); - JsonObject response = new JsonParser().parse(uuidstream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); + 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) { + 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(); final String signature = response.get("signature").getAsString(); + uuidStream.close(); + uuidConnection.disconnect(); - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + Bukkit.getScheduler().runTask(this, new Runnable() { @Override public void run() { PlayerProfile textureprofile = player.getPlayerProfile(); @@ -476,12 +482,13 @@ public class Main extends JavaPlugin { player.setPlayerProfile(textureprofile); } }); + } else { + uuidConnection.disconnect(); } - uuidconnection.disconnect(); + } else { + nameConnection.disconnect(); } - nameconnection.disconnect(); } catch (Exception exception) { - exception.printStackTrace(); } } }