本文整理匯總了Java中org.bukkit.command.CommandSender.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java CommandSender.equals方法的具體用法?Java CommandSender.equals怎麽用?Java CommandSender.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.command.CommandSender
的用法示例。
在下文中一共展示了CommandSender.equals方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCommand
import org.bukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <playerName> <amount>");
return true;
}
Integer amount = JavaUtils.tryParseInt(args[1]);
if (amount == null) {
sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a valid number.");
return true;
}
if (amount <= 0) {
sender.sendMessage(ChatColor.RED + "You must send money in positive quantities.");
return true;
}
// Calculate the senders balance here.
Player senderPlayer = sender instanceof Player ? (Player) sender : null;
int senderBalance = senderPlayer != null ? plugin.getEconomyManager().getBalance(senderPlayer.getUniqueId()) : 1024;
if (senderBalance < amount) {
sender.sendMessage(ChatColor.RED + "You tried to pay " + EconomyManager.ECONOMY_SYMBOL + amount + ", but you only have " + EconomyManager.ECONOMY_SYMBOL + senderBalance
+ " in your bank account.");
return true;
}
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); // TODO: breaking
if (sender.equals(target)) {
sender.sendMessage(ChatColor.RED + "You cannot send money to yourself.");
return true;
}
Player targetPlayer = target.getPlayer();
if (!target.hasPlayedBefore() && targetPlayer == null) {
sender.sendMessage(ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[0] + ChatColor.GOLD + "' not found.");
return true;
}
if (targetPlayer == null)
return false; // won't happen, IntelliJ compiler won't ignore
// Make the money transactions.
if (senderPlayer != null)
plugin.getEconomyManager().subtractBalance(senderPlayer.getUniqueId(), amount);
plugin.getEconomyManager().addBalance(targetPlayer.getUniqueId(), amount);
targetPlayer.sendMessage(ChatColor.YELLOW + sender.getName() + " has sent you " + ChatColor.GOLD + EconomyManager.ECONOMY_SYMBOL + amount + ChatColor.YELLOW + '.');
sender.sendMessage(ChatColor.YELLOW + "You have sent " + ChatColor.GOLD + EconomyManager.ECONOMY_SYMBOL + amount + ChatColor.YELLOW + " to " + target.getName() + '.');
return true;
}
示例2: sendMessageToViewer
import org.bukkit.command.CommandSender; //導入方法依賴的package包/類
public void sendMessageToViewer(Player sender, CommandSender viewer, String sanitizedMessage, ChannelMessageEvent event, boolean offensive, int violationsAttached, PlayerViolationManager violationManager, boolean forceNoSend) {
boolean senderPresent = sender != null;
String senderName = senderPresent ? sender.getName(viewer) : "Console";
String senderDisplayName = senderPresent ? sender.getDisplayName(viewer) : ChatColor.GOLD + "*" + ChatColor.AQUA + "Console";
String message = MessageFormat.format(
this.getFormat(),
senderName,
senderDisplayName,
event.getMessage(),
sanitizedMessage
);
boolean allowSend = true;
if (viewer instanceof Player) {
switch (PlayerSettings.getManager((Player) viewer).getValue(Settings.FILTER_SETTING, FilterOptions.class)) {
case NONE:
allowSend = true;
break;
case OFFENSIVE:
allowSend = !offensive;
break;
case ALL:
allowSend = violationsAttached == 0;
break;
}
}
boolean isSender = viewer.equals(event.getSender());
StringBuilder builder = new StringBuilder();
if (isSender) {
if (offensive || violationsAttached != 0) {
if (violationManager.getScore() * this.partial < this.scoreThreshold) {
builder.append(ChatColor.GOLD);
} else {
builder.append(ChatColor.RED);
}
builder.append(ChatColor.BOLD).append(WARNING_SYMBOL).append(ChatColor.RESET);
}
builder.append(this.underlineViolations(violationManager, message, event));
viewer.sendMessage(builder.toString());
} else if (allowSend && !forceNoSend) {
this.sendMessageToViewer(sender, viewer, sanitizedMessage, event);
}
}