cn.nukkit.command.defaults.DayLockCommand Maven / Gradle / Ivy
package cn.nukkit.command.defaults;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandParameter;
import cn.nukkit.command.exceptions.CommandSyntaxException;
import cn.nukkit.command.utils.CommandParser;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.level.GameRule;
import cn.nukkit.level.GameRules;
import cn.nukkit.level.Level;
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public class DayLockCommand extends VanillaCommand {
public DayLockCommand(String name) {
super(name, "commands.daylock.description", "", new String[]{"alwaysday"});
this.setPermission("nukkit.command.daylock");
this.getCommandParameters().clear();
this.addCommandParameters("default", new CommandParameter[]{
CommandParameter.newEnum("lock", true, new String[]{"true", "false"})
});
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return false;
}
CommandParser parser = new CommandParser(this, sender, args);
try {
boolean lock = true;
if (args.length > 0) {
lock = parser.parseBoolean();
}
Level level = parser.getTargetLevel();
GameRules rules = level.getGameRules();
if (lock) {
rules.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
level.stopTime();
level.setTime(5000);
} else {
rules.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, true);
level.startTime();
}
} catch (CommandSyntaxException e) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", "\n" + this.getCommandFormatTips()));
return false;
}
return true;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy