use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class TimingsExport method run.
@Override
public void run() {
this.sender.sendMessage(new TranslationContainer("nukkit.command.timings.uploadStart"));
this.out.add("data", JsonUtil.mapToArray(this.history, TimingsHistory::export));
String response = null;
try {
HttpURLConnection con = (HttpURLConnection) new URL("http://timings.aikar.co/post").openConnection();
con.setDoOutput(true);
con.setRequestProperty("User-Agent", "Nukkit/" + Server.getInstance().getName() + "/" + InetAddress.getLocalHost().getHostName());
con.setRequestMethod("POST");
con.setInstanceFollowRedirects(false);
PGZIPOutputStream request = new PGZIPOutputStream(con.getOutputStream());
request.setLevel(Deflater.BEST_COMPRESSION);
request.write(new Gson().toJson(this.out).getBytes("UTF-8"));
request.close();
response = getResponse(con);
if (con.getResponseCode() != 302) {
this.sender.sendMessage(new TranslationContainer("nukkit.command.timings.uploadError", new String[] { String.valueOf(con.getResponseCode()), con.getResponseMessage() }));
if (response != null) {
Server.getInstance().getLogger().alert(response);
}
return;
}
String location = con.getHeaderField("Location");
this.sender.sendMessage(new TranslationContainer("nukkit.command.timings.timingsLocation", location));
if (!(this.sender instanceof ConsoleCommandSender)) {
Server.getInstance().getLogger().info(Server.getInstance().getLanguage().translateString("nukkit.command.timings.timingsLocation", location));
}
if (response != null && !response.isEmpty()) {
Server.getInstance().getLogger().info(Server.getInstance().getLanguage().translateString("nukkit.command.timings.timingsResponse", response));
}
File timingFolder = new File(Server.getInstance().getDataPath() + File.separator + "timings");
timingFolder.mkdirs();
String fileName = timingFolder + File.separator + new SimpleDateFormat("'timings-'yyyy-MM-dd-hh-mm'.txt'").format(new Date());
FileWriter writer = new FileWriter(fileName);
writer.write(Server.getInstance().getLanguage().translateString("nukkit.command.timings.timingsLocation", location) + "\n\n");
writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(this.out));
writer.close();
Server.getInstance().getLogger().info(Server.getInstance().getLanguage().translateString("nukkit.command.timings.timingsWrite", fileName));
} catch (IOException exception) {
this.sender.sendMessage(TextFormat.RED + "" + new TranslationContainer("nukkit.command.timings.reportError"));
if (response != null) {
Server.getInstance().getLogger().alert(response);
}
Server.getInstance().getLogger().logException(exception);
}
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class TimingsExport method start.
@Override
public synchronized void start() {
if (this.sender instanceof RemoteConsoleCommandSender) {
this.sender.sendMessage(new TranslationContainer("nukkit.command.timings.rcon"));
run();
} else {
super.start();
}
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class Command method broadcastCommandMessage.
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
Set<Permissible> users = source.getServer().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
TranslationContainer result = new TranslationContainer("chat.type.admin", new String[] { source.getName(), message });
TranslationContainer colored = new TranslationContainer(TextFormat.GRAY + "" + TextFormat.ITALIC + "%chat.type.admin", new String[] { source.getName(), message });
if (sendToSource && !(source instanceof ConsoleCommandSender)) {
source.sendMessage(message);
}
for (Permissible user : users) {
if (user instanceof CommandSender) {
if (user instanceof ConsoleCommandSender) {
((ConsoleCommandSender) user).sendMessage(result);
} else if (!user.equals(source)) {
((CommandSender) user).sendMessage(colored);
}
}
}
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class BlockBed method onActivate.
@Override
public boolean onActivate(Item item, Player player) {
int time = this.getLevel().getTime() % Level.TIME_FULL;
boolean isNight = (time >= Level.TIME_NIGHT && time < Level.TIME_SUNRISE);
if (player != null && !isNight) {
player.sendMessage(new TranslationContainer("tile.bed.noSleep"));
return true;
}
Block blockNorth = this.north();
Block blockSouth = this.south();
Block blockEast = this.east();
Block blockWest = this.west();
Block b;
if ((this.getDamage() & 0x08) == 0x08) {
b = this;
} else {
if (blockNorth.getId() == this.getId() && (blockNorth.getDamage() & 0x08) == 0x08) {
b = blockNorth;
} else if (blockSouth.getId() == this.getId() && (blockSouth.getDamage() & 0x08) == 0x08) {
b = blockSouth;
} else if (blockEast.getId() == this.getId() && (blockEast.getDamage() & 0x08) == 0x08) {
b = blockEast;
} else if (blockWest.getId() == this.getId() && (blockWest.getDamage() & 0x08) == 0x08) {
b = blockWest;
} else {
if (player != null) {
player.sendMessage(new TranslationContainer("tile.bed.notValid"));
}
return true;
}
}
if (player != null && !player.sleepOn(b)) {
player.sendMessage(new TranslationContainer("tile.bed.occupied"));
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class TimingsExport method getResponse.
private String getResponse(HttpURLConnection con) throws IOException {
InputStream is = null;
try {
is = con.getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(b)) != -1) {
bos.write(b, 0, bytesRead);
}
return bos.toString();
} catch (IOException exception) {
this.sender.sendMessage(TextFormat.RED + "" + new TranslationContainer("nukkit.command.timings.reportError"));
Server.getInstance().getLogger().warning(con.getResponseMessage(), exception);
return null;
} finally {
if (is != null) {
is.close();
}
}
}
Aggregations