Created
February 14, 2016 10:57
-
-
Save haniokasai/6f625100a97ff49ae7a7 to your computer and use it in GitHub Desktop.
nukkit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.test.plugin.tutorialplugin; | |
import cn.nukkit.Player; | |
import cn.nukkit.block.Block; | |
import cn.nukkit.command.Command; | |
import cn.nukkit.command.CommandSender; | |
import cn.nukkit.event.EventHandler; | |
import cn.nukkit.event.Listener; | |
import cn.nukkit.event.player.PlayerInteractEvent; | |
import cn.nukkit.plugin.PluginBase; | |
import cn.nukkit.utils.TextFormat; | |
public class Main extends PluginBase implements Listener{ | |
public void onEnable() { | |
getLogger().info("起動しました"); | |
this.getServer().getPluginManager().registerEvents(this, this);//必須 | |
} | |
//プレイヤーが触ったブロックのIDがわかります。 | |
@EventHandler | |
public void onTouch(PlayerInteractEvent event){//ブロックが触られたら | |
Player player = event.getPlayer();///プレイヤー | |
Block item = event.getBlock();//触られたブロック | |
player.sendMessage(TextFormat.YELLOW + "It id is " + item.getId());//idをプレイヤーに表示します | |
} | |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args){ | |
switch(command.getName()){ | |
case "ip"://ipコマンドの時... | |
/////args[0] つまり /ip <ここ> があるかどうか判断します。 | |
try{if(args[0] != null){}} | |
catch(ArrayIndexOutOfBoundsException e){ | |
System.out.println("args0がないです"); | |
return false;//終了 | |
} | |
////// | |
Player playerx = this.getServer().getPlayer(args[0]);//player | |
if(!(playerx instanceof Player)){///プレイヤーかどうか | |
sender.sendMessage(TextFormat.GREEN + "プレイヤーの名前を入れましょう"); | |
}else{ | |
sender.sendMessage(TextFormat.GREEN + "プレイヤー名:"+ args[0]+" ip:"+playerx.getAddress()); | |
} | |
return true;//終了 | |
} | |
return false;//終了 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment