本文整理匯總了Java中org.bukkit.command.CommandSender類的典型用法代碼示例。如果您正苦於以下問題:Java CommandSender類的具體用法?Java CommandSender怎麽用?Java CommandSender使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CommandSender類屬於org.bukkit.command包,在下文中一共展示了CommandSender類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onTabComplete
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
public List<String> onTabComplete(CommandSender sender, String[] args) {
if (args.length == 0) {
return new ArrayList<>(this.commandArguments.keySet());
}
else {
if (this.commandArguments.containsKey(args[0].toLowerCase())) {
return this.commandArguments.get(args[0].toLowerCase()).onTabComplete(sender, args);
}
else {
List<String> completions = new ArrayList<>();
for (String key : this.commandArguments.keySet()) {
if (key.toLowerCase().startsWith(args[0].toLowerCase())) {
completions.add(key);
}
}
return completions;
}
}
}
示例2: onCommand
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is only executable by players.");
return true;
}
Player player = (Player) sender;
LogoutTimer logoutTimer = plugin.getTimerManager().getLogoutTimer();
if (!logoutTimer.setCooldown(player, player.getUniqueId())) {
sender.sendMessage(ChatColor.YELLOW + "Your " + logoutTimer.getDisplayName() + ChatColor.YELLOW + " timer is already active.");
return true;
}
sender.sendMessage(ChatColor.YELLOW + "Your " + logoutTimer.getDisplayName() + ChatColor.YELLOW + " timer has started.");
return true;
}
示例3: 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: " + getUsage(label));
return true;
}
long duration = JavaUtils.parse(args[1]);
if (duration == -1L) {
sender.sendMessage(ChatColor.RED + "Invalid duration, use the correct format: 10m 1s");
return true;
}
SettingsYML.DEFAULT_DEATHBAN_DURATION = duration;
Command.broadcastCommandMessage(sender, ChatColor.RED + "Base death-ban time set to " + DurationFormatUtils.formatDurationWords(duration, true, true) + " (not including multipliers, etc).");
return true;
}
示例4: onTabComplete
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length != 2 || !(sender instanceof Player)) {
return Collections.emptyList();
}
Player player = (Player) sender;
PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player);
if (playerFaction == null) {
return Collections.emptyList();
}
List<String> results = new ArrayList<>();
for (Player target : Bukkit.getOnlinePlayers()) {
if (!target.equals(player) && player.canSee(target) && !results.contains(target.getName())) {
Faction targetFaction = plugin.getFactionManager().getPlayerFaction(target);
if (targetFaction != null && playerFaction != targetFaction) {
if (playerFaction.getRequestedRelations().get(targetFaction.getUniqueID()) != RELATION && playerFaction.getRelations().get(targetFaction.getUniqueID()) != RELATION) {
results.add(targetFaction.getName());
}
}
}
}
return results;
}
示例5: processCmd
import org.bukkit.command.CommandSender; //導入依賴的package包/類
public boolean processCmd(CommandSender s, String[] arg) {
sender = s;
args = arg;
if (forcePlayer) {
if (!(s instanceof Player)) {
sender.sendMessage(new Messaging.MessageFormatter().format("error.must-be-player"));
return false;
} else {
player = (Player) s;
}
}
if (!Util.hp(sender, cmdName))
sender.sendMessage(new Messaging.MessageFormatter().format("error.cmd-no-perm"));
else if (argLength > arg.length)
s.sendMessage(ChatColor.DARK_RED + "Wrong usage: " + ChatColor.GRAY +"/swr " + helper());
else return run();
return true;
}
示例6: run
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@WithCommand
public void run(CommandSender sender, @WithName("plugin") @WithOptional Plugin plugin) {
Collection<HotbarId> hotbars;
if (plugin != null) {
Registry<HotbarId> reg = hotbars().get(plugin);
hotbars = reg.get();
} else
hotbars = hotbars().get();
StringJoiner str = new StringJoiner(GRAY + ", ");
for (HotbarId hotbar : hotbars)
str.add(AQUA + hotbar.getGlobalId());
if (hotbars.size() > 0)
sender.sendMessage(GOLD + "Showing " + hotbars.size() + " hotbars: " + str);
else
sender.sendMessage(RED + "No hotbar found.");
}
示例7: start
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Command(
aliases = {"on", "start"},
desc = "Start logging packets",
min = 0,
max = 1
)
public void start(CommandContext args, CommandSender sender) throws CommandException {
if(sender instanceof Player || args.argsLength() >= 1) {
final Player player = (Player) getCommandSenderOrSelf(args, sender, 0);
if(PacketTracer.start(player, Bukkit.getLogger())) {
sender.sendMessage("Started packet trace for " + player.getName(sender));
}
} else if(traceAll.compareAndSet(false, true)) {
onlinePlayers.all().forEach(player -> PacketTracer.start(player, Bukkit.getLogger()));
sender.sendMessage("Started global packet trace");
}
}
示例8: onCommand
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
Plugin plugin = getServer().getPluginManager().getPlugin("MeerChat");
Player senderPlayer = getServer().getPlayer(sender.getName());
// If the command was completed by the user.
if (senderPlayer != null) {
senderPlayer.sendMessage("§o[MeerChat is being reloaded - " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "]§o");
restartPlugin(plugin);
senderPlayer.sendMessage("§o[MeerChat has been reloaded - " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "]§o");
}
// If the command was completed by the console.
else {
Bukkit.broadcastMessage("[Server] §o[MeerChat is being reloaded - " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "]§o");
restartPlugin(plugin);
Bukkit.broadcastMessage("[Server] §o[MeerChat has been reloaded - " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "]§o");
}
return true;
}
示例9: setInputs
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
public void setInputs(CommandSender initiator, String[] args) {
if (this.shouldLearn) {
initiator
.sendMessage("Stop the learning before testing. use /nn stoplearning");
return;
}
if (args.length > 1) {
boolean test = false;
try {
test = Boolean.parseBoolean(args[1]);
} catch (Exception e) {
}
binary.changeValueAt(0, 0, test);
} else {
initiator.sendMessage("Provide one value (True or false)");
}
}
示例10: onCommand
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player p = (Player) sender;
if (args.length != 1) {
Chat.player(sender, "&4[SG] &cPlease include the world name");
return true;
}
String name = args[0];
World w = Bukkit.getWorld(name);
if (w == null)
Bukkit.createWorld(new WorldCreator(name));
w = Bukkit.getWorld(name);
p.teleport(w.getSpawnLocation());
Chat.player(sender, "&2[SG] &aTeleported to " + w.getName() + " spawn point");
return true;
}
示例11: onTabComplete
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length != 2 || !(sender instanceof Player)) {
return Collections.emptyList();
} else if (args[1].isEmpty()) {
return null;
} else {
Player player = (Player) sender;
List<String> results = new ArrayList<>(plugin.getFactionManager().getFactionNameMap().keySet());
for (Player target : Bukkit.getOnlinePlayers()) {
if (player.canSee(target) && !results.contains(target.getName())) {
results.add(target.getName());
}
}
return results;
}
}
示例12: PlayerOrderCache
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Inject PlayerOrderCache(IdentityProvider identityProvider, BukkitUserStore userStore, MinecraftService minecraftService) {
prioritiesByPlayer = CacheUtils.newWeakKeyCache(player -> userStore
.getUser(player)
.minecraft_flair()
.stream()
.filter(flair -> minecraftService.getLocalServer().realms().contains(flair.realm))
.map(flair -> flair.priority)
.min(Integer::compare)
.orElse(Integer.MAX_VALUE)
);
comparatorsByViewer = CacheUtils.newWeakKeyCache(strongViewer -> {
final WeakReference<CommandSender> weakViewer = new WeakReference<>(strongViewer);
return (a, b) -> {
// Do not reference strongViewer in here
final CommandSender viewer = weakViewer.get();
if(viewer == null) return 0;
final Identity aIdentity = identityProvider.currentIdentity(a);
final Identity bIdentity = identityProvider.currentIdentity(b);
return ComparisonChain.start()
.compareTrueFirst(a == viewer, b == viewer)
.compareTrueFirst(aIdentity.isFriend(viewer), bIdentity.isFriend(viewer))
.compare(priority(a, aIdentity, viewer), priority(b, bIdentity, viewer))
.compare(aIdentity.getName(viewer), bIdentity.getName(viewer), String::compareToIgnoreCase)
.result();
};
});
}
示例13: onCommand
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
protected void onCommand(CommandSender sender, String[] args) {
if (this.toggle.shouldConfirm() && getToggle((Player) sender, this.toggle)) {
sender.sendMessage(ChatColor.GRAY + "Are you sure you want to " + ChatColor.RED + "disable"
+ ChatColor.GRAY + " the " + this.toggle.getDescription() + "?");
Callbacks.promptConfirm((Player) sender, () -> KCPlayer.getWrapper(sender).toggle(this.toggle));
return;
}
KCPlayer.getWrapper(sender).toggle(this.toggle);
}
示例14: onCommand
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
return true;
}
Player player = (Player) sender;
Location location = player.getLocation();
if (label.equalsIgnoreCase("tphere")) {
if (!(args.length == 0)) {
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Please specify the player you want to teleport to or use /teleport help for more info.");
TeleportHereMenu.newInventory(sender);
return true;
}
if (!sender.hasPermission("core.tp")) {
player.sendMessage(ChatColor.RED + "Sorry, you need core.tp permission to execute /tphere.");
return true;
}
if (args[0].equals(player.getName())) {
player.sendMessage(ChatColor.RED + "Lol, you cannot teleport to yourself dummy.");
return true;
}
Player target1 = Bukkit.getServer().getPlayer(args[1]);
if (target1 == null) {
player.sendMessage(ChatColor.RED + "Can't find user specified.");
return true;
}
target1.teleport(player);
player.sendMessage(ChatColor.YELLOW + "You've teleported " + ChatColor.GREEN + target1.getDisplayName() + ChatColor.YELLOW + " to you!");
player.playSound(location, Sound.ENTITY_ENDERMEN_TELEPORT, 100, 1);
player.playEffect(location, Effect.ENDER_SIGNAL, 1);
target1.playEffect(location, Effect.ENDER_SIGNAL, 1);
return true;
}
}
return false;
}
示例15: onCommand
import org.bukkit.command.CommandSender; //導入依賴的package包/類
@Override
protected void onCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;
String x, y, z, yaw, pitch, world;
x = args[0];
y = args[1];
z = args[2];
yaw = args.length > 3 ? args[3] : Float.toString(player.getLocation().getYaw());
pitch = args.length > 4 ? args[4] : Float.toString(player.getLocation().getPitch());
world = args.length > 5 ? args[5] : player.getWorld().getName();
World worldParsed = Bukkit.getWorld(world);
if (worldParsed == null) {
sender.sendMessage(ChatColor.RED + "Invalid world: " + world);
showUsage(player);
return;
}
try {
player.teleport(new Location(
worldParsed,
Double.parseDouble(x),
Double.parseDouble(y),
Double.parseDouble(z),
Float.parseFloat(yaw),
Float.parseFloat(pitch)
));
player.sendMessage(ChatColor.GREEN + "Teleported to location.");
} catch (NumberFormatException e) {
showUsage(player);
}
}