Search in sources :

Example 26 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class Player method doFirstSpawn.

protected void doFirstSpawn() {
    this.spawned = true;
    this.getAdventureSettings().update();
    this.sendPotionEffects(this);
    this.sendData(this);
    this.inventory.sendContents(this);
    this.inventory.sendArmorContents(this);
    SetTimePacket setTimePacket = new SetTimePacket();
    setTimePacket.time = this.level.getTime();
    this.dataPacket(setTimePacket);
    Position pos = this.level.getSafeSpawn(this);
    PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this, pos);
    this.server.getPluginManager().callEvent(respawnEvent);
    pos = respawnEvent.getRespawnPosition();
    if (this.getHealth() <= 0) {
        RespawnPacket respawnPacket = new RespawnPacket();
        pos = this.getSpawn();
        respawnPacket.x = (float) pos.x;
        respawnPacket.y = (float) pos.y;
        respawnPacket.z = (float) pos.z;
        this.dataPacket(respawnPacket);
    } else {
        RespawnPacket respawnPacket = new RespawnPacket();
        respawnPacket.x = (float) pos.x;
        respawnPacket.y = (float) pos.y;
        respawnPacket.z = (float) pos.z;
        this.dataPacket(respawnPacket);
    }
    this.sendPlayStatus(PlayStatusPacket.PLAYER_SPAWN);
    PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(this, new TranslationContainer(TextFormat.YELLOW + "%multiplayer.player.joined", new String[] { this.getDisplayName() }));
    this.server.getPluginManager().callEvent(playerJoinEvent);
    if (playerJoinEvent.getJoinMessage().toString().trim().length() > 0) {
        this.server.broadcastMessage(playerJoinEvent.getJoinMessage());
    }
    this.noDamageTicks = 60;
    this.getServer().sendRecipeList(this);
    if (this.gamemode == Player.SPECTATOR) {
        InventoryContentPacket inventoryContentPacket = new InventoryContentPacket();
        inventoryContentPacket.inventoryId = ContainerIds.CREATIVE;
        this.dataPacket(inventoryContentPacket);
    } else {
        inventory.sendCreativeContents();
    }
    for (long index : this.usedChunks.keySet()) {
        int chunkX = Level.getHashX(index);
        int chunkZ = Level.getHashZ(index);
        for (Entity entity : this.level.getChunkEntities(chunkX, chunkZ).values()) {
            if (this != entity && !entity.closed && entity.isAlive()) {
                entity.spawnTo(this);
            }
        }
    }
    int experience = this.getExperience();
    if (experience != 0) {
        this.sendExperience(experience);
    }
    int level = this.getExperienceLevel();
    if (level != 0) {
        this.sendExperienceLevel(this.getExperienceLevel());
    }
    // Prevent PlayerTeleportEvent during player spawn
    this.teleport(pos, null);
    if (!this.isSpectator()) {
        this.spawnToAll();
    }
    // Weather
    if (this.level.isRaining() || this.level.isThundering()) {
        this.getLevel().sendWeather(this);
    }
    this.getLevel().sendWeather(this);
    // FoodLevel
    PlayerFood food = this.getFoodData();
    if (food.getLevel() != food.getMaxLevel()) {
        food.sendFoodLevel();
    }
}
Also used : BlockEntity(cn.nukkit.blockentity.BlockEntity) TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 27 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class PluginsCommand method sendPluginList.

private void sendPluginList(CommandSender sender) {
    String list = "";
    Map<String, Plugin> plugins = sender.getServer().getPluginManager().getPlugins();
    for (Plugin plugin : plugins.values()) {
        if (list.length() > 0) {
            list += TextFormat.WHITE + ", ";
        }
        list += plugin.isEnabled() ? TextFormat.GREEN : TextFormat.RED;
        list += plugin.getDescription().getFullName();
    }
    sender.sendMessage(new TranslationContainer("nukkit.command.plugins.success", new String[] { String.valueOf(plugins.size()), list }));
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer) Plugin(cn.nukkit.plugin.Plugin)

Example 28 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class SaveOffCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    sender.getServer().setAutoSave(false);
    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.disabled"));
    return true;
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 29 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class SaveOnCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    sender.getServer().setAutoSave(true);
    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.enabled"));
    return true;
}
Also used : TranslationContainer(cn.nukkit.lang.TranslationContainer)

Example 30 with TranslationContainer

use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.

the class SayCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }
    String senderString;
    if (sender instanceof Player) {
        senderString = ((Player) sender).getDisplayName();
    } else if (sender instanceof ConsoleCommandSender) {
        senderString = "Server";
    } else {
        senderString = sender.getName();
    }
    String msg = "";
    for (String arg : args) {
        msg += arg + " ";
    }
    if (msg.length() > 0) {
        msg = msg.substring(0, msg.length() - 1);
    }
    sender.getServer().broadcastMessage(new TranslationContainer(TextFormat.LIGHT_PURPLE + "%chat.type.announcement", new String[] { senderString, TextFormat.LIGHT_PURPLE + msg }));
    return true;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer) ConsoleCommandSender(cn.nukkit.command.ConsoleCommandSender)

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