Java Code Examples for cn.nukkit.Player#sendMessage()
The following examples show how to use
cn.nukkit.Player#sendMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SetSpawnCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
@Override public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.ingame")); return false; } if (args.length != 0) { this.sendUsage(sender); return false; } Player p = (Player) sender; getAPI().getServer().setDefaultLevel(p.getLevel()); p.getLevel().setSpawnLocation(p); p.sendMessage(TextFormat.YELLOW + Language.translate("commands.setspawn.success")); getAPI().getLogger().info(TextFormat.YELLOW + "Server's spawn point set to " + TextFormat.AQUA + p.getLevel().getName() + TextFormat.YELLOW + " by " + TextFormat.GREEN + p.getName()); return true; }
Example 2
Source File: TPHereCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length != 1) { this.sendUsage(sender); return false; } Player player = api.getServer().getPlayer(args[0]); if (player == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0])); return false; } player.teleport((Player) sender); player.sendMessage(Language.translate("commands.tphere.other", ((Player) sender).getDisplayName())); sender.sendMessage(Language.translate("commands.tphere.success", player.getDisplayName())); return true; }
Example 3
Source File: TPAHereCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length != 1) { this.sendUsage(sender); return false; } Player player = api.getServer().getPlayer(args[0]); if (player == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0])); return false; } if (sender == player) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpa.self")); return false; } api.requestTP((Player) sender, player, false); player.sendMessage(Language.translate("commands.tpahere.invite", ((Player) sender).getName())); sender.sendMessage(Language.translate("commands.tpa.success", player.getDisplayName())); return true; }
Example 4
Source File: TellCommand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@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 false; } String name = args[0].toLowerCase(); Player player = sender.getServer().getPlayer(name); if (player == null) { sender.sendMessage(new TranslationContainer("commands.generic.player.notFound")); return true; } if (Objects.equals(player, sender)) { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.message.sameTarget")); return true; } String msg = ""; for (int i = 1; i < args.length; i++) { msg += args[i] + " "; } if (msg.length() > 0) { msg = msg.substring(0, msg.length() - 1); } String displayName = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()); sender.sendMessage("[" + sender.getName() + " -> " + player.getDisplayName() + "] " + msg); player.sendMessage("[" + displayName + " -> " + player.getName() + "] " + msg); return true; }
Example 5
Source File: EventListener.java From EssentialsNK with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); if (api.isMuted(player)) { event.setCancelled(); player.sendMessage(Language.translate("commands.generic.muted", api.getUnmuteTimeMessage(player))); } }
Example 6
Source File: EventListener.java From EssentialsNK with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerChat(PlayerChatEvent event) { Player player = event.getPlayer(); if (api.isMuted(player)) { event.setCancelled(); player.sendMessage(Language.translate("commands.generic.muted", api.getUnmuteTimeMessage(player))); } }
Example 7
Source File: TeleportNPC.java From FNPC-Nukkit with Do What The F*ck You Want To Public License | 5 votes |
@Override public void onTouch(Player player) { if(this.teleport.getOrDefault("ip",null)!=null && this.teleport.getOrDefault("port",null)!=null) { StrangePacket pk=new StrangePacket(); pk.address=Utils.cast(this.teleport.getOrDefault("ip","")); pk.port=Short.parseShort(Utils.cast(this.teleport.getOrDefault("port",0))); player.dataPacket(pk); } else if(this.teleport.getOrDefault("x",null)==null || this.teleport.getOrDefault("y",null)==null || this.teleport.getOrDefault("z",null)==null) { player.sendMessage("[System] "+TextFormat.RED+"该NPC未设置传送目标"); } else if(this.teleport.getOrDefault("level",null)!=null) { Level level=Main.getInstance().getServer().getLevelByName(Utils.cast(this.teleport.get("level"))); if(level==null) { player.sendMessage("[System] "+TextFormat.RED+"目标传送世界不存在"); } else { player.teleport(new Position(Utils.cast(this.teleport.getOrDefault("x",0)),Utils.cast(this.teleport.getOrDefault("y",0)),Utils.cast(this.teleport.getOrDefault("z",0)),level)); player.sendMessage("[System] "+TextFormat.GREEN+"传送成功"); } } else { player.teleport(new Vector3(Utils.cast(this.teleport.getOrDefault("x",0)),Utils.cast(this.teleport.getOrDefault("y",0)),Utils.cast(this.teleport.getOrDefault("z",0)))); player.sendMessage("[System] "+TextFormat.GREEN+"传送成功"); } }
Example 8
Source File: ReplyNPC.java From FNPC-Nukkit with Do What The F*ck You Want To Public License | 5 votes |
@Override public void onTouch(Player player) { Object[] arr=this.chat.toArray(); if(arr.length>0) { player.sendMessage("<"+this.nametag+"> "+arr[new Random().nextInt(arr.length)]); } }
Example 9
Source File: TakeMoneyCommand.java From EconomyAPI with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String label, String[] args) { if(!this.plugin.isEnabled()) return false; if(!sender.hasPermission("economyapi.command.takemoney")){ sender.sendMessage(TextFormat.RED + "You don't have permission to use this command."); return false; } if(args.length < 2){ sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage()); return true; } String player = args[0]; Player p = this.plugin.getServer().getPlayer(player); if(p != null){ player = p.getName(); } try{ double amount = Double.parseDouble(args[1]); if(amount < 0){ sender.sendMessage(this.plugin.getMessage("takemoney-invalid-number", sender)); return true; } int result = this.plugin.reduceMoney(player, amount); switch(result){ case EconomyAPI.RET_INVALID: sender.sendMessage(this.plugin.getMessage("takemoney-player-lack-of-money", new String[]{player, Double.toString(amount), Double.toString(this.plugin.myMoney(player))}, sender)); return true; case EconomyAPI.RET_NO_ACCOUNT: sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender)); return true; case EconomyAPI.RET_CANCELLED: sender.sendMessage(this.plugin.getMessage("takemoney-failed", new String[]{player}, sender)); return true; case EconomyAPI.RET_SUCCESS: sender.sendMessage(this.plugin.getMessage("takemoney-took-money", new String[]{player, Double.toString(amount)}, sender)); if(p instanceof Player){ p.sendMessage(this.plugin.getMessage("takemoney-money-taken", new String[]{Double.toString(amount)}, sender)); } return true; } }catch(NumberFormatException e){ sender.sendMessage(this.plugin.getMessage("takemoney-must-be-number", sender)); } return true; }
Example 10
Source File: PayCommand.java From EconomyAPI with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String label, String[] args){ if(!this.plugin.isEnabled()) return false; if(!sender.hasPermission("economyapi.command.pay")){ sender.sendMessage(TextFormat.RED + "You don't have permission to use this command."); return false; } if(!(sender instanceof Player)){ sender.sendMessage(TextFormat.RED + "Please use this command in-game."); return true; } if(args.length < 2){ sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage()); return true; } String player = args[0]; Player p = this.plugin.getServer().getPlayer(player); if(p != null){ player = p.getName(); } try{ double amount = Double.parseDouble(args[1]); int result = this.plugin.reduceMoney((Player) sender, amount); switch(result){ case EconomyAPI.RET_INVALID: case EconomyAPI.RET_CANCELLED: sender.sendMessage(this.plugin.getMessage("pay-failed", sender)); return true; case EconomyAPI.RET_NO_ACCOUNT: sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender)); return true; case EconomyAPI.RET_SUCCESS: this.plugin.addMoney(player, amount, true); sender.sendMessage(this.plugin.getMessage("pay-success", new String[]{Double.toString(amount), player}, sender)); if(p instanceof Player){ p.sendMessage(this.plugin.getMessage("money-paid", new String[]{sender.getName(), Double.toString(amount)}, sender)); } return true; } }catch(NumberFormatException e){ sender.sendMessage(this.plugin.getMessage("takemoney-must-be-number", sender)); } return true; }
Example 11
Source File: GiveMoneyCommand.java From EconomyAPI with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String label, String[] args) { if(!this.plugin.isEnabled()) return false; if(!sender.hasPermission("economyapi.command.givemoney")){ sender.sendMessage(TextFormat.RED + "You don't have permission to use this command."); return false; } if(args.length < 2){ sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage()); return true; } String player = args[0]; Player p = this.plugin.getServer().getPlayer(player); if(p != null){ player = p.getName(); } try{ double amount = Double.parseDouble(args[1]); if(amount < 0){ sender.sendMessage(this.plugin.getMessage("givemoney-invalid-number", sender)); return true; } int result = this.plugin.addMoney(player, amount); switch(result){ case EconomyAPI.RET_INVALID: sender.sendMessage(this.plugin.getMessage("reached-max", new String[]{Double.toString(amount)}, sender)); return true; case EconomyAPI.RET_NO_ACCOUNT: sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender)); return true; case EconomyAPI.RET_SUCCESS: sender.sendMessage(this.plugin.getMessage("givemoney-gave-money", new String[]{Double.toString(amount), player}, sender)); if(p instanceof Player){ p.sendMessage(this.plugin.getMessage("givemoney-money-given", new String[]{Double.toString(amount)}, sender)); } return true; } }catch(NumberFormatException e){ sender.sendMessage(this.plugin.getMessage("givemoney-must-be-number", sender)); } return true; }
Example 12
Source File: PayCommand.java From EconomyAPI with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String label, String[] args){ if(!this.plugin.isEnabled()) return false; if(!sender.hasPermission("economyapi.command.pay")){ sender.sendMessage(TextFormat.RED + "You don't have permission to use this command."); return false; } if(!(sender instanceof Player)){ sender.sendMessage(TextFormat.RED + "Please use this command in-game."); return true; } if(args.length < 2){ sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage()); return true; } String player = args[0]; Player p = this.plugin.getServer().getPlayer(player); if(p != null){ player = p.getName(); } try{ double amount = Double.parseDouble(args[1]); int result = this.plugin.reduceMoney((Player) sender, amount); switch(result){ case EconomyAPI.RET_INVALID: case EconomyAPI.RET_CANCELLED: sender.sendMessage(this.plugin.getMessage("pay-failed", sender)); return true; case EconomyAPI.RET_NO_ACCOUNT: sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender)); return true; case EconomyAPI.RET_SUCCESS: this.plugin.addMoney(player, amount, true); sender.sendMessage(this.plugin.getMessage("pay-success", new String[]{Double.toString(amount), player}, sender)); if(p instanceof Player){ p.sendMessage(this.plugin.getMessage("money-paid", new String[]{sender.getName(), Double.toString(amount)}, sender)); } return true; } }catch(NumberFormatException e){ sender.sendMessage(this.plugin.getMessage("takemoney-must-be-number", sender)); } return true; }
Example 13
Source File: TPAcceptCommand.java From EssentialsNK with GNU General Public License v3.0 | 4 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length > 1) { this.sendUsage(sender); return false; } Player to = (Player) sender; if (api.getLatestTPRequestTo(to) == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.noRequest")); return false; } TPRequest request; Player from; if (args.length == 0) { if ((request = api.getLatestTPRequestTo(to)) == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.unavailable")); return false; } from = request.getFrom(); } else { from = api.getServer().getPlayer(args[0]); if (from == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0])); return false; } if ((request = api.getTPRequestBetween(from, to)) != null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.noRequestFrom", from.getDisplayName())); return false; } } from.sendMessage(Language.translate("commands.tpaccept.accepted", to.getDisplayName())); sender.sendMessage(Language.translate("commands.generic.teleporting")); if (request.isTo()) { from.teleport(to); } else { to.teleport(from); } api.removeTPRequestBetween(from, to); return true; }
Example 14
Source File: SetMoneyCommand.java From EconomyAPI with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String label, String[] args) { if(!this.plugin.isEnabled()) return false; if(!sender.hasPermission("economyapi.command.setmoney")){ sender.sendMessage(TextFormat.RED + "You don't have permission to use this command."); return false; } if(args.length < 2){ sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage()); return true; } String player = args[0]; Player p = this.plugin.getServer().getPlayer(player); if(p != null){ player = p.getName(); } try{ double amount = Double.parseDouble(args[1]); if(amount < 0){ sender.sendMessage(this.plugin.getMessage("setmoney-invalid-number", sender)); return true; } int result = this.plugin.setMoney(player, amount); switch(result){ case EconomyAPI.RET_NO_ACCOUNT: sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender)); return true; case EconomyAPI.RET_CANCELLED: sender.sendMessage(this.plugin.getMessage("setmoney-failed", new String[]{player}, sender)); return true; case EconomyAPI.RET_INVALID: sender.sendMessage(this.plugin.getMessage("reached-max", new String[]{Double.toString(amount)}, sender)); return true; case EconomyAPI.RET_SUCCESS: sender.sendMessage(this.plugin.getMessage("setmoney-setmoney", new String[]{player, Double.toString(amount)}, sender)); if(p instanceof Player){ p.sendMessage(this.plugin.getMessage("setmoney-set", new String[]{Double.toString(amount)}, sender)); } return true; } }catch(NumberFormatException e){ sender.sendMessage(this.plugin.getMessage("setmoney-invalid-number", sender)); } return true; }
Example 15
Source File: BlockBed.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onActivate(Item item, Player player) { int time = this.getLevel().getTime() % Level.TIME_FULL; boolean isNight = (time >= Level.TIME_NIGHT && time < Level.TIME_SUNRISE); if (player != null && !isNight) { player.sendMessage(new TranslationContainer("tile.bed.noSleep")); return true; } Block blockNorth = this.north(); Block blockSouth = this.south(); Block blockEast = this.east(); Block blockWest = this.west(); Block b; if ((this.getDamage() & 0x08) == 0x08) { b = this; } else { if (blockNorth.getId() == this.getId() && (blockNorth.getDamage() & 0x08) == 0x08) { b = blockNorth; } else if (blockSouth.getId() == this.getId() && (blockSouth.getDamage() & 0x08) == 0x08) { b = blockSouth; } else if (blockEast.getId() == this.getId() && (blockEast.getDamage() & 0x08) == 0x08) { b = blockEast; } else if (blockWest.getId() == this.getId() && (blockWest.getDamage() & 0x08) == 0x08) { b = blockWest; } else { if (player != null) { player.sendMessage(new TranslationContainer("tile.bed.notValid")); } return true; } } if (player != null && !player.sleepOn(b)) { player.sendMessage(new TranslationContainer("tile.bed.occupied")); } return true; }
Example 16
Source File: TakeMoneyCommand.java From EconomyAPI with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String label, String[] args) { if(!this.plugin.isEnabled()) return false; if(!sender.hasPermission("economyapi.command.takemoney")){ sender.sendMessage(TextFormat.RED + "You don't have permission to use this command."); return false; } if(args.length < 2){ sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage()); return true; } String player = args[0]; Player p = this.plugin.getServer().getPlayer(player); if(p != null){ player = p.getName(); } try{ double amount = Double.parseDouble(args[1]); if(amount < 0){ sender.sendMessage(this.plugin.getMessage("takemoney-invalid-number", sender)); return true; } int result = this.plugin.reduceMoney(player, amount); switch(result){ case EconomyAPI.RET_INVALID: sender.sendMessage(this.plugin.getMessage("takemoney-player-lack-of-money", new String[]{player, Double.toString(amount), Double.toString(this.plugin.myMoney(player))}, sender)); return true; case EconomyAPI.RET_NO_ACCOUNT: sender.sendMessage(this.plugin.getMessage("player-never-connected", new String[]{player}, sender)); return true; case EconomyAPI.RET_CANCELLED: sender.sendMessage(this.plugin.getMessage("takemoney-failed", new String[]{player}, sender)); return true; case EconomyAPI.RET_SUCCESS: sender.sendMessage(this.plugin.getMessage("takemoney-took-money", new String[]{player, Double.toString(amount)}, sender)); if(p instanceof Player){ p.sendMessage(this.plugin.getMessage("takemoney-money-taken", new String[]{Double.toString(amount)}, sender)); } return true; } }catch(NumberFormatException e){ sender.sendMessage(this.plugin.getMessage("takemoney-must-be-number", sender)); } return true; }
Example 17
Source File: TPDenyCommand.java From EssentialsNK with GNU General Public License v3.0 | 4 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length > 1) { this.sendUsage(sender); return false; } Player to = (Player) sender; if (api.getLatestTPRequestTo(to) == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.noRequest")); return false; } TPRequest request; Player from; switch (args.length) { case 0: if ((request = api.getLatestTPRequestTo(to)) == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.unavailable")); return false; } from = request.getFrom(); break; case 1: from = api.getServer().getPlayer(args[0]); if (from == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0])); return false; } if ((request = api.getTPRequestBetween(from, to)) != null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.noRequestFrom", from.getDisplayName())); return false; } break; default: return false; } from.sendMessage(Language.translate("commands.tpdeny.denied", to.getDisplayName())); sender.sendMessage(Language.translate("commands.tpdeny.success", to.getDisplayName())); api.removeTPRequestBetween(from, to); return true; }
Example 18
Source File: MuteCommand.java From EssentialsNK with GNU General Public License v3.0 | 4 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (args.length < 1) { this.sendUsage(sender); return false; } Player player = api.getServer().getPlayer(args[0]); if (player == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0])); return false; } if (sender == player) { sender.sendMessage(TextFormat.RED + Language.translate("commands.mute.self")); return false; } if (args.length > 1) { Duration duration; try { /* /mute lmlstarqaq 0 0 1 */ if (args.length == 5 && isPositiveInteger(args[1]) && isPositiveInteger(args[2]) && isPositiveInteger(args[3]) && isPositiveInteger(args[4])) duration = Duration.ZERO .plusDays(Integer.parseInt(args[1])) .plusHours(Integer.parseInt(args[2])) .plusMinutes(Integer.parseInt(args[3])) .plusSeconds(Integer.parseInt(args[4])); else { String arg = String.join(" ", Arrays.copyOfRange(args, 1, args.length)).trim(); duration = LMLDurationParser.parse(arg); } } catch (Exception e) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.number.invalid")); return false; } if (duration == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.time.invalidtext")); return false; } if (duration.isZero()) { sender.sendMessage(TextFormat.RED + Language.translate("commands.mute.zero")); return false; } String message = api.getDurationString(duration); if (!api.mute(player, duration)) { sender.sendMessage(TextFormat.RED + Language.translate("commands.mute.range")); return false; } sender.sendMessage(Language.translate("commands.mute.success", player.getDisplayName(), message)); player.sendMessage(Language.translate("commands.mute.other", message)); } else { // args.length == 1 api.unmute(player); sender.sendMessage(Language.translate("commands.mute.unmute.success", player.getDisplayName())); player.sendMessage(Language.translate("commands.mute.unmute.other")); } return true; }
Example 19
Source File: BlockBed.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean onActivate(Item item, Player player) { if (this.getLevel().getDimension() != Level.DIMENSION_OVERWORLD) { BedExplosionEvent event = new BedExplosionEvent(player, this, 4); Server.getInstance().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } Explosion explosion = new Explosion(this, event.getForce(), this); explosion.explodeA(); return false; } int time = this.getLevel().getTime() % Level.TIME_FULL; boolean isNight = (time >= Level.TIME_NIGHT && time < Level.TIME_SUNRISE); if (player != null && !isNight) { player.sendMessage(TextFormat.GRAY + "You can only sleep at night"); return true; } Block blockNorth = this.north(); Block blockSouth = this.south(); Block blockEast = this.east(); Block blockWest = this.west(); Block b; if ((this.meta & 0x08) == 0x08) { b = this; } else { if (blockNorth.getId() == this.getId() && (blockNorth.meta & 0x08) == 0x08) { b = blockNorth; } else if (blockSouth.getId() == this.getId() && (blockSouth.meta & 0x08) == 0x08) { b = blockSouth; } else if (blockEast.getId() == this.getId() && (blockEast.meta & 0x08) == 0x08) { b = blockEast; } else if (blockWest.getId() == this.getId() && (blockWest.meta & 0x08) == 0x08) { b = blockWest; } else { if (player != null) { player.sendMessage(TextFormat.GRAY + "This bed is incomplete"); } return true; } } if (player != null && !player.sleepOn(b)) { player.sendMessage(TextFormat.GRAY + "This bed is occupied"); } return true; }
Example 20
Source File: BlockBed.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onActivate(Item item, Player player) { int time = this.getLevel().getTime() % Level.TIME_FULL; boolean isNight = (time >= Level.TIME_NIGHT && time < Level.TIME_SUNRISE); if (player != null && !isNight) { player.sendMessage(new TranslationContainer("tile.bed.noSleep")); return true; } Block blockNorth = this.north(); Block blockSouth = this.south(); Block blockEast = this.east(); Block blockWest = this.west(); Block b; if ((this.getDamage() & 0x08) == 0x08) { b = this; } else { if (blockNorth.getId() == this.getId() && (blockNorth.getDamage() & 0x08) == 0x08) { b = blockNorth; } else if (blockSouth.getId() == this.getId() && (blockSouth.getDamage() & 0x08) == 0x08) { b = blockSouth; } else if (blockEast.getId() == this.getId() && (blockEast.getDamage() & 0x08) == 0x08) { b = blockEast; } else if (blockWest.getId() == this.getId() && (blockWest.getDamage() & 0x08) == 0x08) { b = blockWest; } else { if (player != null) { player.sendMessage(new TranslationContainer("tile.bed.notValid")); } return true; } } if (player != null && !player.sleepOn(b)) { player.sendMessage(new TranslationContainer("tile.bed.occupied")); } return true; }