本文整理汇总了Java中cn.nukkit.command.ConsoleCommandSender类的典型用法代码示例。如果您正苦于以下问题:Java ConsoleCommandSender类的具体用法?Java ConsoleCommandSender怎么用?Java ConsoleCommandSender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConsoleCommandSender类属于cn.nukkit.command包,在下文中一共展示了ConsoleCommandSender类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if(sender instanceof ConsoleCommandSender){
sender.sendMessage(TextFormat.RED + "コンソールはミュートできません。");
return true;
}
Player p = (Player)sender;
if(p.mute){
p.setMute(false);
p.sendImportantMessage(TextFormat.GREEN + "ミュートを解除しました。");
return true;
}else{
p.setMute(true);
p.sendImportantMessage(TextFormat.RED + "ミュートを有効にしました。");
return true;
}
}
示例2: onEnable
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
public void onEnable() {
this.getServer().getPluginManager().registerEvents(this, this);
getDataFolder().mkdir();
this.saveDefaultConfig();
String i ="1";
int t =1200;
int k =1;
while(this.getConfig().exists("Command"+i)){
String ccmmdd =this.getConfig().get("Command"+i).toString();
int Time = Integer.parseInt(this.getConfig().get("Time"+i).toString());
Server.getInstance().getScheduler().scheduleRepeatingTask(new Runnable() {
public void run() {
Server.getInstance().getScheduler().scheduleDelayedTask(new Runnable() {
public void run() {
Server.getInstance().dispatchCommand(new ConsoleCommandSender(),ccmmdd);
}
}, (Time*t));
}
}, (Time*t));
int ii = (Integer.valueOf(i).intValue() + k);
i = Integer.toString(ii);
}
}
示例3: run
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
@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);
OutputStream request = new GZIPOutputStream(con.getOutputStream()) {
{
this.def.setLevel(7);
}
};
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);
}
}
示例4: execute
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
@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;
}
示例5: execute
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (this.forbidConsole && sender instanceof ConsoleCommandSender) {
this.sendInGameMessage(sender);
return false;
} else if (!this.testPermission(sender)) {
return false;
} else if (this.maxArgs != 0 && args.length > this.maxArgs) {
this.sendUsageMessage(sender);
return false;
} else if (this.minArgs != 0 && args.length < this.minArgs) {
this.sendUsageMessage(sender);
return false;
}
boolean success = false;
try {
success = (Boolean) this.method.invoke(this.object, sender, commandLabel, args);
} catch (Exception exception) {
Server.getInstance().getLogger().logException(exception);
}
if (!success) {
this.sendUsageMessage(sender);
}
return success;
}
示例6: execute
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
return true;
}
if (args.length < 2) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
Position pos = new Position(Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]), ((Player) sender).getLevel());
CompoundTag nbt = new CompoundTag()
.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("", pos.getX() + 0.5))
.add(new DoubleTag("", pos.getY()))
.add(new DoubleTag("", pos.getZ() + 0.5)))
.putList(new ListTag<DoubleTag>("Motion")
.add(new DoubleTag("", 0))
.add(new DoubleTag("", 0))
.add(new DoubleTag("", 0)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("", new Random().nextFloat() * 360))
.add(new FloatTag("", 0)));
Entity entity = Entity.createEntity(args[0], pos.getLevel().getChunk((int) pos.getX() >> 4, (int) pos.getZ() >> 4, true), nbt);
entity.spawnToAll();
return true;
}
示例7: execute
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
@Override
public boolean execute(CommandSender commandSender, String commandLabel, String[] args) {
if (commandSender instanceof Player) {
return MainCommand.onCommand(NukkitUtil.getPlayer((Player) commandSender), args);
}
if (commandSender instanceof ConsoleCommandSender || commandSender instanceof RemoteConsoleCommandSender) {
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
}
return false;
}
示例8: getConsoleSender
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
public ConsoleCommandSender getConsoleSender() {
return consoleSender;
}
示例9: execute
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length < 2) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
Player[] players = new Player[]{};
if (args[0].equals("@e") || args[0].equals("@a")) {
players = sender.getServer().getOnlinePlayers().values().toArray(new Player[0]);
} else if (args[0].equals("@p") || args[0].equals("@s")) {
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
return true;
} else {//TODO: CommandBlockCommandSender
players = new Player[]{(Player) sender};
}
} else if (args[0].equals("@r")) {
List<Player> list = Arrays.asList(sender.getServer().getOnlinePlayers().values().toArray(new Player[0]));
if (list.size() <= 0) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
return true;
}
Collections.shuffle(list);
players = new Player[]{list.get(0)};
} else {
if (sender.getServer().getPlayer(args[0]) == null) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
return true;
}
players = new Player[]{sender.getServer().getPlayer(args[0])};
}
String sound = args[1];
Arrays.asList(players).forEach(p -> {
StopSoundPacket pk = new StopSoundPacket();
pk.name = sound;
pk.stopAll = false;
p.dataPacket(pk);
});
return false;
}
示例10: sendHelp
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
public void sendHelp(CommandSender sender, String label, String[] args) {
Player p = sender.isPlayer() ? sender.getServer().getPlayer(sender.getName()) : null;
int pageNumber = 1;
if (args.length == 2 && Utils.isNumeric(args[1])) {
pageNumber = Integer.parseInt(args[1]);
}
int pageHeight;
if (sender instanceof ConsoleCommandSender) {
pageHeight = Integer.MAX_VALUE;
} else {
pageHeight = 5;
}
List<String> helpList = new ArrayList<>();
helpList.add(""); // Really weird Java Machine bug (Usually this will be stored in List but not)
if (sender.hasPermission("is.admin.rename")) {
helpList.add("&e" + label + " rename &7=> &a" + plugin.getLocale(p).adminHelpRename);
}
if (sender.hasPermission("is.admin.kick")) {
helpList.add("&e" + label + " kick &7=> &a" + plugin.getLocale(p).adminHelpKick);
}
if (sender.hasPermission("is.admin.generate")) {
helpList.add("&e" + label + " generate &7=> &a" + plugin.getLocale(p).adminHelpGenerate);
}
if (sender.hasPermission("is.admin.setspawn")) {
helpList.add("&e" + label + " setspawn &7=> &a" + plugin.getLocale(p).adminHelpSpawn);
}
if (sender.hasPermission("is.admin.delete")) {
helpList.add("&e" + label + " delete &7=> &a" + plugin.getLocale(p).adminHelpDelete);
}
if (label.length() > 4) {
helpList.add("");
helpList.add("&eTired to use looooong commands of isadmin? You can use 'isa' for aliases!");
}
int totalPage = helpList.size() % pageHeight == 0 ? helpList.size() / pageHeight : helpList.size() / pageHeight + 1;
pageNumber = Math.min(pageNumber, totalPage);
if (pageNumber < 1) {
pageNumber = 1;
}
sender.sendMessage("§e--- §eAdmin SkyBlock Help Page §a" + pageNumber + " §eof §a" + totalPage + " §e---");
int i = 0;
for (String list : helpList) {
if (i >= (pageNumber - 1) * pageHeight + 1 && i <= Math.min(helpList.size(), pageNumber * pageHeight)) {
sender.sendMessage(list.replace("&", "§"));
}
i++;
}
}
示例11: run
import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
@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", "Sponge/" + Server.getInstance().getName() + "/" + InetAddress.getLocalHost().getHostName()); //It will be Sponge unless Nukkit is added on Aikar's parser side
con.setRequestMethod("POST");
con.setInstanceFollowRedirects(false);
OutputStream request = new GZIPOutputStream(con.getOutputStream()) {
{
this.def.setLevel(7);
}
};
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);
}
}