mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-27 09:55:36 -05:00
Workaround for command block crashes
This commit is contained in:
parent
1d7a4166b1
commit
3d67c5aa34
6 changed files with 114 additions and 147 deletions
|
@ -27,62 +27,6 @@ class CommandSkin implements CommandExecutor {
|
|||
this.main = main;
|
||||
}
|
||||
|
||||
private void changeSkin(final Player player, final String name) {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
try {
|
||||
final URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
|
||||
final HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection();
|
||||
|
||||
if (nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream());
|
||||
final String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString();
|
||||
nameStream.close();
|
||||
nameConnection.disconnect();
|
||||
|
||||
final URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
|
||||
final HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection();
|
||||
|
||||
if (uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream());
|
||||
final 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();
|
||||
|
||||
final PlayerProfile textureProfile = player.getPlayerProfile();
|
||||
textureProfile.clearProperties();
|
||||
textureProfile.setProperty(new ProfileProperty("textures", texture, signature));
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
player.setPlayerProfile(textureProfile);
|
||||
player.sendMessage("Successfully set your skin to " + name + "'s");
|
||||
}
|
||||
}.runTask(main);
|
||||
} else {
|
||||
uuidConnection.disconnect();
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
player.sendMessage("Failed to change skin. Try again later");
|
||||
}
|
||||
}.runTask(main);
|
||||
}
|
||||
} else {
|
||||
nameConnection.disconnect();
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
player.sendMessage("A player with that username doesn't exist");
|
||||
}
|
||||
}.runTask(main);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(main);
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) {
|
||||
final Player player = (Player) sender;
|
||||
|
||||
|
@ -90,7 +34,40 @@ class CommandSkin implements CommandExecutor {
|
|||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||
} else {
|
||||
final String name = args[0];
|
||||
changeSkin(player, name);
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
try {
|
||||
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + name);
|
||||
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||
|
||||
if (skinConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
||||
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
||||
final String uuid = response.get("uuid").getAsString();
|
||||
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
||||
final String texture = rawSkin.get("value").getAsString();
|
||||
final String signature = rawSkin.get("signature").getAsString();
|
||||
skinStream.close();
|
||||
|
||||
final PlayerProfile textureProfile = player.getPlayerProfile();
|
||||
textureProfile.clearProperties();
|
||||
textureProfile.setProperty(new ProfileProperty("textures", texture, signature));
|
||||
|
||||
player.sendMessage("Successfully set your skin to " + name + "'s");
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
player.setPlayerProfile(textureProfile);
|
||||
}
|
||||
}.runTask(main);
|
||||
} else {
|
||||
player.sendMessage("A player with that username doesn't exist");
|
||||
}
|
||||
|
||||
skinConnection.disconnect();
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(main);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,14 @@ class CommandUsername implements CommandExecutor {
|
|||
this.main = main;
|
||||
}
|
||||
|
||||
private void changeUsernameSkin(final Player player, final String[] name) {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) {
|
||||
final Player player = (Player) sender;
|
||||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||
} else {
|
||||
final String[] name = args;
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
try {
|
||||
|
@ -37,31 +44,22 @@ class CommandUsername implements CommandExecutor {
|
|||
final String nameColor = ChatColor.translateAlternateColorCodes('&', String.join(" ", name));
|
||||
final String nameShort = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||
|
||||
final URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + nameShort);
|
||||
final HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection();
|
||||
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + nameShort);
|
||||
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||
|
||||
if (nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream());
|
||||
final String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString();
|
||||
nameStream.close();
|
||||
nameConnection.disconnect();
|
||||
|
||||
final URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
|
||||
final HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection();
|
||||
|
||||
if (uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream());
|
||||
final JsonObject response = new JsonParser().parse(uuidStream).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
|
||||
texture = response.get("value").getAsString();
|
||||
signature = response.get("signature").getAsString();
|
||||
|
||||
uuidStream.close();
|
||||
uuidConnection.disconnect();
|
||||
}
|
||||
if (skinConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
||||
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
||||
final String uuid = response.get("uuid").getAsString();
|
||||
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
||||
texture = rawSkin.get("value").getAsString();
|
||||
signature = rawSkin.get("signature").getAsString();
|
||||
skinStream.close();
|
||||
}
|
||||
|
||||
skinConnection.disconnect();
|
||||
|
||||
final PlayerProfile profile = player.getPlayerProfile();
|
||||
profile.clearProperties();
|
||||
profile.setName(nameShort);
|
||||
|
||||
if (!("".equals(texture)) &&
|
||||
|
@ -69,10 +67,10 @@ class CommandUsername implements CommandExecutor {
|
|||
profile.setProperty(new ProfileProperty("textures", texture, signature));
|
||||
}
|
||||
|
||||
player.sendMessage("Successfully set your username to \"" + nameShort + "\"");
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
player.setPlayerProfile(profile);
|
||||
player.sendMessage("Successfully set your username to \"" + nameShort + "\"");
|
||||
}
|
||||
}.runTask(main);
|
||||
} catch (Exception exception) {
|
||||
|
@ -80,16 +78,6 @@ class CommandUsername implements CommandExecutor {
|
|||
}
|
||||
}.runTaskAsynchronously(main);
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) {
|
||||
final Player player = (Player) sender;
|
||||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||
} else {
|
||||
final String[] name = args;
|
||||
changeUsernameSkin(player, name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package pw.kaboom.extras;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CommandBlock;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
|
||||
class BlockCheck implements Listener {
|
||||
@EventHandler
|
||||
void onBlockPlace(BlockPlaceEvent event) {
|
||||
|
@ -20,6 +25,17 @@ class BlockCheck implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onChunkLoad(ChunkLoadEvent event) {
|
||||
if (!event.isNewChunk()) {
|
||||
for (BlockState block : event.getChunk().getTileEntities()) {
|
||||
if (block instanceof CommandBlock) {
|
||||
block.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onSignChange(SignChangeEvent event) {
|
||||
try {
|
||||
|
|
|
@ -44,27 +44,17 @@ class PlayerConnection implements Listener {
|
|||
main.interactMillisList.put(event.getUniqueId(), System.currentTimeMillis());
|
||||
|
||||
try {
|
||||
final URL nameUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + event.getName());
|
||||
final HttpsURLConnection nameConnection = (HttpsURLConnection) nameUrl.openConnection();
|
||||
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + event.getName());
|
||||
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||
|
||||
if (nameConnection != null &&
|
||||
nameConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader nameStream = new InputStreamReader(nameConnection.getInputStream());
|
||||
final String uuid = new JsonParser().parse(nameStream).getAsJsonObject().get("id").getAsString();
|
||||
nameStream.close();
|
||||
nameConnection.disconnect();
|
||||
|
||||
final URL uuidUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
|
||||
final HttpsURLConnection uuidConnection = (HttpsURLConnection) uuidUrl.openConnection();
|
||||
|
||||
if (uuidConnection != null &&
|
||||
uuidConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader uuidStream = new InputStreamReader(uuidConnection.getInputStream());
|
||||
final 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();
|
||||
if (skinConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
||||
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
||||
final String uuid = response.get("uuid").getAsString();
|
||||
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
||||
final String texture = rawSkin.get("value").getAsString();
|
||||
final String signature = rawSkin.get("signature").getAsString();
|
||||
skinStream.close();
|
||||
|
||||
final PlayerProfile textureProfile = event.getPlayerProfile();
|
||||
textureProfile.clearProperties();
|
||||
|
@ -72,7 +62,8 @@ class PlayerConnection implements Listener {
|
|||
|
||||
main.playerProfile.put(event.getName(), textureProfile);
|
||||
}
|
||||
}
|
||||
|
||||
skinConnection.disconnect();
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,8 @@ class PlayerDamage implements Listener {
|
|||
@EventHandler
|
||||
void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.getEntityType() == EntityType.PLAYER) {
|
||||
if (((event.getCause() == DamageCause.CUSTOM ||
|
||||
event.getCause() == DamageCause.SUICIDE) &&
|
||||
event.getDamage() == Short.MAX_VALUE) ||
|
||||
(event.getCause() == DamageCause.VOID &&
|
||||
event.getDamage() == Float.MAX_VALUE)) {
|
||||
event.setDamage(Float.MAX_VALUE);
|
||||
if (event.getCause() == DamageCause.VOID &&
|
||||
event.getDamage() == Float.MAX_VALUE) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -60,10 +56,7 @@ class PlayerDamage implements Listener {
|
|||
onlinePlayer.sendMessage(event.getDeathMessage());
|
||||
}
|
||||
|
||||
if ((player.getLastDamageCause() != null &&
|
||||
player.getLastDamageCause().getCause() == DamageCause.SUICIDE &&
|
||||
player.getLastDamageCause().getDamage() == Float.MAX_VALUE) ||
|
||||
maxHealthLow) {
|
||||
if (maxHealthLow) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ import org.bukkit.event.Listener;
|
|||
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
|
||||
class ServerCommand implements Listener {
|
||||
private Main main;
|
||||
public ServerCommand(Main main) {
|
||||
|
|
Loading…
Reference in a new issue