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