Search in sources :

Example 1 with SetDifficultyPacket

use of cn.nukkit.network.protocol.SetDifficultyPacket in project Nukkit by Nukkit.

the class DifficultyCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length != 1) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }
    int difficulty = Server.getDifficultyFromString(args[0]);
    if (sender.getServer().isHardcore()) {
        difficulty = 3;
    }
    if (difficulty != -1) {
        sender.getServer().setPropertyInt("difficulty", difficulty);
        SetDifficultyPacket pk = new SetDifficultyPacket();
        pk.difficulty = sender.getServer().getDifficulty();
        Server.broadcastPacket(new ArrayList<>(sender.getServer().getOnlinePlayers().values()), pk);
        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.difficulty.success", String.valueOf(difficulty)));
    } else {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }
    return true;
}
Also used : SetDifficultyPacket(cn.nukkit.network.protocol.SetDifficultyPacket) TranslationContainer(cn.nukkit.lang.TranslationContainer)

Aggregations

TranslationContainer (cn.nukkit.lang.TranslationContainer)1 SetDifficultyPacket (cn.nukkit.network.protocol.SetDifficultyPacket)1