Search in sources :

Example 21 with TranslationContainer

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);
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) PGZIPOutputStream(cn.nukkit.nbt.stream.PGZIPOutputStream) Gson(com.google.gson.Gson) ConsoleCommandSender(cn.nukkit.command.ConsoleCommandSender) RemoteConsoleCommandSender(cn.nukkit.command.RemoteConsoleCommandSender) URL(java.net.URL) Date(java.util.Date) HttpURLConnection(java.net.HttpURLConnection) TranslationContainer(cn.nukkit.lang.TranslationContainer) SimpleDateFormat(java.text.SimpleDateFormat)

Example 22 with TranslationContainer

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();
    }
}
Also used : RemoteConsoleCommandSender(cn.nukkit.command.RemoteConsoleCommandSender) TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 23 with TranslationContainer

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);
            }
        }
    }
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer) Permissible(cn.nukkit.permission.Permissible)

Example 24 with TranslationContainer

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;
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 25 with TranslationContainer

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();
        }
    }
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer)

Aggregations

TranslationContainer (cn.nukkit.lang.TranslationContainer)49 Player (cn.nukkit.Player)24 Level (cn.nukkit.level.Level)6 BlockEntity (cn.nukkit.blockentity.BlockEntity)3 CommandSender (cn.nukkit.command.CommandSender)3 ConsoleCommandSender (cn.nukkit.command.ConsoleCommandSender)3 EntityDamageEvent (cn.nukkit.event.entity.EntityDamageEvent)3 Plugin (cn.nukkit.plugin.Plugin)3 IPlayer (cn.nukkit.IPlayer)2 Command (cn.nukkit.command.Command)2 RemoteConsoleCommandSender (cn.nukkit.command.RemoteConsoleCommandSender)2 EntityDamageByBlockEvent (cn.nukkit.event.entity.EntityDamageByBlockEvent)2 EntityDamageByEntityEvent (cn.nukkit.event.entity.EntityDamageByEntityEvent)2 Item (cn.nukkit.item.Item)2 Enchantment (cn.nukkit.item.enchantment.Enchantment)2 Effect (cn.nukkit.potion.Effect)2 DecimalFormat (java.text.DecimalFormat)2 Type (cn.nukkit.AdventureSettings.Type)1 cn.nukkit.block (cn.nukkit.block)1 BlockEntityItemFrame (cn.nukkit.blockentity.BlockEntityItemFrame)1