• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConsoleCommandSender类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:25,代码来源:MuteCommand.java


示例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);
		}
}
 
开发者ID:haniokasai,项目名称:TimeCommander-Nukkit,代码行数:26,代码来源:Main.java


示例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);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:61,代码来源:TimingsExport.java


示例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;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:36,代码来源:SayCommand.java


示例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;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:30,代码来源:SimpleCommand.java


示例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;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:37,代码来源:SummonCommand.java


示例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;
}
 
开发者ID:IntellectualSites,项目名称:PlotSquared,代码行数:11,代码来源:NukkitCommand.java


示例8: getConsoleSender

import cn.nukkit.command.ConsoleCommandSender; //导入依赖的package包/类
public ConsoleCommandSender getConsoleSender() {
    return consoleSender;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:4,代码来源:Server.java


示例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;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:55,代码来源:StopSoundCommand.java


示例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++;
    }
}
 
开发者ID:TheSolidCrafter,项目名称:ASkyBlock-Nukkit,代码行数:60,代码来源:AdminCMD.java


示例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);
    }
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:61,代码来源:TimingsExport.java



注:本文中的cn.nukkit.command.ConsoleCommandSender类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FileNameMapper类代码示例发布时间:2022-05-21
下一篇:
Java EngineConfiguration类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap